// Hide instruction text for password field
function txt2pwd(obj, pwd){
	obj.style.visibility = "hidden";
	document.getElementById(pwd).focus();
}

// Display instruction text for password field
function pwd2txt(obj, txt){
	if(obj.value.length==0){
		document.getElementById(txt).style.visibility = "visible";
	}
}

// Display instruction text [str] if field is blank
// Clear instruction text if field is clicked
function resetField(obj,str){
	if(obj.value.length==0){
		obj.value=str;
		return;
	}
	if(obj.value==str){
		obj.value="";
	}
}

// Tab switcher
// container = ID of tab container, must be used if more than one tab module is used on page (optional usage if only one tab module is displayed on a page )
// tab = ID of tab (mandatory)
function showTab(tab, container, caso){
	if(typeof(container)=='undefined') {
		container='';
	}
	var i=0;
	do{
		document.getElementById(container+"tab"+i).className = (caso)? "tab":"tabAzul";
		document.getElementById(container+"tab"+i+"content").style.display="none";
		i++;
	}
	while(document.getElementById(container+"tab"+i));
	document.getElementById(container+tab+"content").style.display="block";
	document.getElementById(container+tab).className = (caso)? "activeTab":"activeTabAzul";
}


// Flash detection for Call-to-action teaser
function hasFlash(){
  var ver=6;
	if(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.indexOf("Windows")>-1) {
	  document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & '+ver+'))) \n</script\> \n');
		if(window.hasFlash!=null)
		  return window.hasFlash
	}
	if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
	  var desc=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;
		return parseInt(desc.charAt(desc.indexOf(".")-1))>=ver;
	}
	return false;
} // hasFlash


// replace the HTML Call-to-action box by a flash movie using the Vodafone corporate font
function replaceCTABox(){
	if (hasFlash()) {
		//get data from html-box
		var cta = document.getElementById('ctaLayer');
		var ctaMod = cta.parentNode;
		if (ctaMod!=null && cta!=null) {
			var h1,s,a,l,u,t; h1=s=a=l=u=t='';
			if (cta.getElementsByTagName("h1")[0]!=null) h1= encodeURI(cta.getElementsByTagName("h1")[0].innerHTML);
			if (cta.getElementsByTagName("p")[0]!=null) s = encodeURI(cta.getElementsByTagName("p")[0].innerHTML);
			var w = cta.offsetWidth;
        var h = cta.offsetHeight;
			var flashVars = "head="+h1+"&sub="+s+"&boxw="+w+"&boxh="+h;
			var a = cta.getElementsByTagName("a")[0];
			if (a!=null) {
		    	var l = encodeURI(a.innerHTML);
		    	var u = encodeURI(a["href"]);
		    	var t = a["target"];
          flashVars+="&link="+l+"&url="+u+"&target="+t;
			}
			// hide html-box
			cta.className="ctaLayer hide";
			// and place flash cta box
			var flashURL = "../swf/calltoactionbox.swf?"+flashVars;
			var ctaObjStr = "<object class='ctaLayer' type='application/x-shockwave-flash' data='"+flashURL+"' width='"+w+"' height='"+h+"' id='calltoactionbox'>"
			                +   "<param name='allowScriptAccess' value='sameDomain' />"
									    +   "<param name='movie' value='"+flashURL+"' />"
									    +   "<param name='quality' value='high' />"
									    + "</object>";
		  document.write(ctaObjStr);
		}
	}
} // replaceCTABox


// fold and unfold option sections on shopping cart page
function scFold(optId) {
  var optHeader = document.getElementById(optId);
	if (optHeader!=null) {
		var pattern = new RegExp("(^|\\s)"+optId+"(\\s|$)");
		var trList = document.getElementsByTagName('tr');
	  if (optHeader.className=="scOptShow") {
		  // hide options
			for (i=0; i<trList.length; i++) {
			  if (pattern.test(trList[i].className)) {
				  trList[i].className=optId+" hidden";
				}
			}
      optHeader.className="scOptHide";			
		} else {
		  // show options
			for (i=0; i<trList.length; i++) {

			  if (pattern.test(trList[i].className)) {
				  trList[i].className=optId;
				}
			}			
      optHeader.className="scOptShow";			
		}
	}
} // scFold


function ShowDivHiddeDiv(showDiv, errorDiv)
{
	showDiv.style.visibility="visible";
	showDiv.style.display="block";
	errorDiv.style.visibility="hidden";
	errorDiv.style.display="none";	
}

/*function changeD(obj1,obj2)
{
    if (obj1.style.display=="block"){
		obj1.style.display="none";
		obj2.src="/vodafone/gui08/images/icons/expPlus.gif"
	}else{
		obj1.style.display="block";
		obj2.src="/vodafone/gui08/images/icons/expMinus.gif"
    }
}*/
function changeD(obj1,obj2,caso)
{

	if (caso == null) 
	{
		caso = '';
	}
	if (obj1.style.display=="block"){
		obj1.style.display="none";
		obj2.src="/vodafone/gui08/images/icons/expPlus" + caso + ".gif"
	}else{
		obj1.style.display="block";
		obj2.src="/vodafone/gui08/images/icons/expMinus" + caso + ".gif"
	}
}

/* #### INICIO CARROCEL ####### */
if(!window.VF) {
  VF = new Object();
}

VF.heightH1 = 0;

VF.openLogin = "loginMV";

VF.openTab = "tab3";
VF.hideTab = "";
VF.slidingTab = 0;

VF.positionShowcase = 0;
VF.slidingShowcase = 0;
VF.autoSlideDirectionShowcase = 0;

VF.slideTabTimer = "";
VF.slideShowcaseTimer = "";
VF.autoShowcaseTimer = "";


function moveShowcase(varID, varFunction) {
  if(varFunction == "left" &&  VF.positionShowcase > -190*2 && VF.slidingShowcase == 0) {//andar para a esquerda
    slideShowcase(varID, 193, 0);
  }
  if(varFunction == "right" &&  VF.positionShowcase != 0 && VF.slidingShowcase == 0) {
    slideShowcase(varID, 193, 1);
  }
  clearTimeout(VF.autoShowcaseTimer);
}

function stopAutoSlideShowcase() {
  clearTimeout(VF.autoShowcaseTimer);
}

function startAutoSlideShowcase() {
  VF.autoShowcaseTimer = window.setTimeout("autoSlideShowcase('ulShowcaseItems')", 3000);
}

function slideShowcase(varID, varWidth, varDirection, varLeftValue) {
  if(!varLeftValue && VF.positionShowcase == 0) {//andar para a esquerda
    varLeftValue = 0;
  }  
  if(!varLeftValue && VF.positionShowcase != 0) {//andar para a direita
    varLeftValue = VF.positionShowcase;
  }

  if(varLeftValue > (-varWidth/2)) {
    document.getElementById("aShowcaseControlRight").className = "hidden";
    document.getElementById("aShowcaseControlLeft").className = "visible";
    VF.autoSlideDirectionShowcase = 0;
  }

  if((varLeftValue < (-varWidth/2)) && (varLeftValue > -varWidth*2+20)) {
	//alert(varLeftValue);
    document.getElementById("aShowcaseControlRight").className = "visible";
    document.getElementById("aShowcaseControlLeft").className = "visible";
  }
  
  //if(varLeftValue < ((-varWidth*3) + (varWidth/3))) {
  if(varLeftValue <= (-varWidth*2+20)) {
    document.getElementById("aShowcaseControlRight").className = "visible";
    document.getElementById("aShowcaseControlLeft").className = "hidden";
    VF.autoSlideDirectionShowcase = 1;
  }

  VF.slidingShowcase = 1;
  
  //########### Accção de correr div #################
  //alert("teste=" + varLeftValue);
  if(document.all) {
  
    //document.getElementById(varID).style.left = ((varLeftValue * 140) / 1549) + "px";
    document.getElementById(varID).style.left = varLeftValue + "px";
    //alert(document.getElementById(varID).style.left);
  } else {
  
    //document.getElementById(varID).style.left = ((varLeftValue * 3) / 33) + "px";
    document.getElementById(varID).style.left = varLeftValue + "px";
  }
  
  //document.getElementById(varID).style.left = varLeftValue + "px";
 
  if(varDirection == "0") {
    varLeftValue -= 19;
    if(varLeftValue > (-varWidth + VF.positionShowcase)) {
    //alert(varWidth);
      VF.slideShowcaseTimer = window.setTimeout("slideShowcase('"+varID+"', "+varWidth+", "+varDirection+", "+varLeftValue+")", 1);  
    } else {
      if(document.all) {
		document.getElementById(varID).style.left = varLeftValue + 17 + "px";
        //document.getElementById(varID).style.left = (((-varWidth + VF.positionShowcase) * 140) / 1549) + "px";
      } else {
        //document.getElementById(varID).style.left = (((-varWidth + VF.positionShowcase) * 3) / 33) + "px";
        //document.getElementById(varID).style.left = -varWidth + VF.positionShowcase + "px";
        document.getElementById(varID).style.left = varLeftValue + 17 + "px";
      }
     
      VF.slidingShowcase = 0;
      VF.positionShowcase = -varWidth + VF.positionShowcase;
      clearTimeout(VF.slideShowcaseTimer);
      //alert(VF.positionShowcase);
    }
  } else {
    varLeftValue += 19;
    if(varLeftValue < (VF.positionShowcase + varWidth)) {
      slideShowcaseTimer = window.setTimeout("slideShowcase('"+varID+"', "+varWidth+", "+varDirection+", "+varLeftValue+")", 1);  
    } else {
    
      if(document.all) {
		document.getElementById(varID).style.left = varLeftValue -17 + "px";
		//document.getElementById(varID).style.left = VF.positionShowcase + varWidth+ "px";
        //document.getElementById(varID).style.left = (((VF.positionShowcase + varWidth) * 140) / 1549) + "px";
      } else {
		document.getElementById(varID).style.left = varLeftValue -17 + "px";
		//document.getElementById(varID).style.left = (((VF.positionShowcase + varWidth) * 3) / 33) + "px";
        //document.getElementById(varID).style.left = VF.positionShowcase + varWidth+ "px";
      }
      
      VF.slidingShowcase = 0;
      VF.positionShowcase = VF.positionShowcase + varWidth;
      //alert(VF.positionShowcase);
      clearTimeout(VF.slideShowcaseTimer);
    }
  }
}

function autoSlideShowcase(varID) {
  if(VF.positionShowcase == 0 && VF.autoSlideDirectionShowcase == 0 && VF.slidingShowcase == 0) {
    slideShowcase(varID, 193, VF.autoSlideDirectionShowcase);
    VF.autoSlideDirectionShowcase = 0;
    //alert("1");
  }
  if(VF.positionShowcase == -193 && VF.autoSlideDirectionShowcase == 0 && VF.slidingShowcase == 0) {
    slideShowcase(varID, 193, VF.autoSlideDirectionShowcase);
    VF.autoSlideDirectionShowcase = 1;
    //alert("2");
  }
  if(VF.positionShowcase == -193*2 && VF.autoSlideDirectionShowcase == 1 && VF.slidingShowcase == 0) {
    slideShowcase(varID, 193, VF.autoSlideDirectionShowcase);
    VF.autoSlideDirectionShowcase = 1;
    //alert("3");
  }
  if(VF.positionShowcase == -193 && VF.autoSlideDirectionShowcase == 1 && VF.slidingShowcase == 0) {
    slideShowcase(varID, 193, VF.autoSlideDirectionShowcase);
    VF.autoSlideDirectionShowcase = 0;
    //alert("4");
  }
  VF.autoShowcaseTimer = window.setTimeout("autoSlideShowcase('"+varID+"')", 6000);
}

/* #### FIM CARROCEL ####### */

/*##### INICIO DROP UP/DOWN #### */


function changeTab(varID) {
  VF.heightH1 = 24;
  if(varID == "tab3" && VF.openTab == "tab1" && VF.slidingTab == 0) {
    VF.openTab = varID;
    slideTab("tab3","tab1", 233, 0);
    return true;
  }
  if(varID == "tab2" && VF.openTab == "tab3" && VF.slidingTab == 0) {
    VF.openTab = varID;
    slideTab("tab2","tab3", 233, 0);
    return true;
  }
  if(varID == "tab1" && VF.openTab == "tab3" && VF.slidingTab == 0) {
    VF.openTab = varID;
    slideTab("tab1","tab3", 233, 0);
    return true;
  }
  if(varID == "tab1" && VF.openTab != "tab1" && VF.slidingTab == 0) {
    VF.openTab = varID;
    slideTab("tab1","tab2", 233, 0);
    return true;
  }
  if(varID == "tab2" && VF.openTab != "tab2" && VF.slidingTab == 0) {
    VF.openTab = varID;
    slideTab("tab2","tab1", 233, 0);
    return true;
  }
  if(varID == "tab3" && VF.openTab != "tab3" && VF.slidingTab == 0) {
    VF.openTab = varID;
    slideTab("tab3","tab2", 233, 0);
    return true;
  }
}
function slideTab(varOpenID, varCloseID, varHeight, varHeightValue) {
  if(!varHeightValue) {
    varHeightValue = VF.heightH1;
    //alert(VF.heightH1);
  }
  VF.slidingTab = 1;
  if(document.all) {
    document.getElementById(varOpenID).style.height = (varHeightValue) + "px";
    document.getElementById(varCloseID).style.height = (varHeight - varHeightValue + VF.heightH1) + "px";
    //alert("abrir=" + varOpenID + " fechar=" + varCloseID);
  } else {
    document.getElementById(varOpenID).style.height = (varHeightValue) + "px";
    document.getElementById(varCloseID).style.height = (varHeight - varHeightValue + VF.heightH1) + "px";
  }
  varHeightValue += 12;
  if(varHeightValue <= varHeight) {
    VF.slideTabTimer = window.setTimeout("slideTab('"+varOpenID+"', '"+varCloseID+"', "+varHeight+", "+varHeightValue+")", 4);  
  } else {
    if(document.all) {
    
    //TESTE de imagens
      document.getElementById("img_" + varOpenID).src = "/Vodafone/gui08/images/buttons/menos_" + varOpenID + ".gif";
      document.getElementById("img_" + varCloseID).src = "/Vodafone/gui08/images/buttons/mais_" + varCloseID + ".gif";
      
     // 
      document.getElementById(varOpenID).style.height = (varHeight) + "px";
      document.getElementById(varCloseID).style.height = 24 + "px";
      
    } else {
    
      document.getElementById(varOpenID).style.height = (varHeight) + "px";
      document.getElementById(varCloseID).style.height = 24 + "px";
      
      //TESTE de imagens
      document.getElementById("img_" + varOpenID).src = "/Vodafone/gui08/images/buttons/menos_" + varOpenID + ".gif";
      document.getElementById("img_" + varCloseID).src = "/Vodafone/gui08/images/buttons/mais_" + varCloseID + ".gif";
      
     // 
      
      //alert(document.getElementById(varCloseID).style.height);
    }
    //alert(varOpenID);
    /*
    document.getElementById(varOpenID).className="active";
    document.getElementById(varCloseID).className = "";
    if(VF.hideTab != "") {
      document.getElementById(varCloseID).style.height = "0px";
      document.getElementById(varCloseID).style.display = "none";
    }
    */
    VF.hideTab = "";
    VF.slidingTab = 0;
    VF.heightH1 = 24;
    clearTimeout(VF.slideTabTimer);
  }
}

/*##### FIM DROP UP/DOWN #### */