

/**

 * This function perform the match of selected city or state with current city(as per state) and current state(as per country)

 * if match is found then it returns index else it returns -1

*/

// JavaScript Chalo Shaadi Kare 

var xmlHttp

function GetXmlHttpObject()

{ 

var objXMLHttp=null

if (window.XMLHttpRequest)

{

objXMLHttp=new XMLHttpRequest()

}

else if (window.ActiveXObject)

{

objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

}

return objXMLHttp

} 



function InArray(arr, key)

{

	for (var i=0; i<arr.length; i++)

	{

		if (arr[i] == key)	return i;

	}



	return -1;



}//EOF InArray(arr, key)



function copytolist3(obj_from, obj_to)

{

	var flag		= false; // To check whether value is selected..

	var remove_flag = false; // To check whether value is selected..

	s=0;

	

	for (i=0;i<obj_from.options.length;i++)

	{

		var curr_option = obj_from.options[i];

		

		if(curr_option.selected )

		{

			// To display 'Doesn't Matter' if not added anything..

			if(obj_from == document.frm_main.elements['subcast_t[]'])

			{

				remove_flag = true;				

			}

			

			if(remove_flag == false)

			{

				//Here we are stroing the values which are present in LHS box and RHS box in one array, while populating RHS box we are not populating the values which are already in RHS box and user is again selecting the same value along with new value.

				to_array = new Array(); 

				

				for(j=0;j<obj_to.options.length;j++)

				{			

				if((curr_option.text) == (obj_to.options[j].text))

					{

						to_array[j] = curr_option.text;

						s=1;

						

					}

						

				}

				

			}

			

				if(remove_flag == true)

				{

						var optlen=obj_from.options.length;

					

						for(var j=0; j<optlen;j++)

							{

								//var to_value;							

								to_value = document.frm_main.elements['subcast[]'].options[j].value;		

								s=2;								

							

							}

					

	if (curr_option.value!="")	

     {
	 var tstwe=0;
	var cstghje=document.getElementById('subcast_t[]').length;

		 if(parseInt(cstghje)==1)
			{
			var tstwe=55;
			}
			
		// alert(curr_option.value);

			xmlHttp=GetXmlHttpObject()

			if (xmlHttp==null)

			{

			alert ("Browser does not support HTTP Request")

			return

			} 

			

			var url="ca_s.php?cast="+curr_option.value+"&dd=4";

		

			//window.location=url;

			xmlHttp.onreadystatechange=function()

			{
				if (tstwe!=55)
				{
				document.getElementById('subcast_t[]').length=0;				
				}
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

				{ 

					mearray=xmlHttp.responseText.split("[]");

				

				for (i=0;i<mearray.length-1;i++)

					{

						

						if(mearray[i]!="")

						{

							valcat=mearray[i].split("{}");

							oOption = document.createElement("Option");

							oOption.text =valcat[1];

							oOption.value = valcat[0];

						

							document.getElementById('subcast_t[]').options.add(oOption);

						}

					}

				}

			} 

			xmlHttp.open("GET",url,true)

			xmlHttp.send(null)

	

		}

						 

}

	

			flag = true;



			var new_option	   = curr_option.text;

			var new_option_val = curr_option.value;

		

			//Need to put select mothertongue n caste condition bcoz we hv static option files

			//for occupation n residency status.. which doesnt hv value attribute in option tag.

			//so we hv checked text of the option..

			if(new_option != ""

			&& new_option != "----Select Mother Tongue----"

			&& new_option != "---------Select Caste---------"

			&& new_option_val != "")

			{

				// when user selects anything frm left when doesnt matter at right side, overwriting the doesnt matter value.

				// countryofresidence condition is added bcoz.. we can have "" value as 0th option in countryofresidencearray.. so it resets the whole list..

				if(obj_to.options[0] && (obj_to.options[0].text == "Doesn't Matter" || obj_to.options[0].text == "") && obj_from != document.frm_main.elements['subcast[]'] )
				{
					obj_to.options.length = 0;
				}

				if(new_option != "Doesn't Matter")

				{

					if(remove_flag == false)

					{

						if((new_option && InArray(to_array, new_option) == -1))

						{

							obj_to.options[obj_to.length] = new Option(new_option, new_option_val);

							

						}

					}

				}

				//Removing the option frm the source list n

				//decrementing bcoz now we need to loop thr the new list count

				if(remove_flag){ // Uncomment if u dont want to remove the val frm left list.

				obj_from.options[i] = null;	//we can use obj_from.remove(i);

				i--; // Used for multiple selection..

				}

			}

		

		if(curr_option.value!="" && s==0)

		{

				

			xmlHttp=GetXmlHttpObject()

			if (xmlHttp==null)

			{

			alert ("Browser does not support HTTP Request")

			return

			} 

			

			var url="subct_s.php?subcast="+curr_option.value+"&dd=0";

			//window.location=url;

			xmlHttp.onreadystatechange=function()

			{

				document.getElementById('subcast_t[]').length=0;

				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

				{ 

					mearray=xmlHttp.responseText.split("[]");

					for (i=0;i<mearray.length-1;i++)

					{

						if(mearray[i]!="")

						{

							valcat=mearray[i].split("{}");

							oOption = document.createElement("Option");

							oOption.text =valcat[1];

							oOption.value = valcat[0];

						

							if(oOption.text!="")

							{

							document.getElementById('subcast_t[]').options.add(oOption);

							}

							

						}

					}

				}

	

			} 

			xmlHttp.open("GET",url,true)

			xmlHttp.send(null)

		}

		//else

	//	{

	//		document.getElementById('subcast[]').length=0;

		

	//	}

		} // EO if(curr_option.selected)



	} // EO for (i=0;i<obj_from.options.length;i++)



	if(obj_from.options.length == 0 && remove_flag)

	{

		

		

		if(document.frm_main.elements['communityarray[]'].options.length == 0)

		{

			document.frm_main.elements['caste_fromarray[]'].options.length = 0;

			//document.getElementById('show_hide_caste').style.display = 'none';

		

		}



		// This is done bcoz, we need " " value for 'Doesn't Matter' option in case of community block only so that

		// we can display default mothertongue list..

		// For other elements we need "" value..

		if(obj_from == document.frm_main.elements['communityarray[]']

		|| obj_from == document.frm_main.elements['castearray[]'])

		{

			var value = " ";

		}

		else

		{

			var value = "";

		}

		if(tstwe==55)
		{
		obj_from.options[0] = new Option("Doesn't Matter", value);
		}
	}



	// This block is used to remove the blank separator between the options in the LHS box

	if(obj_from.options.length > 0 && obj_from.options.length <= 2)

	{

			

			if(obj_from.options[0].text == "---------Select Caste---------" && obj_from.options.length == 2)

			{

				if(obj_from.options[1].text =="")

				obj_from.options[1] = null;

			}

			else if(obj_from.options.length == 1 && obj_from.options[0].text == "")

			{

				obj_from.options[0] = null;

			}

			

	}



	if (!flag)

	{

		alert ('Please select the Options');

		return false;

	}
var cp_option = obj_to.options[0];
				if(obj_to.options.length==1);	
				{	
					if(cp_option.text=="Doesn't Matter")
					{
    				obj_to.remove(0);
					}
				}	


	return true;



} // EO function copytolist1(obj_from,obj_to)










