﻿function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}



function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop - obj.scrollTop //curtop += obj.offsetTop //fixed by yaron - the function didn't work correctly when using a scroll
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
		
	return curtop;
}


function checkForm1(){
	var elm=document.form1.searchText
	if (elm.value=='') {alert ('יש לרשום טקסט לחיפוש');elm.focus();return false}
	else {document.form1.btnSubmit.disabled=true;return true}
}


function nonSelected(elm){
	var chk=false;
	for (i=0;i<elm.length && !chk;i++){chk=elm[i].checked}
	return !chk
}

function noBubble(e){
	if (window.event) e = window.event;
	e.cancelBubble=true;
	createCookie('referrer',location.href,1);
}

function ShowProd(prodName){
	createCookie('referrer',location.href,1);
	location.href='/' + prodName;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function openDialog (prodId,Referrer){
	var newWin=window.open('RFI.asp?prodId='+prodId+'&referrer='+Referrer,'newWin11','width=470,height=320,resizable=1,scrollbars=1')
	if (newWin) {newWin.focus()} else {alert('נא לבטל חסימת חלונות קופצים')}
}


function addToFavorite() { 
	var title = "Tochna.co.il - מדריך התוכנה הישראלי";   
	var url = "http://www.tochna.co.il/";

	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 openModal(url, title, width, height ) 
{ 
	var navigatoreName = navigator.appName; 
	if (navigatoreName == "Netscape" ) { 
		try {netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');} catch(e) {}
		newWin=window.open(url, title, 'width=' +width+ ',height=' + height+',chrome,centerscreen,dependent=YES,dialog=YES,modal=YES,resizable=NO,scrollbars=NO,location=0,status=0,menubar=0,toolbar=0');     
		if (newWin) {newWin.focus()} else {alert ('יש לאפשר חלונות קופצים בדפדפן שלך')}

	}else { 
		window.showModalDialog(url, title, "dialogHeight:" + height + "px; dialogWidth:" + width +"px; scroll:no"); 
	} 
} 

function pressOnlyNumeric(e) {
	var keyCode=e.keyCode?e.keyCode:e.charCode
	if (((keyCode < 48) || (keyCode > 57)) && keyCode!=46 && keyCode!=35 && keyCode!=36 && keyCode!=37 && keyCode!=39 && keyCode!=8) {
		if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();	}
		else{
			e.returnValue = false;}

	}
}

function pressOnlyPhone(e) {
	// note: if firefox the delete-key will not function, as it return 46 which is also dot (.), nothing to do about it. IE doesn't fire OnKeyPress at all for delete-key (as well as right/left/home/end etc...)
	var keyCode=e.keyCode?e.keyCode:e.which
	if (((keyCode < 48) || (keyCode > 57)) && keyCode!=45 && keyCode!=35 && keyCode!=36 && keyCode!=37 && keyCode!=39 && keyCode!=8) {
		if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();	}
		else{
			e.returnValue = false;}

	}
}


function Right(str, n) {
	if (n <= 0) 
		return "";
	else if (n > String(str).length)
		return str;
	else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

function Left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}


function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++;
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str){
	return RTrim(LTrim(str));
}


function openWinRegular (url){
	var newWin=window.open (url,'tochna2','');
	if (newWin) {newWin.focus()} else {alert ('יש לאפשר חלונות קופצים בדפדפן שלך')}
}