var strXML;
var ctr;
var irow;					
var str;
var rVal;
strXML="<Fields>"
strXML=strXML+"<txtfld1>1</txtfld1>"
strXML=strXML+"</Fields>"

var ArrPlaces;
var ArrSubPlaces;
var ArrInitials;

function LoadDateControl(iDay,iMonth,iYear,minYear,maxYear,StrFrmName,dropDay,dropMonth,dropYear)
{
		while(document.forms(StrFrmName).item(dropDay).options.length>0)
		{
			document.forms(StrFrmName).item(dropDay).options.remove(0);
		}
		
		while(document.forms(StrFrmName).item(dropMonth).options.length>0)
		{
			document.forms(StrFrmName).item(dropMonth).options.remove(0);
		}
		while(document.forms(StrFrmName).item(dropYear).options.length>0)
		{
			document.forms(StrFrmName).item(dropYear).options.remove(0);
		}				
		
		var oOption=document.createElement("OPTION");
		document.forms(StrFrmName).item(dropDay).options.add(oOption);
		oOption.innerText="DD";
		oOption.value="0";
		oOption.selected = true;
		
		var oOption=document.createElement("OPTION");
		document.forms(StrFrmName).item(dropMonth).options.add(oOption);
		oOption.innerText="MM";
		oOption.value="0";
		oOption.selected = true;

		var oOption=document.createElement("OPTION");
		document.forms(StrFrmName).item(dropYear).options.add(oOption);
		oOption.innerText="YYYY";
		oOption.value="0";
		oOption.selected = true;
		var ctr;
		for(ctr=1;ctr<=31;ctr++)
		{
			var oOption=document.createElement("OPTION");
			document.forms(StrFrmName).item(dropDay).options.add(oOption);
			oOption.innerText=ctr;
			if(ctr<=9)
				oOption.value="0"+ctr;
			else
				oOption.value=ctr;
			if(ctr==iDay)
			{
				oOption.selected = true;
			}			
		}
		for(ctr=1;ctr<=12;ctr++)
		{
			var oOption=document.createElement("OPTION");
			document.forms(StrFrmName).item(dropMonth).options.add(oOption);
			oOption.innerText=ctr;
			if(ctr<=9)			
				oOption.value="0"+ctr;
			else
				oOption.value=ctr;
			if(ctr==iMonth)
			{
				oOption.selected = true;
			}
		}
		for(ctr=minYear;ctr<=maxYear;ctr++)
		{
			var oOption=document.createElement("OPTION");
			document.forms(StrFrmName).item(dropYear).options.add(oOption);
			oOption.innerText=ctr;
			oOption.value=ctr;
			if(ctr==iYear)
			{
				oOption.selected = true;
			}
		}
}
function PlacesSubPlaces_Change(Type)
{
		var icountry=document.frm.dropCountry.options[document.frm.dropCountry.selectedIndex].value;			
		var istate=document.frm.dropState.options[document.frm.dropState.selectedIndex].value;
		var icity=document.frm.dropCity.options[document.frm.dropCity.selectedIndex].value;			
		var iarea=document.frm.dropArea.options[document.frm.dropArea.selectedIndex].value;
					
		switch (Type)
		{
			case "C":
				switch (icountry)
				{
					case "0":
						while(document.frm.dropState.options.length>0)
						{
							document.frm.dropState.options.remove(0);
						}
						while(document.frm.dropCity.options.length>0)
						{
							document.frm.dropCity.options.remove(0);
						}
						while(document.frm.dropArea.options.length>0)
						{
							document.frm.dropArea.options.remove(0);
						}
						//document.frm.txtPinCode.value="";
						var oOption=document.createElement("OPTION");
						document.frm.dropState.options.add(oOption);
						oOption.innerText="Select State";
						oOption.value="0";
						oOption.selected = true;
						
						var oOption=document.createElement("OPTION");
						document.frm.dropCity.options.add(oOption);
						oOption.innerText="Select City";
						oOption.value="0";
						oOption.selected = true;
						
						var oOption=document.createElement("OPTION");
						document.frm.dropArea.options.add(oOption);
						oOption.innerText="Select Area";
						oOption.value="0";
						oOption.selected = true;
						
						break;
					default :
						while(document.frm.dropState.options.length>0)
						{
							document.frm.dropState.options.remove(0);
						}							
						while(document.frm.dropCity.options.length>0)
						{
							document.frm.dropCity.options.remove(0);
						}
						while(document.frm.dropArea.options.length>0)
						{
							document.frm.dropArea.options.remove(0);
						}
						//document.frm.txtPinCode.value="";
						var oOption=document.createElement("OPTION");
						document.frm.dropState.options.add(oOption);
						oOption.innerText="Select State";
						oOption.value="0";
						oOption.selected = true;
						
						var oOption=document.createElement("OPTION");
						document.frm.dropCity.options.add(oOption);
						oOption.innerText="Select City";
						oOption.value="0";
						oOption.selected = true;
						
						var oOption=document.createElement("OPTION");
						document.frm.dropArea.options.add(oOption);
						oOption.innerText="Select Area";
						oOption.value="0";
						oOption.selected = true;							
						
						for(ctr=1;ctr<ArrPlaces.length;ctr++)
						{
							str=ArrPlaces[ctr];
							irow=str.split(",");
							if(irow[4]==2 && irow[3]==icountry)
							{
								var oOption=document.createElement("OPTION");
								document.frm.dropState.options.add(oOption);
								oOption.innerText=irow[1];
								oOption.value=irow[0];
							}
						}						
						break;
				}						
				break;
			case "S":
				switch (istate)
				{
					case "0":
						while(document.frm.dropCity.options.length>0)
						{
							document.frm.dropCity.options.remove(0);
						}
						while(document.frm.dropArea.options.length>0)
						{
							document.frm.dropArea.options.remove(0);
						}
						//document.frm.txtPinCode.value="";
						var oOption=document.createElement("OPTION");
						document.frm.dropCity.options.add(oOption);
						oOption.innerText="Select City";
						oOption.value="0";
						oOption.selected = true;
						
						var oOption=document.createElement("OPTION");
						document.frm.dropArea.options.add(oOption);
						oOption.innerText="Select Area";
						oOption.value="0";
						oOption.selected = true;
						
						break;
					default :
						while(document.frm.dropCity.options.length>0)
						{
							document.frm.dropCity.options.remove(0);
						}
						while(document.frm.dropArea.options.length>0)
						{
							document.frm.dropArea.options.remove(0);
						}
						//document.frm.txtPinCode.value="";
						var oOption=document.createElement("OPTION");
						document.frm.dropCity.options.add(oOption);
						oOption.innerText="Select City";
						oOption.value="0";
						oOption.selected = true;
						
						var oOption=document.createElement("OPTION");
						document.frm.dropArea.options.add(oOption);
						oOption.innerText="Select Area";
						oOption.value="0";
						oOption.selected = true;																
						
						for(ctr=1;ctr<ArrPlaces.length;ctr++)
						{
							str=ArrPlaces[ctr];
							irow=str.split(",");
							if(irow[4]==3 && irow[3]==istate)
							{
								var oOption=document.createElement("OPTION");
								document.frm.dropCity.options.add(oOption);
								oOption.innerText=irow[1];
								oOption.value=irow[0];
							}
						}						
						break;
				}						
				break;
			case "CT":
				switch (icity)
				{
					case "0":
						while(document.frm.dropArea.options.length>0)
						{
							document.frm.dropArea.options.remove(0);
						}
						//document.frm.txtPinCode.value="";
						var oOption=document.createElement("OPTION");
						document.frm.dropArea.options.add(oOption);
						oOption.innerText="Select Area";
						oOption.value="0";
						oOption.selected = true;
						break;
					default :
						while(document.frm.dropArea.options.length>0)
						{
							document.frm.dropArea.options.remove(0);
						}
						//document.frm.txtPinCode.value="";
						var oOption=document.createElement("OPTION");
						document.frm.dropArea.options.add(oOption);
						oOption.innerText="Select Area";
						oOption.value="0";
						oOption.selected = true;
						
						for(ctr=1;ctr<ArrSubPlaces.length;ctr++)
						{
							str=ArrSubPlaces[ctr];
							irow=str.split(",");
							if(irow[4]==3 && irow[3]==icity)
							{
								var oOption=document.createElement("OPTION");
								document.frm.dropArea.options.add(oOption);
								oOption.innerText=irow[1];
								oOption.value=irow[0];
							}
						}
						break;
				}						
				break;
			case "A":
				switch (iarea)
				{
					case "0":
						//document.frm.txtPinCode.value="";
						break;
					default :
						//document.frm.txtPinCode.value="";
						for(ctr=1;ctr<ArrSubPlaces.length;ctr++)
						{
							str=ArrSubPlaces[ctr];
							irow=str.split(",");
							if(irow[0]==iarea)
							{
								break;
							}
						}
						break;
				}
				break;			
			default:
				while(document.frm.dropCountry.options.length>0)
				{
					document.frm.dropCountry.options.remove(0);}
				while(document.frm.dropState.options.length>0)
				{
					document.frm.dropState.options.remove(0);
				}
				while(document.frm.dropCity.options.length>0)
				{
					document.frm.dropCity.options.remove(0);
				}
				while(document.frm.dropArea.options.length>0)
				{
					document.frm.dropArea.options.remove(0);
				}
				//document.frm.txtPinCode.value="";
				var oOption=document.createElement("OPTION");
				document.frm.dropCountry.options.add(oOption);
				oOption.innerText="Select Country";
				oOption.value="0";
				oOption.selected = true;
				
				var oOption=document.createElement("OPTION");
				document.frm.dropState.options.add(oOption);
				oOption.innerText="Select State";
				oOption.value="0";
				oOption.selected = true;
				
				var oOption=document.createElement("OPTION");
				document.frm.dropCity.options.add(oOption);
				oOption.innerText="Select City";
				oOption.value="0";
				oOption.selected = true;

				var oOption=document.createElement("OPTION");
				document.frm.dropArea.options.add(oOption);
				oOption.innerText="Select Area";
				oOption.value="0";
				oOption.selected = true;
				
				for(ctr=1;ctr<ArrPlaces.length;ctr++)
				{
					str=ArrPlaces[ctr];
					irow=str.split(",");
					if(irow[4]==1)
					{
						var oOption=document.createElement("OPTION");
						document.frm.dropCountry.options.add(oOption);
						oOption.innerText=irow[1];
						oOption.value=irow[0];
					}
				}
		}
}
function FillPlacesSubPlaces_Load(icountry,istate,icity,iArea,iPinCode,StrPlacesValue,StrSubPlacesValue)
{
		rVal=StrPlacesValue;
		if(Trim(rVal).length==0)
		{
			rVal= xmlExe(strXML,'FrmGetDatafromXML.aspx?Type=Places')
			rVal=new String(rVal);
		}
		ArrPlaces=rVal.split("|")
		
		rVal=StrSubPlacesValue;
		if(Trim(rVal).length==0)
		{
			rVal= xmlExe(strXML,'FrmGetDatafromXML.aspx?Type=SubPlaces')
			rVal=new String(rVal);
		}
		ArrSubPlaces=rVal.split("|")

		while(document.frm.dropCountry.options.length>0)
		{
			document.frm.dropCountry.options.remove(0);
		}
		while(document.frm.dropState.options.length>0)
		{
			document.frm.dropState.options.remove(0);
		}
		while(document.frm.dropCity.options.length>0)
		{
			document.frm.dropCity.options.remove(0);
		}
		while(document.frm.dropArea.options.length>0)
		{
			document.frm.dropArea.options.remove(0);
		}
		var oOption=document.createElement("OPTION");
		document.frm.dropCountry.options.add(oOption);
		oOption.innerText="Select Country";
		oOption.value="0";
		oOption.selected = true;

		var oOption=document.createElement("OPTION");
		document.frm.dropCountry.options.add(oOption);
		oOption.innerText="India";
		oOption.value="1";
		//oOption.selected = true;
		
		var oOption=document.createElement("OPTION");
		document.frm.dropState.options.add(oOption);
		oOption.innerText="Select State";
		oOption.value="0";
		oOption.selected = true;
		
		var oOption=document.createElement("OPTION");
		document.frm.dropCity.options.add(oOption);
		oOption.innerText="Select City";
		oOption.value="0";
		oOption.selected = true;

		var oOption=document.createElement("OPTION");
		document.frm.dropArea.options.add(oOption);
		oOption.innerText="Select Area";
		oOption.value="0";
		oOption.selected = true;
		/*
		for(ctr=1;ctr<ArrPlaces.length;ctr++)
		{
			str=ArrPlaces[ctr];
			irow=str.split(",");
			if(irow[4]==1 && irow[7]=='P')
			{
				var oOption=document.createElement("OPTION");
				document.frm.dropCountry.options.add(oOption);
				oOption.innerText=irow[1];
				oOption.value=irow[0];
				if(irow[0]==icountry)
				{
					oOption.selected = true;
				}
			}
			if(irow[4]==2 && irow[7]=='P' && irow[3]==icountry)
			{
				var oOption=document.createElement("OPTION");
				document.frm.dropState.options.add(oOption);
				oOption.innerText=irow[1];
				oOption.value=irow[0];
				if(irow[0]==istate)
				{
					oOption.selected = true;
				}
			}
			if(irow[4]==3 && irow[7]=='P' && irow[3]==istate)
			{
				var oOption=document.createElement("OPTION");
				document.frm.dropCity.options.add(oOption);
				oOption.innerText=irow[1];
				oOption.value=irow[0];
				if(irow[0]==icity)
				{
					oOption.selected = true;
				}
			}			
		}		
		for(ctr=1;ctr<ArrSubPlaces.length;ctr++)
		{
			str=ArrSubPlaces[ctr];
			irow=str.split(",");
			if(irow[4]==3 && irow[7]=='S' && irow[3]==icity)
			{
				var oOption=document.createElement("OPTION");
				document.frm.dropArea.options.add(oOption);
				oOption.innerText=irow[1];
				oOption.value=irow[0];
				if(irow[0]==iArea)
				{
					oOption.selected = true;
				}
			}
		}		
		//document.frm.txtPinCode.value=iPinCode;
		*/
}
function FillInitials_Load(iInitials,StrFrmName,StrValue)
{
		rVal=StrValue;
		if(Trim(rVal).length==0)
		{
			rVal= xmlExe(strXML,'FrmGetDatafromXML.aspx?Type=Initials')
			rVal=new String(rVal);
		}

		ArrInitials=rVal.split("|")
		
		while(document.forms(StrFrmName).item("dropInitials").options.length>0)
		{
			document.forms(StrFrmName).item("dropInitials").options.remove(0);
		}
		
		var oOption=document.createElement("OPTION");
		document.forms(StrFrmName).item("dropInitials").options.add(oOption);
		oOption.innerText="Select Intitals";
		oOption.value="0";
		oOption.selected = true;
		
		for(ctr=1;ctr<ArrInitials.length;ctr++)
		{
			str=ArrInitials[ctr];
			irow=str.split(",");
			var oOption=document.createElement("OPTION");
			document.forms(StrFrmName).item("dropInitials").options.add(oOption);
			oOption.innerText=irow[1];
			oOption.value=irow[0];
			if(irow[0]==iInitials)
			{
				oOption.selected = true;
			}
		}
}
function FillCategory_Load(iSelectedId,StrFrmName,StrComboName,StrValue,StrType,iBrandId)
{
		rVal=StrValue;
		if(Trim(rVal).length==0)
		{
			rVal= xmlExe(strXML,'FrmGetDatafromXML.aspx?Type='+StrType)
			rVal=new String(rVal);
		}

		Arr=rVal.split("|")
		
		while(document.forms(StrFrmName).item(StrComboName).options.length>0)
		{
			document.forms(StrFrmName).item(StrComboName).options.remove(0);
		}
		
		var oOption=document.createElement("OPTION");
		document.forms(StrFrmName).item(StrComboName).options.add(oOption);
		oOption.innerText="ALL";
		oOption.value="0";
		oOption.selected = true;
		
		for(ctr=1;ctr<Arr.length;ctr++)
		{
			str=Arr[ctr];
			irow=str.split(",");
			if(irow[2]==iBrandId)
			{
				var oOption=document.createElement("OPTION");
				document.forms(StrFrmName).item(StrComboName).options.add(oOption);
				oOption.innerText=irow[1];
				oOption.value=irow[0];
				if(irow[0]==iSelectedId)
				{
					oOption.selected = true;
				}
			}
		}
}
function FillCombo_Load(iSelectedId,StrFrmName,StrComboName,StrValue,StrType,DefaultZero)
{
		rVal=StrValue;
		if(Trim(rVal).length==0)
		{
			rVal= xmlExe(strXML,'FrmGetDatafromXML.aspx?Type='+StrType)
			rVal=new String(rVal);
		}

		Arr=rVal.split("|")
		
		while(document.forms(StrFrmName).item(StrComboName).options.length>0)
		{
			document.forms(StrFrmName).item(StrComboName).options.remove(0);
		}
		if(DefaultZero=='Y')
		{
			var oOption=document.createElement("OPTION");
			document.forms(StrFrmName).item(StrComboName).options.add(oOption);
			oOption.innerText="----- Select -----";
			oOption.value="0";
			oOption.selected = true;
		}		
		for(ctr=1;ctr<Arr.length;ctr++)
		{
			str=Arr[ctr];
			irow=str.split(",");
			var oOption=document.createElement("OPTION");
			document.forms(StrFrmName).item(StrComboName).options.add(oOption);
			oOption.innerText=irow[1];
			oOption.value=irow[0];
			if(irow[0]==iSelectedId)
			{
				oOption.selected = true;
			}
		}
}
function xmlExe(strValue,strFileName)
{
	var objXML;
	var rValue;
	objXML=new ActiveXObject("Microsoft.XMLDOM");
	objHTTP=new ActiveXObject("Microsoft.XMLHTTP");
	objXML.loadXML(strValue)
	objHTTP.open("POST",strFileName,false);
	objHTTP.send(objXML);
	if(objHTTP.readystate)
	{
		rValue=objHTTP.responseText;
		return rValue;
	}				
}