// Inclui no objecto String o método trim();
String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};

// 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=1;
	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


// FAQs SYSTEM
function changeD(obj1,obj2,caso)
{

	if (obj1.style.display=="block"){
		obj1.style.display="none";
		obj2.src="/gui08/images/icons/expPlus" + caso + ".gif"
		
	}else{
		obj1.style.display="block";
		obj2.src="/gui08/images/icons/expMinus" + caso + ".gif"
	}
}

/*///// INICIO ROLLOVER BOTOES APAGAR /////*/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*///// FIM ROLLOVER BOTOES APAGAR /////*/

/* ########### INICIO CARROCEL ######## */
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) {
    varLeftValue = 0;
  }  
  if(!varLeftValue && VF.positionShowcase != 0) {
    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)) {
    document.getElementById("aShowcaseControlRight").className = "visible";
    document.getElementById("aShowcaseControlLeft").className = "visible";
  }
  
  if(varLeftValue < ((-varWidth*2) + (varWidth/2))) {
    document.getElementById("aShowcaseControlRight").className = "visible";
    document.getElementById("aShowcaseControlLeft").className = "hidden";
    VF.autoSlideDirectionShowcase = 1;
  }

  VF.slidingShowcase = 1;
  if(document.all) {
    document.getElementById(varID).style.left = ((varLeftValue * 140) / 1549) + "em";
  } else {
    document.getElementById(varID).style.left = ((varLeftValue * 3) / 33) + "em";
  }
  if(varDirection == "0") {
    varLeftValue -= 16;
    if(varLeftValue >= (-varWidth + VF.positionShowcase)) {
      VF.slideShowcaseTimer = window.setTimeout("slideShowcase('"+varID+"', "+varWidth+", "+varDirection+", "+varLeftValue+")", 6);  
    } else {
      if(document.all) {
        document.getElementById(varID).style.left = (((-varWidth + VF.positionShowcase) * 140) / 1549) + "em";
      } else {
        document.getElementById(varID).style.left = (((-varWidth + VF.positionShowcase) * 3) / 33) + "em";
      }
      VF.slidingShowcase = 0;
      VF.positionShowcase = -varWidth + VF.positionShowcase;
      //alert(VF.positionShowcase);
      clearTimeout(VF.slideShowcaseTimer);
    }
  } else {
    varLeftValue += 16;
    if(varLeftValue <= (VF.positionShowcase + varWidth)) {
      slideShowcaseTimer = window.setTimeout("slideShowcase('"+varID+"', "+varWidth+", "+varDirection+", "+varLeftValue+")", 6);  
    } else {
      if(document.all) {
        document.getElementById(varID).style.left = (((VF.positionShowcase + varWidth) * 140) / 1549) + "em";
      } else {
        document.getElementById(varID).style.left = (((VF.positionShowcase + varWidth) * 3) / 33) + "em";
      }
      VF.slidingShowcase = 0;
      VF.positionShowcase = VF.positionShowcase + varWidth;
      //alert(VF.positionShowcase);
      clearTimeout(VF.slideShowcaseTimer);
    }
  }
}

/* ########### FIM CARROCEL ######## */