var x;
layerTop=181;
subCompanyLeft=154;
subServicesLeft=350;
subContactLeft=550;
subLogisticsLeft=295;
subCustomerServicesLeft=488;
sublogimanLeft=462;
subBidsLeft=405;

stopPoint=8;
activeDiv="";
layerOn="";
activeButton="";
buttonOn="";

function onButtonNoDiv(ButtonName){
	clearTimeout(x);
	layersGone('');
	if (buttonOn != "")
		setButtons(buttonOn, 'off');
	buttonOn=ButtonName;
	setButtons(buttonOn, 'on');
}

function setButtons(ButtonName, onOff){

	if (ButtonName == "home")
		document.home.src="buttons/home_"+onOff+".gif";
	if (ButtonName == "company")	
		document.company.src="buttons/company_"+onOff+".gif";
	if (ButtonName == "services")	
		document.services.src="buttons/services_"+onOff+".gif";
	if (ButtonName == "infosystems")	
		document.infosystems.src="buttons/infosystems_"+onOff+".gif";
	if (ButtonName == "sales")	
		document.sales.src="buttons/sales_"+onOff+".gif";
	if (ButtonName == "logistics")	
		document.logistics.src="buttons/logistics_info_"+onOff+".gif";
	if (ButtonName == "customer")	
		document.customer.src="buttons/customer_serv_"+onOff+".gif";
	if (ButtonName == "maman")	
		document.maman.src="buttons/maman_"+onOff+".gif";
	if (ButtonName == "contact")	
		document.contact.src="buttons/contact_top_"+onOff+".gif";
	if (ButtonName == "english")	
		document.english.src="buttons/english_"+onOff+".gif";
	if (ButtonName == "logiman")	
		document.logiman.src="buttons/logiman_"+onOff+".gif";	
	if (ButtonName == "order")	
		document.order.src="buttons/order_"+onOff+".gif";	
	if (ButtonName == "Bids")	
		document.sales.src="buttons/sales_"+onOff+".gif";	

}

function setLayers(){
	document.all.subCompany.style.top=layerTop;
	document.all.subServices.style.top=layerTop;
	document.all.subContact.style.top=layerTop;
	document.all.subLogistics.style.top=layerTop;
	document.all.subCustomerServices.style.top=layerTop;
	document.all.sublogiman.style.top=layerTop;
	document.all.subBids.style.top=layerTop
	layersGone('');	
	resizeLayers();
}

function loadPage(bannerName, divName, buttonName){
	resizeLayers();
	if (divName != "")
		activeDiv=divName;
    if (buttonName != "")
		activeButton=buttonName;
	//setActiveButton("home");
	ActivateWorkingDiv();
}

function ActivateWorkingDiv(){
	clearTimeout(x);
	layersGone(activeDiv);
	
	if (activeDiv != ""){
		str1 = eval("document.all." + activeDiv + ".style");	
		str = getImageIdByLayer(activeDiv);
		str2 = getImageByLayer(activeDiv);
		str = eval("document." + str)	
			
		if (str1.visibility!='visible'){	
			str1.visibility='visible';
				
		}
	}
	if (activeButton != ""){
		if (buttonOn!="")
			setButtons(buttonOn, 'off');		
		buttonOn=activeButton;
		setButtons(activeButton, 'on');
	}
}

function resizeLayers(){
	str = document.all.subCompany.style.width
	layerName=eval(document.all.subCompany.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(subCompanyLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - subCompanyLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);
	 
	str = document.all.subServices.style.width
	layerName=eval(document.all.subServices.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(subServicesLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - subServicesLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);

	str = document.all.subContact.style.width
	layerName=eval(document.all.subContact.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(subContactLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - subContactLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);
	 

	str = document.all.subLogistics.style.width
	layerName=eval(document.all.subLogistics.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(subLogisticsLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - subLogisticsLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);

	str = document.all.subCustomerServices.style.width
	layerName=eval(document.all.subCustomerServices.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(subCustomerServicesLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - subCustomerServicesLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);	 	 	 
	 
	 
	 str = document.all.sublogiman.style.width
	layerName=eval(document.all.sublogiman.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(sublogimanLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - sublogimanLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);
	 
	 str = document.all.subBids.style.width
	layerName=eval(document.all.subBids.style);
	if (document.body.offsetWidth > (parseInt(str.slice(0, str.length - 2 )) + parseInt(subBidsLeft)) + parseInt(stopPoint))
	 layerName.left = document.body.offsetWidth - subBidsLeft - parseInt(str.slice(0, str.length - 2 ))
	else
	 layerName.left = parseInt(stopPoint);
	 
}


function layersGone(leaveOn){
	if (leaveOn != "subCompany")
		document.all.subCompany.style.visibility='hidden'
	if (leaveOn != "subServices")	
		document.all.subServices.style.visibility='hidden'
	if (leaveOn != "subContact")
		document.all.subContact.style.visibility='hidden'	
	if (leaveOn != "subLogistics")
		document.all.subLogistics.style.visibility='hidden'
	if (leaveOn != "subCustomerServices")
		document.all.subCustomerServices.style.visibility='hidden'		
	if (leaveOn != "sublogiman")
		document.all.sublogiman.style.visibility='hidden'		
		
	if (leaveOn != "subBids")
		document.all.subBids.style.visibility='hidden'		
}

function LayerShow(layerName, buttonName){
	clearTimeout(x);
	layersGone('');
	str = eval("document.all." + layerName + ".style");
	str.visibility='visible';
	layerOn=layerName;
	if (buttonOn!="")
		setButtons(buttonOn, 'off');
	buttonOn=buttonName;
	setButtons(buttonOn, 'on');
	
}

function activateTimer(){
	clearTimeout(x);
	x = setTimeout('ActivateWorkingDiv()', 500)
} 

function killTimer(){
	clearTimeout(x);
}

function getImageByLayer(layerName){
	if (layerName=="subCompany")
		return "company";
	else if (layerName=="subServices")
		return "services";
	else if (layerName=="subContact")
		return "contact_top";
	else if (layerName=="subLogistics")
		return "logistics_info";
	else if (layerName=="subCustomerServices")
		return "customer_serv";
	else if (layerName=="sublogiman")
		return "logiman";
	else if (layerName=="subBids")
		return "Bids";
	
}

function getImageIdByLayer(layerName){
	if (layerName=="subCompany")
		return "company";
	else if (layerName=="subServices")
		return "services";
	else if (layerName=="subContact")
		return "contact";
	else if (layerName=="subLogistics")
		return "logistics";
	else if (layerName=="subCustomerServices")
		return "customer";
	else if (layerName=="sublogiman")
		return "logiman";
	else if (layerName=="subBids")
		return "Bids";

}


function emailCheck(emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/

/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"

/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"

/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'

/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"

// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("יש להזין כתובת דואר אלקטרוני חוקית")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("יש להזין כתובת דואר אלקטרוני חוקית")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("יש להזין כתובת דואר אלקטרוני חוקית")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("יש להזין כתובת דואר אלקטרוני חוקית")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("יש להזין כתובת דואר אלקטרוני חוקית")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="יש להזין כתובת דואר אלקטרוני חוקית"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}


function RollOverMenu() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('hsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('hsrc');
        imgarr[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'))
        }
        imgarr[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc)
        }
    }
  }
}
//onload=RollOverMenu;


function MM_preloadImages() 
{
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}