function deliveryCourier()
{
	document.getElementById("deliveryCourier").style.display = 'block';
  	document.getElementById("pickUp").style.display = 'none';
	document.getElementById("deliveryBymail").style.display = 'none';
}

function pickUp()
{
	document.getElementById("deliveryCourier").style.display = 'none';
	document.getElementById("pickUp").style.display = 'block';
	document.getElementById("deliveryBymail").style.display = 'none';
}

function deliveryBymail()
{
	document.getElementById("deliveryCourier").style.display = 'none';
	document.getElementById("pickUp").style.display = 'none';
	document.getElementById("deliveryBymail").style.display = 'block';
}

function checkPickUp()
{
	$FirstName = document.getElementById("FirstName").value
	$LastName = document.getElementById("LastName").value
	$Phone = document.getElementById("Phone_2").value	
    $delivery = document.getElementById("delivery_pickup").value
    
    $FirstName = TrimStr($FirstName);    
	$LastName = TrimStr($LastName);
	$Phone = TrimStr($Phone);	
	
	if ($FirstName=="" || $LastName=="" || $Phone=="")
	{
		alert("Заполнены не все поля формы");
		
	}	
	else
	{
		var xmlhttp = createXmlHttpRequestObject()
        xmlhttp.open('GET', 'ajax/saveData.php?FirstName='+encodeURIComponent($FirstName)+'&LastName='+encodeURIComponent($LastName)+'&Phone='+encodeURIComponent($Phone)+'&delivery='+encodeURIComponent($delivery),false);
        xmlhttp.send(null); 
        if(xmlhttp.status == 200) 
        {        	
        	goStep2();
        }
	}
}

function checkDeliveryBymail()
{	
	$Country = document.getElementById("Country_mail").value
	$PostIndex = document.getElementById("PostIndex_mail").value
	$SubRegion = document.getElementById("SubRegion_mail").value
	$Town = document.getElementById("Town_mail").value
	$Adress = document.getElementById("Adress_mail").value
	$FirstName = document.getElementById("FirstName_mail").value
	$LastName = document.getElementById("LastName_mail").value
	$Phone = document.getElementById("Phone_mail").value
	
	$Country = TrimStr($Country);    
	$PostIndex = TrimStr($PostIndex);    
	$SubRegion = TrimStr($SubRegion);    
	$Town = TrimStr($Town);    
	$Adress = TrimStr($Adress);    
	$FirstName = TrimStr($FirstName);    
	$LastName = TrimStr($LastName);
	$Phone = TrimStr($Phone);
	
	$delivery = document.getElementById("delivery_mail").value
	
	if ($Country=="" || $PostIndex=="" || $SubRegion=="" || $Town=="" || $Adress=="" || $FirstName=="" || $LastName=="" || $Phone=="")
	{
		alert("Заполнены не все поля формы");
	}
	else
	{
	    var xmlhttp = createXmlHttpRequestObject()
        xmlhttp.open("GET", "ajax/saveData.php?Country="+encodeURIComponent($Country)+"&PostIndex="+encodeURIComponent($PostIndex)+"&SubRegion="+encodeURIComponent($SubRegion)+"&Town="+encodeURIComponent($Town)+"&Adress="+encodeURIComponent($Adress)+"&FirstName="+encodeURIComponent($FirstName)+"&LastName="+encodeURIComponent($LastName)+"&Phone="+encodeURIComponent($Phone)+"&delivery="+encodeURIComponent($delivery),false);
        xmlhttp.send(null); 
        if(xmlhttp.status == 200) 
        {
        	goStep2();
        }
	}
}

function checkDeliveryCourier()
{	
	$Town = document.getElementById("Town_courier").value
	$Adress = document.getElementById("Adress_courier").value
	$FirstName = document.getElementById("FirstName_courier").value
	$LastName = document.getElementById("LastName_courier").value
	$Phone = document.getElementById("Phone_courier").value

	$Town = TrimStr($Town);    
	$Adress = TrimStr($Adress);    
	$FirstName = TrimStr($FirstName);    
	$LastName = TrimStr($LastName);
	$Phone = TrimStr($Phone);
	
	$delivery = document.getElementById("delivery_courier").value
	
	if ($Town=="" || $Adress=="" || $FirstName=="" || $LastName=="" || $Phone=="")
	{
		alert("Заполнены не все поля формы");
	}
	else
	{
	    var xmlhttp = createXmlHttpRequestObject()
        xmlhttp.open('GET', 'ajax/saveData.php?Town='+encodeURIComponent($Town)+'&Adress='+encodeURIComponent($Adress)+'&FirstName='+encodeURIComponent($FirstName)+'&LastName='+encodeURIComponent($LastName)+'&Phone='+encodeURIComponent($Phone)+'&delivery='+encodeURIComponent($delivery),false);
        xmlhttp.send(null);         
        if(xmlhttp.status == 200) 
        {
            goStep2();        	
           //alert(xmlhttp.responseText);        
        }	
	}
}

function goStep2()
{	
	window.location.href = "http://bookhunter.ru/index.php?flag=doOrder&step=2";  		
	//window.location.href = "http://localhost/bookhunter/index.php?flag=doOrder&step=2";  		
}

function finishOrder()
{	 
	 $comment = document.getElementById("comment").value;
	 var xmlhttp = createXmlHttpRequestObject()	 	 
	 xmlhttp.open("GET", "ajax/finishOrder.php?comment="+encodeURIComponent($comment),false);
     xmlhttp.send(null); 
     if(xmlhttp.status == 200) 
     {
     	window.location.href = "http://bookhunter.ru/index.php?flag=doOrder"; 	
     	//window.location.href = "http://localhost/bookhunter/index.php?flag=doOrder";  		
     }		
}

function endOrder()
{	 
	 var xmlhttp = createXmlHttpRequestObject()	 		   
	 xmlhttp.open("GET", "ajax/endOrder.php",false);
     xmlhttp.send(null); 
    
     if(xmlhttp.status == 200) 
     {
     	window.location.href = "http://bookhunter.ru/index.php?flag=basket";	
     	//window.location.href = "http://localhost/bookhunter/index.php?flag=basket";  		
     }	
}

function TrimStr(s) {
  s = s.replace( /^\s+/g, '');
  return s.replace( /\s+$/g, '');
}
