/* function make the MAIN DIV visibility as visible and display as show ***/
var SERVER_PATH,IMG_PATH;
var js_country_for_city = "";



function check_if_all_values_selected(chk_name, hidden_field)
{

	var all_castes_selected = true;

	for(i=0; i< chk_name.length; i++)
	{
		if(!chk_name[i].value) 
			continue;
		if(!chk_name[i].checked)
		{
			all_castes_selected = false;
			break;
		}
	}

	if(all_castes_selected == true)
	{
		for (counter = 0; counter < chk_name.length; counter++)
				chk_name[counter].checked=!chk_name[counter].value;

		if(hidden_field)
		{
			hidden_field.value = "";
		}
	}

	return true;
}

function show_hide_sort_drop_down(show_hide)
{
	try
	{
		if(fn_js_featuredmatch_yn=='Y')
		{
			return true;
		}
	}
	catch (err)
	{
	}

	if(document.getElementById('sort_drop_drown'))
		document.getElementById('sort_drop_drown').style.display=show_hide;
}





function check_uncheck_obj(current_field, all_objs, val)
	{

	if(current_field.checked)
		{			
			if(!val)
			{		
			for (counter = 0; counter < all_objs.length; counter++)
				if(all_objs[counter].value)
					all_objs[counter].checked=false;
			}
			else 
			{			
			all_objs[0].checked=false;
		} 

	} // EO if(current_field.checked)

} // EO function check_uncheck_obj(current_field, all_objs, val)



function data_updated(frm, current_field)
{
	var all_objs = new Array();
	eval("all_objs = frm." + current_field.name);

	if(!all_objs)
		return false;

	check_uncheck_obj(current_field, all_objs, current_field.value);

	return true;

}

function maximize_minimize(obj,div_id)
{
	var hideControls	= document.getElementById('show_refine_sub_div');
	var hideControls_1	= document.getElementById(div_id+'_1');
	var hideControls_2	= document.getElementById(div_id+'_2');
	if (obj.id == "minimize")
	{
		hideControls.style.display='none';
		hideControls_1.style.display='none';
		hideControls_2.style.display='none';
		obj.id = "maximize";
		obj.src = IMG_PATH + "/imgs/bullet/plus-symbol.jpg";
		document.cookie = "max_min=minimize;";

		if(document.getElementById('religion1'))
			hide_div("religion1");

		if(document.getElementById('mothertongue_div'))
			hide_div("mothertongue_div");

	}
	else
	{
		hideControls_1.style.display='block';
		hideControls_2.style.display='block';
		obj.id = "minimize";
		obj.src = IMG_PATH + "/imgs/bullet/minus-symbol.jpg";
		document.cookie = "max_min=maximize;";
	}

}//EO function maximize_minimize(obj,div_id)

function check_keyword_refine(obj)
{
	var _iMinLength = 4;

	myString = new String(obj.value);
	var keyword = myString.trim();

	if(keyword && keyword.length < _iMinLength)
	{
		alert('Please enter atleast '+_iMinLength+' characters.');
		return false;
	}

	return true;

} // EO function check_keyword()

function restrict_selection(source_obj_name)
{
	var max = source_obj_name.countryarray.length;
	var total = 0;
	for (counter = 0; counter < source_obj_name.countryarray.length; counter++)
	{
		if(source_obj_name.countryarray[counter].checked)
		{
			total += 1;
			//var hidden_val
		}

		if(total > 10)
		{
			alert("You can select Max 10 values.");
			return false;
		}

	}

}


function show_div(showControls, b)
{
   if(showControls)
  {
	
	var link_substr = b.id.substr(0,8);
	var curleft = curtop = 0;
			if (b.offsetParent) {
				do {
					curleft += b.offsetLeft;
					curtop += b.offsetTop;
				} while (b = b.offsetParent);
			}

	showControls.style.visibility='visible';
	showControls.style.display='block';

	if(showControls.getAttribute("id") != "show-add-to-fav-msg")
	{
		showControls.style.top = curtop+100;
		showControls.style.left = curleft-196;
	}
	else
	{
		showControls.style.top = curtop+15;
		showControls.style.left = curleft;

	} // EO if(div_id != "show-add-to-fav-msg")
	if (link_substr == "featured")
	{
//		alert(document.getElementById("featured_members_div").offsetLeft);
//		total_width = eval(document.getElementById("featured_members_div").offsetLeft) + 556;
		c = document.getElementById("featured_members_div");
		cur_left = c.offsetLeft;
		if (c.offsetParent) {
				do {
					cur_left += c.offsetLeft;
				} while (c = c.offsetParent);
			}
		total_width = cur_left + 556;
		if (eval(curleft)+256 > total_width)
		{
			curleft = curleft - (118);
		}
		curtop += 13;
		showControls.style.left = curleft;
		showControls.style.top = curtop
	}
	else if(link_substr == "refinely")
	{
		showControls.style.top = curtop+26;
		showControls.style.left = curleft;
	}

  }//EO if(showControls)
//alert("b in fun"+b);

}//EO function show_div(div_id)



/* function make the send her/him personalised message DIV visibility as visible and display as show ***/

function show_hidden_person_div(hidden_person_id)
{
	var showhidden_person = document.getElementById(hidden_person_id);

	if(showhidden_person)
	 {
		showhidden_person.style.visibility='visible';
		showhidden_person.style.display='block';

	}//EO if(hideControls)

}


/* function make the MAIN DIV visibility as hidden and display as hide ***/
function hide_div(div_id)
{

  var hideControls = document.getElementById(div_id);

  if(hideControls)
  {
	// Show "Sort Order By" drop down
	show_hide_sort_drop_down("block");

	hideControls.style.visibility='hidden';
	hideControls.style.display='none';

  }//EO if(hideControls)

}//EO function hide_div(div_id)



/* following function is used to handle response of express interest, accept interest,decline interest... and so on **/

var confirm_msg = false;

function submit_express_interest(frmobject,file_url,link_name,profileid,IMG_PATH, from_personalise_link,current_link_desc,sTextArea, sTextInput, iMaxLimit)
{
	
	if(from_personalise_link == "yes")
	{
	
		var _oDF        = frmobject; //document.forms[frmobject];
		var _oTxtA      = _oDF.elements[sTextArea];
		var _iMaxLength = (!iMaxLimit) ? 100 : iMaxLimit;
		var _iCharLeft  = _oTxtA.value.length;

		_oDF.elements[sTextInput].value = _iCharLeft;

		if(_iCharLeft > _iMaxLength)
		{
			_oTxtA.value = _oTxtA.value.substring(0, _iMaxLength);
			_oDF.elements[sTextInput].value = _iMaxLength;
			alert('You can enter only '+_iMaxLength+' characters.');
			return false;
		}
	}

	var img = "<span style=\"padding-left:75px;\"><img src=\""+ IMG_PATH + "/imgs/profiles/loading-ajax.gif\"></span>";

		var member_express_interest = false;

		current_link_desc = typeof(current_link_desc) != 'undefined' ? current_link_desc : 'null';

		if(current_link_desc == 'member_express_interest')
		{
			if(frmobject.acceptdecline[0].checked == true)
			{
				member_express_interest = true;
				link_name = "Accepted Member";

			}

			if(frmobject.acceptdecline[1].checked == true)
			{
				member_express_interest = true;
				link_name = "Declined Member";

			}

			if(frmobject.acceptdecline[0].checked == false && frmobject.acceptdecline[1].checked == false)
			{
				member_express_interest = true;
				link_name = "Accepted Member";
			}

		}

	// to change the content inside the main div
	overwrite_sourceid = "show_inside_content_div_" + profileid;

	//to change the content from exress interest<-> send reminnder and so on
	td_id = "link_change_id_" + profileid;

	//to hide and show the mail div id which was intially hide and show after click on link
	show_main_div_id = "show_main_div_" + profileid;

	if(confirm_msg == true)
	{

		   var answer = false;
		   answer = confirm("Are you sure you want to decline interest in this member?");

		   if(answer == false)
		   {
			   confirm_msg = false;
			   return false;
		   }
	}

	frmobject.action=file_url;
	var status = AjaxRequest.submit(frmobject,{
	'onLoading':function(req){
		document.getElementById("close_id").style.display="none";
		document.getElementById(overwrite_sourceid).innerHTML= img;
		if (window.ActiveXObject)
		{	var iframe_height = document.getElementById('show_main_div').offsetHeight - 30;
			if(document.getElementById('frame_id'))
			document.getElementById('frame_id').style.height= iframe_height+"px";
		}
		}
	,'onSuccess':function(req){

		document.getElementById("close_id").style.display="block";

		if(from_personalise_link == "yes")
		{
			//to check whether user has opened send him/her pesonalise mesg div
			pesonalise_mesg_div = "hid_send_pers_" + profileid;

			if(document.getElementById(pesonalise_mesg_div).style.display == 'block')
			{
				hide_div(pesonalise_mesg_div);
			}
		}

		if(link_name == "")
		{
			link_name_display = "Send Reminder";
		}
		else
		{
			link_name_display = link_name;
		}
		div_id_to_change = document.getElementById(td_id);
		if(div_id_to_change != null)
		{
			document.getElementById(td_id).innerHTML = "<span style='font:normal 11px verdana; color:#0066CC;'>"+link_name_display+"&nbsp;<img src='"+IMG_PATH+"/imgs/bullet/blue-arrow.gif' border='0' style='margin-bottom:-2px;'></span>";
		}
		div_id_to_change = document.getElementById("pos_featured_"+td_id);
		if(div_id_to_change != null)
		{
			div_id_to_change.innerHTML = "<span style='font:normal 11px verdana; color:#0066CC;'>"+link_name_display+"&nbsp;</span>";
		}

		if(link_name == 'Send Reminder')
		{
			if(current_link_desc == 'you_cancel_interest')
			{
				if(document.getElementById('cancel_#'+profileid) != null)
				{
					if(document.getElementById('cancel_#'+profileid).src)
					{
						document.getElementById('cancel_#'+profileid).src = IMG_PATH + "/imgs/icons/icon_open.gif";
						document.getElementById('cancel_#'+profileid).height = "14";
						document.getElementById('cancel_#'+profileid).vspace = "0";
						document.getElementById('cancel_#'+profileid).setAttribute("title", "Awaiting Response")

					}
				}
			}
			else
			{
				if(document.getElementById('trans-smile-'+profileid) != null)
				{
					document.getElementById('trans-smile-'+profileid).src = IMG_PATH + "/imgs/icons/icon_open.gif";

					document.getElementById('trans-smile-'+profileid).setAttribute("title", "Awaiting Response")
				}
			}


		}



		if(link_name == "Accepted Member" && member_express_interest == true)
		{
			if(document.getElementById('contact_#'+profileid) != null)
			{
				document.getElementById('contact_#'+profileid).src = IMG_PATH + "/imgs/icons/icon_accept.gif";
				document.getElementById('contact_#'+profileid).setAttribute("title", "Accepted")
			}
		}
		else if(link_name == "Declined Member" && member_express_interest == true)
		{
			if(document.getElementById('contact_#'+profileid) != null)
			{
				document.getElementById('contact_#'+profileid).src = IMG_PATH + "/imgs/icons/icon_decline.gif";
				document.getElementById('contact_#'+profileid).setAttribute("title", "Declined")
			}
		}
		else if(link_name == 'Declined Member')
		{
			if(document.getElementById('accept_#'+profileid) != null)
			{
				document.getElementById('accept_#'+profileid).src = IMG_PATH + "/imgs/icons/icon_decline.gif";
				document.getElementById('accept_#'+profileid).setAttribute("title", "Declined")
			}

		}else if(link_name == 'Accepted Member')
		{
			if(document.getElementById('decline_#'+profileid) != null)
			{
				document.getElementById('decline_#'+profileid).src = IMG_PATH + "/imgs/icons/icon_accept.gif";
				document.getElementById('decline_#'+profileid).setAttribute("title", "Accepted")
			}
		}
		else if(link_name == 'Cancel Interest')
		{
			if(document.getElementById('accept_#'+profileid) != null)
			{
				document.getElementById('accept_#'+profileid).src = IMG_PATH + "/imgs/icons/icon-heart-cancel.gif";
				document.getElementById('accept_#'+profileid).setAttribute("title", "Cancelled")
			}
		}
		
		document.getElementById(overwrite_sourceid).innerHTML = req.responseText;

		if (window.ActiveXObject)
		{	
			var iframe_height = document.getElementById('show_main_div').offsetHeight - 30;
			if(document.getElementById('frame_id'))
			document.getElementById('frame_id').style.height= iframe_height+"px";
		}

	}
	,'timeout':30000
	,'onTimeout':function(req){ alert('A problem occurred while communicating with the server.\nPlease make sure you are connected to the Internet and try again in sometime.'); return false;}
	,'onError':function(req){
		alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
		}
	}
	)
	return status;
}


function send_password(file_url, overwrite_sourceid)
{
	
	var status = AjaxRequest.get(
	{

		'url':file_url
		,'onSuccess':function(req){

		show_hidden_person_div(overwrite_sourceid);


		}
		,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	 }
	 );





}


function show_content_layer(my_url, profileid, link_name, show_layer, featured)
{

	var img = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\" style=\"height:120px;\" valign=\"top\"><tr><td class=\"top_left_png\" align=\"left\"></td><td class=\"top_middle_png\"></td><td class=\"top_right_png\"></td></tr><tr><td class=\"left_border_png\" align=\"left\" align=\"top\"></td><td bgcolor=\"#ffffff\" style=\" font: normal 11px verdana;\" valign=\"middle\" align=\"center\"><img src=\""+ IMG_PATH + "/imgs/profiles/loading-ajax.gif\"></td><td class=\"right_border_png\"></td></tr><tr><td class=\"bottom_left_png\"></td><td class=\"bottom_middle_png\"></td><td class=\"bottom_right_png\"></td></tr></table>";
	var img_fav = "<span style=\"padding-left:175px;\"><img src=\""+ IMG_PATH + "/imgs/profiles/loading-ajax-small.gif\"></span>";

	var inside_inner_div;
	obj_div = document.getElementById(show_layer);


	if(link_name != "already_in_fav" && link_name != "add_to_fav")
	{
			show_link_td_id = "link_change_id_" + profileid;
			if (featured == "Y")
			{
				show_link_td_id = "featured_link_change_id_" + profileid;
			}
			b = document.getElementById(show_link_td_id);

			inside_inner_div = obj_div;
		}
		else if(link_name == "already_in_fav" || link_name == "add_to_fav")
		{
			ob_inner_div = document.getElementById('display-message-add-to-fav');
			//alert("ob_inner_div :"+ob_inner_div);

			fav_link_change_id = "fav_link_" + profileid;
			b = document.getElementById(fav_link_change_id);

			//alert("b 1:"+b);
		    ob_fav = document.getElementById('fav_'+profileid);
			//alert("ob_fav 1:"+ob_fav);

			inside_inner_div = ob_inner_div;


		}
	inside_inner_div.innerHTML = "";

	var status = AjaxRequest.get(
	{

		'url':my_url
		,'onLoading':function(req){

			if(link_name != "already_in_fav" && link_name != "add_to_fav"){
					inside_inner_div.innerHTML = img;
				}
			else{
					inside_inner_div.innerHTML = img_fav;
				}
			show_div(obj_div, b); }
		,'onSuccess':function(req){
			//obj_div.style.border = '0';


			var temp = new Array();
			var temp = req.responseText.split("||");

			if(link_name == "already_in_fav")
			{
				inside_inner_div.innerHTML = temp[0];
				b.innerHTML = "<img src='"+IMG_PATH+"/imgs/bullet/favorite.jpg' width='15' height='16' border='0' vspace='0' align='absmiddle'> Favorite";
				ob_fav.src = IMG_PATH + "/imgs/icons/icon_fav.gif";
				ob_fav.setAttribute("title", "favorites")
			}
			else if(link_name == "add_to_fav")
			{

				inside_inner_div.innerHTML = temp[0];
				b.innerHTML = "<img src='"+IMG_PATH+"/imgs/bullet/add-to-fav.gif' width='18' height='14' border='0' vspace='0' align='absmiddle'> Add to Favorites";
				//alert("ob_fav :"+ob_fav);
				ob_fav.src = IMG_PATH + "/imgs/icons/transparent-fav.gif";

			}
			else
			{
				inside_inner_div.innerHTML = temp[0];

				if (window.ActiveXObject)
				{
					var iframe_height = document.getElementById('show_main_div').offsetHeight - 20;
					if(document.getElementById('frame_id'))
					document.getElementById('frame_id').style.height= iframe_height+"px";
				}
			}

		}
		,'timeout':30000
		,'onTimeout':function(req){ alert('A problem occurred while communicating with the server.\nPlease make sure you are connected to the Internet and try again in sometime.'); return false;}
		,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}

		}
	 );

	 return status;


  } // EO function_name()


  function show_already_in_fav(profileid, memberlogin)
  {

	fav_link_change_id = "fav_link_" + profileid;

	b = document.getElementById(fav_link_change_id);

	var msg = "To view all members in your favorites list <a href=\""+SERVER_PATH+"/partner_search/matrimonial_search/favourites.php\">click here</a><br><br>To remove "+profileid+" from your favorites list, <a href='#' onclick=\"javascript:show_content_layer('/ssi/p-action/addremovefav-ajax.php?profileid="+profileid+"&memberlogin="+memberlogin+"&removefromfav=Y','"+profileid+"','add_to_fav', 'show-add-to-fav-msg'); return false;\">click here</a>";

	obj_div = document.getElementById("show-add-to-fav-msg");
	show_div(obj_div, b);

	document.getElementById("display-message-add-to-fav").innerHTML = msg;

   }

  function show_visitor_layer(visitor_div_id, profileid, search_result_id, featured)
  {
		var link;
		show_link_td_id = "link_change_id_" + profileid;
		if (featured == "Y")
		{
			show_link_td_id = "featured_link_change_id_" + profileid;
		}
		b = document.getElementById(show_link_td_id);

		showControls_visitor = document.getElementById(visitor_div_id);

		show_div(showControls_visitor, b);

		document.getElementById('visitor_id').innerHTML = profileid;
		featured_link = "";
		if (featured == "Y")
		{
			featured_link = "&featured=Y";
		}

		link = escape('/partner_search/matrimonial_search/showprofile.php?profileid='+profileid+featured_link+'&set='+search_result_id+'&set_profiles=&set_profiles_back=#action&vcase=express_interest');

		document.getElementById('show_visitor_link').innerHTML = "<a  class='smallbluelink' href='/registration/user/login.php?go="+link+"'>Login now</a>";

  }

  function show_same_gender_layer(same_gender_div_id, profileid, featured)
  {
		show_link_td_id = "link_change_id_" + profileid;
		if (featured == "Y")
		{
			show_link_td_id = "featured_link_change_id_" + profileid;
		}
		b = document.getElementById(show_link_td_id);

		showControls_same_gender = document.getElementById(same_gender_div_id);

		show_div(showControls_same_gender, b);

		document.getElementById('same_gender_id').innerHTML = profileid;


  }

  function trim(str, chars)
  {
	return ltrim(rtrim(str, chars), chars);
  }

  function ltrim(str, chars)
  {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
  }

  function rtrim(str, chars)
  {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
  }

function show_refine_sub_layer_new(type, label, div_id, gender)
{
	var selected_values = new String();
	var img = "<br><br><center><img src=\""+ IMG_PATH + "/imgs/profiles/loading-ajax.gif\" align=\"center\"></center><br><br>";

	if(type == "")
	{
		return false;
	}

	var top_txt = "";
	var show_preselection = "";


	if(label == "mothertongue")
	{
		top_txt = "Mother Tongue:";
	}
	else if(label == "caste")
	{
		top_txt = "Caste:";
	}


	if(type == "mothertongue")
	{
		
		selected_values = fn_js_mothertongue_selected;
		show_preselection = fn_js_cast_selected;
		

	}
	else if(type == "caste")
	{
		selected_values = fn_js_cast_selected;
		show_preselection = fn_js_mothertongue_selected;
		
	}
	else if(type == "show_state")
	{
		selected_values = document.getElementById('country-state-city').value;

		if(selected_values == "")
		{
			alert("Please select country.");
			return false;
		}

		show_preselection = js_stateofresidence;
		top_txt = "State:";
	}
	else if(type == "show_city")
	{
		var country_sel = document.getElementById('country-state-city').value;
	
		if(country_sel == "")
		{
			alert("Please select country.");
			return false;
		}

		if(country_sel.indexOf("|India|") >= 0
			|| country_sel.indexOf("| India|") >= 0
			|| country_sel.indexOf("| USA|") >= 0
			|| country_sel.indexOf("|USA|") >= 0
			)
		{

			selected_values = js_stateofresidence+"@" + country_sel;
		
		if(js_stateofresidence == "")
		{
			alert("Please select state.");
			return false;
		}

		}
		else
		{
			if(js_stateofresidence == "")
			{
				selected_values = "| @"+country_sel;
			}
			else
			{
				selected_values = js_stateofresidence+"@" + country_sel;
			}

		}


		show_preselection = js_nearestcity;
		top_txt = "City:";
	}


	if(label == "country")
	{
		selected_values = document.getElementById('country').value;
		top_txt = "Country:";
	}
	else if(label == "country-state-city")
	{
		selected_values = document.getElementById('country-state-city').value;
		top_txt = "Country:";
	}
	else if(label == "marital")
	{
		selected_values = document.getElementById('marital').value;
		top_txt = "Marital Status:";
	}
	else if(label == "profession")
	{
		selected_values = js_occupation;
		top_txt = "Profession:";
	}
	else if(label == "specialcase")
	{
		selected_values = document.getElementById('specialcase').value;
		top_txt = "Special Cases:";
	}

	if(type == "mothertongue" || type == "caste")
	{

		religion = document.getElementById('religion').value;
		mothertongue = document.getElementById('mothertongue').value;
		gender = document.getElementById('gender').value;
		selected_caste = document.getElementById('caste').value;

		if(!religion)
		{
			alert("Please select Religion");
			return false;
		}

		my_url = "/ssi/ajax-com-mt-caste.php?community=" + escape(religion) + "&mothertongue=" + escape(mothertongue)+ "&gender=" + escape(gender)+"&return_type=html&selected_caste="+escape(selected_caste);

	}
	else
	{
		my_url = "/ssi/p-action/modify-checkbox-html.php?type="+escape(type)+"&label="+escape(label)+"&selected_values="+escape(selected_values)+"&gender="+escape(gender)+"&pre_selection="+escape(show_preselection);
	}

	//alert(my_url); //return false;
	dest_id = document.getElementById("show_refine_sub_div");
	dest_inner_id = document.getElementById("show_refine_sub_div1");

	if(document.getElementById('religion1'))
		hide_div("religion1");

	if(document.getElementById('mothertongue_div'))
		hide_div("mothertongue_div");

	var status = AjaxRequest.get(
	{
		'url':my_url
		,'onLoading':function(req){
			document.getElementById("layer_top_txt").innerHTML = ""; 

			// Hide "Sort Order By" drop down
			show_hide_sort_drop_down("none");

			dest_inner_id.innerHTML = ""; 
			show_div(dest_id, div_id);
			dest_inner_id.innerHTML = img;

		}
		,'onSuccess':function(req)
		{
			document.getElementById("layer_top_txt").innerHTML = top_txt;
			
			dest_inner_id.innerHTML = req.responseText;

				if(dest_id.offsetHeight > '200')
					document.getElementById('frame_div_id').style.height = "160px";
					
				}
		,'timeout':30000
		,'onTimeout':function(req){ alert('A problem occurred while communicating with the server.\nPlease make sure you are connected to the Internet and try again in sometime.'); return false;}
		,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	}
	 );
}


function set_hidden_value(label, obj, type)
{
	if(label == "mothertongue")
	{
		chk_name = new Array();
		chk_name = obj.mothertonguearray;
	}
	else if(label == "religion")
	{
		chk_name = new Array();
		chk_name = obj.religionarray;
	}
	else if(label == "caste")
	{
		chk_name = new Array();
		chk_name = obj.castearray;
	}
	else if(label == "marital")
	{
		chk_name = new Array();
		chk_name = obj.maritalarray;
	}
	else if(label == "country" || label == "country-state-city")
	{
		chk_name = new Array();
		chk_name = obj.countryarray;
	}
	else if(label == "state")
	{
		chk_name = new Array();
		chk_name = obj.statearray;
	}
	else if(label == "city")
	{
		chk_name = new Array();
		chk_name = obj.cityarray;
		/*if(chk_name.constructor.toString().indexOf("Array") == -1)
		{
			alert('is not array');
		}
		else
		{
			alert('is array');
		}*/

	
	}
	else if(label == "profession")
	{
		chk_name = new Array();
		chk_name = obj.professionarray;
	}
	else if(label == "specialcase")
	{
		chk_name = new Array();
		chk_name = obj.specialcasearray;
	}
	
	

	var hidden_val = "|";
	var hidden_val_caste = "";
	var flag_check = false;
	var temp_religion_caste = "";
	var temp_caste = "";
	
	for (counter = 0; counter < chk_name.length; counter++)
	{
		if(chk_name[counter].checked)
		{
			if(chk_name[counter].value != "")
			{
				flag_check = true;
				//Space required here
				hidden_val = hidden_val + chk_name[counter].value + "| ";
				temp_religion_caste = chk_name[counter].value.split(":");
				temp_caste = temp_religion_caste[1];
				if(!temp_caste)
					temp_caste = temp_religion_caste[0];

				hidden_val_caste = hidden_val_caste + ", " + temp_caste;
			}

			//var hidden_val
		}

	}

	if(!chk_name.length){
		flag_check = true;
		hidden_val = hidden_val + chk_name.value + "| ";
	}

	if(flag_check == false)
	{
		hidden_val = "";
	}

	// If a Religion has been selected...
	if(flag_check == true && label == "religion")
	{
		// ...uncheck "Doesn't Matter"
		chk_name[0].checked = false;
	}

	//selected_mt_ct = check_multiple_entry_combobox("castearray[]","Y");
	//hidden_val = "|"+hidden_val+"|"

	document.getElementById(label).value = hidden_val;
	
	if(label == "mothertongue")
	{
		fn_js_mothertongue_selected = hidden_val;

		check_if_all_values_selected(chk_name, document.getElementById('mothertongue'), fn_js_mothertongue_selected);

		document.getElementById('mothertongue_selcted').innerHTML = short_string(hidden_val);

		if(type)
		{
			document.getElementById('caste_selected').innerHTML = "&nbsp;Doesn't Matter";
			document.getElementById('caste').value = "";
			fn_js_cast_selected = "";

			if(!hidden_val)
			{
				for (counter = 0; counter < chk_name.length; counter++)
				{
					if(!chk_name[counter].value)
					{
						chk_name[counter].checked=true;					
						break;
					}
				}				
			}

		}

	if(document.getElementById('mothertongue_div'))
		hide_div("mothertongue_div");

		//alert(dest_id);

	}
	else if(label == "caste")
	{
		fn_js_cast_selected = hidden_val;
		
		if(!hidden_val_caste)
			hidden_val_caste = hidden_val;


		hidden_val_caste = hidden_val_caste.trim();

		if(hidden_val_caste)
		{
			hidden_val_caste = hidden_val_caste.replace(/,/g, "|");
			document.getElementById('caste_selected').innerHTML = short_string(hidden_val_caste+"  ");
		}
		else
		{
			document.getElementById('caste_selected').innerHTML = "&nbsp;Doesn't Matter";

			for (counter = 0; counter < chk_name.length; counter++)
			{
				if(!chk_name[counter].value)
				{
					chk_name[counter].checked=true;
					break;
				}
			}

		}

	}
	else if(label == "marital")
	{
		document.getElementById('marital_selected').innerHTML = short_string(hidden_val);

	}
	else if(label == "country")
	{
		document.getElementById('country_selected').innerHTML = short_string(hidden_val);
		check_if_all_values_selected(chk_name, "");
	}
	else if(label == "country-state-city")
	{
		document.getElementById('country_selected').innerHTML = short_string(hidden_val);


		document.getElementById('state_selected').innerHTML = "&nbsp;Doesn't Matter";

		document.getElementById('city_selected').innerHTML = "&nbsp;Doesn't Matter";

		js_stateofresidence = "";
		
		js_nearestcity = "";

		document.getElementById('state').value = "";

		document.getElementById('city').value = "";

	}
	else if(label == "state")
	{
		js_stateofresidence = hidden_val;
		document.getElementById('state_selected').innerHTML = short_string(hidden_val);

		document.getElementById('city_selected').innerHTML = "&nbsp;Doesn't Matter";

		js_nearestcity = "";

		document.getElementById('city').value = "";
	}
	else if(label == "city")
	{
		js_nearestcity = hidden_val;
		document.getElementById('city_selected').innerHTML = short_string(hidden_val);

	}
	else if(label == "profession")
	{
		js_occupation = hidden_val;
		document.getElementById('profession_selected').innerHTML = short_string(hidden_val);
	}
	else if(label == "specialcase")
	{
		document.getElementById('specialcase').value = hidden_val;
		document.getElementById('specialcase_selected').innerHTML = short_string(hidden_val);
	}

	if(label == "religion")
	{
		document.getElementById('religion').value = hidden_val;
		document.getElementById('religion_selected_value').innerHTML = short_string(hidden_val);

		if(type)
		{


			var religion_value        = document.getElementById('religion').value;
			var caste_value           = document.getElementById('caste').value;
			var caste_label           = document.getElementById('caste_selected').value;

			var arr_selected_religion = religion_value.split("|");
			var arr_selected_caste    = caste_value.split("|");
			var new_caste_value       = "";
			var religion_from_caste   = "";
			var caste                 = "";
			var only_caste            = "";
			var new_caste_label       = "";
			var selected_caste_length = arr_selected_caste.length;


			check_if_all_values_selected(chk_name, document.getElementById('religion'), "");

			for(i=0; i< selected_caste_length; i++)
			{
                caste = arr_selected_caste[i].trim();
                if(!caste) 
					continue;

					religion_from_caste = caste.split(":");
					only_caste = religion_from_caste[1];

					if(!only_caste)
						only_caste = religion_from_caste[0];

					religion_from_caste =  religion_from_caste[0];

					if(religion_value.search(religion_from_caste)>0)
					{
					   new_caste_value += "| " + caste;
					   new_caste_label += "| " + only_caste;
					}

			}

			if(new_caste_value)
				new_caste_value += "| ";

			if(new_caste_label)
				new_caste_label += "| ";

			document.getElementById('caste').value = new_caste_value;
			document.getElementById('caste_selected').innerHTML = short_string(new_caste_label);

			if(!religion_value)
			{
				for (counter = 0; counter < chk_name.length; counter++)
				{
					if(!chk_name[counter].value)
					{
						chk_name[counter].checked=true;
						break;
					}
				}
			}	

			fn_js_cast_selected = new_caste_value;

		}

		if(document.getElementById('religion1'))
			hide_div("religion1");
	}

	hide_div("show_refine_sub_div");

	return false;
}


function short_string(full_string)
{
	if(full_string == "")
	{
		return new_string = "Doesn't Matter";
	}

	var string = new String();
	var new_string  = new String();
	var string_temp2 = new Array();
	
	string_temp = full_string.substring(1,full_string.length-2);

	string_temp2 = string_temp.split("|");
	
	new_string = string_temp2[0];
	
	if(string_temp2[0].length > 13 || string_temp2.length > 1)
	{
		string = string_temp2[0].substring(0,13);
		new_string = string + "...";
	}
		
	new_string = "<a name=\"#\" class=\"tip\" onmouseover=\"tooltip('"+string_temp2+"');\" onmouseout=\"exit();\">&nbsp;"+new_string+"</a>";

	
	return new_string;

}


function refine_validation(srch_name)
{
	var alert_str='';
	var motherounge_selected_flag =0;
	var cast_selected_flag =0;
	var country_selected_flag =0;
	var ageto = document.getElementById('ageto').options[document.getElementById('ageto').selectedIndex].text;
	var agefrom = document.getElementById('agefrom').options[document.getElementById('agefrom').selectedIndex].text;
	
	if(fn_js_cast_selected)
	{
		motherounge_selected_flag = 1;
	}

	if(fn_js_mothertongue_selected)
	{
		cast_selected_flag = 1;
	}
	
	if(srch_name == "city_search" && document.getElementById('country-state-city').value != "")
	{
		country_selected_flag = 1;
	}
	else if(srch_name != "city_search" && document.getElementById('country').value != "")
	{
		country_selected_flag = 1;
	}

	if(ageto < agefrom)
	{
		alert_str = alert_str + "Invalid Age selected\n";
	}

	if(eval(ageto - agefrom) > 10)
	{
		alert_str = alert_str + "Age ranges exceeds 10 years.\nChange age ranges or use Smart Search\n";
	}


	if((motherounge_selected_flag !=1 && cast_selected_flag != 1 && country_selected_flag != 1 && !document.getElementById('religion').value) || ( !document.getElementById('religion').value && !document.getElementById('mothertongue').value && !document.getElementById('caste').value && !document.getElementById('country').value ))
	{
		alert_str = alert_str + "Please select atleast Mother Tongue or Religion/Caste or Country.\n";
	}

	if(srch_name == "keyword_search")
	{
		if(document.getElementById('keyword_txt') != null)
		{
			if(document.getElementById('keyword_txt').value != "min. 4 characters")
			{
				//alert("sssss"+document.getElementById('keyword_txt'));
				return check_keyword_refine(document.getElementById('keyword_txt'));
			}
		}

	}
	if(alert_str != '')
	{
		alert(alert_str);
		return false;
	}


}

function keyword_label_to_textbox(keyword)
{
	document.getElementById('keyword_id').innerHTML = "<input type='text' name='keyword_txt' id='keyword_txt' value='"+keyword+"'>";

}