<!-- This file Contains all the function that are related to user section-->

	 function ValidateDeleteOrder()
	{
	    var ch=0;
	    len = document.frmlist.elements.length;
		var i=0;
		for( i=0 ; i<len ; i++) 
		{
		
			if (document.frmlist.elements[i].name=='chk_id[]') 
				{
	
					if (document.frmlist.elements[i].checked==1)
						{
					
							ch = 1;
						}
				}
		}	
	
		if (ch == 1)
		{
			if(confirm('Confirm Delete'))
			{
				//document.frmlist.action="submit.php?mode=deletecrewcategory";
				//document.frmlist.submit();
				deleteorder();
			}
			else 
				return false;

		}
		else
		{
			alert("Please Select Order(s) to delete.");	
			return false;
		}
	}

 
function deleteorder()
 {
			var a_arry=new Array(); 
			 var checkLen=document.getElementsByName('chk_id[]').length;
			//alert(checkLen);
			var y=0;
		   for(i=0;i<checkLen;i++)
			 {	//alert(i); 
				if(document.all.frmlist.elements[i].checked==true) 
				 { 	    
								   var arry=document.all.frmlist.elements[i].value;
								  // alert(arry);
								   var x=arry.length;
								   //alert(x);
								   a_arry[y]=arry;
									   y++;
				  }
				
			 }
			 var arrycount=a_arry.length;
			 //alert(arrycount);
  //var url='display_company.php?DELETE='+DELETE+'&arrycount='+arrycount+'&a_arry='+a_arry;  
  			var xmlhttp1 = new cl_xmlHttpObject();				
			xmlhttp1.open("POST","delete_order.php?arrycount="+arrycount+"&a_arry="+a_arry,true);
				xmlhttp1.onreadystatechange = function()
			{
				 if (xmlhttp1.readyState <4) {
	 
						 document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
						  //display_info(xmlhttp1.responseText);
	  
					  }
					  else if(xmlhttp1.readyState ==4)
							{
								if(xmlhttp1.status==200)
								{
									get_message(xmlhttp1.responseText)
									GetOrderInfo();
									//display_info(xmlhttp1.responseText);
								}
								else
								{
								display_info("An Error Occured:"+ xmlhttp1.statusText);
								}
							}
			};
    	   xmlhttp1.send(null);  

 }

	
	function PlaceOrdersInfo(page,id)
	{
		var id= id;
		var page= page;
		//var sid = document.getElementById("txtcustomerid").value;
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","order_list.php?page="+page+"&id="+id,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			 if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
	
	
function PlaceOrdersInfo1(page,id)
	{
		var id= id;
		var page= page;
		//var sid = document.getElementById("txtcustomerid").value;
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","order_list.php?page="+page+"&id="+id,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			 if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
		
	
	
	
	

function EditOrderInfo(orderid)
	{   	//alert(orderid);		
       	var orderid= orderid;
		var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","edit_order.php?id="+orderid,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		 if (xmlhttp1.readyState <4) {
 
                     document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
    }







function UpdateOrderInfo(id)
	{   
		//var sid = document.getElementById("txtcustomerid").value;		
       var xmlhttp1 = new cl_xmlHttpObject();
	  			
			if(id)
			{
				var id= id;
				var mode = "Edit";
				var service = document.getElementById("txtservice").value;
				var project = document.getElementById("txtproject").value;
				var concept = document.getElementById("txtconcept").value;
				var userid = document.getElementById("txtuserid").value;
				var status = document.getElementById("txtstatus").value;
				var shippingcharges = document.getElementById("txtshippingcharges").value;
				var budgetcost = document.getElementById("txtbudgetcost").value;
				var realcost = document.getElementById("txtrealcost").value;				
				var startdate = document.getElementById("txtstartdate").value;
				var finishdate = document.getElementById("txtfinishdate").value;
				var urlworkfolder = document.getElementById("txturlworkfolder").value;	
				
				var txtstaus_first = document.getElementById("txtstaus_first").value;
				var txt_firstcost = document.getElementById("txt_firstcost").value;	
				var txtstartdate_firstmiles = document.getElementById("txtstartdate_firstmiles").value;
				var txtfinishdate_firstmiles = document.getElementById("txtfinishdate_firstmiles").value;
				
				var txtstaus_second = document.getElementById("txtstaus_second").value;
				var txt_secondcost = document.getElementById("txt_secondcost").value;	
				var txtstartdate_secondmiles = document.getElementById("txtstartdate_secondmiles").value;
				var txtfinishdate_secondmiles = document.getElementById("txtfinishdate_secondmiles").value;
				
				var txtstaus_third = document.getElementById("txtstaus_third").value;
				var txt_thirdcost = document.getElementById("txt_thirdcost").value;	
				var txtstartdate_thirdmiles = document.getElementById("txtstartdate_thirdmiles").value;
				var txtfinishdate_thirdmiles = document.getElementById("txtfinishdate_thirdmiles").value;
				
				var txtstaus_fourth = document.getElementById("txtstaus_fourth").value;
				var txt_fourthcost = document.getElementById("txt_fourthcost").value;	
				var txtstartdate_fourthmiles = document.getElementById("txtstartdate_fourthmiles").value;
				var txtfinishdate_fourthmiles = document.getElementById("txtfinishdate_fourthmiles").value;
				
				xmlhttp1.open("POST","add_order_submit.php?id="+id+"&mode="+mode+"&service="+service+"&project="+project+"&concept="+concept+"&userid="+userid+"&status="+status+"&budgetcost="+budgetcost+"&realcost="+realcost+"&startdate="+startdate+"&finishdate="+finishdate+"&urlworkfolder="+urlworkfolder+"&txtstaus_first="+txtstaus_first+"&txtstartdate_firstmiles="+txtstartdate_firstmiles+"&txtfinishdate_firstmiles="+txtfinishdate_firstmiles+"&txtstaus_second="+txtstaus_second+"&txtstartdate_secondmiles="+txtstartdate_secondmiles+"&txtfinishdate_secondmiles="+txtfinishdate_secondmiles+"&txtstaus_third="+txtstaus_third+"&txtstartdate_thirdmiles="+txtstartdate_thirdmiles+"&txtfinishdate_thirdmiles="+txtfinishdate_thirdmiles+"&txtstaus_fourth="+txtstaus_fourth+"&txtstartdate_fourthmiles="+txtstartdate_fourthmiles+"&txtfinishdate_fourthmiles="+txtfinishdate_fourthmiles+"&txt_firstcost="+txt_firstcost+"&txt_secondcost="+txt_secondcost+"&txt_thirdcost="+txt_thirdcost+"&txt_fourthcost="+txt_fourthcost,true);
	
			}
			else
			{
				var mode = "Add"
				var service = document.getElementById("txtservice").value;
				var project = document.getElementById("txtproject").value;
				var concept = document.getElementById("txtconcept").value;
				var userid = document.getElementById("txtuserid").value;
				var status = 'Pending';
				var shippingcharges = '';
				var budgetcost = document.getElementById("txtbudgetcost").value;
				var realcost = document.getElementById("txtrealcost").value;				
				var startdate = document.getElementById("txtstartdate").value;
				var finishdate = document.getElementById("txtfinishdate").value;
				var urlworkfolder = document.getElementById("txturlworkfolder").value;	
				
				var txtstaus_first = 'Started';
				var txt_firstcost = document.getElementById("txt_firstcost").value;
				var txtstartdate_firstmiles = document.getElementById("txtstartdate_firstmiles").value;
				var txtfinishdate_firstmiles = document.getElementById("txtfinishdate_firstmiles").value;
				
				var txtstaus_second = 'Started';	
				var txt_secondcost = document.getElementById("txt_secondcost").value;
				var txtstartdate_secondmiles = document.getElementById("txtstartdate_secondmiles").value;
				var txtfinishdate_secondmiles = document.getElementById("txtfinishdate_secondmiles").value;
				
				var txtstaus_third = 'Started';
				var txt_thirdcost = document.getElementById("txt_thirdcost").value;
				var txtstartdate_thirdmiles = document.getElementById("txtstartdate_thirdmiles").value;
				var txtfinishdate_thirdmiles = document.getElementById("txtfinishdate_thirdmiles").value;
				
				var txtstaus_fourth = 'Started';
				var txt_fourthcost = document.getElementById("txt_fourthcost").value;
				var txtstartdate_fourthmiles = document.getElementById("txtstartdate_fourthmiles").value;
				var txtfinishdate_fourthmiles = document.getElementById("txtfinishdate_fourthmiles").value;
				xmlhttp1.open("POST","add_order_submit.php?mode="+mode+"&service="+service+"&project="+project+"&concept="+concept+"&userid="+userid+"&status="+status+"&budgetcost="+budgetcost+"&realcost="+realcost+"&startdate="+startdate+"&finishdate="+finishdate+"&urlworkfolder="+urlworkfolder+"&txtstaus_first="+txtstaus_first+"&txtstartdate_firstmiles="+txtstartdate_firstmiles+"&txtfinishdate_firstmiles="+txtfinishdate_firstmiles+"&txtstaus_second="+txtstaus_second+"&txtstartdate_secondmiles="+txtstartdate_secondmiles+"&txtfinishdate_secondmiles="+txtfinishdate_secondmiles+"&txtstaus_third="+txtstaus_third+"&txtstartdate_thirdmiles="+txtstartdate_thirdmiles+"&txtfinishdate_thirdmiles="+txtfinishdate_thirdmiles+"&txtstaus_fourth="+txtstaus_fourth+"&txtstartdate_fourthmiles="+txtstartdate_fourthmiles+"&txtfinishdate_fourthmiles="+txtfinishdate_fourthmiles+"&txt_firstcost="+txt_firstcost+"&txt_secondcost="+txt_secondcost+"&txt_thirdcost="+txt_thirdcost+"&txt_fourthcost="+txt_fourthcost,true);
	
			}
	
	
        xmlhttp1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

        xmlhttp1.onreadystatechange = function()
    	{
    		
			
			if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								get_message(xmlhttp1.responseText)
								PlaceOrdersInfo();
								//display_info(xmlhttp1.responseText);								
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
						
    	};

    xmlhttp1.send(null);
    }
	
	
	
	
	
	
	
function AddOrderInfo()
	{   			
       	var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","edit_order.php",true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
}
	
	
	
	
	
	
	
	
	function CallOrderCancel()
	{  
		
		var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","order_list.php",true);
        xmlhttp1.onreadystatechange = function()
    	{
    		if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
    }
