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 RemoveFromCart(cid)
{
	
	var agree = confirm("Are you sure to delete from cart?");
	if(agree)
	{
		var url = "controller/ctl_remove_cart.php?cid=" + cid;
		window.location.href = url;
	}
	else
	{
		return false;
	}
}
function ProceedCheckout()
{
	
	var bill = document.getElementById('totalbill');
	if(bill.value=="" || bill.value == null || bill.value == '0')
	{
		alert('You have no Item(s) in your shopping cart');
		return false;
	}
	else
	{	
		var url = "pages-billship.html";
		document.location.href = url;
	}			 		 
}
function ViewOrderDetails(ordernumber)
{
	var url = 'order_details.php?id=' + ordernumber;
	window.open(url,'Order Details Window', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=1000, scrollbars=1');

}
function emailcheck(str) 
{

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 return true					
}
function contactvalidation()
{
	var fname = document.contact.fname;
	if(fname.value == "" || fname.value==null || name.value=='Name')
	{
		alert('Please Enter First Name');
		fname.focus();
		return false;
	}
	
	var lname = document.contact.lname;
	if(lname.value == "" || lname.value==null || lname.value=='Name')
	{
		alert('Please Enter Last Name');
		lname.focus();
		return false;
	}
	
	var emailID = document.contact.email;
	if ((emailID.value==null)||(emailID.value=="")||(emailID.value=="Email"))
	{
		alert("Please Enter Email ID");
		emailID.focus();
		return false;
	}
	
	if (emailcheck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		return false;
	}
	
	var phone = document.contact.phoneno;
	if(phone.value==null || phone.value=="")
	{
		alert('Please Enter Phone Number');
		phone.focus();
		return false;
	}
	
	if(checkPhone(phone.value)==false)
	{
		phone.value="";
		phone.focus();
		return false;
	}	
	
	var comment = document.contact.detail;
	if(comment.value == "" || comment.value==null)
	{
		alert('Please Enter Your Detail');
		comment.focus();
		return false;
	}
	
	var security_code = document.contact.security_code;
	if(security_code.value == "" || security_code.value==null)
	{
		alert('Please Enter Security Code');
		security_code.focus();
		return false;
	}
	
				
	return true;
}
function newvald()
{
	var emailID = document.newsletter.email;
	if ((emailID.value==null)||(emailID.value=="")||(emailID.value=="Email"))
	{
		alert("Please Enter Email ID");
		emailID.focus();
		return false;
	}
	if (emailcheck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		return false;
	}					
	return true;
}
function checkPhone(str) 
{
	var phone2 = /^(([0-9]{1})*[- -(]*([0-9a-zA-Z]{3})*[- -)]*[0-9a-zA-Z]{3}[- -]*[0-9a-zA-Z]{4})+$/; 
	if (str.match(phone2)) 
	{
   		//return true;
 	} 
	else 
	{
 		alert('Please Enter validate Phone e.g: 1-345-123-4567');
		return false;
 	}
}
function SetPaymentmode(id)
{
	var url = "controller/ctl_paymentmodes.php?id=" + id;
	httpObject =  getHTTPObject();
	if(httpObject!=null)
	{
		httpObject.open("GET",url,true);
		httpObject.send(null);
		httpObject.onreadystatechange = GetReplyship; 
	}
}
