﻿onLoadArr = new Array;
function onLoadPage(){
	var n
	for(n=0;n<onLoadArr.length; n++){
			objType = typeof(onLoadArr[n])
			if(objType=="string"){
				eval(onLoadArr[n])	
			}else if(objType == "function"){
				onLoadArr[n]()
			}
			//alert(onLoadArr[n])
	}
	
	
}
var agt,MSIE
agt=navigator.userAgent.toLowerCase();
NAV = agt.indexOf('netscape')!=-1
FFOX=agt.indexOf('firefox')!=-1
MSIE =agt.indexOf('msie')!=-1


var CIO
function openCal(p){
	CIO= document.getElementById(p)
	MSIE?openDialog2("/admin/html/culc.html",205,290):WOpener("/admin/html/culc.html",205,290);
}
function setCal(day1, month1, year1){
	CIO.innerHTML=day1 + "/" + month1 + "/" + year1
	eval("fo01.p_day.value='"+day1+"'")
	eval("fo01.p_month.value='"+month1+"'")
	eval("fo01.p_year.value='"+year1+"'")

}
function deleteNode( nodeObj){
	inOb = nodeObj.parentNode
	try{
		inOb.removeChild(nodeObj)
	}catch(e){
		try{
			nodeObj.removeMe(true)	
		}catch(e){
			try{
				nodeObj.removeNode(true)
			}catch(e){
				return false
			}
		}		
	}
	return true
}

var popstageS
function WOpener(lnk,winwid ,winhigh,scrol,resize ){
	
	if(resize==null)resize=0
	if(scrol==null)scrol=0
	if(popstageS!=null){popstageS.close();}
	if(winwid==null){winwid = 100}
	if(winhigh==null){winhigh=100}
	popstageS =   window.open(lnk,'tour', 'width='+winwid+',height='+winhigh+',scrollbars='+scrol+',left=50,top=20,menubar=0,location=0,toolbar=0,status=0,resizable='+resize)
	
	sti=setTimeout("WOpenerCheck()",500)

	}
	function WOpenerCheck(){
			window.popstageS.focus()
		} 
	flashShow=function(w,h,s,name, returnOnly, flashVars){
		if(name==null)name="fl999"
		if(!flashVars){
			flashVars=""
		}
		var htm = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+w+'" height="'+h+'" id="'+name+'" align="middle">'+
			'<param name="allowScriptAccess" value="always" >'+
		'<param name="movie" value="'+s+'" >'+
		'<param name="menu" value="false" >'+
		'<param name="quality" value="high" >'+
		'<param name="flashvars" value="'+  flashVars+'" >'+
		'<param name="wmode" value="transparent" >'+
		'<param name="bgcolor" value="#ffffff" >'+
		'<param name="allowFullScreen" value="true" >'+
		'<embed src="'+s+'" menu="false" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+w+'" height="'+h+'" name="'+name+'" flashvars="'+ flashVars +'" align="middle"  allowScriptAccess="always" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" >'+
		'</object>'
		if(!returnOnly){
			document.write(htm)	
		}
		return htm
		
	}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function emailVal(string){
valid = false
for (n=3;n<string.length;n++){
 	if(string.charAt(n)=="@" && n < (string.length - 5) ){
		for(nn=string.length-5;nn<string.length-2;nn++){
		if(string.charAt(nn)=="."){
		valid = true
		}		
		}	
	}		
}
return valid
}
function mapPointer(L,T){

}
function phoneVal(string){
	string = string.split(" ");
	string = string.join("");
	string = string.split("-");
	string = string.join("");
	p_phone_digits = 0
	re  = false
	for (n=0;n< string.length;n++){
			if (!isNaN(string.charAt(n))){
			p_phone_digits++
					if(p_phone_digits>7){
						re = true
						break;
					}
			} else {
			 p_phone_digits = 0	
			}
	}
	return re;
}



function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}

function toMany(p){
	if(p.value.length>400){
		tmp=p.value.substring(1,400)
		p.value=tmp
	}

}
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function ajaxObj(url, Qform, Method){
	//prompt('', url)
	if(!Method) Method = "POST"
	if (!Qform)Qform = ""
	var xmlHttp;
	var xmlHttp;
	try { 
		// Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest(); 
	}catch (e){  // Internet Explorer  
		try	{ 
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}catch (e){  
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");     
			}catch (e){ 
				alert("Your browser does not support AJAX!");
				return false;      
			}
		}
	}
	//xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	xmlHttp.open(Method,url,true);
	xmlHttp.send(Qform)
	return xmlHttp
}
function clrPx(p){
return eval(p.substring(0,p.indexOf("px")))
}
function openDialog(lnk,wi,hi){
	dial = window.showModalDialog("dlFrame.asp?lnk="+lnk,window,'dialogHeight:'+hi+'px;dialogWidth:'+wi+'px;status:0;help:0;center:1;help:1;unadorned:1;scroll:no;status:yes;')
	return dial
	}
function openDialog2(lnk,wi,hi){
	dial = window.showModalDialog("/admin/html/dlFrame.asp?"+lnk,window,'dialogHeight:'+hi+'px;dialogWidth:'+wi+'px;status:0;help:0;center:1;help:1;unadorned:1;scroll:no;status:yes;')
	return dial
	}
function compr(str,comp){
	tmpA=" "+str+" "
	tmpB=" "+comp+" "
	if(tmpB.indexOf(tmpA)>-1)
		return str
	else
		return ""
	}
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}
function replaceQuerystring(p_key, p_val, p_query){
	var didnt_replace = true 
	var tmpReturn = ""
	arrQueryTokkens = p_query.split("&")
	for( n=0; n<arrQueryTokkens.length; n++){
		
		tokken = arrQueryTokkens[n].split("=")
		if ( tokken.length>0){
			//alert(tokken[0])
			if (tokken[0] == p_key){
				if (p_val.length>0 ){
					tokken[1] = p_val
					arrQueryTokkens[n] =  tokken.join( "=")
				}else{
					arrQueryTokkens[n] = ""
				}			
				didnt_replace = false
				break;
			}
		}
	}
	if( didnt_replace ){	
		if (p_val.length >0 ){			
			tmpReturn = arrQueryTokkens.join("&") + "&" + p_key + "=" + p_val
		}else{
			tmpReturn = arrQueryTokkens.join("&")
		}
	}else{
		tmpReturn = arrQueryTokkens.join("&")
	}
	//tmpReturn = replace(tmpReturn, \&&\g, "&")
	return tmpReturn	
}
document.myGetElementsByClassName = function(className) {
		var children = document.getElementsByTagName('*') || document.all;
		var elements = new Array();
	  
		for (var i = 0; i < children.length; i++) {
			var child = children[i];
			var classNames = child.className.split(' ');
			for (var j = 0; j < classNames.length; j++) {
				if (classNames[j] == className) {
					elements.push(child);
					break;
				}
			}
		}
		return elements;
	}
function insertAfter(parent, node, referenceNode){
	if(referenceNode.nextSibling){
		parent.insertBefore(node, referenceNode.nextSibling);
	} else {
		parent.appendChild(node);
	}
}


function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
Array.prototype.contains = function (element){
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == element)
		{
			return true;
		}
	}
		return false;
};
Array.prototype.indexOf = function (element){
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == element)
		{
			return i;
		}
	}
		return -1;
};

function trace(p){
		try{
			console.log(p)
		} catch(e){}	
		
}
function trace(p){
		try{
			console.log(p)
		} catch(e){}	
		
}
var formElements = {
	initMonths : function(o){
		var t,n
		for(n=0; n<13; n++){
			t= document.createElement("OPTION")
			t.value=n;
			t.innerHTML = n?n:'חודש';
			o.appendChild(t)
		}
	}, //initMonths
	initDays : function(o){
		var t,n
		for(n=0; n<31; n++){
			t= document.createElement("OPTION")
			t.value=n;
			t.innerHTML = n?n:'יום';
			o.appendChild(t)
		}
	}, //initDays
	initYears : function(o){
		var t,n
		for(n=1940; n<1991; n++){
			t= document.createElement("OPTION")
			t.value= n>1940?n:0;
			t.innerHTML = n>1940?n:'שנה';
			o.appendChild(t)
		}
	}, //initDays
	valuesOnly: function(o, regX){
		var lastValue = o.value
		function rememberLast(){
			lastValue = o.value
		}
		function check(){
			if(!o.value.length) return
			if(!regX.test(o.value)){
				o.value = lastValue
			}
			rememberLast()
			
		}
		o.onkeyup = check
		o.onkeydown = check
		o.onpaste = check
		o.onchange = check
		o.oncut = check
		o.onfocus = check //input.ondrop
		o.onblur =check
	} // valuesOnly
	
	
}


_$$ = function(x){return " return  "+ x +".getElementsByTagName(p)"}

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClassName(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClassName(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}
function switchTitles(str, alt){
	if(str){
		if(trim(str).length>0){
			return str	
		}
	}
	return alt	
}
var  request = function(p){
	var ME = this
	ME.x="a"
	url = document.location.href
	qMarkIndex = url.indexOf("?")
	ME.queryString = {} 
	if(qMarkIndex>0){
		var query =url.substring(url.indexOf("?")+1, url.length)
		queryArr = query.split("&")
		for(var n=0; n<queryArr.length; n++){
			t= queryArr[n].split("=")
			if(t.length>1){
				ME.queryString[t[0]] = decodeURI(t[1])
			}
		}
	}
	return ME
}()



function getPageInnerSize(){
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return {width:window.innerWidth, height:window.innerHeight}
	}else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return {width: document.documentElement.clientWidth, height: document.documentElement.clientHeight}
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return {width:  document.body.clientWidth, height: document.body.clientHeight}
	}
}
function merge(a,b){
	for(var t in b) a[t] = b[t]
	return a
	
}

/*  URL encode / decode  http://www.webtoolkit.info/ */
var Url = {
	// public method for url encoding
	encode: function(string) {
		return escape(this._utf8_encode(string));
	},
	// public method for url decoding
	decode: function(string) {
		return this._utf8_decode(unescape(string));
	},
	// private method for UTF-8 encoding
	_utf8_encode: function(string) {
		string = string.replace(/\r\n/g, "\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if ((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	// private method for UTF-8 decoding
	_utf8_decode: function(utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while (i < utftext.length) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if ((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i + 1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i + 1);
				c3 = utftext.charCodeAt(i + 2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

var regExpEmail =  /^[a-zA-Z0-9@\-\.\'\_]+$/
var regExpemailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
var regNumbers =  /^[0-9]+$/
