// JavaScript Document
var http = createRequestObject();

function createRequestObject()
 {  
	// find the correct xmlHTTP, works with IE, FF and Opera
	var xmlhttp;
	try {
  	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {
    	xmlhttp=null;
    }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function editShippingAdd()
{	
	this.setByVal("shipCo_nm",this.getByVal("upd_shipCo_nm"));
	this.setByVal("shAddr1",this.getByVal("upd_shAddr1"));
	if(this.getByVal("upd_shAddr2")!="")
	{
		this.setByVal("shAddr2",this.getByVal("upd_shAddr2"));
	}
	
	this.setByVal("shipCountry",this.getByVal("upd_shipCountry"));
	
	this.setByVal("shipState",this.getByVal("upd_shipState"));
	
	this.setByVal("shipCity",this.getByVal("upd_shipCity"));
	this.setByVal("shZipcode",this.getByVal("upd_shZipcode"));
	if(this.getByVal("upd_shPrzipcode")!="")
	{
		this.setByVal("shPrzipcode",this.getByVal("upd_shPrzipcode"));
	}
	this.setByVal("shTele",this.getByVal("upd_shTele"));
	if(this.getByVal("upd_shTele1")!="")
	{
		this.setByVal("shTele1",this.getByVal("upd_shTele1"));
	}
	if(this.getByVal("upd_shTele2")!="")
	{
		this.setByVal("shTele2",this.getByVal("upd_shTele2"));
	}
	this.setByVal("shFax",this.getByVal("upd_shFax"));
	if(this.getByVal("upd_shFax1")!="")
	{
		this.setByVal("shFax1",this.getByVal("upd_shFax1"));
	}
	if(this.getByVal("upd_shFax2")!="")
	{
		this.setByVal("shFax2",this.getByVal("upd_shFax2"));
	}
	
	document.getElementById("DivShipCo_nm").innerHTML = this.getByVal("upd_shipCo_nm");
	document.getElementById("DivShAddr1").innerHTML = this.getByVal("upd_shAddr1");
	document.getElementById("DivShAddr2").innerHTML = this.getByVal("upd_shAddr2");
	document.getElementById("DivShipCity").innerHTML = this.getByVal("upd_shipCity");
	var shZipCode = this.getByVal("upd_shZipcode");
	if(this.getByVal("upd_shPrzipcode"))
	{
		shZipCode += "-"+this.getByVal("upd_shPrzipcode");
	}
	document.getElementById("DivShZipcode").innerHTML = shZipCode;
	var shTeleNo = this.getByVal("upd_shTele");
	if(this.getByVal("upd_shTele1")!="")
	{
		shTeleNo += "-"+this.getByVal("upd_shTele1")
	}
	if(this.getByVal("upd_shTele2")!="")
	{
		shTeleNo += "-"+this.getByVal("upd_shTele2")
	}
	document.getElementById("DivShTele").innerHTML = shTeleNo;
	
	var shFaxeNo="";
	if(this.getByVal("upd_shFax")!="")
	{
		 shFaxeNo += this.getByVal("upd_shFax");
	}
	if(this.getByVal("upd_shFax1")!="")
	{
		shFaxeNo += "-"+this.getByVal("upd_shFax1")
	}
	if(this.getByVal("upd_shFax2")!="")
	{
		shFaxeNo += "-"+this.getByVal("upd_shFax2")
	}
	document.getElementById("DivSfaxno").innerHTML = shFaxeNo;
	
	// country selection
	var combo = document.getElementById("upd_shipCountry");
	document.getElementById("DivScountry").innerHTML = combo.options[combo.selectedIndex].text;
	
	var comboState = document.getElementById("upd_shipState");
	document.getElementById("DivSstate").innerHTML = comboState.options[comboState.selectedIndex].text

}

function set_shippling(obj)
		{
			//alert('testing.....................'+this.getByVal("company_nm"));	
			if (obj.checked==true)
			{
				/********* copy and display selected country ****************/
				selectObj = document.getElementById("shipCountry");
				for(index = 0; index < selectObj.length; index++)
				{
					if(selectObj[index].value == this.getByVal("Country"))
						selectObj.selectedIndex = index;
				}
				/* copy and display selected state of respective country **************/
				stateRequest_same(this.getByVal("Country"),this.getByVal("state"),"shipState");
				
				this.setByVal("shipCo_nm",this.getByVal("company_nm"));
				this.setByVal("shAddr1",this.getByVal("add1"));
				this.setByVal("shAddr2",this.getByVal("add2"));
				this.setByVal("shipCity",this.getByVal("city"));
				this.setByVal("shZipcode",this.getByVal("zipcode"));
				this.setByVal("shPrzipcode",this.getByVal("przipcode"));
				this.setByVal("shTele",this.getByVal("tele"));
				this.setByVal("shTele1",this.getByVal("tele1"));
				this.setByVal("shTele2",this.getByVal("tele2"));
				this.setByVal("shFax",this.getByVal("fax"));
				this.setByVal("shFax1",this.getByVal("fax1"));
				this.setByVal("shFax2",this.getByVal("fax2"));
			}
			else
			{
				this.setByVal("shipCo_nm",'');
				this.setByVal("shAddr1",'');
				this.setByVal("shAddr2",'');
				this.setByVal("shipCity",'');
				this.setByVal("shZipcode",'');
				this.setByVal("shPrzipcode",'');
				this.setByVal("shTele",'');
				this.setByVal("shTele1",'');
				this.setByVal("shTele2",'');
				this.setByVal("shFax",'');
				this.setByVal("shFax1",'');
				this.setByVal("shFax2",'');
			}
		}
		
		
	function getByVal(fldName)
	{
		var fldValue ='';
		//alert(fldName);
		fldValue = document.getElementById(fldName).value;
		
		return fldValue;
	}
	function setByVal(fldName,setValue)
	{
		var fldValue ='';
		//alert(fldName+" :: "+setValue);
		document.getElementById(fldName).value = setValue;
	}
	
	
	
/************* Change billing and shippign state drop-down with respective country ************/
	function changeState(id,divName,selectNm)
		{
			var url="showstate.php?cid="+id+"&divNm="+divName+"&selectNm="+selectNm;  
			http.open("GET",url,true);   
			if(divName == 'divStateInfo')
			{
				http.onreadystatechange = handleHttpResponse_stateBill; 
			}
			else if(divName == 'SH_divStateInfo')
			{
				http.onreadystatechange = handleHttpResponse_stateShip; 
			}
			else
			{
				http.onreadystatechange = handleHttpResponse_state; 
			}
			http.send(null);  
		}
		
		function handleHttpResponse_stateBill() 
		{  
			if (http.readyState == 4)
			{                
				if(http.status==200) 
				{     
					var results=http.responseText; 
					document.getElementById('divStateInfo').innerHTML = results;    
				}
			}
		}    
		
		function handleHttpResponse_stateShip() 
		{  
			if (http.readyState == 4)
			{                
				if(http.status==200) 
				{     
					var results=http.responseText; 
					document.getElementById('SH_divStateInfo').innerHTML = results;    
					
				}
			}
		}    
		
		function handleHttpResponse_state() 
		{  
			if (http.readyState == 4)
			{                
				if(http.status==200) 
				{     
					var results=http.responseText; 
					document.getElementById('StateInfo').innerHTML = results;    
					
				}
			}
		}   
		
		
	/************ Make Shipping State drop-down same as Billing drop-down ***********/	
		function stateRequest_same(id,sid,selectName)
		{
			var url="showstate.php?cid="+id+"&sid="+sid+"&selectNm="+selectName; 
			/*var answer = confirm ("https://yagna/ocb/development/"+url)
			if(answer)
			{
			 window.open("https://yagna/ocb/development/"+url);
			}*/
			http.open("GET",url,true);   
			http.onreadystatechange = handleHttpResponse_samestate; 
			http.send(null);  
		}
		
		function handleHttpResponse_samestate() 
		{              
			if (http.readyState == 4)
			{                
				if(http.status==200) 
				{     
					var results=http.responseText; 
					document.getElementById('SH_divStateInfo').innerHTML = results;    
				}
			}
		}   
		
		
/****************************************************************************/		
/**************** Check box validate for view cart items ********************/
/****************************************************************************/
function chk_delItems()
{
	var cnt_chk=0;
	var totChkBox = 0;
	for( j=0; j<document.forms[1].elements.length; j++)
	{
		if(document.forms[1].elements[j].type=="checkbox")
		{	
			totChkBox++;
			if(document.forms[1].elements[j].checked==true)
			{
				cnt_chk++;
			}	
		}
	}
	/*********** Debug code ***************/
	/*	 alert(cnt_chk +"!=="+ totChkBox)	
		return false; 					  
		else if(cnt_chk == totChkBox)
		{
			alert("Cannot remove all items from cart");
		}
	/*********** Debug code ***************/
	
		if(cnt_chk > 0)
		{
			 var del = confirm("Are you sure want to delete this. ?");
				if(del)
				{   return true; 
				}
				else
				{   return false; 
				}
		}
		else
		{	
			 alert("Select atleast one product to delete");	
			return false;
		}	
	
}

/****************************************************************************/
/****************************************************************************/
