// JavaScript Document


	var pickup = false;
	var delivery = true;
	
function init()
{

	handleState();
	
	  if(document.getElementById && document.createElement &&
document.createTextNode){
           activatePopupDivs();
         }
		 
		 
fNewPDFWindows();

}

function deliveryCheck(element)
{
	  if (element.checked) {
	  	delivery = true;
		pickup = false;
        }else{
	  	delivery = false;
		pickup = true;
		}
	handleState();
}

function pickupCheck(element)
{
	  if (element.checked) {
	  	delivery = false;
		pickup = true;
        }else{
	  	delivery = true;
		pickup = false;
		}
		handleState();
}

function handleState()
{
 	if (pickup) {
		    document.getElementById("input-pickup").style.display = "block";
        }else{
		    document.getElementById("input-pickup").style.display = "none";
		}
		
	if (delivery) {
		    document.getElementById("input-deliveryaddress").style.display = "block";
        }else{
		    document.getElementById("input-deliveryaddress").style.display = "none";
		}

}

function validate_required(field,defaultText,alerttxt)
{
with (field)
{
if (value==null||value==""||value==defaultText)
  {alert(alerttxt);return false;}
else {return true}
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}

function match_email(field1,field2,alerttxt)
{
if (field1.value!=field2.value)
  {alert(alerttxt);return false;}
else {return true}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(contactname,"contact name","Please provide a contact name...")==false)
  {contactname.focus();return false;}
if (validate_required(contactphone,"contact phone #","Please provide a contact phone number...")==false)
  {contactphone.focus();return false;}
  if (validate_required(contactmobile,"contact mobile #","Please provide a contact mobile number...")==false)
  {contactmobile.focus();return false;}
if(validate_email(contactemail,"Please provide a valid e-mail address!")==false)
  {contactemail.focus();return false;}
  if(match_email(contactemail,confirmcontactemail,"Email address' don't match, Please check.")==false)
  {contactemail.focus();return false;}
  if (validate_required(date,"date of function","Please provide the function date...")==false)
  {date.focus();return false;}
  if (validate_required(functiontype,"type of function","What kind of function is it? Morning Tea/Lunch etc?")==false)
  {functiontype.focus();return false;}
  if (validate_required(pax,"# of people","Please provide the number of people its for...")==false)
  {pax.focus();return false;}
  
 	if (deliveryorpickup[0].checked){
	//Pickup
		 if (validate_required(pickuptime,"pickup time","What time will you pick the order up?...")==false)
  			{pickuptime.focus();return false;}
	}  
	else if(deliveryorpickup[1].checked){
	//Delivery
			 if (validate_required(deliveryaddress,"delivery address","Please provide the delivery address...")==false)
  			{deliveryaddress.focus();return false;}
			if (validate_required(deliverytime,"delivery time","What time will you need the order delivered?...")==false)
  			{deliverytime.focus();return false;}
	
	}
	
	if(!sandwichesCheck.checked && !rollsCheck.checked && !fruitCheck.checked && !nibblesCheck.checked && !cheeseCheck.checked && !canapesCheck.checked && !combo1Check.checked && !combo2Check.checked && !combo3Check.checked && !morningCheck.checked && !dipsCheck.checked && !sweetsCheck.checked)
	{
		alert("Please check which menu items you are interested in...");
		sandwichesCheck.focus();
		return false;
	}
	
	
  
}
}

// send http requests
      function sendHttpRequest(url,callbackFunc,respXml){
         var xmlobj=null;
         try{
           xmlobj=new XMLHttpRequest();
         }
         catch(e){
           try{
             xmlobj=new ActiveXObject("Microsoft.XMLHTTP");
           }
           catch(e){
             alert('AJAX is not supported by your browser!');
             return false;
           }
         }
         xmlobj.onreadystatechange=function(){
           if(xmlobj.readyState==4){
             if(xmlobj.status==200){
               respXml?eval
(callbackFunc+'(xmlobj.responseXML)'):eval
(callbackFunc+'(xmlobj.responseText)');
             }
           }
         }
         // open socket connection
         xmlobj.open('GET',url,true);
         // send http header
         xmlobj.setRequestHeader('Content-Type','text/html; charset=UTF-8');
         // send http request
         xmlobj.send(null);
      }
      // display fill pop-up DIVS with server contents
      function displayResults(content){
         var popupdiv=document.getElementById('popup');
         if(!popupdiv){return};
         popupdiv.innerHTML='';
         popupdiv.innerHTML=content;
      }
      // display Pop Up div element
      function displayPopupDiv(e){
         var posx=0;
         var posy=0;
         if(!e){var e=window.event};
         // determine target DIV
         var targ=e.target?e.target:e.srcElement;
         // calculate mouse coordinates
         if(e.pageX||e.pageY){
           posx=e.pageX;
           posy=e.pageY;
         }
         else if(e.clientX||e.clientY){
           posx=e.clientX;
           posy=e.clientY;
           // check for scroll offsets in IE 6
           if(document.documentElement.scrollLeft ||
document.documentElement.scrollTop){
             posx+=document.documentElement.scrollLeft;
             posy+=document.documentElement.scrollTop;
           }
         }
         // assign attributes to pop-up DIV element and append
         // it to web document tree
         var div=document.getElementById('popup');
         if(!div){
           var div=document.createElement('div');
           div.setAttribute('id','popup');
           div.className='popupdiv';
		   div.innerHTML="<img src='./images/loading.gif'";
           document.getElementsByTagName('body')[0].appendChild
(div);
           sendHttpRequest('getMenuDetails.php?id='+targ.id,'displayResults');        
         }
         // move pop-up DIV element
         div.style.top=posy+5+'px';
         div.style.left=posx-250+'px';
      }
      // remove pop-up DIV element
      function hidePopupDiv(){
         var div=document.getElementById('popup');
         if(!div){return};
         div.parentNode.removeChild(div);
      }
      // activate pop-up DIV elements
      function activatePopupDivs(){
         var divs=document.getElementsByTagName('a');
         if(!divs){return};
         for(var i=0;i<divs.length;i++){
           if(divs[i].className=='popupcontainer'){
             // display pop-up DIV element
             divs[i].onmousemove=displayPopupDiv;
             // hide pop-up DIV element
             divs[i].onmouseout=hidePopupDiv;
           }
         }
      }
	  
	  function fNewPDFWindows()
{
	if (!document.getElementsByTagName) return false;
	 var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
	if (links[i].href.indexOf('.pdf') !== -1) {
	links[i].onclick =
	function() {
	 window.open(this.href,'popper','resizable,scrollbars,width=800,height=600');
	 return false;
	}
	links[i].title += "\n(opens in a new window)";
	var img = document.createElement("img");
	img.setAttribute("src", "/images/new-win-icon.gif");
	img.setAttribute("alt", "(opens in a new window)");
	links[i].appendChild(img);
	}
	}
}
  
