﻿// JScript File

function copytolist(obj_from, obj_to)
{
    
  var flag		= false; // To check whether value is selected..
	var remove_flag = false; // To check whether value is selected..
	
	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.getElementById('ctl00_ContentPlaceHolder1_lstreligion_to') 
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcaste_to')
		   || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstedu_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lsteduIn_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstoccupation_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcountry_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lststate_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcity_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcitizen_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstmaritalStatus_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstIncome_to')
			)
			{
				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;
					}
				}
			}
						
			flag = true;

			var new_option	   = curr_option.text;
			var new_option_val = curr_option.value;
	//	alert(curr_option.text);
//		alert(curr_option.value);
//		
			//Need to put select religion 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 Religion----"	&& 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_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);
							//to.options[index] = new Option( o.text, o.value, false, false);

						}
					}
				}

				//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..
				
				}
			}

		} // EO if(curr_option.selected)

	} // EO for (i=0;i<obj_from.options.length;i++)
	
	if(obj_from.options.length == 0 && remove_flag)
	{
		
		// 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.getElementById('ctl00_ContentPlaceHolder1_lstreligion_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcaste_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstedu_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lsteduIn_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstoccupation_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcountry_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lststate_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcity_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstcitizen_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstmaritalStatus_to')
			 || obj_from == document.getElementById('ctl00_ContentPlaceHolder1_lstIncome_to')
		 )
		{
			var value = " ";
		}
		else
		{
			var value = "";
		}

		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.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;
	}

	return true;

} // EO function copytolist1(obj_from,obj_to</>)

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 Display4()
{	   
  	var community_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstreligion_to');
	var caste_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstcaste_to');
	var education_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstedu_to');
	var educationIn_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lsteduIn_to');
	var occupation_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstoccupation_to');
	var country_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstcountry_to');
	var state_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lststate_to');
	var city_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstcity_to');
	var citizen_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstcitizen_to');
	var mstatus_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstmaritalStatus_to');
	var income_obj	= document.getElementById('ctl00_ContentPlaceHolder1_lstIncome_to');
	
	var community	= "";
	var caste		= "";
	var education	= "";
	var educationIn	= "";
	var occupation	= "";
	var country	    = "";
	var state	    = "";
	var city	    = "";
	var citizen	    = "";
	var mstatus     = "";
	var income      = "";
			
	if(community_obj)
	{
        for(var i=0; i < community_obj.options.length; i++)
	    {
	        community_value = community_obj.options[i].value;
			
		    if(!community.match(community_value))// && community_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
		    {
			    community += new String(community_value) + ","; // Taking only 1st element like 'Hindu'.
		    }
		} // EO for(var i=0; i < community_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hidden1').value=community;
    }
  	if(caste_obj)
	{
        for(var i=0; i < caste_obj.options.length; i++)
	    {
		    var caste_value = caste_obj.options[i].value;
		    if(!caste.match(caste_value))// && community_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
            {
			    caste += new String(caste_value) + ","; // Taking only 1st element like 'Hindu'.
		    }
        } // EO for(var i=0; i < community_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hidden2').value=caste;
    }
    
    if(education_obj)
	{
        for(var i=0; i < education_obj.options.length; i++)
		{
			var education_value = education_obj.options[i].value;
			if(!community.match(education_value))// && community_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				education += new String(education_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < community_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hdneducation').value=education;
    }
  
    if(educationIn_obj)
	{
        for(var i=0; i < educationIn_obj.options.length; i++)
		{
			var educationIn_value = educationIn_obj.options[i].value;
			if(!educationIn.match(educationIn_value))// && community_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				educationIn += new String(educationIn_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < community_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_HdneducationIn').value=educationIn;
    }
    
    if(occupation_obj)
    {
        for(var i=0; i < occupation_obj.options.length; i++)
		{
			var occupation_value = occupation_obj.options[i].value;
			if(!occupation.match(occupation_value))// && occupation_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				occupation += new String(occupation_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < occupation_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hdnoccupation').value=occupation;
    }
  
    if(country_obj)
    {
        for(var i=0; i < country_obj.options.length; i++)
		{
			var country_value = country_obj.options[i].value;
			if(!country.match(country_value))// && country_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				country += new String(country_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < country_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hdncountry').value=country;
    }
  
    if(state_obj)
    {
        for(var i=0; i < state_obj.options.length; i++)
		{
			var state_value = state_obj.options[i].value;
			if(!state.match(state_value))// && state_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				state += new String(state_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < state_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hdnstate').value=state;
    }
    
    if(city_obj)
    {
        for(var i=0; i < city_obj.options.length; i++)
		{
			var city_value = city_obj.options[i].value;
			if(!city.match(city_value))// && city_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				city += new String(city_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < city_obj.options.length; i++)
      document.getElementById('ctl00_ContentPlaceHolder1_Hdncity').value=city;
    }
    
    if(citizen_obj)
    {
		for(var i=0; i < citizen_obj.options.length; i++)
		{
			var citizen_value = citizen_obj.options[i].value;
			if(!citizen.match(citizen_value))// && citizen_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				citizen += new String(citizen_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < citizen_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_Hdncitizen').value=citizen;
    }
  
    if(mstatus_obj)
    {
        for(var i=0; i < mstatus_obj.options.length; i++)
		{
			var mstatus_value = mstatus_obj.options[i].value;
			
			if(!mstatus.match(mstatus_value))// && mstatus_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				mstatus += new String(mstatus_value) + ","; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < mstatus_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_HdnmaritalStatus').value=mstatus;
    }
  
    if(income_obj)
    {
        for(var i=0; i < income_obj.options.length; i++)
		{
	        var income_value = income_obj.options[i].value;
			
			if(!income.match(income_value))// && mstatus_obj.options[0].text != "Doesn't Matter" ) // Not to insert duplicate values..
			{
				income+= new String(income_value) + "/"; // Taking only 1st element like 'Hindu'.
			}
		} // EO for(var i=0; i < income_obj.options.length; i++)
        document.getElementById('ctl00_ContentPlaceHolder1_hdnIncome').value=income;
    }
}

  
function statuschange(val)
{

if(val == "Single")
{
	document.getElementById('ctl00_ContentPlaceHolder1_trchild').style.visibility = 'Hidden';
}
else
{
	document.getElementById('ctl00_ContentPlaceHolder1_trchild').style.visibility = 'Visible';
}
}//EOF InArray(arr, key)
  
  

