var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}

function populate_form(){
	//age from
	ul1= document.getElementById('age_from_ul');
	if(ul1)
	{
		s = '<li> </li>';
		for(i=18;i<=99;i++){
			s = s + "<li onclick=\"select_option(this,'"+i+"');\">"+i+"</li>";
	}
		ul1.innerHTML = s;
	}
	div1 = document.getElementById('age_from_div');
	if (div1 && age_from > 0)
	{
		div1.innerHTML = age_from;
		document.getElementById('age_from').value = age_from;
	}
	//age_to
	ul2 = document.getElementById('age_to_ul');
	if(ul2)
	{
		s = '<li> </li>';
		for(i=19;i<=100;i++){
			s = s + "<li onclick=\"select_option(this,'"+i+"');\">"+i+"</li>";
		}
		ul2.innerHTML = s;
	}

	div2 = document.getElementById('age_to_div');
	if (div2 && age_to > 0)
	{
		div2.innerHTML = age_to;
		document.getElementById('age_to').value = age_to;
	}


	var inp = new Array('user_zip','keyword', 'type');
	for(i=0;i<inp.length;i++){
		document.getElementById(inp[i]).value = eval(inp[i]);
	}
	var sel = new Array("user_dating", "country_id", "user_orientation", "radius", "display");
	for(i=0;i<sel.length;i++)
	{
		el = document.getElementById(sel[i]);
		for(j=0;j<el.options.length;j++)
		{
			if(el.options[j].value == eval(eval("sel[i]")))
			{
				el.selectedIndex = j;
				break;
			}
		}
	}
	if((country_id == '31' ||country_id == '181' ||country_id == '182') && state_id != '')
	{
		get_state(document.getElementById('country_id').value, state_id);
		/*
		if(county_id != '')
		{
			window.setTimeout('get_county(document.getElementById("state_id"), county_id)', 100);
		}
		*/
	}
}
function get_state_old(sel, curr)
{
	if(!sel) return;
	htm1 = document.getElementById('state_holder');
	htm2 = document.getElementById('county_holder');
	if(sel.value == '31' || sel.value == '181' || sel.value == '182')
	{
		htm1.innerHTML = '<blink>Loading ... please wait</blink>';
		htm2.innerHTML = 'US, Canada & UK only(choose the country and state first)';
		xmlhttp.open("GET", '/include/ax/state_county.php?op=get_state&country_id=' + sel.value + '&curr='+curr,true);
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4) {
				var data = xmlhttp.responseText;
				htm1.innerHTML = data;
			}
		}
		xmlhttp.send(null);
	}
	else
	{
		htm1.innerHTML = 'US, Canada & UK only(choose the country first)';
	}
}

function get_state(cntry, cur)
{
	if(cntry < 1) return;
	if(cntry == '31' || cntry == '181' || cntry == '182')
	{
		$.get('include/ax/state_county.php', {op: 'get_state', country_id: cntry, curr: cur, srch: 1}, function(data) {$('#state_holder').html(data);redraw_selectboxes();});
	}
	else
	{
		$('#state_holder').html('<select name="state_id" id="state_id" onchange="get_state(this.options[this.selectedIndex].value)" class="dropdown1" rel="fancy_select_regular_settings_account" label_class="" open_class="selectbox_opened selectgrey_opened selectbox_openedinactive" close_class="selectbox_closed selectgrey_closed selectbox_closedinactive"><option value="0">Select country</option></select>');
		redraw_selectboxes();
	}
}

function zip_keydown(val)
{
	if(val.length < 3)
	{
		//disable_radius(10);
		return false;
	}
	enable_radius(10, true);
	return true;
}

function enable_radius(val, isFancy)
{
	if(isFancy)
	{
		var divv = document.getElementById('fancysel_radius');
		divv.getElementsByTagName('DIV')[0].innerHTML = val;
		divv.getElementsByTagName('INPUT')[0].value = val;
		divv.setAttribute('openclass', 'selectbox_opened selectgrey_opened');
		divv.setAttribute('close_class', 'selectbox_closed selectgrey_closed');
		divv.setAttribute('onclick', "activateSelect(this, 'selectbox_opened selectgrey_opened', 'selectbox_closed selectgrey_closed');");
		divv.setAttribute('class', 'selectbox_closed selectgrey_closed');
	}
	else
	{
		var divv = document.getElementById('radius');
		divv.setAttribute('openclass', 'selectbox_opened selectgrey_opened');
		divv.setAttribute('close_class', 'selectbox_closed selectgrey_closed');
	}
	return true;
}

function disable_radius(val)
{
	var divv = document.getElementById('fancysel_radius');
	divv.getElementsByTagName('DIV')[0].innerHTML = val;
	divv.getElementsByTagName('INPUT')[0].value = val;
	divv.setAttribute('openclass', 'selectbox_opened selectgrey_opened selectbox_openedinactive');
	divv.setAttribute('close_class', 'selectbox_closed selectgrey_closed selectbox_closedinactive');
	divv.setAttribute('onclick', "activateSelect(this, 'selectbox_opened selectgrey_opened selectbox_openedinactive', 'selectbox_closed selectgrey_closed selectbox_closedinactive');");
	divv.setAttribute('class', 'selectbox_closed selectgrey_closed selectbox_closedinactive');
}

function set_selected(objID, objValue)
{
	selectObj = document.getElementById(objID);
	for(var i=0; i<selectObj.length; i++)
	{
		if(selectObj.options[i].value == objValue)
		{
			selectObj.selectedIndex = i;
			return;
		}
	}
}

function set_text(objID, objValue)
{
	document.getElementById(objID).value = objValue;
}