fontController.prototype.crank    = fontSizeAdjust;
fontController.prototype.init     = setStyle;
fontController.prototype.setStyle = setStyle;

function fontController() {
	/*ESTE ES EL TAMAŅO POR DEFECTO QUE NO TIENE CSS*/
	this.normalSize = 70;
	this.maxSize    = 115;
	this.minSize    = 59;
	this.sizeUnit   = '%';
	this.curVolume  = (Get_Cookie("fontVolume")) ? parseFloat(Get_Cookie("fontVolume")) : this.normalSize;
}

function fontSizeAdjust(sizeIncrement) {
	this.curVolume += sizeIncrement;
	if (sizeIncrement > 0) {this.curVolume = Math.min(this.curVolume, this.maxSize);
	} else {this.curVolume = Math.max(this.curVolume, this.minSize);}
	Set_Cookie("fontVolume", this.curVolume, 180, "/");
	this.setStyle();
}

function setStyle() {	
	document.getElementsByTagName('body')[0].style.fontSize = this.curVolume + this.sizeUnit;

}

// Object Constructor
var fontVolume = new fontController();

//This function fixes a bug in IE where inputs don't repaint correctly when dynamically
//changing the font size.
function ieTextboxFontSizeChangeBugFix() {
	var inputs = document.getElementsByTagName('input');
	for (x=0; x < inputs.length; x++) {
		if (inputs[x].type == 'text' && inputs[x].className != 'FIFdisplayBox') {
			inputs[x].onresize = ieTextboxFontSizeChangeBugFix2;
		}
	}
}
function ieTextboxFontSizeChangeBugFix2() {
	this.style.display = 'none';
	this.style.display = '';
}
if (window.attachEvent) {//trigger IE
	window.attachEvent("onload", ieTextboxFontSizeChangeBugFix);
}

//This function adds the font volume to the hidden form field
//so that it can be logged as a client side action event
//upon form submission
function setFontVolHiddenFld(fieldName)
{
		var DOM = document.getElementsByTagName("INPUT"); 
		for (i=0; i<DOM.length; i++) 
		{
			obj = DOM.item(i);	
			if (obj.name == fieldName)
			{
				//check if font volume exists...this is in case
				//the page does not include the font widget
				if (typeof(fontVolume) != 'undefined')
				{
					obj.value = fontVolume.curVolume;
					break;
				}		
			}	 
		}
		addFontSizeToQS();

	return false;
}


//These functions are required to add the font volume to the 
//query string of all links on the page so that this can be
//logged as a client side action event
function addFontSizeToQS()
{
	for (var i = 0; i < document.links.length; i++)
	{
		if (typeof document.links[i].linkOnClick == 'undefined' && 
				document.links[i].href.indexOf("#")==-1 &&
				document.links[i].href.indexOf("javascript:")!=0
			  )
		{
			document.links[i].linkOnClick=document.links[i].onclick;
			document.links[i].onclick = function(){addFontSize(this); return this.linkOnClick();}
		}
	}
}

function addFontSize(link)
{
	if (typeof(fontVolume) != 'undefined')
	{
    	setLinkQSParam(link, "currFontVol", fontVolume.curVolume);
	}
}

function setLinkQSParam(link, param, newParamVal){
	//break the URL...the first index will be the URL
	//starting from index one, the value will alternate between
	//param name and param value
	//	urlArray[0]=http://www.hewitt.com
	//	urlArary[1]=paramOneName
	//	urlArary[2]=paramOneValue
	//	urlArary[3]=paramTwoName
	//	urlArary[4]=paramTwoValue
	var urlArray=link.href.toString().split(/\?|&|=/);
	
	var newURL=urlArray[0]+"?";
	var foundParam=false;
	for( var i=1; i<urlArray.length; i+=2 ){
		if( i!=1 ){
			newURL+="&";
		}
		
		//param name
		newURL+=urlArray[i];
		if(urlArray[i].toLowerCase()==param.toLowerCase()){
			newURL+="="+newParamVal;
			foundParam=true;
		}else{
			newURL+="="+urlArray[i+1];
		}
	}
	
	if(!foundParam){
		if(urlArray.length>1){
			newURL+="&";
		}
		newURL+=param+"="+newParamVal;
	}
	
	link.href=newURL;
}

