function getScales(what){
	if(bt()=="IE"){
		switch(what){
			case 1:
				return screen.width;
			break;
			
			case 2:
				return screen.height;
			break;
			
			case 3:
				return document.documentElement.clientWidth;
			break;
			
			case 4:
				return document.documentElement.clientHeight;
			break;
		}
	}else{
		switch(what){
			case 1:
				return screen.width;
			break;
			
			case 2:
				return screen.height;
			break;
			
			case 3:
				return window.innerWidth;
			break;
			
			case 4:
				return window.innerHeight;
			break;
		}
	}
}

function ManuiBlink(num){
	res = num%2
	
	switch(res){
		case 0:
			m$("subScribeManui").className = "";
		break;
		
		case 1:
			m$("subScribeManui").className = "blink";
		break;
	}

	num+=1
	
	if(num<9)
		setTimeout("ManuiBlink("+num+")", 500);
}

function blinkObj(who,num){	
	if(num>0){
		if(m$(who).style.visibility!="hidden")
			m$(who).style.visibility = "hidden";
		else
			m$(who).style.visibility = "visible";
	
	num = num-1;
	
	setTimeout("blinkObj('"+who+"',"+num+")",500);
	}
}

function checkRadio(who){
	if(m$(who))
		m$(who).checked = true;
}

function funcDelay(what,tm){
	setTimeout(what, tm);
}

function relPage(){
	
	playerStatus = m$("layerStatus").value;
	pReloadCount = m$("ReloadCount").value*1;
	
	if(playerStatus==0){
		if(pReloadCount==0){
			m$("ReloadCount").value = m$("ReloadCountIron").value;
			//if(confirm("האם ברצונך לרענן את המסך?"));
			document.location.reload();
		}else{
			m$("ReloadCount").value = pReloadCount-1;

			if(m$("secondRel")){
				pVal = m$("ReloadCount").value;
				pMinutes = addZero(Math.floor(pVal/60));
				pSeconds = addZero(Math.floor(pVal%60));
				
				m$("secondRel").innerHTML =  pMinutes + ":" + pSeconds;
			}
		}
	}
	
	setTimeout("relPage()", 1000);
}

function addZero(str){
	if(str<10)
		return "0"+str;
	else
		return str;
}

function handlyRel(){
	document.location.reload();
}

function PopWINwh(str,namei,w,h){
   window.open(str,namei,'top='+(screen.height-h)/2+',left='+(screen.width-w)/2+',width='+w+',height='+h+',scrollbars=No,status=no,toolbar=no,menubar=no,location=no,resizable=no,titlebar=no');
}

function bt(){
	browserName=navigator.appName;
	if(browserName=="Netscape")
		return "NIE";
	else
		return "IE";
}

function TimeCounter(d,m,h,n,s){
	var topDate = "";
	var s = s*1;
	var n = n*1;
	var h = h*1;
	
	s+=1
	
	if(s>=60){ s=0;	n+=1; }		
	if(n>=60){ n=0;	h+=1; }
	if(h>=24){ 
		m$("topDate").innerHTML = "";
		
		var url = "/Ajax/GetServerTime.asp?sid=" + Math.random();
		xmlHttp=GetXmlHttpObjectSubject(xmlHttpResultsGeneral);
		xmlHttp.open("POST", url , false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      	xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send();
		
		pstrtohandle = xmlHttp.responseText;
		
		pSplit = pstrtohandle.split(",");
		d = pSplit[0];
		m = pSplit[1];
		h = pSplit[2]*1;
		n = pSplit[3]*1;
		s = pSplit[4]*1;
	}
	
	if(s.toString().length==1)
		sShow = "0"+s.toString();
	else
		sShow = s.toString();
		
	if(n.toString().length==1)
		nShow = "0"+n.toString();
	else
		nShow = n.toString();
		
	if(h.toString().length==1)
		hShow = "0"+h.toString();
	else
		hShow = h.toString();
	
	//topDate = hShow+":"+nShow+":"+sShow;
	topDate = d + " " + m + ", " + hShow + ":" + nShow + ":" + sShow + " |";
	
	m$("topDate").innerHTML = topDate;
	
	setTimeout("TimeCounter('"+d+"','"+m+"',"+h+","+n+","+s+")", 1000);
}

function Conf(what) { 
	if(confirm(what)) { 
		return true;  
	}else{ 
		return false; 
	} 
} 

function OnlyNumbers(e){
	evt = e || window.event;
  	keyPressed = evt.which || evt.keyCode;

	if (keyPressed!=46 && keyPressed!=8 && keyPressed!=9 && keyPressed!=18 && (keyPressed <= 46 || keyPressed > 57 || keyPressed == 47))
	{
		if(bt()=="IE"){
			event.returnValue = false;
		}else{
			e.preventDefault();
		}
	}
}

function OnlyNumbersCalculator(e){
	evt = e || window.event;
  	keyPressed = evt.which || evt.keyCode;
	
	if(keyPressed==13){
		if(m$("BaseShaar"))
			CalculatePercents();
			
		if(m$("BaseShaarSide"))
			CalculatePercentsSide();
	}else{
		if (keyPressed!=46 && keyPressed!=8 && keyPressed!=9 && keyPressed!=18 && (keyPressed <= 46 || keyPressed > 57 || keyPressed == 47))
		{
			if(bt()=="IE"){
				event.returnValue = false;
			}else{
				e.preventDefault();
			}
		}
	}
}


function OnlyNumbersInt(e){
	evt = e || window.event;
  	keyPressed = evt.which || evt.keyCode;

	if (keyPressed!=8 && keyPressed!=9 && keyPressed!=18 && (keyPressed < 46 || keyPressed > 57 || keyPressed == 47))
	{
		if(bt()=="IE"){
			event.returnValue = false;
		}else{
			e.preventDefault();
		}
	}
}


function DoNothing(e){
	evt = e || window.event;
  	keyPressed = evt.which || evt.keyCode;
	
	if(bt()=="IE"){
		event.returnValue = false;
	}else{
		e.preventDefault();
	}
}

function DoNothingPast(e){
	evt = e || window.event;
  	keyPressed = evt.which || evt.keyCode;
	
	if (keyPressed!=118 && keyPressed!=46 && keyPressed!=8){
		if(bt()=="IE"){
			event.returnValue = false;
		}else{
			e.preventDefault();
		}
	}
}



function setUpFile(num,who){
	switch(who.id.substring(0, who.id.length-2)){
		case "Attachment":
			m$("FakeFile_"+num).value = m$("Attachment_"+num).value;
			m$("FakeFile_"+num).focus();
		break;
		
		case "FakeFile":
			m$("FakeFile_"+num).value = "";
			m$("LableFile_"+num).innerHTML = "<input type=\"file\" name=\"Attachment_"+num+"\" id=\"Attachment_"+num+"\" class=\"RealInput\" onchange=\"setUpFile("+num+",this)\" />";
			m$("Attachment_"+num).value = "";
		break;
	}
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength);
}


function DateFormat(e,who){
	var pLen = who.value.length;
	var evt = e || window.event;
	var keyPressed = evt.which || evt.keyCode;
	
	if ((keyPressed < 46 || keyPressed > 57 || keyPressed == 47) && keyPressed!=8){
		try{
			event.returnValue = false;
		} catch(er){
			e.preventDefault();
		}	
	}
	
	if((pLen==2||pLen==5)&&keyPressed!=8)
		who.value = who.value + "/";
		
	if(m$("immediate"))
		m$("immediate").checked = false;
}

function TimeFormat(e,who){
	var pLen = who.value.length;
	var evt = e || window.event;
	var keyPressed = evt.which || evt.keyCode;
	
	if ((keyPressed < 46 || keyPressed > 57 || keyPressed == 47) && keyPressed!=8){
		try{
			event.returnValue = false;
		} catch(er){
			e.preventDefault();
		}
	}
	
	if(pLen==2&&keyPressed!=8)
		who.value = who.value + ":";
	
	if(m$("immediate"))
		m$("immediate").checked = false;
}

function isNumber(val){
	if(!/(^\d+$)|(^\d+\.\d+$)/.test(val))
		return false;
	else
		return true;
}

function isDate(val){
	xmlHttp=GetXmlHttpObjectSubject(xmlHttpResultsGeneral);
	xmlHttp.open("POST", "/Ajax/isDate.asp?sid=" + Math.random() , false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send("Value=" + escape(val));
	
	pstrtohandle = xmlHttp.responseText;
	
	if(pstrtohandle!="OK")
		return false;
	else
		return true;
}

function isDatePass(val){
	var url = "/Ajax/IsDateTimePass.asp?sid=" + Math.random();
	xmlHttp=GetXmlHttpObjectSubject(xmlHttpResultsGeneral);
	xmlHttp.open("POST", url , false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send("Value=" + escape(val));
    
	pstrtohandle = xmlHttp.responseText;
	
	if(pstrtohandle!="OK")
		return false;
	else
		return true;
}


function isTime(val){
	xmlHttp=GetXmlHttpObjectSubject(xmlHttpResultsGeneral);
	xmlHttp.open("POST", "/Ajax/isTime.asp?sid=" + Math.random() , false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send("Value=" + escape(val));
	
	pstrtohandle = xmlHttp.responseText;
	
	if(pstrtohandle!="OK")
		return false;
	else
		return true;
}

function isMenaya(val){
	xmlHttp=GetXmlHttpObjectSubject(xmlHttpResultsGeneral);
	xmlHttp.open("POST", "/Ajax/isMenaya.asp?sid=" + Math.random() , false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send("Name=" + escape(val));
	
	pstrtohandle = xmlHttp.responseText;

	if(pstrtohandle!="OK")
		return false;
	else
		return true;
}

function cutString(val,from,to){
	return val.substring(from, to);
}

function m$(identObg){
	return document.getElementById(identObg);
}


function delSpace(what){
	return what.replace(/ /g, "");
}

function RateIt(who){	
	pSplit = who.id.split("_");
	pType = pSplit[0];
	pExtra = pSplit[1];
	pID = pSplit[2];
	
	//alert(pType.toString() + "_Rating('"+who.name+"','"+pExtra+"','"+pID+"')")
	
	setTimeout(pType.toString() + "_Rating('"+who.name+"','"+pExtra+"','"+pID+"')",1);
}

//////// Email check
//String.prototype.trim = function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }

function echeck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1) return false;
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;

		if (str.indexOf(at,(lat+1))!=-1) return false;

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;

		if (str.indexOf(dot,(lat+2))==-1) return false;
		
		if (str.indexOf(" ")!=-1) return false;

 		return true;
}

function ShowBlock(id,steps){
	if(steps=="")
		steps = "slow";
		
	$("#"+id+"").show(steps);
}

function HideBlock(id,steps){
	if(steps=="")
		steps = "slow";
		
	$("#"+id+"").hide(steps);
}

function trim(val) {
	return val.replace(/^\s*/, "").replace(/\s*$/, "");
}

function xmlHttpResultsGeneral(){ 
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ } 
}

function doSelect(who){
	who.select();
}

function urlHandler(urlString){
	pLayer = "";
	pLeft = urlString.substring(0,urlString.toLowerCase().indexOf("lightbox[")-1);
	pRight = urlString.substring(urlString.toLowerCase().indexOf("lightbox[")).toLowerCase().replace("lightbox[width]=", "").replace("lightbox[height]=", "").replace("&", ",").split(",");
	pWidth = pRight[0]*1;
	pHeight = pRight[1]*1;
	
	m$("layerStatus").value = 1;
	
	var url = pLeft;
	xmlHttp=GetXmlHttpObjectSubject(xmlHttpResultsGeneral);
	xmlHttp.open("POST", url , false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send();
	
	pLayer = pLayer + "<a href=\"javascript:;\" class=\"CloseBtnLy\" onclick=\"CloseNewLayer()\"></a><table cellpadding=\"0\" cellspacing=\"0\" class=\"mainLayerTable\">";
	pLayer = pLayer + "<tr><td class=\"TcrnR\"></td><td class=\"TcrnT\"></td><td class=\"TcrnL\"></td></tr>";
	pLayer = pLayer + "<tr><td class=\"CcrnR\"></td><td class=\"CcrnT\"><div class=\"w\" style=\"width:"+pWidth+"px; height:"+pHeight+"px;\">"+xmlHttp.responseText+"</div></td><td class=\"CcrnL\"></td></tr>";
	pLayer = pLayer + "<tr><td class=\"BcrnR\"></td><td class=\"BcrnT\"></td><td class=\"BcrnL\"></td></tr>";
	pLayer = pLayer + "</table>";
	
	m$("divAlertContText").innerHTML = pLayer;
	
	CenterItem("#divAlertCont");
	
	$("#divAlertWrap").fadeIn();
	$("#divAlertCont").fadeIn();
}

function CloseNewLayer(){
	if(m$("layerClose").value==1){
		m$("layerStatus").value = 0;
		$('#divAlertCont').fadeOut();
		$('#divAlertWrap').fadeOut();
		m$("divAlertContText").innerHTML = "";
	}
}

function CenterItem(theItem){
    var winWidth=$(window).width();
    var winHeight=$(window).height();
    var windowCenter=winWidth/2;
    var itemCenter=$(theItem).width()/2;
    var theCenter=windowCenter-itemCenter;
    var windowMiddle=winHeight/2;
    var itemMiddle=$(theItem).height()/2;
    var theMiddle=windowMiddle-itemMiddle;
    if(winWidth>$(theItem).width()){ //horizontal
        $(theItem).css('left',theCenter);
    } else {
        $(theItem).css('left','0');
    }
    if(winHeight>$(theItem).height()){ //vertical
        $(theItem).css('top',theMiddle);
    } else {
        $(theItem).css('top','0');
    }
}


$(window).resize(function() {
    CenterItem("#divAlertCont");
});

// For design file upload field
var W3CDOM = (document.createElement && document.getElementsByTagName);
 
function init() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='images/SelectFile.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].getAttribute('noscript')) continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'FileRealHidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		if (x[i].value)
			x[i].onchange();
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

//////// Ajax
function GetXmlHttpObjectSubject(handler){ 
var objXmlHttp=null;

if (navigator.userAgent.indexOf("MSIE")>=0){ 
	var strName="Msxml2.XMLHTTP";
	if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
		strName="Microsoft.XMLHTTP";
	} 
        try{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler;
			return objXmlHttp;
		} 
catch(e){ 
	alert("Error. Scripting for ActiveX might be disabled");
	return;
	} 
} 

objXmlHttp=new XMLHttpRequest();
objXmlHttp.onload=handler;
objXmlHttp.onerror=handler;
return objXmlHttp;
}
