//COMMON VARIABLES

var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
var ff = (navigator.appName.indexOf('Mozilla')>-1);

function go(where) {

	window.location.href=where;
}

function resizeMe(size) {

	if (size=="1") {
		window.resizeTo(800,600);
	}
	else if (size=="2") {
		window.resizeTo(1024,768);
	}
	else if (size=="3") {
		window.resizeTo(1280,720);
	}
	else if (size=="4") {
		window.resizeTo(1600,1200);
	}
	
		

}

//***************************************************************************************

//FORM SCROLL
function formScroll(whichForm) {

	var i;
	var j=document.forms[whichForm].elements.length -1; //Remove the submit

	for (i=1;i<j;i++) {

	str=document.forms[whichForm].elements[i];
	strValue=str.value;
	strName=str.name;
	strNameLength=strName.length;
//alert (strValue);
	if (!strValue && strName.substring(0,1)=="f" || !strValue && strName.substring(0,1)=="n") {
		alert ("You haven't completed the field [" + strName.substring(1,strNameLength) + "]");
		str.focus();
		return false;
	}

	if (strName.substring(0,1)=="n") {
		strValue=strValue.replace(" ","");
	}
	if (isNaN(strValue) && strName.substring(0,1)=="n") {
		alert ("The field [" + strName.substring(1,strNameLength) + "] is a numeric field only");
		str.focus();
		return false;
	}
	if (whichForm!="addArticleForm1") {
		//CALL CHECK FOR CHARACTER VALIDATION
			var result=validChar(strValue);
			if (!result) {
				return false;
			}
		}
	}
return true;
}

//***************************************************************************************

function validChar(str) {

var validChars="  ()//\\,1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.':;-!\n\r";

var strLength=str.length;

	for (var i=0; i<strLength; i++) {
        	if (validChars.indexOf(str.charAt(i)) < 0) {
            	alert("Invalid characters in " +  str + "\r\nPlease change '" + str.charAt(i) + "'");
            	return false;
        	}
	}

return true;
}

//***************************************************************************************
function checkForm(formName) {

if (document.forms[formName].iaction) {
	if (document.forms[formName].iaction.value=="registerMe" || document.forms[formName].iaction.value=="saveDetails") {
		if (document.forms[formName].iignore1.value=="pass") {
			var result=passwordCheck(formName);
			if (!result) {
				return false;
			}
			var result=confirmEmail(formName);
			if (!result) {
				return false;
			}
		}
	}
	if (document.forms[formName].iaction.value=="registerMe" || document.forms[formName].iaction.value=="saveDetails" || document.forms[formName].iaction.value=="contactDetails") {
		if (document.forms[formName].iignore2.value=="email") {
			var result=confirmEmail(formName);
			if (!result) {
				return false;
			}
		}

		if (document.forms[formName].iignore3.value=="TaC") {
			if (!document.forms[formName].ftac.checked) {
				alert ("Please read and agree to our Terms and Conditions");
				return false;
			}
		}
	}
}
var result=formScroll(formName);
if (result) {
	return true;
}
return false;
}
//***************************************************************************************
function passwordCheck(formName) {
	if (document.forms[formName].fpassword.value!=document.forms[formName].fpasswordConfirmed.value) {
		alert ("The password fields do not match");
		return false;
	}
return true;
}
//***************************************************************************************
function confirmEmail(formName) {
	if (document.forms[formName].femail.value!=document.forms[formName].fconfEmail.value) {
		alert ("The email fields do not match");
		return false;
	}
return true;
}
//***************************************************************************************

function resizeWindow(w,h) {

	window.resizeTo(w,h);
}

//***************************************************************************************

function closeWindow() {

	window.close();
}

//***************************************************************************************

function delayCloseWindow() {

	setTimeout("window.close()",1000);
}

//***************************************************************************************

function ccCheck(monthNow,yearNow) {

	var result=checkForm("ccDetails");
	if (result) {
		//alert(monthNow + "," + yearNow);
		var ccExpiryMonth=document.ccDetails.nccExpiryDateMonth.value;
		var ccExpiryYear=document.ccDetails.nccExpiryDateYear.value;
		if (ccExpiryMonth<monthNow && ccExpiryYear<=yearNow) {
			alert ("The card expiry date has already passed");
			return false;
		}
		var message="We are ready to process your order.\n";
		message=message + " Please do not press any buttons until you are \n";
		message=message + " directed to the next page. \n";
		message=message + " Press OK to continue or cancel to return \n";
		var result=confirm (message);
		if (result) {
			return true;	
		}
	}
return false;
}

function clearText(field) {

var defaultText="search";
	

	//if (field.value==defaultText) {

		field.value="";
	//}
	//else {

		//field.value=defaultText;
	//}
}

