var lastID = 0;
function SelectImg(hostedsitepath, imageName, imgMaxWidth, imgMaxHeight) {

	var imgName = document.getElementById('image')
	/*hostedsitepath = "http://www.terralec.co.uk/"*/
	imgName.src = hostedsitepath + "product_images/info/" + imageName;
	imgName.name = imageName;

	var imgNameHid = document.getElementById('hid_imageName')
	imgNameHid.name = imageName;

	imgName.removeAttribute('width');
	imgName.removeAttribute('height');
	var imgWidth = imgName.naturalWidth || imgName.width;
	var imgHeight = imgName.naturalHeight || imgName.height;

	if (imgWidth > imgMaxWidth)
	{
		imgName.width = imgMaxWidth;
	} else if (imgHeight > imgMaxHeight)
	{
		imgName.height = imgMaxHeight;
	} else {
		imgName.height = imgHeight;
		imgName.width = imgWidth;
	}
}

function showVarOptions(variantID)
{
	addToBasket = eval("document.forms['frm_products'].csvIDAdd_" + variantID)
	variantSelect = eval("document.getElementById('variantSelect" + variantID + "')")
	variantOption = eval("document.forms['frm_products'].csvID_" + variantID)
	variantText = eval("document.getElementById('variantText" + variantID + "')")
	if (addToBasket.checked) {
		changevisibility('show','variantSelect' + variantID)
	} else {
		if (variantSelect.style.visibility=='visible') {
			changevisibility('hide','variantSelect' + variantID)
		}
		variantText.innerHTML = '';
		variantOption.options.selectedIndex = 0;
	}
}
function closeVarOptions(variantID)
{
	addToBasket = eval("document.forms['frm_products'].csvIDAdd_" + variantID)
	variantSelect = eval("document.getElementById('variantSelect" + variantID + "')")
	variantOption = eval("document.forms['frm_products'].csvID_" + variantID)
	variantText = eval("document.getElementById('variantText" + variantID + "')")
	if (variantOption.selectedIndex == 0) {
		if (addToBasket.checked)
		{
			addToBasket.checked = false
		}
		variantText.innerHTML = ""
	}
		changevisibility('hide','variantSelect' + variantID)
}

function changeVariantOptions(variantID)
{
/*	var str = '';
	var elem = "document.forms['frm_products'].elements;
	for(var i = 0; i < elem.length; i++)
	{
	str += i + " : Type:" + elem[i].type + " ";
	str += "Name:" + elem[i].name + " ";
	str += "Value:" + elem[i].value + " \n";
	}
	alert(str);
*/
	variantOption = eval("document.forms['frm_products'].csvID_" + variantID)
	variantText = eval("document.getElementById('variantText" + variantID + "')")
	togglevisibility('variantSelect' + variantID);
	closeVarOptions(variantID)
	if (variantOption.selectedIndex != 0) {variantText.innerHTML = variantOption.options[variantOption.selectedIndex].text + '<br /><a href="javascript:changevisibility(\'show\',\'variantSelect' + variantID + '\')")>change</a>';}
}


function displayThumb(imgMaxWidth, imgMaxHeight) {
	var imgName = document.getElementById('image')

	imgName.removeAttribute('width');
	imgName.removeAttribute('height');
	var imgWidth = imgName.naturalWidth || imgName.width;
	var imgHeight = imgName.naturalHeight || imgName.height;

	if (imgWidth > imgMaxWidth)
	{
		imgName.width = imgMaxWidth;
	} else if (imgHeight > imgMaxHeight)
	{
		imgName.height = imgMaxHeight;
	} else {
		imgName.height = imgHeight;
		imgName.width = imgWidth;
	}
}


// Set the horizontal and vertical position for the popup
var PositionX = 100;
var PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
var defaultWidth  = 500;
var defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = false;

// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=auto,statusbar=0,toolbar=0,menubar=0,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;

function popImage(hostedsitepath, imageName,imageTitle,thumb){
	/*hostedsitepath = "http://www.terralec.co.uk/"*/
	if (thumb) {
		imageURL = hostedsitepath + "product_images/" + imageName
	} else {
		imageURL = hostedsitepath + "product_images/" + document.getElementById('hid_imageName').name
	}

	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;} a {color: #000; font: 12px arial;}</style>');
		writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('isSafari = (navigator.userAgent.indexOf("Safari"))!=-1;');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('function reSizeToImage(){');
		writeln('	 if (isIE || isSafari){');
		writeln('		width=document.images[0].width+40;');
		writeln('		height=document.images[0].height+100;');
		writeln('		if (height > 768) {');
		writeln('		window.resizeTo(width,768);');
		writeln('		} else {');
		writeln('		window.resizeTo(width,height);');
		writeln('		}');
		writeln('		} else if (isNN){');
		writeln('		width=document.images["img_imageToDisplay"].width+40;');
		writeln('		height=document.images["img_imageToDisplay"].height+40;');
		writeln('		if (height > 768)');
		writeln('		{');
		writeln('		window.innerWidth=width;');
		writeln('		window.innerHeight=768;');
		writeln('		} else {');
		writeln('		window.innerWidth=width;');
		writeln('		window.innerHeight=height;');
		writeln('		}');
		writeln('		}');
		writeln('}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose)
			writeln('</head><body bgcolor="#FFFFFF" scroll="auto" onload="reSizeToImage();doTitle();self.focus()">')
		else
			writeln('</head><body bgcolor="#FFFFFF" scroll="auto" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		//writeln(imageURL + '-' + thumb + '-' + document.getElementById('hid_imageName').name);
		writeln('<CENTER><div id="largeImage"><a href="javascript:window.close();"><img name="img_imageToDisplay" src='+imageURL+' style="display:block; border: 0px;"><BR />Close window</a></CENTER></body></html>');
		close();
	}
}

function clearThisField(fieldName) {
	var el = document.getElementById(fieldName);
	if (el.value==el.defaultValue)
		{ el.value='';
	} else if (el.value=='') {
		el.value=el.defaultValue;
	}
}

function hideWarranty(t){
	el = document.getElementById(t);
	el.style.display="none";
}

function updateRelative(option_name, showStock, stkaFreeMessage, stkaExpectedMessage, stkaExpectedDateMessage, stkaExpectedDaysMessage, stkaOutofStockMessage, strStock_generalMessage, strStock_DD_js, strStock_lowStock_js, strStock_lowStockLevel_js, strStock_moreThanStock_js, strStock_moreThanStockLevel_js, strVariantsSelectedMsg) {
	var strValue;
	var strArrValue;
	var ftrRelativeIDValue;
	var strKeyValue;
	var strCurrentValue;
	var intLen;
	var blnValid;
	var strFeatureValue;
	var strSelectedValue;
	var stockMessage;
	var stockExpectedMessage;
	var strVariantsSelectedMsg;

	if (strVariantsSelectedMsg == undefined) {
		strVariantsSelectedMsg = "Only ";
	}


	stockMessageExpected = ""
	stockMessage = ""

	intFeatureCount = arrFeature[0].length; //get titles
	intValueCount = arrFeature.length; // get total number of value rows (inc. titles)


  //alert(intFeatureCount);
  //alert(intValueCount);

	var arrValue = new Array(intFeatureCount);

	//for each dropdown
	for(i=1;i<intFeatureCount;i++) {

	var featureOption = (arrFeature[0][i].indexOf("option_") != -1); // See if a "option" is present in string

		//get current value of current feature dropdown and store in array for lookup later
		if (featureOption)
		{
		eval('arrValue[' + i + '] = document.forms["frm_products"].' + arrFeature[0][i] + '.value');
		}


		//if current feature name does not equal selected dropdown (and is a dropdown)
		if ((arrFeature[0][i]!=option_name && (featureOption))) {
			//clear values from current dropdown
			eval('document.forms["frm_products"].' + arrFeature[0][i] + '.length=1');
			//add default option
			//eval('document.forms["frm_products"].' + arrFeature[0][i] + '[0].text=\'Select an option\';');
			eval('document.forms["frm_products"].' + arrFeature[0][i] + '[0].value="";');
		}
	}

	//for each record in feature array
	for(j=1;j<intValueCount;j++) { // start at row 2 - after the titles
			blnValid = true;

			//for each feature in current record
			for(i=1;i<intFeatureCount-1;i++) { // start at item 2 - ignore product ID
				//if current feature = selected dropdown and selected dropdown value != feature value and selected dropdown value != nothing then record not a valid combination
				if (arrFeature[0][i]==option_name && arrValue[i]!=arrFeature[j][i] && arrValue[i]!="") {
					blnValid = false;
				}
				//alert(arrFeature[j][i] + " - " + blnValid + " - " + option_name + " - " + i)
			}

			//alert(blnValid)

			if (blnValid==true) {
				//for each dropdown (-1 removes productPrice from loop)
				for(i=1;i<intFeatureCount-1;i++) {
				var featureOption = (arrFeature[0][i].indexOf("option_") != -1); // See if a "option" is present in string
				if (featureOption)
					{

					blnValid = true;
					//get reference to dropdown object
					eval('objOption=document.forms["frm_products"].' + arrFeature[0][i]);
					//for each item in dropdown list
					for(k=0;k<objOption.length;k++) {
						//if feature value already in dropdown (added in previous loop) set false so not added again.
						if (arrFeature[j][i]==objOption[k].value) {
							blnValid = false;
							//alert(arrFeature[j][i])
						}
					}
					//if valid record and not already in dropdown then add
					if (blnValid==true) {
						objOption.length = objOption.length + 1;
						index=objOption.length - 1;
						objOption[index].value=arrFeature[j][i];
						objOption[index].text=arrFeature[j][i];
						//set value based off lookup value stored in arrValue
						if(arrValue[i]==arrFeature[j][i]) {
							objOption.options.selectedIndex=index;
						}
					}
				}
			}
		}
		}




	var tmpCounter = false

	for(j=1;j<intValueCount;j++) {
		//selected dropdown value != feature value
		blnValid = true;
		for(i=1;i<intFeatureCount-1;i++) {
		var featureOption = (arrFeature[0][i].indexOf("option_") != -1); // See if a "option" is present in string
		if (featureOption)
		{
			eval('ddNumber=(document.forms["frm_products"].' + arrFeature[0][i] +');');
			if (ddNumber.length == 2)  {
				ddNumber.options.selectedIndex=1;
				//document.forms["frm_products"].productPrice.value="\u00A3" + arrFeature[j][intFeatureCount-1];
			}
			if(arrValue[i]!=arrFeature[j][i])
				blnValid = false;
			}
		}

		if (blnValid)
		{
			tmpCounter = true
			document.forms["frm_products"].productPrice.value=strVariantsSelectedMsg + "\u00A3" + arrFeature[j][intFeatureCount-1];
			if (showStock)
			{
				//alert(arrFeature[j][intFeatureCount]-8)
				if (arrFeature[j][intFeatureCount-8] == "S") // Check if the variant is a stock product
				{
					if (parseInt(arrFeature[j][intFeatureCount-6]) > 0) {
						if ((parseInt(arrFeature[j][intFeatureCount-6])  <= parseInt(strStock_lowStockLevel_js)) && parseInt(strStock_lowStockLevel_js) != 0) {
							// low stock
							// if low stock stock value is less than or equal to current stock
							strStock_lowStock_js = strStock_lowStock_js.replace("_lowStock_",  strStock_lowStockLevel_js)
							stockMessage = strStock_lowStock_js.replace("_stock_",  arrFeature[j][intFeatureCount-6])
							//stockMessage = strStock_lowStock_js.replace("_lowStock_",  strStock_lowStockLevel_js)
						} else if ((parseInt(arrFeature[j][intFeatureCount-6]) >= parseInt(strStock_moreThanStockLevel_js)) && parseInt(strStock_moreThanStockLevel_js) != 0) {
							// elseif more than stock value is more than or equal to current stock
							strStock_moreThanStock_js = strStock_moreThanStock_js.replace("_stock_", arrFeature[j][intFeatureCount-6])
							stockMessage = strStock_moreThanStock_js.replace("_moreThanStock_", strStock_moreThanStockLevel_js)
						} else {
							// stkaFree
							stockMessage = stkaFreeMessage.replace("_stock_", arrFeature[j][intFeatureCount-6])
						}

					} else { // if stock is less than or equal to 0
						if (arrFeature[j][intFeatureCount-5] > 0) {
							// stkaExpected
							//alert(stkaExpectedMessage)
							if (arrFeature[j][intFeatureCount-3] != "" && arrFeature[j][intFeatureCount-3] > 0) {
								// stkaExpectedDays
								stkaExpectedDaysMessage = stkaExpectedDaysMessage.replace("_expected_", arrFeature[j][intFeatureCount-5])
								stockMessage = stkaExpectedDaysMessage.replace("_expecteddays_", arrFeature[j][intFeatureCount-3])

							}else if (arrFeature[j][intFeatureCount-4] != "" && arrFeature[j][intFeatureCount-4] > 0) {
								// stkaExpectedDate
								stockMessage = stkaExpectedDateMessage.replace("_expecteddate_", arrFeature[j][intFeatureCount-4])

							} else {
								stkaExpectedMessage = stkaExpectedMessage.replace("_expected_", arrFeature[j][intFeatureCount-5])
								stockMessage = stkaExpectedMessage.replace("_expecteddays_", arrFeature[j][intFeatureCount-3])
							}
						} else {
							// Out of stock
							stockMessage = stkaOutofStockMessage;
						}
					}
				} else if (arrFeature[j][intFeatureCount-8] == "DD") {
					// Check if the variant is a direct dispatch
					stockMessage = strStock_DD_js
				} else {
					// Else display general stock message
					stockMessage = strStock_generalMessage
				}

				//document.forms["frm_products"].stockAvailable.value= stockMessage;
				document.getElementById("stockAvailable").innerHTML= stockMessage;
			}
		}
	}

	if (tmpCounter == false)
	{
		document.forms["frm_products"].productPrice.value=document.forms["frm_products"].productPrice.defaultValue
		if (showStock)
		{
			//document.forms["frm_products"].stockAvailable.value="";
			document.getElementById("stockAvailable").innerHTML= "";
		}
	}

}


function placeValue(string,formField,formName){
eval("document." + formName+ "." + formField + ".value = string;");
}

function decision(message, url){
	if(confirm(message)) location.href = url;
}

function SwitchMenu(obj){
	if(document.getElementById){
	var tab = document.getElementById("tabs").getElementsByTagName("a");
	var el = document.getElementById(obj);
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
	obj = Right(obj,1);
		if(ar[obj].style.display != "block") {
			if(el.style.display == "none"){
				for (var i=0; i<ar.length; i++){
					tab['menu_'+i].className = 'inactive';
					ar[i].style.display = "none";
				}
				tab['menu_'+obj].className = 'active';
				el.style.display = "block";
			}
		}
	}
}
function Right(STRING,CHARACTER_COUNT){
return STRING.substring((STRING.length - CHARACTER_COUNT),STRING.length);
}


function submitFormVariants(variantID,prdID) {
		document.forms["frm_products"].buy.value = variantID;
		document.forms["frm_products"].prdID.value = prdID;
	if (checkForm('frm_products'))
	{
		document.forms["frm_products"].submit();
	}
}

function submitFormKit(hosted_site_path, prdID) {
		document.forms["frm_products"].buy.value = prdID;
		document.forms["frm_products"].prdID.value = prdID;
		document.forms["frm_products"].action = hosted_site_path + 'kit.asp';
	if (checkForm('frm_products'))
	{
		document.forms["frm_products"].submit();
	}
}

function init() {
	centralise('main');
}

function focusForm(){
	if(!document.forms){
		return;
		}
		if(document.forms.length<1){
		return;
	}
	document.forms[0].elements[0].focus();
}

function message(message){
	alert(message);
}

function decision(message, url){
	if(confirm(message)) location.href = url;
}

function navigateTo(url){
	location.href =  url
	/*location.href = '/dev2/terralec/' + url*/
	/*location.href = '/terralec_dev/' + url*/
}


function navigateToSecure(url){
	location.href = url
}


function colourChooser(div_id, colour, formName){
	var myElement = document.getElementById(div_id);
	var myElementText = document.getElementById('colourHex');
	myElementText.innerHTML = colour;
	myElement.style.backgroundColor = colour;
	eval("document." + formName+ ".hidden_colour.value = colour;");
}

function clearForm(formName){
	var element;
	var elementCount;
	eval("elementCount=document.forms[\"" + formName + "\"].length;")
	for (var i = 0; i < elementCount; i++)
	{
		eval("element=document.forms[\"" + formName + "\"].elements[i];")
		if (element.type == "text" || element.type == "textarea")
			{
			element.value='';
			}
		}
	}


function submitForm(formName,qString,actionURL,encType){
if (typeof(actionURL) != 'undefined')
	{
		eval("document.forms[\"" + formName + "\"].action = actionURL;")
	}
if (typeof(encType) != 'undefined')
	{
		eval("document.forms[\"" + formName + "\"].encoding = encType;")
	}
if (typeof(qString) == 'undefined')
	{
		eval("document.forms[\"" + formName + "\"].submit();");
	}
else
	{
		eval("document.forms[\"" + formName + "\"].action = document.forms[\"" + formName + "\"].action + qString;")
		eval("document.forms[\"" + formName + "\"].submit();")
	}
}

function checkFormVeggie () {
		
	var delAdd =  document.getElementById('delAddress').style.display;
	
	if (delAdd == "block")
	{
		//delivery address validation	
				
		var titleField = document.getElementById('wordDelTitle').value;
		if (titleField.length == 0)
		{
			alert('You must select a title from the drop down box.');
			return false;
		}
		
		var initialField = document.getElementById('wordDelInitials').value;
		if (initialField.length == 0)
		{
			alert('You must enter your initials');
			return false;
		}
		
		var surnameField = document.getElementById('wordDelSurname').value;
		if (surnameField.length == 0)
		{
			alert('You must enter your surname');
			return false;
		}
		
		var addressField = document.getElementById('wordDelAddress1').value;
		if (addressField.length == 0)
		{
			alert('You must enter the first line of your delivery address.');
			return false;
		}
		var townField = document.getElementById('wordDelAddress3').value;
		if (townField.length == 0)
		{
			alert('Please enter the town for your delivery address.');
			return false;
		}
		
		var postcodeField = document.getElementById('wordDelPostcode').value;
		if (postcodeField.length ==0)
		{
			alert('You must enter a postcode for your delivery address');
			return false;
		}
		
		
		checkForm('custom_checkout');
		
	}
	else 
	{
		checkForm('custom_checkout');
	}
}

function checkForm(formName,qString,actionURL,encType) {
	var boxesFound = 0;
	var boxesChecked = 0;
	var elementCount;
	var element;
	var element2;
	var returnval;
	returnval=true;
	eval("elementCount=document.forms[\"" + formName + "\"].length;")
	for (var j = 0; j < elementCount; j++)
	{
		eval("element=document.forms[\"" + formName + "\"].elements[j];")
		var indx = element.name.indexOf('_agree');
		if (indx != -1)
		{
			fieldname=element.name.substring(0,indx);
			if (element.checked == false)
			{
				alert(element.value);
				returnval = false;
				return false;
			}
		}
		indx = element.name.indexOf('_required');
		if (indx != -1)
		{
			var fieldname=element.name.substring(0,indx);
			eval("element2=document.forms[\"" + formName + "\"].elements[fieldname];")
			if (element2.value.length == 0)
			{
				alert(element.value);
				j = (elementCount);
				if (element2.type != "hidden")
				{
					element2.focus();
				}
				returnval = false;
			}
		}
		indx = element.name.indexOf('_checkbox');
		if (indx != -1)
		{
			boxesFound ++;
			if (element.checked)
			{
				boxesChecked ++;
			}
		}
		indx = element.name.indexOf('_number');
		if (indx != -1)
		{
			fieldname=element.name.substring(0,indx);
			eval("element2=document.forms[\"" + formName + "\"].elements[fieldname];")
			if (isNaN(parseInt(element2.value))==true && element2.value.length!=0)
			{
				alert(element.value);
				j = (elementCount);
				if (element2.type != "hidden"){
					element2.focus();
				}
			returnval = false;
			}
		}

		indx = element.name.indexOf('_hex');
		if (indx != -1)
		{
			fieldname=element.name.substring(0,indx);
			eval("element2=document.forms[\"" + formName + "\"].elements[fieldname];")
			if (isHex(element2.value)==false && element2.value.length!=0)
			{
				alert(element.value);
				j = (elementCount);
				if (element2.type != "hidden"){
				element2.focus();
			}
			returnval = false;
			}
		}
	}

	if (boxesFound > 0 && boxesChecked < 1)
	{
	alert('You must choose at least one Check Box.'); returnval = false;
	}

	if (returnval == true)
	{
		submitForm(formName,qString,actionURL,encType);
		indx = element.name.indexOf('submitButton');
		if (indx != -1)
		{
			disableButton(formName);
		}
	}
}



function postcodeValidate(strFieldName) {
	var strInput;
	eval ('strInput=' + formName + '.' + strFieldName + '.value')
	if (strInput=='') {
	return (true);
	}

	var j;
	var blnOutPre = (false);
	var blnOutSuf = (false);
	var strOutPrefix = '';
	var strOutSuffix = '';
	var strInDigit = '';
	var strInChars ='';
	var blnValid = (true);
	strInput = toAlNum(strInput);
	for (j=0;j<strInput.length;j++) {
		if (blnOutPre==false) {
			if (j==0 && isNaN(strInput.charAt(j))==false) {
				blnValid = (false);
			}
			if (j>1 && isNaN(strInput.charAt(j))) {
				blnValid = (false);
			}
			if (isNaN(strInput.charAt(j))==false) {
				blnOutPre = (true);
			} else {
				strOutPrefix = strOutPrefix + strInput.charAt(j);
			}
		}
		if (blnOutPre && blnOutSuf==false) {
			if (strOutSuffix.length > 2) blnValid = (false);
				if (j < (strInput.length - 3)) {
					strOutSuffix = strOutSuffix + strInput.charAt(j);
				} else {
					blnOutSuf = (true);
				}
			}
			if (blnOutSuf) {
				if (isNaN(strInput.charAt(j)) && strInput.charAt(j).toUpperCase()!='O') blnValid = (false);
				if(strInput.charAt(j).toUpperCase()=='O') {
					strInDigit = '0';
				} else {
					strInDigit = strInput.charAt(j);
				}
				if (isNaN(strInput.charAt(j+1))==false || isNaN(strInput.charAt(j+2))==false) blnValid = (false);
				strInChars = strInput.charAt(j+1) + strInput.charAt(j+2);
				if (blnValid) {
					return (true);
				}
			}
		}
		return (false);
	}

function isHex(string){
	var hexchars = "0123456789ABCDEFabcdef";
	for (var i=0; i< string.length; i++){
		if (hexchars.indexOf(string.charAt(i)) == -1) {
			return false;
		}
	}
	return true;
}

function dom_check(){
	if (document.getElementById)
	dom='yes'
	//alert("DOM compliant!");
	else
	dom='no'
	location.href='non_dom.asp?usrID=12AC8845-E625-4449-959E-8A7ABE6F6029';
}

function centralise(div_id) {
var innerWidth = window.innerWidth?1:0
var myElement = document.getElementById(div_id);

var box_left, box_top, schMarginHeight, schContentWidth, magic_offset, screen_width;

schContentWidth = 760;
schMarginHeight = 8;

if(innerWidth==1) {
	screen_width = window.innerWidth
} else {
	screen_width = document.body.clientWidth
}

if ((screen_width)-(schMarginHeight*2)<=schContentWidth){
	box_left = schMarginHeight;
} else {
	box_left = (screen_width-schContentWidth)/2;
}

myElement.style.left = box_left + "px";
myElement.style.top = schMarginHeight + "px";
myElement.style.width = schContentWidth +"px";
}

function changecolor(div_id, action){
var myElement = document.getElementById(div_id);
	if (action=='nav_on'){
		myElement.style.backgroundColor = '#FFFFCC';
		myElement.style.color = '';
	} else {
		myElement.style.backgroundColor = '';
		myElement.style.color = '';
	}
}

function makevisible(div_id){
	var myElement = document.getElementById(div_id);
	myElement.style.visibility = 'visible';
}

function itemMouseOver(itemID, action) {
	for(i=0;i<array.length;i++) {
		if(array[i][0]==itemID) {
			if(array[i][2]!='') {
				changevisibility(action,array[i][2]);
			}
				if(array[i][1]!='idN0') {
				if(action=='hide') {
				changecolor(array[i][1],'nav_off');
			} else {
				changecolor(array[i][1],'nav_on');
			}
				itemMouseOver(array[i][1],action);
			}
		}
	}
}

function changevisibility(status,values){
	var value_array = values.split("~");
	for (loop=0; loop < value_array.length;loop++)
	{
		var myElement = document.getElementById(value_array[loop]);
		if (status == 'hide') {
			myElement.style.visibility = 'hidden';
			myElement.style.display = 'none';
		} else {
			myElement.style.visibility = 'visible';
			myElement.style.display = 'block';
		}
	}
}

function togglevisibility(div_id){
	var myElement = document.getElementById(div_id);
	if (myElement.style.visibility == 'visible' | myElement.style.visibility == '')
	{
		myElement.style.visibility = 'hidden';
		myElement.style.display = 'none';
	} else {
		myElement.style.visibility = 'visible';
		myElement.style.display = 'block';
	}
}

function openWindow(url,window_name,width,height){
	var options='';
	options='menubar=1,toolbar=1,location=1,statusbar=1,scrollbars=1,resizable=1,width='+ width +',height='+ height;
	window.open(url,name,options);
}

function closeWindow(name){
	window.close(name);
}

function check(div_id){
	var myElement = document.getElementById(div_id);
	var l = myElement.style.left;
	var t = myElement.style.top;
	var w = myElement.style.width;
	var h = myElement.style.height;
	alert("Position is: left " + l + ", top " + t + ", width " + w +", height "  + h);
}

function disableButton(formName){
	var buttonLocation = eval(formName + ".submitButton");
	buttonLocation.disabled = true;
	buttonLocation.value = '... Please wait...';
}

function toAlNum(strInput) {
	var strOutput;
	strOutput = '';
	for (j=0;j<strInput.length;j++) {

	if((strInput.charCodeAt(j) > 47 && strInput.charCodeAt(j) < 58) || (strInput.charCodeAt(j) > 64 && strInput.charCodeAt(j) < 91) || (strInput.charCodeAt(j) > 96 && strInput.charCodeAt(j) < 123)) strOutput = strOutput + strInput.charAt(j);
	}
	return strOutput;
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") &&
	   anchor.getAttribute("rel") == "external")
	 anchor.target = "_blank";
	}
}
window.onload = externalLinks;