
/*****************************************************************************
* Site: J_functions.js
******************************************************************************
* collection of global functions
******************************************************************************
*	'-------------------------------------------------------------------------*
*	' Write By		: yossi Aharoni & ilan mazuz										  *
*	' Company		: Scepia LTD															  *
*	' Date			: Febuary 2001															  *
*	' updated at	:18/06/2001																  *
******************************************************************************
* Contents:
*
* - cleanCData(str)								: cleans the <![CDATA[]]> tags from a string .
* - checkForm(whatToCheck,theAction)		:
* - checkMultiForm(theForm,theAction)		:
* - checkSearch(url)    :		
* - doKeyup(this)									: Move to the next TabIndex As needed			
* - enumForm()										: enumerate the form objects with the "field" prefix + its tab index
* - GetCookie(sName)								: Chack if there is a Cookie and return true/false
* - go(address)									: nevigate to 'address'
* - hasVScroll()									: check for vertical scroll bars
* - hasHScroll()									: check for horisontal scroll bars
* - hidemenus(i)									:
* - img_on_off(imgNum,on)						:
* - imgOnOff(img,on)								:
* - isnull()										: Tests whether the given argument is empty or null
* - iif(q,truePart,falsePart)					: the clasic iif of vb
* - nz(param,val)									: if the param is null or 0 return val or "" if val not sopplied
* - openWindow(fName)							: open Window with the specific location
* - replaceBlankChar(str) 						: replace the (chr(10) and the chr(13)) with <br>
* - SetCookie(sName, sValue)					: update a user coocie 
* - showHideDiv(obj,dontCancelBubble,colaps,e)
* - showHideTag(obj)								: faq
* - trim(str)										: trim string
* - validForm(obj)								: Cahck if Input date are correct
* - cleanSearchText(text)					 : Clean that laters !@#$%^&*)([]{}|\/
********************************************************************************/
var dbgString = "";//global var for debuging 2 file in the system
var _menusCreated = false;

// initilize the navigator param
var ns = (navigator.appName=="Netscape")? true : false
var ie = (navigator.appName!="Netscape")? true : false

//*******************************************************************
// cleans the <![CDATA[]]> tags from a string .
function cleanCData(str){
	if(str.indexOf("<![CDATA[")==0)	return (str.substring(9,str.length-9-3));
	return str;
}
//*******************************************************************
function imgOnOff(img,on){
imgSrc=img.src
imgSrc = imgSrc.toLowerCase( )
	if(on){
		imageOn=imgSrc.substring(0,imgSrc.indexOf("off.gif")) + "on.gif"
		document.images[img.name].src =imageOn
	}
	else{
		imageOff=imgSrc.substring(0,imgSrc.indexOf("on.gif")) + "off.gif"
		document.images[img.name].src =imageOff
	}
}
/**********************************************************/
function hidemenus(i){
	status = "Done"
	document.all["divSubmenu"+i].style.visibility="hidden"
}

/**********************************************************/
function go(address) {
	//window.document.title="yossi"
	window.location=address
}

//*******************************************************************
// Tests whether the given argument is empty or null
function isnull(arg) {
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
//*******************************************************************
function iif(q,truePart,falsePart){
	//the clasic iif of vb
	return (q) ? truePart : falsePart;
}
//*******************************************************************
function nz(param,val){
	//if the param is null or 0 return val or "" if val not sopplied
	return(
		isnull(param)
		? ((!isnull(val)) ? val : "") 
		: param
	)
}
//*******************************************************************
//check for vertical scroll bars
function hasVScroll(){
	return(screen.availHeight < document.body.scrollHeight)
}
//check for horisontal scroll bars
function hasHScroll(){
	return(screen.availWidth < document.body.scrollWidth)
}
//*******************************************************************
function replaceBlankChar(str){
	if(isnull(str)) return "";
	str = str.replace(/<p>/gi,"").replace(/<\/p>/gi,"<BR>")
	var str2="";
	for (var i=0;i<str.length;i++){
		if(str.charCodeAt(i)==13 || str.charCodeAt(i)==10)
			str2+= "<BR>";
		else
			str2+=str.charAt(i);
   }                    
	return(str2);
}
//*******************************************************************
function SetCookie(sName, sValue){
	document.cookie = sName + "=" + escape(sValue) + ";expires=Mon, 31 Dec 2099 23:59:59 UTC;path=/"
}
//*******************************************************************
// enumerate the form objects with the "field" prefix + its tab index
function enumForm() {
	for (var i=0; i < document.forms(0).elements.length; i++)
		document.forms(0).elements(i).id = "field" + document.forms(0).elements(i).tabIndex
	document.all['field1'].focus()
}
//*******************************************************************
//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
}
//*******************************************************************
// Trim strings. 
// Removes white spaces from beginning and end of a string.
function trim(str){
	try {
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e) {return str;}
}
//*******************************************************************
function changeClass(obj,clas){
	obj.className = clas;
}
//*******************************************************************
function fontChange(obj,fontColor) {
	obj.style.color = fontColor
}
//*******************************************************************
function showHideTag(obj){
	obj = docObj(obj)
	if	(obj.style.display == "none")		obj.style.display = "";
	else 											obj.style.display = "none";
	
}
//*******************************************************************
var x_time
function showHideDiv(obj,dontCancelBubble,colaps,e){
	if(!obj) return
	if(!_menusCreated){
		return
	 }
	if(!ns){
		if (isnull(dontCancelBubble)) window.event.cancelBubble = true;
	}
	
	obj=docObj(obj);
	//alert(obj.style.display)
	showHideDiv.theOpenSideBar = docObj(showHideDiv.theOpenSideBar);

	if(!isnull(showHideDiv.theOpenSideBar) && showHideDiv.theOpenSideBar != obj && colaps){
		var tempObj = showHideDiv.theOpenSideBar;
		showHideDiv.theOpenSideBar = "";
		showHideDiv(tempObj,dontCancelBubble,colaps,e);//hide the open div
	}
	else if(showHideDiv.theOpenSideBar == obj){
		showHideDiv.theOpenSideBar = null;
	}
			
	//the function itself
	if(visibleDivId==obj.id){
		s_flag=false;
		visibleDivId='';	
	}
	else{
		s_flag=true;
		hideMenusDiv();
	}
	
	if (obj.style.display == "none" && e.type != "mouseout"){
		obj.style.display = "";
		if(String(obj.id).indexOf("sideBarDiv")>-1) showHideDiv.theOpenSideBar = obj;
	}
	if (obj.id!=visibleDivId && obj.style.display == "" && (e.type == "mouseout" || e.type=="mouseleave")){
		visibleDivId=obj.id;
		s_flag=true;
		x_time=setTimeout('hideMenusDiv()',10);
	}
}
showHideDiv.theOpenSideBar= null;

var visibleDivId='';
var s_flag=true;
//*******************************************************************
function hideMenusDiv(){
 	try{
	if(s_flag){
		document.getElementById(visibleDivId).style.display = "none";
	}
	}catch(e){}
	clearTimeout(x_time)


}
showHideDiv.theOpenSideBar= null;
//*******************************************************************
function toggleImg(id,src){
	document.images[id].src = src;
}
//*******************************************************************
//check if the param is an object or string,if string-return refernce to the object with this name
function docObj(obj){
	if(typeof(obj) != "object"){
		return(document.getElementById(obj));
	}
	return obj;
}
//*******************************************************************
function openWindow(url,param,wName){
	wName = nz(wName,"defWin")
	//if(isnull(param)) param = "scrollbars=yes,toolbar=no,resizable=0,left=100,top=100,width=420,height=420"
	if(isnull(param)) param = "scrollbars=no,toolbar=no,resizable=0,left=0,top=0,width=550,height=450"
	var win = window.open(url, wName ,param);
	win.focus();
}
//*******************************************************************
function openNewWindow(url){
	var win = window.open(url,"win");
	win.focus()
}
//*******************************************************************
function checkSearch(url) { 	//check only the sended object in the form
	if(isnull(document.forms.searchForm.searchText.value)) return;
	go(url + "?pi=search&search=true&searchText=" + document.searchForm.searchText.value +"&p=1");
}
//*******************************************************************
//Move to the next required Field
function doKeyup (elementParam) {
	if (elementParam.value.length < elementParam.size)	return
	var newElement = elementParam.tabIndex + 1
	if (newElement == elementParam.form.elements.length) newElement = 0
	document.all['field'+newElement].focus()
}
//*******************************************************************
function keyPress(){
	if(event.keyCode=='13') return true
	return false
}
//*******************************************************************
function cleanSearchText(text){
	var temp = text
	var err = 0
	if(text.length < 2 ){
		if(text.length < 1)
			alert(clientDic.SEARCH_FEILD_EMPTY + ", " + clientDic.TWO_LETTERS)
		else 
			alert(clientDic.TWO_LETTERS )
	return text		
	}
	var errStr= "~!@#$%^&*/\|{}?[].,=-+_)(:;'<>"
	var flag = true
	while(flag){
		flag=false
		for(var i = 0 ; i < errStr.length ; i++){
			var mychar= errStr.charAt(i)
			if(text.indexOf(mychar) != -1){
				err++
				lclEndText = text.substring(text.indexOf(mychar)+1,text.length)
				text = text.substring(0,text.indexOf(mychar)) + lclEndText
				flag = true
			}
		}
	}
	if(text!= temp) {
		if(err < 2)	alert("worong character")//alert("השתמשת בתו לא חוקי ותו זה יוסר") 
		else		alert("worong characters")//alert("השתמשת בתוים לא חוקיים ותוים אלה יוסרו")
	}	
	return text 
}
//***********************************
function goToSearch(){
	if(document.all["searchInput"].value==""){
		alert(clientDic.ENTER_SOMETHING)
		document.all['searchInput'].focus()
		return
	}
	if(!charOk(document.all['searchInput'].value,"\"\'&><")){
		alert(clientDic.BAD_CHARS)
		document.all['searchInput'].focus()
		return
	}
	window.location=modulesPath+"?pi="+searchPI+"&word="+document.all["searchInput"].value
}
