function htmlData(url, qStr)
{
	var zoneid = document.getElementById('shipping_state').value;
	
	if(document.form_checkout.shipping_state.value!='Select State' || zoneid!='')
	{
		document.getElementById("txtResult").innerHTML= "<img src='http://www.catchallhere.com/images/LoadingProgressBar.gif' border='0'>";
	
	   if (url.length==0)
	   {
		   document.getElementById("txtResult").innerHTML="";
		   return;
	   }
	   xmlHttp=GetXmlHttpObject()
	   if (xmlHttp==null)
	   {
		   alert ("Browser does not support HTTP Request");
		   return;
	   }
	
	   url=url+"?"+qStr;
	   url=url+"&sid="+Math.random();
	   
	   xmlHttp.onreadystatechange=stateChanged;
	   xmlHttp.open("GET",url,true) ;
	   xmlHttp.send(null);  
	}
}

function GetXmlHttpObject(handler)
{
   var objXMLHttp=null
   if (window.XMLHttpRequest)
   {
       objXMLHttp=new XMLHttpRequest()
   }
   else if (window.ActiveXObject)
   {
       objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
   }
   return objXMLHttp
}


function stateChanged()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
           document.getElementById("txtResult").innerHTML= xmlHttp.responseText;
   }
   else {
           //alert(xmlHttp.status);
   }
}
function check_state()
{
	var ct='zone_id='+document.form_checkout.shipping_state.value;
	return ct;
}	

function check_form()
{
	var err=0;
	if(document.getElementById('bname').value=='')
	{
		//alert('Please Enter Billing Name');
		//document.getElementById('bname').focus();
		document.getElementById('billing_info_textbox_bname').innerHTML="&nbsp;*&nbsp;Billing Name Missing";
		document.getElementById('billing_info_textbox_bname').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_bname').innerHTML="";
	}
	if(document.getElementById('bemail').value=='')
	{
		//alert('Please Enter Billing Email');
		//document.getElementById('bemail').focus();
		document.getElementById('billing_info_textbox_bemail').innerHTML="&nbsp;*&nbsp;Billing Email Missing";
		document.getElementById('billing_info_textbox_bemail').style.color='#FF0000';
		err=1;
	}
	else
	{
		var AtPos = document.form_checkout.bemail.value.indexOf("@");
		var StopPos = document.form_checkout.bemail.value.lastIndexOf(".");
		if (AtPos == -1 || StopPos == -1) 
		{
			//alert('Not a valid email address');
			//document.getElementById('bemail').focus();
			document.getElementById('billing_info_textbox_bemail').innerHTML="&nbsp;*&nbsp;Invalide Email ID";
			document.getElementById('billing_info_textbox_bemail').style.color='#FF0000';
			err=1;
		}
		else
		{
			document.getElementById('billing_info_textbox_bemail').innerHTML="";
		}
	}
	if(document.form_checkout.bcountry.options[document.form_checkout.bcountry.selectedIndex].text=="Select Billing Country")
	{
		//alert('Please Select Billing Country');
		//document.getElementById('bcountry').focus();
		document.getElementById('billing_info_textbox_bcountry').innerHTML="&nbsp;*&nbsp;Select Billing Country";
		document.getElementById('billing_info_textbox_bcountry').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_bcountry').innerHTML="";
	}
	if(document.getElementById('bstate').value=='')
	{
		//alert('Please Enter Billing State / Province');
		//document.getElementById('bstate').focus();
		document.getElementById('billing_info_textbox_bstate').innerHTML="&nbsp;*&nbsp;Enter Billing State";
		document.getElementById('billing_info_textbox_bstate').style.color='#FF0000';
		err=1;
	}
	else
	{
			document.getElementById('billing_info_textbox_bstate').innerHTML="";	
	}
	if(document.getElementById('barea').value=='')
	{
		//alert('Please Enter Billing City / Location');
		//document.getElementById('barea').focus();
		document.getElementById('billing_info_textbox_barea').innerHTML="&nbsp;*&nbsp;Enter Billing City/Location";
		document.getElementById('billing_info_textbox_barea').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_barea').innerHTML="";
	}
	if(document.getElementById('bcontact').value=='')
	{
		//alert('Please Enter Billing Contact No.');
		//document.getElementById('bcontact').focus();
		document.getElementById('billing_info_textbox_bcontact').innerHTML="&nbsp;*&nbsp;Enter Billing Contact No.";
		document.getElementById('billing_info_textbox_bcontact').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_bcontact').innerHTML="";
	}
//Checking Shipping Details
	if(document.getElementById('dname').value=='')
	{
		//alert('Please Enter Shipping Name');
		//document.getElementById('dname').focus();
		document.getElementById('billing_info_textbox_dname').innerHTML="&nbsp;*&nbsp;Enter Shipping Name";
		document.getElementById('billing_info_textbox_dname').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_dname').innerHTML="";
	}
	if(document.form_checkout.shipping_state.options[document.form_checkout.shipping_state.selectedIndex].text=="Select State")
	{
		//alert('Please Select Shipping State');
		document.getElementById('billing_info_textbox_shipping_state').innerHTML="&nbsp;*&nbsp;Select Shipping State";
		document.getElementById('billing_info_textbox_shipping_state').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_shipping_state').innerHTML="";
	}
	if(document.form_checkout.location_id.options[document.form_checkout.location_id.selectedIndex].text=="Select Location")
	{
		alert('Please Select Shipping City / Location\n\rFollow the The RED marks fields');
		err=1;
		return false;
	}
	if(document.getElementById('daddress').value=='')
	{
		//alert('Please Enter Shipping Address');
		//document.getElementById('daddress').focus();
		document.getElementById('billing_info_textbox_daddress').innerHTML="&nbsp;*&nbsp;Enter Shipping Address";
		document.getElementById('billing_info_textbox_daddress').style.color='#FF0000';
		err=1;
	}
	else
	{
		document.getElementById('billing_info_textbox_daddress').innerHTML="";	
	}
	if(document.getElementById('dzip').value=='')
	{
		//alert('Please Enter Shipping ZipCode');
		//document.getElementById('dzip').focus();
		document.getElementById('billing_info_textbox_dzip').innerHTML="&nbsp;*&nbsp;Enter Shipping Zip";
		document.getElementById('billing_info_textbox_dzip').style.color='#FF0000';
		err=1;
	}
	else
	{	
		document.getElementById('billing_info_textbox_dzip').innerHTML="";
	}
	
	if(err==1)
	{
		alert("Please Fill up the form carefully.\n\rFollow the The RED marks fields");	
		return false;
	}
}

function getHTTPObject()
{
   	if (window.ActiveXObject)
       return new ActiveXObject("Microsoft.XMLHTTP");   
	else 
	if (window.XMLHttpRequest)
	   return new XMLHttpRequest();   
	else 
	{      
		alert("Your browser does not support AJAX.");      
		return null;   
	}
}
function createObject() 
{
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		request_type = new XMLHttpRequest();
	}
	return request_type;
}
var http = createObject();

function get_coupon()
{
	var code=document.getElementById('coupon_code').value;
	var total=document.getElementById('cart_total').value;
	var table_id=document.getElementById('table_id').value;

// Optional: Show a waiting message in the layer with ID ajax_response
	document.getElementById('coupon_status').innerHTML = "Updating ......"
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	//var code=document.getElementById('coupon_code').value;
	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	var url='check_coupon.php?code='+code+'&&cart_total='+total+'&&table_id='+table_id+'&&nocache = '+nocache;
	//alert(url);
	http.open('get', url,true);
	
	http.onreadystatechange = loginReply;
	http.send(null);
}
function loginReply() 
{
	if(http.readyState == 2)
	{
		document.getElementById('coupon_status').innerHTML = "Searching ....";
	}
	if(http.readyState == 3)
	{
		document.getElementById('coupon_status').innerHTML = "Searching ...";
	}
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 0)
		{
			document.getElementById('coupon_status').innerHTML = '<font color=#ff0000>Invalid Coupon</font>';
			//document.getElementById('coupon_error').value='User name error';
			//document.getElementById('user').focus();
			alert('Invalid Coupon');
			window.location='paynow.html';
		} 
		else
		if(response == 1)
		{
			//document.getElementById('coupon_status').innerHTML='<font color=#1c6702>Congrats...</font>';
			//document.getElementById('user_error').value='';
			window.location='paynow.html';
		}
		else
		if(response == 2)
		{
			document.getElementById('coupon_status').innerHTML='<font color=#ff0000>Invalid Coupon</font>';			
			alert('Invalid Coupon');
			window.location='paynow.html';
		}
		else
		if(response == 3)
		{
			document.getElementById('coupon_status').innerHTML='<font color=#ff0000>Invalid Coupon</font>';
			//document.getElementById('coupon_error').value='User name error';
			//document.getElementById('user').focus();
			alert('Invalid Coupon');
			window.location='paynow.html';
		}
	}
}

function update_cart(ids)
{
	var qty=document.getElementById(ids).value;
	url='http://www.catchallhere.com/my_cart/update/'+ids+'/'+qty;
	window.location=url;
}
