var reqObj = null;
function createRequest(){
	try {
	   reqObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (err)	{
			try {
			reqObj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (err2) {
			try {
			   reqObj = new XMLHttpRequest();
			}
			catch (err3) {
			   reqObj = null;
			}
		}
	}
	return reqObj;
}
function addCart1(prod,price,qty){
	xmlhttp = createRequest();
	if(xmlhttp != null){
			//var att_val = getattributes(ckname);
		var param    = 'pid=' + prod + '&qty=' + qty + '&price=' + price  + '&action=add2cart';
		
		//if(att_val != '')
			//param += '&atts=' + att_val;
		xmlhttp.open("POST", "add2cart.php?rand="+Math.random(1,10), true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", param.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = echoCart;
		xmlhttp.send(param);
	}
}

function pop_addCart(prod){
	if(prod != ''){
		xmlhttp = createRequest();
		if(xmlhttp != null){
			var prod_arr = prod.split('#');
			var pid   = prod_arr[0];
			var price = prod_arr[1];
			var param = 'pid=' + pid + '&qty=1&price=' + price  + '&action=add2cart';
			
			xmlhttp.open("POST", "add2cart.php?rand="+Math.random(1,10), true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", param.length);
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.onreadystatechange = echoCart;
			xmlhttp.send(param);
			closepopup();
		}
	}
}

function addCart_meal(prod, hiddengroup, buttongroup){
	if(prod != ''){
		xmlhttp = createRequest();
		if(xmlhttp != null){
			var prod_arr = prod.split(',');
			if(prod_arr.length != 3){
				alert('You have not selected products from all the three options (Curry, Vegetable, Rice)');
			}
			else{

				var param = 'prod=' + prod + '&action=meal2cart';

				frm=document.mnufrm;
				element_len = frm.elements.length;
				for (i=0; i<element_len; i++){
					this_element = frm.elements[i]; 
					if (this_element.type == 'hidden' && this_element.name.match(hiddengroup)){
						this_element.value = '0';
					}

					if (this_element.type == 'button' && this_element.name.match(buttongroup)){
						this_element.style.backgroundColor="#F8F8FC";
						this_element.style.color="#030";
					}
				}

				frm.prod.value = '';
				
				xmlhttp.open("POST", "add2cart.php?rand="+Math.random(1,10), true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", param.length);
				xmlhttp.setRequestHeader("Connection", "close");
				xmlhttp.onreadystatechange = echoCart;
				xmlhttp.send(param);
			}
		}
	}
	else{
		alert('You have not selected products from all the three options (Curry, Vegetable, Rice)');
	}
}

function selectitems(id, selpro, selobj, price, hiddengroup, buttongroup){
	frm=document.mnufrm;
	if(selpro.value=='0'){

		element_len = frm.elements.length;
		for (i=0; i<element_len; i++){
			this_element = frm.elements[i]; 
			if (this_element.type == 'hidden' && this_element.name.match(hiddengroup)){
				this_element.value = '0';
			}

			if (this_element.type == 'button' && this_element.name.match(buttongroup)){
				this_element.style.backgroundColor="#F8F8FC";
				this_element.style.color="#030";
			}
		}

		selpro.value = id+'@'+price;
		selobj.style.backgroundColor="#47AB47";
		selobj.style.color="#FFFFFF";

	}

	var selected_prod = '';
	element_len = frm.elements.length;
	for (i=0; i<element_len; i++){
		this_element = frm.elements[i]; 
		if (this_element.type == 'hidden' && this_element.name.match('sel_prod_') && this_element.value != '0'){
			selected_prod += this_element.value + ',';
		}
	}

	selected_prod = selected_prod.substring(0, (selected_prod.length-1));
	frm.prod.value = selected_prod;
}

function delCart(cbid) {
	xmlhttp = createRequest();
	if(xmlhttp != null){
		var param    = 'cbid=' + cbid  + '&action=del';
		xmlhttp.open("POST", "add2cart.php?rand="+Math.random(1,10), true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", param.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = echoCart;
		xmlhttp.send(param);
	}
}

function showCart() {
	xmlhttp = createRequest();
	if(xmlhttp != null){
		var param    = '';
		xmlhttp.open("POST", "add2cart.php?rand="+Math.random(1,10), true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", param.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = echoCart;
		xmlhttp.send(param);
	}
}


function emptyCart(cbid) {
	if(confirm("Are you sure to empty cart?")){
		xmlhttp = createRequest();
		if(xmlhttp != null){
			var param    = '&action=delall';
			xmlhttp.open("POST", "add2cart.php?rand="+Math.random(1,10), true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", param.length);
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.onreadystatechange = echoCart;
			xmlhttp.send(param);
		}
	}
}

function echoCart(){
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var text1  = xmlhttp.responseText;
			document.getElementById('mini_cart_result').innerHTML = text1;
		}
	}
	return true;
}

function pop_additems(prod, opt){
        if(opt==3)
            {
                meat=1;
            }
        else if(opt==5)
            {
                veg=1;
            }
        else if(opt==4)
            {
                rice=1;
            }
        else if(opt==2)
            {
                other=1;
            }

	if(prod != ''){
		xmlhttp = createRequest();
		if(xmlhttp != null){
			var prod_arr = prod.split('#');
			var pid   = prod_arr[0];
			var price = prod_arr[1];
			var param = 'opt='+opt +'&pid=' + pid + '&qty=1&price=' + price  + '&action=add2cart';
			
			xmlhttp.open("POST", "popupmenu.php?rand="+Math.random(1,10), true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", param.length);
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.onreadystatechange = echoCart2;
			xmlhttp.send(param);
			closepopup();
		}
	}
}
function echoCart2(){
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var responsetxt  = xmlhttp.responseText;
                        var text_arr = responsetxt.split("###");
			/*if(text_arr['0'] == 0)
				document.getElementById('inst').innerHTML = '';
			else
				document.getElementById('inst').innerHTML = text_arr['0'];*/

			if(text_arr['1'] != '0')
				document.getElementById('mini_cart_result').innerHTML =text_arr['1'];
		}
	}
	return true;
}


/*function getattributes(chkname){
	var frm = document.mnufrm
	var att_arr = '';
	element_len = frm.elements.length;
	for (i=0; i<element_len; i++){
		this_element = frm.elements[i]; 
		if (this_element.type == 'checkbox' && this_element.checked == true && this_element.name.match(chkname)){
			att_arr += this_element.value + ',';
		}
		if (this_element.type == 'select-one' && this_element.value != '' && this_element.name.match(chkname)){
			att_arr += this_element.value + ',';
		}
	}

	return att_arr.substring(0, (att_arr.length-1));
}*/

function openpopup_printpage(theURL){
    window.open(theURL,'printpage','scrollbars,resizable,height=550,width=300');
}


function windowopen(URL,widthwin,heightwin){
	 var screenH = screen.height;
	 var screenW = screen.width;
	 var fromLeft = parseInt((screenW-widthwin)/2);
	 var fromTop = parseInt((screenH-heightwin)/2);
	var newwin=window.open(URL,'invitation_guest_email','width='+widthwin+',height='+heightwin+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,top='+fromTop+',left='+fromLeft)
	if(window.focus) newwin.focus();
}

function chk_availabilty(chkval){				
	if(chkval != ''){
		xmlhttp = createRequest();
		if(xmlhttp != null){
			xmlhttp.open("GET", "postcode.php?tochk="+chkval+"&rand="+Math.random(1,10), true);
			xmlhttp.onreadystatechange = post_chk_availabilty;
			xmlhttp.send(null);
		}
	}
	else{
		alert("Enter your postcode");
		return;
	}
}

function post_chk_availabilty(){
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var text1  = xmlhttp.responseText;
			document.getElementById('chkresult').innerHTML = text1;
		}
	}
	return true;
}

function postcode_checker(pcode){
	if(pcode != ''){
		xmlhttp = createRequest();
		postcode_status = '';
		if(xmlhttp != null){
			document.getElementById('chkresult').innerHTML = '';
			document.getElementById('chkresult').innerHTML = "Validating Postcode...";
			xmlhttp.onreadystatechange = doValidate;
			xmlhttp.open("GET", "SimplyLookup/ajx_postcode_checker.php?postcode="+pcode+"&rand="+Math.random(1,10), true);
			xmlhttp.send(null);
		}
	}
	else{
		alert("Enter your postcode");
		return;
	}
}

function doValidate(){
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var text1  = xmlhttp.responseText;
			alert(text1);
			if(text1 == 0){
				document.getElementById('chkresult').innerHTML = 'Invalid postcode!';
			}
			else{
				document.getElementById('chkresult').innerHTML = text1;
			}
		}
	}
}


function postcode_validate(pcode){
	if(pcode != ''){
		xmlhttp = createRequest();
		postcode_status = '';
		if(xmlhttp != null){
			xmlhttp.open("GET", "SimplyLookup/ajx_postcode_checker.php?postcode="+pcode+"&rand="+Math.random(1,10), true);
			xmlhttp.onreadystatechange = pValidate;
			xmlhttp.send(null);
		}
	}
}
var postchkstatus=0;
function pValidate(){
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var text1  = xmlhttp.responseText;

			if(text1 == 0){
				//alert('Invalid postcode!');
				postchkstatus=1;
			}
			else{
				postchkstatus=0;
			}
		}
	}
}

function showoption(arg){
	if (arg == 1) {
		document.getElementById('individual').style.display = 'none';
		document.getElementById('meal').style.display = '';
	}
	else{
		document.getElementById('meal').style.display = 'none';
		document.getElementById('individual').style.display = '';
	}

}