// JavaScript Document
function add()
	{
		document.getElementById('ad_tr').innerHTML='<tr><td><select name="category[]" id="category"><option value="">Select Commodity</option><?php echo commodity_dropdown();?></select></td><td>Quantity : </td><td><input type="text" id="qty" name="qty[]" size="5" /></td><td>Total $Value : </td><td><input type="text" id="amount" name="amount[]" size="5" /></td></tr>'
		}
function add_row()
{

 var ni = document.getElementById('ad_tr');
 var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+5;
  numi.value = num;
  
    var divIdName = 'ad'+num+'tr';
	var category=document.getElementById("category").value;
	var qty=document.getElementById("qty").value;
	var amount=document.getElementById("amount").value;
  xmlHttp=GetXmlHttpObject()
  var url="create_ship_row.php";
  url=url+"?page=ship_it&";
  url=url+"Select category="+category+"&qty="+qty+"&amount="+amount;
   var newdiv = document.createElement('ad_tr');
   newdiv.setAttribute('id',divIdName);
  //newdiv.innerHTML = document.getElementById('ad_tr')+'<a href=javascript:removeElement("'+divIdName+'")>Delete</a>';
  ni.appendChild(newdiv);
  //alert(url)
  xmlHttp.onreadystatechange=shomessage;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null); 
 
 }
 function removeElement(divNum) {
  var d = document.getElementById('ad_tr');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}
 function delete_row()
{
	
	
	var category=document.getElementById("category").value;
	var qty=document.getElementById("qty").value;
	var amount=document.getElementById("amount").value;
  xmlHttp=GetXmlHttpObject()
  var url="delete_ship_row.php";
  url=url+"?page=ship_it&";
  url=url+"Select category="+category+"&qty="+qty+"&amount="+amount;
  //alert(url)
  xmlHttp.onreadystatechange=shomessage1;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null); 
 
 }
 function shomessage1()
{

 if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	document.getElementById('ad_tr').innerHTML=document.getElementById('ad_tr').innerHTML-xmlHttp.responseText;
	//alert(xmlHttp.responseText);
		}
}

function GetXmlHttpObject()
    { 
      var objXMLHttp=null
        if (window.XMLHttpRequest)
         {
          objXMLHttp=new XMLHttpRequest()
       }
     else if (window.ActiveXObject)
     {
       objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
       }
         return objXMLHttp
    }
function showDiv(opendiv)
{
	if(document.getElementById(opendiv).style.display=="none")
	{
	
		document.getElementById(opendiv).style.display='block';
		return false;
		
	}
	else
	{
		document.getElementById(opendiv).style.display='none';
		
		return false;
	}
}
function showDivShip(ship_div)
{
	if(document.getElementById(ship_div).style.display=="none")
	{
	
		document.getElementById(ship_div).style.display='block';
		return false;
		
	}
	else
	{
		document.getElementById(ship_div).style.display='none';
		
		return false;
	}
}
function check_terms()
{
 if (!document.ship_pay.check.checked) 
			 {
				alert( "Please check the terms and conditions." );
				document.ship_pay.check.focus();
				return false;
			}
			else
			{
			return true;
			}
}
/////////////post the order
 
function submit_order()
{
	var cnt;
	var arr;
	cnt=document.ad_store.category.length;
	//cnt=document.getElementById('category').length;
	alert(cnt);
  xmlHttp=GetXmlHttpObject()
//  var url="create_ship_row.php";
  url=url+"?page=ship_it&";
  url=url+"Select category="+category+"&qty="+qty+"&amount="+amount;
  //alert(url)
  xmlHttp.onreadystatechange=shomessage;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null); 
 
 }
 
function submit_order1()
{
	var cnt;
	var arr;
	//cnt=document.ad_store.category.length;
	//cnt=document.getElementById('category').length;
	cnt = document.all['ad_store'].length;
		var sels=document.getElementsByTagName('select');
		alert(sels.length);
	//		for(i=0;i<=sel.length;i++){
				//		alert(sel[i]);
						
					//}
	
  xmlHttp=GetXmlHttpObject()
//  var url="create_ship_row.php";
  url=url+"?page=ship_it&";
  url=url+"Select category="+category+"&qty="+qty+"&amount="+amount;
  //alert(url)
  xmlHttp.onreadystatechange=shomessage;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null); 
 
 }
 
function shomessage()
{

 if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	//document.getElementById('ad_tr').innerHTML+=xmlHttp.responseText;
	//alert(xmlHttp.responseText);
var ni = document.getElementById('ad_tr');
 var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+5;
  numi.value = num;
    var divIdName = 'ad'+num+'tr';
	 var newdiv = document.createElement('ad_tr');
    newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = xmlHttp.responseText+'<a href=javascript:removeElement("'+divIdName+'")>Delete</a>';
  ni.appendChild(newdiv);
		}
}

function get_shipping_address(order_id,user_id)
{
		//cnt=document.getElementById('category').length;
  xmlHttp=GetXmlHttpObject()
  var url="get_address.php";
  url=url+"?order_id="+order_id;
  xmlHttp.onreadystatechange=showshipadd;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null); 
 
 }
 function showshipadd()
{

 if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	document.getElementById('show_add').innerHTML=xmlHttp.responseText;
	
		}
}


