// JavaScript Document
// NOTE: THIS CODE IS DUPLICATED IN ajax2.js - please copy to ajax2.js when done.
var xmlHttp
var ststate
var sttr
/****************************************************************************************************************/
function fillstates(str,strstate,strtr)
{
var url="/getstates.php?cid=" + str.value;
var val=str.value;
ststate=strstate;
sttr=strtr;
if(document.getElementById(sttr).style.display=="none");
document.getElementById(sttr).style.display="";
/*if(ststate=="state1")
{
	if(document.getElementById("statetr1").style.display="none");
	document.getElementById("statetr1").style.display="";
	//document.getElementById("statetr1").innerHTML="<TD class='arial_15'>Province / State:</TD><TD id='statetd'><select name="+ ststate +" id=" + ststate +" class='textfield'><option value='0'>---select state---</option></select>*</TD>";

}
else
{
   if(document.getElementById("statetr").style.display="none")
	document.getElementById("statetr").style.display="";
//document.getElementById("statetr").innerHTML="<TD class='arial_15'>Province / State:</TD><TD id='statetd'><select name="+ ststate +" id=" + ststate +" class='textfield'><option value='0'>---select state---</option></select>*</TD>";
}*/
/*if(!element)
{
//document.getElementById("statetd").innerHTML="<select name='state' id='state'></select>";
if(ststate=="state1")
{
	alert(document.getElementById("statetr1").style.display);
	document.getElementById("statetr1").style.display="";
	//document.getElementById("statetr1").innerHTML="<TD class='arial_15'>Province / State:</TD><TD id='statetd'><select name="+ ststate +" id=" + ststate +" class='textfield'><option value='0'>---select state---</option></select>*</TD>";

}
else
{
	alert(document.getElementById("statetr").style.display);
	document.getElementById("statetr").style.display="";
//document.getElementById("statetr").innerHTML="<TD class='arial_15'>Province / State:</TD><TD id='statetd'><select name="+ ststate +" id=" + ststate +" class='textfield'><option value='0'>---select state---</option></select>*</TD>";
}
var element=document.getElementById(ststate);
}*/
var element=document.getElementById(ststate);

if(str.value==0)
{
	while (element.options.length > 0)
        element.options[0] = null;
		option= new Option;
		option.value=0;
		option.text="---SELECT---";
    element.options[element.options.length] = option;
}
else
{

while (element.options.length > 0)
        element.options[0] = null;
		option= new Option;
		option.value=0;
		option.text="loading states....";
    element.options[element.options.length] = option;
xmlHttp=GetXmlHttpObject(statefillstates)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}
}


function statefillstates() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
if(xmlHttp.responseText=="")
{
/*	if(ststate=="state1")
//document.getElementById("statetr1").innerHTML="";	
document.getElementById("statetr1").style.display="none";	
else
//document.getElementById("statetr").innerHTML="";
document.getElementById("statetr").style.display="none";*/
document.getElementById(sttr).style.display="none"
}
else
fillcombo(document.getElementById(ststate),xmlHttp.responseText);
} 
}


function displaycountrydetails(str)
{
	var url="getcountrydetail.php?cid=" + str.value +"&mode=c";
	xmlHttp=GetXmlHttpObject(statedisplaycountry)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function statedisplaycountry()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		str=xmlHttp.responseText
		ele=str.split("|");
		countryname=ele[0];
		countrycode=ele[1];
		document.getElementById("wtxtModCountry").value=countryname;
		document.getElementById("wtxtModCountrycode").value=countrycode;
	}
	
}

function fillstatesformodify(str)
{
var url="getstates.php?cid=" + str.value;
var val=str.value
var element=document.getElementById("wddlState");
while (element.options.length > 0)
        element.options[0] = null;
		option= new Option;
		option.value=0;
		option.text="loading states....";
    element.options[element.options.length] = option;
xmlHttp=GetXmlHttpObject(statefillstatesformodify)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}

function statefillstatesformodify() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
fillcombo(document.getElementById("wddlState"),xmlHttp.responseText);
} 
}

function displaystatedetails(str)
{
	var url="getcountrydetail.php?cid=" + str.value +"&mode=s";
	xmlHttp=GetXmlHttpObject(statedisplaystate)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function statedisplaystate()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		str=xmlHttp.responseText
		ele=str.split("|");
		statename=ele[0];
		statecode=ele[1];
		document.getElementById("wtxtModState").value=statename;
		document.getElementById("wtxtModStatecode").value=statecode;
	}
	
}

function showpaymentmethods(id)
{
var url="/system/displaypaymentmethods.php?billid=" + id;
	xmlHttp=GetXmlHttpObject(statepaymentmethods);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}

function statepaymentmethods()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		str=xmlHttp.responseText;
		document.getElementById('tbldisplay').innerHTML=str;
	}
	
}

function delpaymentdetails(bid,mode,ptid)
{
	if(window.confirm("Confirm Delete"))
	{
	var url="/system/savepaymentmethods.php?billid=" + bid +"&ptid=" + ptid + "&mode=" + mode;
	xmlHttp=GetXmlHttpObject(statesavepaymethods)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
	}
	else
	return false;
}
function savepaymentdetails(bid,pmethod,pdesc,mode)
{
var url="/system/savepaymentmethods.php?billid=" + bid +"&pmethod=" + pmethod +"&pdesc=" + pdesc +"&mode=" + mode;
	xmlHttp=GetXmlHttpObject(statesavepaymethods)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function statesavepaymethods()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		str=xmlHttp.responseText
		arr=str.split(":");
		if(arr[1]=="success")
		{
		alert("inserted Successfully");
		showpaymentmethods(arr[0],'tbldisplay');
		}
		else
		if(arr[1]=="updated")
		{
		alert("Updated Successfully");
		showpaymentmethods(arr[0],'tbldisplay');
		}
		else
		if(arr[1]=="deleted")
		{
		alert("Deleted Successfully");
		showpaymentmethods(arr[0],'tbldisplay');
		}
		else
		
		if(arr[1]=="This method already exists")
		{
			alert("This Payment Option  already exists");
		showpaymentmethods(arr[0],'tbldisplay');
		}
		else
		if(str=="failed")
		alert("error in inserting");
	}
	
}
function swappaymentpriority(bid,priority,str)
{
	var url="/system/swappaymentpriority.php?billid=" + bid +"&priority=" + priority +"&str=" + str;
	xmlHttp=GetXmlHttpObject(stateswap)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}
function stateswap()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		 str=xmlHttp.responseText
		showpaymentmethods(str,'tbldisplay');
	}
	
}

function fillcombo(element,optionsHTML)
{
	 if(optionsHTML=="")
	 {
		 while (element.options.length > 0)
        element.options[0] = null;
		option= new Option;
		option.value=0;
		option.text="----SELECT-----";
    element.options[element.options.length] = option;
	document.getElementById("hdnsubserviceexist").value="no";
	 }
	if(optionsHTML.split("|")!="")
	{
	while (element.options.length > 0)
        element.options[0] = null;
		var ele=optionsHTML.split("|");
		option= new Option;
		option.value=0;
		option.text="----SELECT-----";
    element.options[element.options.length] = option;
	 for (var x = 0; x < ele.length-1; x=x+2)
	 {
            option = new Option;
			option.value=ele[x];
			option.text=ele[x+1];
	    element.options[element.options.length] = option;
     }
	}
}
function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
/*alert("This example doesn't work in Opera") 
return */
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 


