//limit text areas
//----------------
function textLimit(field, maxlen, elementname) {
	if (field.value.length > maxlen + 1)
		alert('Your ' + elementname + ' input has been truncated. The limit is ' + maxlen + ' characters.');
	if (field.value.length > maxlen)
		field.value = field.value.substring(0, maxlen);
}

//display basket items
//--------------------
function displayItemsViewer(basketVal) {
	//alert("basketVal = " + basketVal); 
	if (document.layers){
		//Netscape 4 specific code
		document.divitemviewer.innerHTML = basketVal;
	}
	if (document.getElementById){
		//Netscape 6 specific code
		document.getElementById("divitemviewer").innerHTML = basketVal;
	}
	if (document.all){
		//IE4+ specific code
		document.all.divitemviewer.innerHTML = basketVal;
	}
}

//histry back button
//-------------------
function toBeCompleted() {
	alert("This feature is to be completed soon, requires payment gateway/design sign off.");
	//return false;
}

//country selector
//----------------
function openInter(type){

  if (document.getElementById)
  if(type=='on')
    document.getElementById("idd").style.visibility="visible"; 
      else document.getElementById("idd").style.visibility="hidden";

  return false;
}

//Forms Button Hanlders
//----------------------
function submitForm(passedForm) {
	document.forms[passedForm].submit();
}

function resetForm(passedForm) {
	document.forms[passedForm].reset()
}

//handle terms and conditions
//---------------------------
function checkFormValidate(passedform){
	if (document.forms[passedform].chkTerms.checked==false) {
		alert("Please accept our terms and conditions, to proceed with sign up.")		
		document.forms[passedform].chkTerms.focus();
		return false;
	}
	return true;
}

//histry back button
//-------------------
function goBackPage() {
	history.go(-1);
}

//image rollovers
//------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Handles Page Printing - Opens Popup
//-----------------------------------
function printPage(){
	pagetoPrint = location.href
	alert(pagetoPrint);
	//window.print();
	var pos = pagetoPrint.indexOf("?")
	alert(pos);
	if (pos >= 0) {
		strQVar	= "&"
	}
	else {
		strQVar = "?"
	}	

	alert(strQVar);	
	openPopUpWindow(pagetoPrint + strQVar + 'bolPrint=True','popUpPrintPage','500','600','yes')
}

//Handles Page Printing
//---------------------
function printPageLoad(){
	window.print();
}

//Handles window close
//--------------------
function closeWindow(){
	window.close();
}

//Handles Page email
//------------------
function sendEmailtoFriend(){
	pagetoEmail = location.href
	openPopUpWindow('rotigrill-email-page.asp?pagetoEmail='+pagetoEmail,'popUpSendPageEmail','400','200','no')
}	

//Pulls in the forms styslsheet if the browser is compatible
//-----------------------------------------------------------------------------------------
function getFormstyles(adminVal) {
	var nn6 = document.getElementById ? !document.all ? true:false:false;
	var ie5 = document.getElementById ? document.all ? true:false:false;
	var ie4 = document.all ? true:false;
	var nn4 = document.layers ? true:false;
	
	if(ie5 || ie4 || nn6) {
		if (adminVal == 'adminSite') {
			document.write('<link rel="Stylesheet" href="/media/css/forms.css" type="text/css"/>');
		}
		else {
			document.write('<link rel="Stylesheet" href="/media/css/forms.css" type="text/css"/>');
		}
	}
}

//Default status name
//--------------------------------
defaultStatus ="Rotgrill"

//PopUp Window Function
//---------------------------------------
var win = ""

function openPopUpWindow(mypage,myname,w,h,scroll) {
if (win!="") {
 win.close();
 }
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

//changes main window location - acts as popup remote
//---------------------------------------------------
function remotePageCall(sendPage) {
	//alert(sendPage);
	window.opener.location.href=sendPage; 
	window.close();
}

//confirmation script
//-------------------
function confSendUser(pageSend,message) {
	var senduser = confirm(message);
	
	if (senduser == true) {
		submitForm(pageSend);
	}
	else {
		return false;
	}
}