function modalToggle()
{
	$("#quicklogin").toggle();
	$("#quickmodal").toggle();
}

function update(where)
{
	var currLocation=window.location.toString();
	var currLocationArray=currLocation.split('#');
	if(currLocationArray.length>1){
		if(currLocationArray[1]=='advanced'){
			var theFormSearch='form_search2';
			var theDomain='domain2';
		}
		else {
			var theFormSearch='form_search1';
			var theDomain='domain1';
		}
	}
	else {
		var theFormSearch='form_search1';
		var theDomain='domain1';
	}
	var data = $("#"+theFormSearch).serialize();
	var domain = $("#"+theDomain).val();
	
	if ( domain != '' )
	{
		if ( domain.length < 2 )
		{
			alert('Domain keyword must be longer than 2 characters long.');
			return false;
		}
	}

	//this.location = 'search2.php?search=1&'+data+'&page='+where;
	 var html = '';
	 var html = $.ajax({
					   type: "POST",
					   url: "index.php?ajax=1&page="+where,
					   data: data+'&search=1',
					   async: false
					 }).responseText;
	


	$("#content").html(html);

	return false;
}
function checkUpdate()
{
	var currLocation=window.location.toString();
	var currLocationArray=currLocation.split('#');
	if(currLocationArray.length>1){
		if(currLocationArray[1]=='advanced'){
			var theFormSearch='form_search2';
			var theDomain='domain2';
		}
		else {
			var theFormSearch='form_search1';
			var theDomain='domain1';
		}
	}
	else {
		var theFormSearch='form_search1';
		var theDomain='domain1';
	}
	var data = $("#"+theFormSearch).serialize();
	var domain = $("#"+theDomain).val();
	
	if ( domain != '' )
	{
		if ( domain.length < 2 )
		{
			alert('Domain keyword must be longer than 2 characters long.');
			return false;
		}
	}

	return true;
}
function colsort(what,how)
{
	update('1&orderby='+what+'&order='+how);
}

function page(where)
{
	update(where);
	return false;
}

var _path = '/';

function isset(varname)
{
	if(typeof( window[ varname ] ) != "undefined") return true;
	else return false;
}

function sure(msg)
{
	if (msg == undefined)
	{
		var msg = 'Are you sure?';
	}

	var ask = confirm(msg);
	if (ask == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function showstates()
{
	var country = $("#country").val();
	changecountry(country);

	if (country === 'US')
	{
		$("#state-p").fadeIn();
		$("#states").removeAttr("disabled");
	}
	else
	{
		if ($("#state-p").css("display") != 'none' )
		{
			$("#state-p").fadeOut();
			$("#states").attr("disabled","disabled");
		}
	}
}

function changecountry(country)
{
	country = country.toLowerCase();
	if ( country == '')
	{
		$("#countryimg").remove();
	}

	if ($("#countryimg").length > 0 )
	{
		//$("#countryimg").attr("src","/images/flags/"+country+".gif");
	}
	else
	{
		//$("#country").after("<img style=\"margin-left:5px;\" src=\"/images/flags/"+country+".gif\" id=\"countryimg\" alt=\"\"/>");
	}
}

function cp_imadd()
{
	var count = $(".ims").length;

	if ((count+1) > 5)
	{
		alert('You can only add up to 5 different type of IM Screen Names');
		return false;
	}

	var height = $("#im_opt").children("strong").css("height");
	var height2 = height.replace(/px/,'');

	var newheight = parseInt(height2) + 20 +"px";

	$("#im_opt").children("strong").css("height",newheight);

	var next = count+1;

	$(".ims:last").after("<span class=\"ims\">\n<input type=\"text\" name=\"im["+next+"]\" class=\"inputtext\" style=\"width:120px;\" />\n<select name=\"im_prog["+next+"]\" id=\"im_prog_"+next+"\"><option value=\"aim\">AIM</option><option value=\"skype\">Skype</option><option value=\"msn\">MSN</option><option value=\"ym\">Yahoo!</option><option value=\"gtalk\">gTalk</option></select>\n</span>");

	$(".ims:last").hide();
	$(".ims:last").slideDown('fast');

	return false;
}

function useropt()
{
	$("#useropt").toggle();
}

function changebg(what,to)
{
	switch (to)
	{
		case 'yes' :	var color = '#F2FFE4 url(\'/images/sign_yes.png\') no-repeat 95% 50%'; break;
		case 'no':		var color = '#FFF2F2 url(\'/images/sign_no.png\') no-repeat 95% 50%'; break;
		case 'def':		var color = '#F8FAFD'; break;
	}
	
	//$('#'+what).parent().css("background-color",color);
	$('#'+what).parent().css("background",color);
	$('#'+what).focus();
	
	if ( to == 'no')
	{
		$("#"+what).parent().find("small").css("color","red");
		$("#"+what).parent().find("span").css("color","red");
	}
	else
	{
		$("#"+what).parent().find("small").css("color","#9e9e9e");
		$("#"+what).parent().find("span").css("color","#9e9e9e");
	}
}

function locksubmit(what)
{
	if ( what == 1 )
	{
		$("#submitbutton").attr("disabled","disabled");
	}
	else
	{
		$("#submitbutton").removeAttr("disabled");
	}
}
