var isIE = ((document.all)? true  : false );
var isNS6 = ((document.getElementById && !document.all)? true: false );


if (!document.getElementById){
	document.getElementById = function (id){
							if (document.all){
								return document.all[id];
							}
						}
}


var navImagesNames = ["","tb_solution","tb_MDarticles","tb_life","tb_ask","tb_when"];
var navImages = new Array (navImagesNames.length);

for (var i=1 ; i<navImagesNames.length; i++){
	navImages[i] = [new Image(), new Image()];
	navImages[i][0].src = "images/" + navImagesNames[i] + ".gif";
	navImages[i][1].src = "images/" + navImagesNames[i] + "_OVER.gif";

}

function rollover (sender, isOver){
	sender.src = navImages[parseInt(sender.id.substr(9))][isOver].src ;
}

var HPnavImagesNames = ["","","home_life","home_when","home_MDarticles","home_ask"];
var HPnavImages = new Array (HPnavImagesNames.length);

for (var i=1 ; i<HPnavImagesNames.length; i++){
	HPnavImages[i] = [new Image(), new Image()];
	HPnavImages[i][0].src = "images/" + HPnavImagesNames[i] + ".gif";
	HPnavImages[i][1].src = "images/" + HPnavImagesNames[i] + "_OVER.gif";

}

function HProllover (sender, isOver){
	sender.src = HPnavImages[parseInt(sender.id.substr(7))][isOver].src ;
}

function sendFriend(){
	window.open ("sendFriend.asp?page="+self.location,"","left=10,top=10,width=405,height=529,resizable=no,scaleable=no,status=yes,scrollbars=no");
}

function mailingList(){
	window.open ("mailingList.asp","","left=10,top=10,width=421,height=500,status=yes,scrollbars=yes");
}

function expect(){
	window.open ("expect.asp","","left=10,top=10,width=600,height=529,resizable=no,scaleable=no,status=yes,scrollbars=no");
}

function registerMail(){
	window.open ("mailingList.asp","","left=10,top=10,width=380,height=230,resizable=yes,scaleable=yes,status=yes,scrollbars=no");
}




function markTop (pageName){
	pageName = "tb_" + pageName ;

	var fatherImgNum = -1;
	for (var i=1 ; i<navImagesNames.length; i++){
		if (document.images["fatherImg"+i].src.indexOf (pageName) > -1 ){
			fatherImgNum = i;
			break;
		}
	}

	if (fatherImgNum>-1){
		for (var i=1 ; i<navImagesNames.length; i++){
			if (navImagesNames[i]==pageName){
				document.images["fatherImg"+fatherImgNum].src = navImages[i][1].src;
			}
		}
	}
}

var Validator={
	templates:{
		email:[ /^[\w\-\.]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/,"כתובת מייל חוקית" ],
		numeric:[ /^\d+$/,"ספרות" ]
	},

	check:function (oForm,fExtra) {
		var oInp,
			aErrs=[],
			vErr;

		for (var iInp=0;iInp<oForm.length;iInp++) {
			oInp=oForm[iInp];

			if (oInp.type && !oInp.disabled && (vErr=this.funcs[this.types[oInp.type]](oInp))) aErrs[aErrs.length]=vErr;
		}

		if (typeof fExtra=="function" && (vErr=fExtra(oForm))) {
			if (typeof vErr=="object" && vErr.join) {
				for (var iErr=0;iErr<vErr.length;iErr++) aErrs[aErrs.length]=vErr[iErr];
			}
			else aErrs[aErrs.length]=vErr;
		}

		if (aErrs.length) {
			alert("השגיאות הבאות אותרו:\n\n * "+aErrs.join("\n * "));
			return false;
		}

		return true;
	},

	templates:{
		email:[ /^[\w\-\.]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/,"כתובת מייל חוקית" ],
		numeric:[ /^\d+$/,"ספרות" ]
	},

	types:{
		"text":0,
		"hidden":0,
		"textarea":0,
		"password":0,
		"file":0,
		"submit":0,
		"button":0,
		"radio":1,
		"checkbox":2,
		"select-one":3,
		"select-multiple":3
	},

	funcs:[
		// textual
		function (oInp) {
			if (oInp.getAttribute("template") && !Validator.templates[oInp.getAttribute("template")]) throw new Error("No such template '"+oInp.getAttribute("template")+"'");

			if (oInp.getAttribute("required")!=null && !oInp.value) return "'"+oInp.getAttribute("desc")+"' - שדה זה נדרש.";

			if (oInp.getAttribute("template")!=null && oInp.value && !Validator.templates[oInp.getAttribute("template")][0].test(oInp.value)) return "'"+oInp.getAttribute("desc")+"' צריך לכלול "+Validator.templates[oInp.getAttribute("template")][1]+".";

			if (oInp.getAttribute("min")!=null || oInp.getAttribute("max")!=null) {
				if (oInp.getAttribute("template")=="numeric" || oInp.getAttribute("template")=="float") {
					if (
						oInp.value
						&&
						(
							(oInp.getAttribute("max") && +oInp.value>oInp.getAttribute("max"))
							||
							(oInp.getAttribute("min") && +oInp.value<oInp.getAttribute("min"))
						)
					) {
						return "'"+oInp.getAttribute("desc")+"' צריך להיות מספר "+
							(oInp.getAttribute("min") ? "מעל ל-"+oInp.getAttribute("min") : "")+
							(oInp.getAttribute("min") && oInp.getAttribute("max")? " ו" : "")+
							(oInp.getAttribute("max") ? "מתחת ל-"+oInp.getAttribute("max") : "")+
							".";
					}
				}
				else if (+oInp.value.length>oInp.getAttribute("max") || +oInp.value.length<oInp.getAttribute("min")) {
					return "אורכו של '"+oInp.getAttribute("desc")+"' צריך להיות "+
						(oInp.getAttribute("min") ? "מעל ל-"+oInp.getAttribute("min") : "")+
						(oInp.getAttribute("min") && oInp.getAttribute("max")? " ו" : "")+
						(oInp.getAttribute("max") ? " מתחת ל-"+oInp.getAttribute("max") : "")+
						".";
				}
 			}

			if (oInp.getAttribute("rx")!=null && oInp.getAttribute("rxerror")!=null && !new RegExp(oInp.getAttribute("rx"),oInp.getAttribute("rxflags")).test(oInp.value)) return "'"+oInp.getAttribute("desc")+"' "+oInp.getAttribute("rxerror");

		},

		// radio
		function () {
			return "";
		},

		// checkbox
		function () {
			return "";
		},

		// select
		function (oInp) {
			if (oInp.getAttribute("invalid")!=null && (oInp.selectedIndex==-1 ||  oInp.selectedIndex==+oInp.getAttribute("invalid"))) return "'"+oInp.getAttribute("desc")+"' - שדה זה נדרש";
		}
	],

	// Textarea

	// onkeypress="return Validator.limit(this)"
	limit:function (oTA) {
		if (+oTA.value.length==oTA.getAttribute("maxlength")) return false;
	},

	// onkeyup="return Validator.count(this)"
	count:function (oTA,oCnt) {
		if (oTA.value.length>+oTA.getAttribute("maxlength")) oTA.value=oTA.value.substring(0,+oTA.getAttribute("maxlength"));
		if (oCnt) oCnt.innerText=oTA.getAttribute("maxlength")-oTA.value.length;
	}
};

function addEvent(sEvent,fFunc,oEl) {
	oEl=oEl || window;
	if (oEl.addEventListener) oEl.addEventListener(sEvent.replace(/^on/,""),fFunc,false);
	else oEl.attachEvent((sEvent.indexOf("on")!=0 ? "on" : "")+sEvent,fFunc);
}
