﻿// Set focus to fields onLoad event for searchUnits form
function sFOL(){
	var ltx ;
	if( isIE ){
	gED("locations").style.display = 'block'; 
		ltx = window.document.forms["form_searchCity"].locations_text;
		//if( ltx == undefined ) ltx = window.document.forms[1].locations_text;
		ltx.select();
		ltx.focus();
	} else {
		ltx = gEN( "locations" );
		ltx.firstChild.focus();
//		alert("Set location field focus for FireFox ltx:"  + ltx );
	}
 }
  
 // Cut procedure name - Get element by ID function
function gED( en	// element name
){
	return document.getElementById( en );
}
// Cut procedure name - Get elements by Name function
function gEsN( en	// element name
){
	return document.getElementsByName( en );
}
// Get first element by name
function gEN( en	// element name
){
	var e = gEsN( en );
	return e == null ? e : e[0];
}
// Get first element value - by Element Name
function gVEN( en	// element name
){
	var e = gEN( en );
	return e == null ? e : e.value ;
}
// Get element value - by Element ID
function gVED( en	// element name
){
	var e = gED( en );
	return e == null ? e : e.value ;
}


function tKP( e	// event
){
	if( window.event ){
		if( e.keyCode == 13 ){ 
			checkFields("0",""); //form's JS Header functions
		} 
	} else {
		if( e.which == 13 ){
			checkFields("0",""); //form's JS Header functions
			e.preventDefault();
		} 
	}
}

function checkFields(){
	var fm  = window.document.forms["form_searchCity"];
	var elmnt  = "";
	var myValue="";
	var ctx, cpp;	// current "..._text" element, "..._popup" element
 	if( moz ){
 		cpp =  gEN( "locations" ).firstChild;
 	}else{
 		cpp   = gEN( "locations_popup" );
 	}
	elmnt = cpp.selectedIndex;
	if (elmnt == -1) {
		alert( "הערך שהקלדת אינו מופיע ברשימת הישובים - הקלד ערך חדש או בחר מהרשימה" );
		cpp.selectedIndex = 0;
 		if( ! moz ){
			ctx = gEN( "locations_text" ); // fm.locations_text;
			ctx.value = "בחר ישוב" ;
			ctx.select();
			ctx.focus();
		}
		fm.cityID.value=""
		return false;
	}else if (elmnt != 0) {
		myValue = cpp.options[elmnt].value;
		if (myValue !="" && myValue !=undefined ){
		    fm.cityID.value=myValue;
		    var action=siteUrl+"products/city.asp?cityID="+myValue;
		    document.getElementById("form_searchCity").action=action;
			document.getElementById("form_searchCity").submit();
		}else{
	        alert("לא ניתן להשלים את החיפוש כפי שביקשת - יש לבחור שדה ישוב");
	        return false;
	    }
	}else{
	   alert("לא ניתן להשלים את החיפוש כפי שביקשת - יש לבחור שדה ישוב");
	   return false;
	}
	
}


