//BROWSERS
var recentBrowser=false; 
var isIE=false;
var isFF=false;
var isIE8=false;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	isIE=true;
	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	if (ieversion>=8){isIE8=true;}
	else if (ieversion>=7){isIE7=true;}
	else if (ieversion>=6){isIE6=true;}
	else if (ieversion>=5){isIE5=true;}
}
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
	isFF=true;
	var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	if (ffversion>=3){isFF3=true;}
	else if (ffversion>=2){isFF2=true;}
	else if (ffversion>=1){isFF1=true;}
}
if ((parseInt(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape") != -1) || ((parseInt(navigator.appVersion) >= 6 && navigator.appName.indexOf("Netscape") != -1))){
	recentBrowser=true;
}

//STYLES BROWSER ADJUSTMENT
if(!isIE || isIE8){
	document.write("<link rel='stylesheet' type='text/css' href='css/screen_mz.css' media='screen'>");
}


//BREAK OUT OF FRAMES
if (window.location != top.location){top.location.href=window.location};

//DATE & TIME
var days = new Array(7);
days[1]="Sunday";days[2]="Monday";days[3]="Tuesday";days[4]="Wednesday";days[5]="Thursday";days[6]="Friday";days[7]="Saturday";
var months = new Array(12);
months[1]="Jan";months[2]="Feb";months[3]="Mar";months[4]="Apr";months[5]="May";months[6]="Jun";months[7]="Jul";months[8]="Aug";months[9]="Sep";months[10]="Oct";months[11]="Nov";months[12]="Dec";
var today = new Date();
var day = days[today.getDay() + 1]
var month = months[today.getMonth() + 1]
var date = today.getDate();
var year=today.getYear(); 
if(year<2000){year = year + 1900;}


//CHECK EMAIL
function checkemail(emailobj){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(emailobj.value)){
		testresults=true;
	}else{
		testresults=false;
		alert("Please ensure your email address is valid");
		emailobj.focus();
		emailobj.select();
	}
	return (testresults);
}

//BUILD EMAIL
function buildemail(emailname,emaildom){
	window.open("mailto:"+emailname+"@"+emaildom);
}


//COOKIE HANDLING
function deletecookies(){//deletes ALL cookies
	var cstring=unescape(document.cookie);
	var carray=cstring.split(";");
	for(i=0;i<carray.length;i++){
		var cpair = carray[i].split("=");
		var cname = cpair[0];
		if(i!=0){cname=cname.substring(1,cname.length);}
		setcookie(cname,"",-1);//set expiry to -1 days
	}
	history.go(0);
}
function getexpirydate(nodays){
   var UTCstring;
   Today = new Date();
   nomilli=Date.parse(Today);
   Today.setTime(nomilli+nodays*24*60*60*1000);
   UTCstring = Today.toUTCString();
   return UTCstring;
}
function getcookie(cookiename) {
   var cookiestring=""+document.cookie;
   var index1=cookiestring.indexOf(cookiename);
   if (index1==-1 || cookiename=="") return ""; 
   var index2=cookiestring.indexOf(';',index1);//stringName.indexOf(searchValue, [fromIndex])
   if (index2==-1) index2=cookiestring.length; 
   return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setcookie(cname,value,duration){//TO DELETE A SINGLE COOKIE SEND duration VALUE -1 
  cookiestring=escape(cname)+"="+escape(value)+"; expires="+getexpirydate(duration);
  document.cookie=cookiestring;
  if(!getcookie(cname)){
  return false;
  }
  else{
   return true;
  }
}

//CURRENCY FORMATTING
function twodp(n) {
   n+=.005;
   ns = " "+n;
   ns = ns.substring(1,ns.length);
   var dp = ns.indexOf(".");
   if (dp < 0) ns = ns+".00";
   else if (dp == ns.length-2) ns = ns+"0";
   else if (dp < ns.length-1) ns = ns.substring(0,dp+3);
   return ns;
}

function check_form_contact(){
	with (document.form_contact){
		if(name.value==""){alert("Please enter your name."); document.form_contact.name.focus();return false;}
		if(!email.value.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)){alert("Please ensure you entered a valid email address."); document.form_contact.email.focus();return false;}
		if(email.value.match(/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/)){alert("Please ensure you entered a valid email address."); document.form_contact.email.focus();return false;}
		if(message.value==""){alert("Please enter your message"); document.form_contact.message.focus();return false;}
		return true;
	}
}

function check_form_newsletter(){
	with (document.form_contact){
		if(!email.value.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)){alert("Please ensure you entered a valid email address."); document.form_contact.email.focus();return false;}
		if(email.value.match(/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/)){alert("Please ensure you entered a valid email address."); document.form_contact.email.focus();return false;}
		return true;
	}
}
