// JavaScript Document


function selectAllCheckBoxes(thisobj,id,num){
	if(thisobj.checked==true){
		for(var c=1; c<=num; c++){
			document.getElementById(id+c).checked=true;
		}
		
	}else{
		for(var c=1; c<=num; c++){
			document.getElementById(id+c).checked=false;
		}
		
	}
}

var xmlHttp
function validations(str,id)
{
		//alert(str);
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  } 
	var url="./include/ajx.php"
	url=url+"?str="+encodeURIComponent(str);
	url=url+"&id="+id
	url=url+"&sid="+Math.random()
	//url=escape(url);
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 

function stateChanged() 
{ 
	//document.forml.create.disabled = true;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var str=xmlHttp.responseText
			//alert(str);
		var arr=str.split("##");
		var part_num=0;
		while (part_num < arr.length){
			part_num = part_num+1;
		}
		
		switch (arr[0])
		{
		
		case 'find_state':
			//alert(arr[1]);
			if(arr[2]=="true"){
				var counties = arr[1].split("%%");
				var countiesid = arr[3].split("%%");
				document.getElementById("find_county").options.length=0;
				for(var state_num = 0;state_num < counties.length; state_num++){
					var oOption = document.createElement("OPTION");
					document.getElementById("find_county").options.add(oOption);
					oOption.text = counties[state_num];
					oOption.value = countiesid[state_num];
				}
			}
			break;

		case 'sell_state':
			//alert(arr[1]);
			if(arr[2]=="true"){
				var counties = arr[1].split("%%");
				var countiesid = arr[3].split("%%");
				document.getElementById("sell_county").options.length=0;
				for(var state_num = 0;state_num < counties.length; state_num++){
					var oOption = document.createElement("OPTION");
					document.getElementById("sell_county").options.add(oOption);
					oOption.text = counties[state_num];
					oOption.value = countiesid[state_num];
				}
			}
			break;

		case 'register_state':
			//alert(arr[1]);
			if(arr[2]=="true"){
				var counties = arr[1].split("%%");
				var countiesid = arr[3].split("%%");
				document.getElementById("register_county").options.length=0;
				for(var state_num = 0;state_num < counties.length; state_num++){
					var oOption = document.createElement("OPTION");
					document.getElementById("register_county").options.add(oOption);
					oOption.text = counties[state_num];
					oOption.value = countiesid[state_num];
				}
			}
			break;

		case 'packa_state':
			//alert(arr[1]);
			if(arr[2]=="true"){
				var counties = arr[1].split("%%");
				var countiesid = arr[3].split("%%");
				document.getElementById("packa_county").options.length=0;
				for(var state_num = 0;state_num < counties.length; state_num++){
					var oOption = document.createElement("OPTION");
					document.getElementById("packa_county").options.add(oOption);
					oOption.text = counties[state_num];
					oOption.value = countiesid[state_num];
				}
			}
			break;

		case 'iedit_state':
			//alert(arr[1]);
			if(arr[2]=="true"){
				var counties = arr[1].split("%%");
				var countiesid = arr[3].split("%%");
				document.getElementById("packa_county").options.length=0;
				for(var state_num = 0;state_num < counties.length; state_num++){
					var oOption = document.createElement("OPTION");
					document.getElementById("packa_county").options.add(oOption);
					oOption.text = counties[state_num];
					oOption.value = countiesid[state_num];
				}
			}
			break;
			
		default :
			alert("AJAX proccess has some problem");
		}
	}
	
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
