// ****************************
// * Correct PNG Transparency *
// ****************************
function correctPNG()
{
	if(navigator.userAgent.indexOf("MSIE")!= -1)
	{
		for(var i=0; i<document.images.length; i++)
	    {
			var img = document.images[i]
		  	var imgName = img.src.toUpperCase()
		  		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		     	{
			 		var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 		var imgStyle = "display:inline-block;" + img.style.cssText 
			 			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 			if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle		
			 				var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		     				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 				img.outerHTML = strNewHTML
			 			i = i-1
		     	}
	      }
	  }
}
// Add to window onload method
if (window.addEventListener)      //DOM method for binding an event
	window.addEventListener("load", correctPNG, false)
else if (window.attachEvent)      //IE exclusive method for binding an event
	window.attachEvent("onload", correctPNG)
else if (document.getElementById) //support older modern browsers
	window.onload=correctPNG
// ******* //
// * End * //
// ******* //

// *********************************************** //
// * Open new window function - without toolbars * //
// *********************************************** //
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}
// ******* //
// * End * //
// ******* //

// ******************************************** //
// * Open new window function - with toolbars * //
// ******************************************** //
var win=null;
function NewWindow1(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=yes,toolbar=yes,resizable=yes';
	win=window.open(mypage,myname,settings);
}
// ******* //
// * End * //
// ******* //

// ************************************************************* //
// * Open new window function - without toolbars (resizeable ) * //
// ************************************************************* //
var win=null;
function NewWindow2(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(mypage,myname,settings);
}
// ******* //
// * End * //
// ******* //

// *************************** //
// * Form Field Progress Bar * //
// *************************** //

function textCounter(field,counter,maxlimit,linecounter)
{
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else
	{ 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop)
{
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
// ******* //
// * End * //
// ******* //

// ********************************* //
// * E-mail Friend form validation * //
// ********************************* //
function JS_EmailFriend()
{
	var error = "";
	
	if (document.getElementById("recipient_name").value == "")
	{
		error += "* Please fill in your friend's name   \n";
	}
	if (document.getElementById("recipient_email").value == "")
	{
		error += "* Please fill in your friend's email address   \n";
	}
	if ((document.getElementById("recipient_email").value.indexOf ('@',0) == -1 ||
		document.getElementById("recipient_email").value.indexOf ('.',0) == -1) &&
		document.getElementById("recipient_email").value != "")
	{
		error += "* You must enter a valid friend's email address   \n";
	}
	if (document.getElementById("sender_name").value == "")
	{
		error += "* Please fill in your name   \n";
	}
	if (document.getElementById("sender_email").value == "")
	{
		error += "* Please fill in your email address   \n";
	}
	if ((document.getElementById("sender_email").value.indexOf ('@',0) == -1 ||
		document.getElementById("sender_email").value.indexOf ('.',0) == -1) &&
		document.getElementById("sender_email").value != "")
	{
		error += "* You must enter a valid email address";
	}
	if (error != "")
	{
		alert(error);
		return (false);
	}
	else
	{
		return (true);
	}
}
// ******* //
// * End * //
// ******* //

// ***************************************************************
// * Function to validate string against valid characters listed *
// ***************************************************************
function IsValidChars(strString)
{
	var strValidChars = "0123456789-'\" ?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   	var strChar;
   	var blnResult = true;
	
	if (strString.length == 0) return false;
   		for (i = 0; i < strString.length && blnResult == true; i++)
      	{
      		strChar = strString.charAt(i);
      			if (strValidChars.indexOf(strChar) == -1)
         		{
         			blnResult = false;
         		}
      	}
   	return blnResult;
}
// ******* //
// * End * //
// ******* //

// ***********************************
// * Function for LEFT in JavaScript *
// ***********************************
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
// ******* //
// * End * //
// ******* //

// ************************************
// * Function for RIGHT in JavaScript *
// ************************************
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// ******* //
// * End * //
// ******* //

// *********************************************
// * Function to allow only NUMERIC keystrokes *
// *********************************************
function giveWarningAndFixValue(field)
{ 
	//removes all non-numeric value and replaces 
	//alert("You can only use whole numeric values. Please don't use comma's."); 
	var value = parseInt(field.value); 
	if(!isNaN(value)) field.value = value; 
	else field.value = ""; 
	//used for NS4.7 because when changing value the cursor is placed in front of the value, instead of behind 
	if(document.layers) field.select(); 
}
// ******* //
// * End * //
// ******* //

// **************************************************
// * Function to check for NUMERIC values in string *
// **************************************************
function isNumericValue(str)
{ 
	var isValid = true; 
	if(str.search(/^[0-9]+$/) == -1)
	{ 
		isValid = false; 
	}
	return isValid;
}
// ******* //
// * End * //
// ******* //

// *********************************************
// * Function to evoke above NUMERIC functions *
// *********************************************
function checkValue(field)
{ 
	if(!isNumericValue(field.value))
	{ 
		giveWarningAndFixValue(field); 
	} 
}
// ******* //
// * End * //
// ******* //

// ********************************************************
// * Function to CHECK / UNCHECK all checkboxes in a form *
// ********************************************************
function checkUncheckAll(theElement, theField)
{
	var arrContent = new Array;	
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name == theField)
		{
			theForm[z].checked = theElement.checked;
		}
	}
}
// ******* //
// * End * //
// ******* //

// ***********************************************************************
// * Function to check if ALL checkbox in a form are checked / unchecked *
// ***********************************************************************
function checkAll(theElement, theField)
{
	var total = 1;
	
	if(eval("document." + theElement.form.name +"." + theField + ".length"))
	{
		var max = eval("document." + theElement.form.name +"." + theField + ".length");
		
		for (var idx = 1; idx < max; idx++)
		{
			if (eval("document." + theElement.form.name +"." + theField + "[" + idx + "].checked") == true)
			{
	    		total += 1;
	   		}
		}
		if(total < idx)
		{
			eval("document." + theElement.form.name +"." + theField + "_0.checked = false")
		}
		else
		{
			eval("document." + theElement.form.name +"." + theField + "_0.checked = true")
		}
		
	}
	else
	{
		eval("document." + theElement.form.name + "." + theField + "_0.checked = " + theElement.form.theElement.checked)	
	}
}
// ******* //
// * End * //
// ******* //

// ***************************************************
// * Function to check / uncheck location checkboxes *
// ***************************************************
// All UK
function checkLocationAllUK()
{
	if(document.FrmSearch.location[1].checked == true)
	{
		document.FrmSearch.location[2].checked = true
		document.FrmSearch.location[3].checked = true
		document.FrmSearch.location[4].checked = true
		document.FrmSearch.location[5].checked = true
		document.FrmSearch.location[6].checked = true
		document.FrmSearch.location[7].checked = true
		document.FrmSearch.location[8].checked = true
		document.FrmSearch.location[9].checked = true
		document.FrmSearch.location[10].checked = true
		document.FrmSearch.location[11].checked = true
		document.FrmSearch.location[12].checked = true
		document.FrmSearch.location[13].checked = true
		document.FrmSearch.location[14].checked = true
		document.FrmSearch.location[15].checked = true
		document.FrmSearch.location[16].checked = true
		document.FrmSearch.location[17].checked = true
		document.FrmSearch.location[18].checked = true
		document.FrmSearch.location[19].checked = true
		document.FrmSearch.location[20].checked = true
		document.FrmSearch.location[21].checked = true
		document.FrmSearch.location[22].checked = true
		document.FrmSearch.location[23].checked = true
		document.FrmSearch.location[24].checked = true
	}
	else
	{
		document.FrmSearch.location[2].checked = false
		document.FrmSearch.location[3].checked = false
		document.FrmSearch.location[4].checked = false
		document.FrmSearch.location[5].checked = false
		document.FrmSearch.location[6].checked = false
		document.FrmSearch.location[7].checked = false
		document.FrmSearch.location[8].checked = false
		document.FrmSearch.location[9].checked = false
		document.FrmSearch.location[10].checked = false
		document.FrmSearch.location[11].checked = false
		document.FrmSearch.location[12].checked = false
		document.FrmSearch.location[13].checked = false
		document.FrmSearch.location[14].checked = false
		document.FrmSearch.location[15].checked = false
		document.FrmSearch.location[16].checked = false
		document.FrmSearch.location[17].checked = false
		document.FrmSearch.location[18].checked = false
		document.FrmSearch.location[19].checked = false
		document.FrmSearch.location[20].checked = false
		document.FrmSearch.location[21].checked = false
		document.FrmSearch.location[22].checked = false
		document.FrmSearch.location[23].checked = false
		document.FrmSearch.location[24].checked = false
	}
};
// England
function checkLocationEngland()
{
	if(document.FrmSearch.location[2].checked == true)
	{
		document.FrmSearch.location[3].checked = true
		document.FrmSearch.location[4].checked = true
		document.FrmSearch.location[5].checked = true
		document.FrmSearch.location[6].checked = true
		document.FrmSearch.location[7].checked = true
		document.FrmSearch.location[8].checked = true
		document.FrmSearch.location[9].checked = true
		document.FrmSearch.location[10].checked = true
		document.FrmSearch.location[11].checked = true
		document.FrmSearch.location[12].checked = true
		document.FrmSearch.location[13].checked = true
		document.FrmSearch.location[14].checked = true
	}
	else
	{
		document.FrmSearch.location[3].checked = false
		document.FrmSearch.location[4].checked = false
		document.FrmSearch.location[5].checked = false
		document.FrmSearch.location[6].checked = false
		document.FrmSearch.location[7].checked = false
		document.FrmSearch.location[8].checked = false
		document.FrmSearch.location[9].checked = false
		document.FrmSearch.location[10].checked = false
		document.FrmSearch.location[11].checked = false
		document.FrmSearch.location[12].checked = false
		document.FrmSearch.location[13].checked = false
		document.FrmSearch.location[14].checked = false
	}
};
// England > North
function checkLocationNorth()
{
	if(document.FrmSearch.location[3].checked == true)
	{
		document.FrmSearch.location[4].checked = true
		document.FrmSearch.location[5].checked = true
		document.FrmSearch.location[6].checked = true
	}
	else
	{
		document.FrmSearch.location[4].checked = false
		document.FrmSearch.location[5].checked = false
		document.FrmSearch.location[6].checked = false
	}
};
// England > Central
function checkLocationCentral()
{
	if(document.FrmSearch.location[7].checked == true)
	{
		document.FrmSearch.location[8].checked = true
		document.FrmSearch.location[9].checked = true
		document.FrmSearch.location[10].checked = true
	}
	else
	{
		document.FrmSearch.location[8].checked = false
		document.FrmSearch.location[9].checked = false
		document.FrmSearch.location[10].checked = false
	}
};
// England > South
function checkLocationSouth()
{
	if(document.FrmSearch.location[11].checked == true)
	{
		document.FrmSearch.location[12].checked = true
		document.FrmSearch.location[13].checked = true
		document.FrmSearch.location[14].checked = true
	}
	else
	{
		document.FrmSearch.location[12].checked = false
		document.FrmSearch.location[13].checked = false
		document.FrmSearch.location[14].checked = false
	}
};
// Scotland
function checkLocationScotland()
{
	if(document.FrmSearch.location[15].checked == true)
	{
		document.FrmSearch.location[16].checked = true
		document.FrmSearch.location[17].checked = true
		document.FrmSearch.location[18].checked = true
	}
	else
	{
		document.FrmSearch.location[16].checked = false
		document.FrmSearch.location[17].checked = false
		document.FrmSearch.location[18].checked = false
	}
};
// Wales
function checkLocationWales()
{
	if(document.FrmSearch.location[19].checked == true)
	{
		document.FrmSearch.location[20].checked = true
		document.FrmSearch.location[21].checked = true
		document.FrmSearch.location[22].checked = true
	}
	else
	{
		document.FrmSearch.location[20].checked = false
		document.FrmSearch.location[21].checked = false
		document.FrmSearch.location[22].checked = false
	}
};
// ******* //
// * End * //
// ******* //

// ********************************************************
// * return the value of the radio button that is checked *
// * return an empty string if none are checked, or       *
// * there are no radio buttons                           *
// ********************************************************
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
// ******* //
// * End * //
// ******* //

// ******************************************
// * Function to set or reset radio buttons *
// ******************************************
function setCheckedValue(radioObj, newValue)
{
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
// ******* //
// * End * //
// ******* //