function toggle(id){id.style.display=id.style.display=="none" ? "" : "none"}
function expose(id,items) {for(i=1;i<=items;i++)if(i==id)document.getElementById(i).className=""; else document.getElementById(i).className="hidden"}
function addToFavorite(title,url){ 
    if(window.sidebar)//Mozilla Firefox Bookmark 
        window.sidebar.addPanel(title,url,"")
    else if(window.external)//IE Favorite 
        window.external.AddFavorite( url,title)
    else if(window.opera && window.print)//Opera Hotlist 
        return true
}
function setHome(lang,url){
    if(lang=='he')
        securityAlert = "! פעולה זו נמנעה בשל הגדרות הדפדפן שלך\n'about:config' כדי לאפשר את ביצוע הפעולה, יש להקליד בשורת הכתובת של הדפדפן\nTrue ל 'signed.applets.codebase_principal_support' ולשנות את ערכו של הפרמטר"
    else
        securityAlert = "This action was aviod by your browser !\nIf you want to enable, please enter 'about:config' in your address line, and change the value of 'signed.applets.codebase_principal_support to True'"
    if(document.all){
        document.body.style.behavior="url(#default#homepage)"
        document.body.setHomePage(url)
    } else if(window.sidebar){
        if(window.netscape){
            try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
        }
        catch(e){
            alert(securityAlert)
        }
    }
    var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch)
    prefs.setCharPref("browser.startup.homepage",url);
    }
}
function search(query,lang,search){
	if (lang=="he"){
		min = 2
		queryAlert = ".(" + "נא הזן את הביטוי שברצונך לחפש (לפחות " + min + " תווים"
	} else {
		min = 2
		queryAlert = "Please enter a search term (at least " + min + " characters)."
	}
	if (query.value.length < min) {
		alert(queryAlert)
		query.focus()
		query.select()
		return
	} else {
		window.location ="search.asp?lang=" + lang + "&amp;search=" + search + "&amp;query=" + query.value
	}
}
function newWindow(url,name,width,height,top,left,fullscreen,channelmode,toolbar,location,directories,status,menubar,scrollbars,resizable){
	if (top=='c') top = screen.height/2-height/2
	if (left=='c') left = screen.width/2-width/2
	winObject = window.open(url,name,'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',fullscreen=' + fullscreen + 'channelmode=' + channelmode + ',toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',scrollbars=' + scrollbars + ',resizable=' + resizable + '\'')
	winObject.focus()
}
function clean(form,success) {
    form.reset();
    for(i=0;i<form.elements.length;i++)form.elements[i].style.backgroundColor = success
}
function checkField(field,flag,color,bgcolor) {
	if (flag=="str") success = field.value!=""; else success = flag
	if (success) document.getElementById(field.id).style.backgroundColor = bgcolor; else document.getElementById(field.id).style.backgroundColor = color
	return success
}
function getKey(e){
	var key = window.event ? e.keyCode : e.which;
    return key;
}
function verifyKey(e,invalidChars){
    if(invalidChars==1){
        invalidChars = '\"\\\',@:.!`[]'
    }
	var key = window.event ? e.keyCode : e.which;
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i)
		if (String.fromCharCode(key).indexOf(badChar, 0) != -1) return false
	}
	return true
}
function onKeyPressBlockNumbers(e){
	var key = window.event ? e.keyCode : e.which;
	if(key==0 || key==8)return true;
	var keychar = String.fromCharCode(key);
	reg = /\d/;
	return !reg.test(keychar);
}
function onKeyPressAllowNumbers(e){
	var key = window.event ? e.keyCode : e.which;
	if(key==0 || key==8)return true;
    return !(key < 48 || key > 57);
}
function onKeyPressAvoidQuotes(e){
	var key = window.event ? e.keyCode : e.which;
	if(key==0 || key==8)return true;
    return !(key == 39 || key == 34);
}
function select_color(inputBox){
	var param_color=new Object();
	param_color.value=inputBox.value;
    sel_color = showModalDialog( "selcolor.htm",param_color,"dialogWidth:340px;dialogHeight:360px;status:no;help:no;resizable:no;scroll:no"); 
    if (sel_color){inputBox.value = sel_color;inputBox.style.backgroundColor = sel_color}
}
function valHex(inputBox,direction){	//test for valid hex scheme input: 6 characters, 0-9, a-f, A-F
	if (direction=="rtl"){
		colorAlert = "a-f נא הזן ערך צבע תקין - 6 תווים, השתמש ב 0-9 ו"
	} else {
		colorAlert = "Enter a valid hex color scheme - 6 characters using 0-9 and a-f"
	}
	textVal = inputBox.value
	var i=0
	var j=1
	var val=0	//if val=1, proceed; else, prompt for valid input
	if (textVal.substring(i,j)!="#"){textVal="#" + textVal}	//add # if it's not there already
	while (j<textVal.length){
		i++
		j++
		if ((textVal.length==7) && ((textVal.substring(i,j) == 0) || (textVal.substring(i,j) == 1) || (textVal.substring(i,j) == 2) || (textVal.substring(i,j) == 3) || (textVal.substring(i,j) == 4) || (textVal.substring(i,j) == 5) || (textVal.substring(i,j) == 6) || (textVal.substring(i,j) == 7) || (textVal.substring(i,j) == 8) || (textVal.substring(i,j) == 9)) || ((textVal.substring(i,j) == "A") || (textVal.substring(i,j) == "a") || (textVal.substring(i,j) == "B") || (textVal.substring(i,j) == "b") || (textVal.substring(i,j) == "C") || (textVal.substring(i,j) == "c") || (textVal.substring(i,j) == "D") || (textVal.substring(i,j) == "d") || (textVal.substring(i,j) == "E") || (textVal.substring(i,j) == "e") || (textVal.substring(i,j) == "F") || (textVal.substring(i,j) == "f"))){
			val=1
		} else {
			val=0
            j=textVal.length	//on error, stop validating and alert
			alert (colorAlert)
			inputBox.value = ""
			inputBox.focus()
			inputBox.select()
		}
	}
	return val
}
function setQty(field,action){
    value = parseInt(field.value)
    if (isNaN(value)) value = 1
    if (action=='-'){if (value>1) value--} else value++
    field.value = value
}
function validEmail (email) {
	var validEmail=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	if(!validEmail.test(email))return false;
	return true;
}
function validUrl (link,url,message) {
    periodPos = url.value.indexOf(".", 1)
    if (periodPos == -1 || periodPos+3>url.value.length){
        alert(message)
        url.focus()
        url.select()
        return false
    }
    link.href = "http://"+url.value
    return true
}
function validDNS (url) {
    var periods = url.split(".").length
    var ip = true
    for (var i=0; i<periods&&ip; i++)ip=!isNaN(url.split(".")[i])
    if (ip){
        if (periods<4)return false
    } else {
        if (periods<3)return false
    }
    return true
}
function validFormat(link,url,formats,direction){
	if (direction=="rtl"){
		addressAlert = "נא הזן את כתובת הקובץ"
		extensionAlert = formats + " ניתן להשתמש רק בפורמט"
	} else {
		addressAlert = "Please enter the file address"
		extensionAlert = "Only " + formats + " format can be used"
	}
    if(url.value==""){
		alert(addressAlert)
		url.focus()
		return false
    } else {
        extension = url.value.split(".")[url.value.split(".").length - 1]
        for(i=0;i<formats.split(",").length-1;i++){
            extension = extension.toLowerCase()
            found = extension!=""&&extension==formats.split(",")[i]
            if(found){
                link.href = url.value
                return true
            }
        }
		alert(extensionAlert)
		url.focus()
		url.select()
        return false
    }
}
function validPhone (phone) {
	analyzed = "";
	for(var i=0; i<phone.length; i++)if(phone.charCodeAt(i) >= 48 && phone.charCodeAt(i) <= 57) analyzed+=phone.charAt(i)+"";
	counter = 1
	if(analyzed.length != 9 && analyzed.length != 10 && analyzed.length != 11 || analyzed == null) {
        return false
	} else {
		if(analyzed.charAt(0) != "0" && analyzed.charAt(0) != "1" && analyzed.charAt(0) != "9") {
            return false
		} else {
			for(a=1; a<analyzed.length; a++) {
				for(b=0; b<10; b++) {
					if(analyzed.charAt(a) == b+"" && analyzed.charAt(1) != 0) counter+=1;
				}
			}
			if(counter == 9 || counter == 10 || counter == 11) {
                return true
			} else {
                return false
			}
		}
	}
}
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}