//General Vars//////////////
///////////////////////////
var ie=document.all
var ns=document.layers
var ns6=document.getElementById&&!document.all

var xOffset, yOffset; 
var mousex, mousey;
var crossobj;

var Keep="";
var hideIt;
//document.onmousedown=initializedrag
//document.onmouseup=new Function("dragapproved=false")
//document.onmousemove = getmousepos();

//deal with cursor over layer

//simple browser check
f7_v4=(parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<=5)?1:0
f7_ie=(document.all && f7_v4)?1:0
f7_ns=(f7_ie)?0:1
//f7_ns=(document.layers && f7_v4)?1:0


document.onmousemove = f7_getmousepos;
if (f7_ns) document.captureEvents(Event.MOUSEMOVE)


function f7_getmousepos(e){
	if(f7_ns){mousex=e.pageX; mousey=e.pageY}
	if(f7_ie){mousex=event.clientX; mousey=event.clientY;}
	}


//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------



// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left


function showPopup (eventObj, targetObjectId, Opener, WinSize, lang, Stick, xSet, ySet) {
   
    if(eventObj) {
	Keep=targetObjectId;
	
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	hideall();
	
	crossobj=document.getElementById? document.getElementById(targetObjectId) : document.all[targetObjectId];
	OpenerObj=document.getElementById? document.getElementById(Opener) : document.all[Opener];
	
	//Set WinSize
	var WinSizeStyle = WinSize ? WinSize : 700;
	crossobj.style.width=WinSizeStyle;
	//alert(WinSizeStyle);
	
	//Set default language (this sets the xSet and ySet to be minus or +)
	// 0 is hebrew
	// 1 is english
	var LangVal= lang ? lang : 0;
	//Setting if the window is a dropdown, default is no
	var xDefaultOffSet= lang ? (WinSizeStyle+10): -(WinSizeStyle+10);
	
	//Set XOffset and yOffSet for the window
	//alert(xSet + " " + ySet);
	xOffset = xSet ? xSet: 0;
	yOffset = ySet ? ySet: 0;
	//alert(xOffset + " " + yOffset);
	
	
	//Set pop up position 
	//Stick=0 (does not exist) then the popup is according to cursor position
	//Stick=1 (exist) then the popup is according to element left or right bottom (according to language)
	//Default is cursor position
	var newXCoordinate, newYCoordinate;
	var Sticky= (Stick==null) ? 1 : Stick;
	//alert(OpenerObj.id);
	var objCor=FindXYWH(OpenerObj);
	//alert("x: " + objCor.x + " " + "y: " + objCor.y + " " + "w: " + objCor.w + " " + "h: " + objCor.h + " ");
	if (Sticky)
	{
		
		if (!LangVal)
		{
		newXCoordinate = (objCor.x)?objCor.x + (objCor.w) - WinSizeStyle + xOffset +((document.body.scrollLeft)?document.body.scrollLeft:0):objCor.x + ((document.body.scrollLeft)?document.body.scrollLeft:0);
		newYCoordinate = (objCor.y)?objCor.y  + yOffset + document.body.scrollTop :objCor.y + document.body.scrollTop;
		}
		else
		{
		newXCoordinate = objCor.x + xOffset + objCor.w;
		newYCoordinate = objCor.y + yOffset + objCor.h + document.body.scrollTop;
		}
	}
	else
	{
		newXCoordinate = objCor.x + xOffset + objCor.w - WinSizeStyle;
		newYCoordinate = objCor.y + yOffset + objCor.h + document.body.scrollTop;
		
	}
	
	
	//if the window is a dropdown then we check the mousepos and accordingly we hide or show the window
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	
	
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'block') ) {
	   return	true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
    
} // showPopup



function hideall(){
	//alert (Keep);
	for(i=1;i<arr.length;i++){  
		hideIt=false; 
		checkmouse(arr[i]);
		//alert(arr[i] + " " + hideIt + Keep);
		if(Keep!=arr[i] && hideIt==true){ 
			changeObjectVisibility(arr[i], 'none');
		}
	}	
}
function checkmouse(Name){
	var obj, objCor;
	
	obj=document.getElementById? document.getElementById(Name) : document.all[Name];
	objCor=FindXYWH(obj);
	//check if the mouse is in the range of the children
	if((mousex>=objCor.x && mousex<=(objCor.x + objCor.w) && mousey>=objCor.y && mousey<=(objCor.y + objCor.h))){
		hideIt=false;
		}
	else{
		hideIt=true;
	}
	
	return hideIt;
}

function hideDrop(){
	Keep="";
	setTimeout('hideall()',500)
}


// Find the x,y location in pixels for a relatively positioned object
// returns an object with .x and .y properties.
function FindXY(obj){
	var x=0,y=0;
	while (obj!=null){
		x+=obj.offsetLeft-obj.scrollLeft;
		y+=obj.offsetTop-obj.scrollTop;
		obj=obj.offsetParent;
	}
	return {x:x,y:y};
}

// Find the x,y location in pixels for a relatively positioned object
// returns an object with .x, .y, .w (width) and .h (height) properties.
function FindXYWH(obj){
	var objXY = FindXY(obj);
	return objXY?{ x:(objXY.x), y:objXY.y, w:obj.offsetWidth, h:obj.offsetHeight }:{ x:0, y:0, w:0, h:0 };
}



//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//------------------------ Functions enabling drop down - mouse over functions ---------------------

//Gets the position of each layer, goes one by one
//If the mouse is inside it leaves it visible, if it isn't it hides it




		
// ***********************
// hacks and workarounds *
// ***********************

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
//document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	obj1=document.getElementById? document.getElementById(objectId) : document.all[objectId];
	//bj1.filters.item(0).Apply();
	styleObject.display = newVisibility;
	//obj1.filters.item(0).Play();
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject




function showhide(what){
	//What_Var= what + '.style.display'
	//document.write (eval(What_Var))
	//What_Var= what + 'style.display'
if (eval(what + '.style.display')=='none'){
	eval(what + '.style.display=""');
	}
	else{
	eval(what + '.style.display="none"')
	}
}

function hide(what){
	eval(what + '.style.display="none"')
}

function show(what){
	eval(what + '.style.display=""')
}

function validateEmail(Obj) {
/************************************************
DESCRIPTION: Validates that a string contains a
valid email pattern.

PARAMETERS:
strValue - String to be tested for validity
RETURNS:
True if valid, otherwise false.

REMARKS: Accounts for email with country appended
does not validate that email contains valid URL
type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var txtObj=document.getElementById? document.getElementById(Obj) : document.all[Obj];
var IsValid;
//var objRegExp  =/(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
var objRegExp  =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/
//check for valid email
IsValid=objRegExp.test(trim(txtObj.value));
if (txtObj.value!="" && IsValid==false)
	{
		return false;
	}
	else
	{
		return true;
	}
}

//--------------------- Is Numeric
var numbers=".0123456789";
  function isNumeric(x) {
    // is x a String or a character?
    if(x.length>1) {
      // remove negative sign
      x=Math.abs(x)+"";
      for(j=0;j<x.length;j++) {
        // call isNumeric recursively for each character
        number=isNumeric(x.substring(j,j+1));
        if(!number) return number;
      }
      return number;
    }
    else {
      // if x is number return true
      if(numbers.indexOf(x)>=0) return true;
      return false;
    }
  }
  
  function trim(str)
   {
     s = str.replace(/^(\s)*/, '');
     s = s.replace(/(\s)*$/, '');
     return s;
   }


