// JavaScript Document

var theFontSize;
theFontSize = "1.2em";


function windowInitialization() {
	var wrapper = document.getElementById("content");
	var myStyle = wrapper.style;
	
	if (getCookie("fSize")) {		
		myStyle.fontSize = getCookie("fSize");
	} else {
	setCookie("fSize",theFontSize);
	}
	
}

function changeFontSize(option) {

	var wrapper = document.getElementById("content");
	var myStyle = wrapper.style;
	var fSize = myStyle.fontSize;
	
	if(option == 1){			
		myStyle.fontSize = "1.2em";
		setCookie("fSize",myStyle.fontSize);
		return false;
	}
	
	if(option == 2){			
		myStyle.fontSize = "1.4em";
		setCookie("fSize",myStyle.fontSize);
		return false;
	}
	
	if(option == 3){			
		myStyle.fontSize = "1.6em";
		setCookie("fSize",myStyle.fontSize);
		return false;
	}
	
}


function setCookie(name, value, expires, path, domain, secure) {
	var temp = name + "=" + escape(value);
	if (expires) {
		temp += "; expires=" + expires.toGMTString();
	}
	if (path) {
		temp += "; path=" + path;
	}
	if (domain) {
		temp += "; domain=" + domain;
	}
	if (secure) {
		temp += "; secure";
	}
	document.cookie = temp;
}

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ",i) + 1;
		if (i == 0) break;
	}
	return null;
}

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf(";",offset);
	if (endstr == -1) {
			endstr = document.cookie.length;
	}
	return unescape (document.cookie.substring(offset,endstr));
}

function deleteCookie (name,path,domain) {
	if (getCookie(name)) {
		var temp = name + "=";
		temp += ((path)? "; path=" + path : "");
		temp += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		document.cooie = temp;
	}
}


//Function name: emailValidate
//Author: Weixiong Shi, rhul_shiweixiong@yahoo.co.uk
//Version: 1.0, 2/7/2006
//Usage: Check the validation of email address 
//Inputs: formName(name of form), eleName(name of element),msgName(name of the tag to dispy error message)
//Output: return true or false value, display the error message, focus on the element 
//
function emailValidate(formName,eleName,msgName) {   
	var theForm = document[formName];
	var theEmail = theForm[eleName].value;
	var dispMsg = document.getElementById(msgName);

	if (theEmail!=""){  // When the content exsits
		var atLoc = theEmail.indexOf("@",1);
		var dotLoc = theEmail.indexOf(".",atLoc +2 ) ;
		var len = theEmail.length;
	
		if (atLoc > 0 && dotLoc > 0 && len > dotLoc + 2) {
			dispMsg.firstChild.nodeValue = "OK!";   // The message when the address is valid
			return true;
		} else {
			//theForm[eleName].focus();
			dispMsg.firstChild.nodeValue = "\"" +theEmail + "\" is not valid."; // The error message when the address is not valid
			return false;
		}
	} else {
		//theForm[eleName].focus();
		dispMsg.firstChild.nodeValue = "* Required";
		return false;
	}
}

//Function name: fillValidate
//Author: Weixiong Shi, rhul_shiweixiong@yahoo.co.uk
//Version: 1.0, 2/7/2006
//Usage: Check if the element is filled
//Inputs: formName(name of form), eleName(name of element),msgName(name of the tag to dispy error message)
//Output: return true or false value, display the error message, focus on the element 
//

function fillValidate(formName,eleName,msgName) {
	var theForm = document[formName];
	var theElement = theForm[eleName];
	var dispMsg = document.getElementById(msgName);
	
	if (theElement.value != "") {
		dispMsg.firstChild.nodeValue = "OK!";
		return true;
	} else {
		//theElement.focus();
		dispMsg.firstChild.nodeValue = "* Please fill in.";
		return false;
	}
}

//Function name: selectValidate
//Author: Weixiong Shi, rhul_shiweixiong@yahoo.co.uk
//Version: 1.0, 2/7/2006
//Usage: Check if the dropdown list is selected
//Inputs: formName(name of form), eleName(name of element),msgName(name of the tag to dispy error message)
//Output: return true or false value, display the error message, focus on the element 
//Notice: the Default value is '0', which means users didn't make any choice
function selectValidate(formName,eleName,msgName) {
	var theForm = document[formName];
	var theElement = theForm[eleName];
	var dispMsg = document.getElementById(msgName);
	
	if (theElement.value !=0){
		dispMsg.firstChild.nodeValue = "OK!";
		return true;
	} else {
		//theElement.focus();
		dispMsg.firstChild.nodeValue = "* Please select.";
		return false;
	}
}

function formValidate(formName) {   // for the form on contact.html
	if (!selectValidate(formName,'title','emsg_title')) return false;
	if (!fillValidate(formName,'realname','emsg_name')) return false;
	if (!emailValidate(formName,'email','emsg_email')) return false;
	
	/*  */
}

function profileValidate(formName) {
	if (!selectValidate(formName,'title','emsg_title')) return false;
	if (!fillValidate(formName,'realname','emsg_name')) return false;
	if (!emailValidate(formName,'email','emsg_email')) return false;
	if (!fillValidate(formName,'address','emsg_address')) return false;
	if (!fillValidate(formName,'postcode','emsg_postcode')) return false;
	
	if (!fillValidate(formName,'telephone_day','emsg_telephone_day')) {
		return false;}
	else {
		var a = document.getElementById('emsg_telephone_day');
		if (!isNumeric(document[formName].telephone_day.value)) { a.firstChild.nodeValue="* Please fill in numbers"; return false;}
	}
		
	if (!fillValidate(formName,'telephone_night','emsg_telephone_night')) {
		return false;}
	else {
		var a = document.getElementById('emsg_telephone_night');
		if (!isNumeric(document[formName].telephone_night.value)){ a.firstChild.nodeValue="* Please fill in numbers";return false;}
	}
	
	document[formName].orderinfo.disabled = false;	
}

function isNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

