var browserName=navigator.appName.toLowerCase();; 
var isIE = browserName.toLowerCase().indexOf("explorer")>-1

//************************************************************
//* Tests whether the given argument is empty or null
//************************************************************
function isnull(arg) {
	if(typeof(arg) == "object"){
		if(arg==null)
			return true;
		else
			return false;
	}

	arg = arg+'';
	var rv =(arg == '' || arg == 'null' || arg == 'undefined'); 
	return rv;
}

//************************************************************
//* Padding the given value with zero beffor the number
//************************************************************
function zeroPad(v, len){ 
	if (isnull(len)) len = 2;
	
	var str = new String(v);
	while (str.length < len) str = '0' + str;
	return str;
}

//************************************************************
//* null value function
//************************************************************
function nvl() {
	for (var i=0; i<arguments.length; i++)
		if (!isnull(arguments[i])) 
			return arguments[i];
	
	return "";
}

//************************************************************
//* Removes white spaces from beginning and end of a string.
//************************************************************
function trim(str){
	try {
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e) {return str;}
}


//************************************************************
//* set the url as the requested
//************************************************************
function go(address) {
	window.location=address
}

/////////////////////////////////////////////////////////////////////////////////////////
function escapeXmlChars(str) {
	str = str + '';
	return (str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"))
}

function unescapeXmlChars(str) {
	str = str + '';
	return (str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&"))
}


/////////////////////////////////////////////////////////////////////////////////////////
function delCookie(cookieName)
{
	var t = new Date()
	set_cookie(cookieName,"",(t.getFullYear()-30),t.getMonth(),t.getDate(),"/")
	//redirect the member to the home page (root)
	window.location.href = "/";
}

/////////////////////////////////////////////////////////////////////////////////////////
//* there are 2 function of the get cookie because i dont want to search all the references for each of them
/////////////////////////////////////////////////////////////////////////////////////////
//Chack If there is a Cookie
function getCookie(sName){
	// cookies are separated by semicolons
	var aCookie = document.cookie.split(";");
	for (var i=0; i < aCookie.length; i++){
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == trim(aCrumb[0]))return unescape(aCrumb[1]);
	}
	return null;// a cookie with the requested name does not exist
}

/////////////////////////////////////////////////////////////////////////////////////////
function get_cookie ( cookie_name){
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results ){
	return ( unescape ( results[1] ) );
  }
  else return null;
}

/////////////////////////////////////////////////////////////////////////////////////////
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ){
	var cookie_string = name + "=" +  value ;
	if ( exp_y ) {
		var expires = new Date ( exp_y, exp_m, exp_d );
		cookie_string += "; expires=" + expires.toGMTString();
	}
	if ( path ) cookie_string += "; path=" + escape ( path );
	if ( domain ) cookie_string += "; domain=" + escape ( domain );
	if ( secure ) cookie_string += "; secure";
	//alert(cookie_string)
	document.cookie = cookie_string;
}

/*
/////////////////////////////////////////////////////////////////////////////////////////
//this is from the site
function saveUserLang(obj)
{ 
	set_cookie("siteLang", escape(obj.value),2020,12,25,"/")
	window.location.reload();
} 
////////////////////////////////////
//this is from the admin
function saveUserLang(obj)
{ 
	setCookie("userLang" ,obj.value);
	window.location.href = window.location;
} 
*/
/////////////////////////////////////////////////////////////////////////////////////////
function openWindow(url,param,wName){
	wName = nvl(wName,"defWin")
	//param = nvl(param,"scrollbars=no,toolbar=no,resizable=0,left=0,top=0,width=550,height=450");
	if(isnull(param)) 
		var win = window.open(url, wName);
	else
		var win = window.open(url, wName ,param);
	win.focus();
}

/////////////////////////////////////////////////////////////////////////////////////////
var lastObjID = "";
function showHideDiv(objID){
	try{
		if(objID != lastObjID)
			document.getElementById(lastObjID).style.display="none"
	}
	catch(e){}
	if(document.getElementById(objID).style.display=="none"){
		document.getElementById(objID).style.display=""
	}
	else{
		document.getElementById(objID).style.display="none"
	}
	lastObjID = objID;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

var activeElementID = "";
function showActiveElement(ElementID){
	try{
		if(ElementID != activeElementID){
			document.getElementById(activeElementID).style.display="none"
		}
	}
	catch(e){}
	
	document.getElementById(ElementID).style.display="";
	activeElementID = ElementID;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
var arrImages = [];
function imgOnOff(img,on){
	if(isnull(arrImages[img.src])){
		arrImages[img.src] = new Image();
		arrImages[img.src].src = img.src;
	}
	//if(arrImages[img.src]==true) alert()
	imgSrc=arrImages[img.src].src;//img.src
	imgSrc = imgSrc.toLowerCase( )
	if(on){
		imageOn=imgSrc.substring(0,imgSrc.indexOf("off.gif")) + "on.gif"
		//document.images[img.name].src =imageOn
		img.src = imageOn
	}
	else{
		imageOff=imgSrc.substring(0,imgSrc.indexOf("on.gif")) + "off.gif"
		//document.images[img.name].src =imageOff
		img.src = imageOff
	}
}

//************************************************************
// Return a formatted dialog features string
//************************************************************
function dlgFeatures(w, h, win) {
	if (win) {
		var x = win.screenLeft + (win.document.body.clientWidth-w)/2;
		var y = win.screenTop  + (win.document.body.clientHeight-h)/2;
	}
	else {
		var x = screenLeft + (document.body.clientWidth-w)/2;
		var y = screenTop  + (document.body.clientHeight-h)/2;
	}
	if (x > screen.availWidth || y > screen.availHeight) {
		x = (screen.availWidth -  w)/2;
		y = (screen.availHeight - h)/2;
	}

	return 'dialogLeft:'+x+'px;dialogTop:'+y+'px;'+
			 'dialogWidth:'+w+'px;dialogHeight:'+h+'px;'+
			 'status:no; scroll:no; edge:no;help:no;'
}

function alertSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
	}
	window.alert( 'Width = ' + myWidth + ' and height = ' + myHeight );
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	window.alert( 'Horizontal scrolling = ' + scrOfX + '\nVertical scrolling = ' + scrOfY );
}

/////////////////////////////////////////////////////////////////////////////////////////
//
function cutString(strParam,len,addDots,notComplite){
	//return only 'len' chars from the 'str' param, and if 'addDots' = true added 3 ... in the end
	if(isnull(strParam) || len== 0 ) return "";
	if(isnull(notComplite)) notComplite=false
	str = strParam//cleanHtmlTags(strParam)
	if (String(str).length <= len) return str;

	var temp = String(str).substring(0,len);
	if(addDots == true && (String(str).length-len)<3){
		return str
	}
	var temp2 = "";

	if(!notComplite){
		// complite the last word...
		for (var i = len;i < String(str).length;i++){
			temp2 = String(str).substring(i,i+1);
			if (temp2 == ' ') break;
			temp +=temp2
		}
	}
	//alert(String(str).length + "\n" + len + "\n" + temp + "\n" + temp.length)
	return temp.length < str.length && addDots == true ? temp + "..." : temp;
}

/////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////
///Add to favorits/ bookmark. need to be upgraded for all browsers
/////////////////////////////////////////////////////////////////////////////////////////
function addFavorite(url,title)
{
	if (window.sidebar) {
		// Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, url,"");	
	} 
	else if( window.external ) { 
		// IE Favorite		
		window.external.AddFavorite( url, title); 
	}	
	else { 
		alert("You need to click CTRL+D to bookmark us."); 
	}
}

