function SearchKeyPress()
{
	if (event.keyCode == 13)
	{
		sendSearchForm();
	}
}

function sendForm()
{
	var frm = document.Form1;
	
	if (trim(frm.subject.value) == "")
	{
		alert('נא להזין נושא פנייה');
		frm.subject.focus();
		return;
	}
	
	if (trim(frm.contact_name.value) == "")
	{
		alert('נא להזין את שם הפונה');
		frm.contact_name.focus();
		return;
	}
	
	if (trim(frm.contact_phone.value) == "" && trim(frm.contact_email.value) == "")
	{
		alert('נא להזין טלפון או כתובת דוא"ל');
		frm.contact_phone.focus();
		return;
	}
	
	if (trim(frm.contact_email.value) != "")
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		if (!filter.test(frm.contact_email.value)) 
		{
			alert('כתובת הדוא"ל שהוזנה אינה תקינה');
			frm.contact_email.focus();
			return;
		}		
	}
	
	document.Form1.submit();
}

function FillCity(area_id)
{
	var oHTTP = new ActiveXObject("MSXML2.XMLHTTP");
		oHTTP.open("GET","../../Shared/Library/GetCitiesByArea.aspx?areaID=" + area_id,false);
		oHTTP.send();			
		
	var oXML = new ActiveXObject("MSXML2.DOMDocument");
		oXML.async = false;
		oXML.validateOnParse = false;
		oXML.loadXML(oHTTP.responseText);
		
	//alert(oHTTP.responseText);
		
	if (oXML.parseError != 0)
	{
		alert(oXML.parseError.reason);
	}
	else 
	{
		var select = document.Form1.cities;
		var nodes = oXML.selectNodes("//Cities");
		var node;
		var option;
		
		var optionsCount = select.options.length;
		for(var i=0; i < optionsCount; i++)
		{
			select.options.remove(0);
		}
		
		//Insert the first option 
		option = document.createElement("OPTION");
		select.options.add(option);
		option.innerText = "כל היישובים";
		option.value	 = "-1";
			
		while (node = nodes.nextNode())
		{
			option = document.createElement("OPTION");
			select.options.add(option);
			option.innerText = node.childNodes[1].text;
			option.value	 = node.childNodes[0].text;
		}
	}
}

function resetForm()
{
	document.Form1.reset();	
	document.Form1.searchStr.value = "";		
	document.Form1.categoryList.selectedIndex = 0;
	document.Form1.areaList.selectedIndex = 0;
	
	FillCity(-1);
}

function resetContactForm()
{
	document.Form1.reset();	
	document.Form1.contact_email.value = "";		
	document.Form1.contact_phone.value = "";		
	document.Form1.contact_name.value = "";		
	document.Form1.subject.value = "";		
	document.Form1.details.value = "";		
}

function sendSearchForm()
{
	var href = "../SearchResuts/SearchResuts.aspx?pi=17";
	
	if (document.Form1.categoryList.value != -1)
	{
		href += "&catID=" + document.Form1.categoryList.value;
	}
	if (document.Form1.areaList.value != -1)
	{
		href += "&areaID=" + document.Form1.areaList.value;
	}
	if (document.Form1.cities.value != "")
	{
		href += "&cityID=" + document.Form1.cities.value;
	}
	if (trim(document.Form1.searchStr.value) != "")
	{
		href += "&str=" + document.Form1.searchStr.value;
	}
	
	document.location.href = href;
}

//////////////////////
function trim(str)
{
	try {
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e) {
		return str;
	}
}
//////////////////////
function isnull(arg)
{
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
//////////////////////
function nvl()
{
	for (var i=0; i<arguments.length; i++) {
		if (!isnull(arguments[i])) return arguments[i];
	}
	return null;
}	


