
var version=0; //Browser version - IE only
if (navigator.appVersion.indexOf("MSIE")!=-1){
    temp=navigator.appVersion.split("MSIE")
    version=parseFloat(temp[1])
}

//-- Show/Hide functions --//
function resetAll(lyrId) { 
	var divs = document.getElementsByTagName('div'); 
	var links = document.getElementsByTagName('a'); 
	for(i=0;i<divs.length;i++){ 
		if(divs[i].id.match(lyrId)){
			divs[i].style.display='none';
		} 
	
	} 
	for(i=0;i<links.length;i++){ 
		if(links[i].id.match('link_' + lyrId)){
		
            links[i].style.background = "url(/common/images/b-tabs-off.gif) #F1EACC  no-repeat top right";
            links[i].style.color = "#ba9800";
		} 
	}
}


function showHide(nr) {
    resetAll('sh');
    current = (document.getElementById(nr).style.display == 'block') ? 'none' : 'block';
    document.getElementById(nr).style.display = current;
    
    document.getElementById('link_' + nr).style.background = "url(/common/images/b-tabs-selected.gif) #ba9800  no-repeat top right";
    document.getElementById('link_' + nr).style.color = "#ffffff";
}

function TipAFriend()
{
    window.open('TipAFriend.aspx','TipAFriend', 'scrollbars=yes, toolbar=no, resizable=no,top=0,left=0, width=500,height=300');
}

//IE Dropdown navigation
sfHover = function() {
	// Support the standard nav without a class of nav.
	var el = document.getElementById("navTop").firstChild;
	el.className ="navTop";
	if(!/\bnav\b/.test(el.className) && el.tagName == "UL")
		setHover(el);

	// Find all unordered lists.
	var ieNavs = document.getElementsByTagName('ul');
	for(i=0; i<ieNavs.length; i++) {
		var ul = ieNavs[i];
		// If they have a class of nav add the menu hover.
		if(/\bnav\b/.test(ul.className))
			setHover(ul);
	}

}


if (version>0 && version < 7){
	if (window.attachEvent && version < 7){ 
		window.attachEvent("onload", sfHover);
		//Write styles
		document.write("<style>ul.navTop iframe {position: absolute;  z-index: -1; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);} * html ul.primary-nav li { z-index: 201; }</style>");
	}
	//Load tab navigation for IE 7+ browsers
	else{
		var ct = checkTabs();
	}
}
 

//
function setHover(nav) {
	var ieULs = nav.getElementsByTagName('ul');
	if (navigator.appVersion.substr(22,3)!="5.0") {
		// IE script to cover <select> elements with <iframe>s
		for (j=0; j<ieULs.length; j++) {
			var ieMat=document.createElement('iframe');
			if(document.location.protocol == "https:")
				ieMat.src="//0";
			else if(window.opera != "undefined")
				ieMat.src="";
			else
				ieMat.src="javascript:false";
			ieMat.scrolling="no";
			ieMat.frameBorder="0";
			ieMat.style.width=ieULs[j].offsetWidth+"px";
			ieMat.style.height=ieULs[j].offsetHeight+"px";
			ieMat.style.zIndex="-1";
			ieULs[j].insertBefore(ieMat, ieULs[j].childNodes[0]);
			ieULs[j].style.zIndex="101";
		}
		// IE script to change class on mouseover
		var ieLIs = nav.getElementsByTagName('li');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			// Add a sfhover class to the li.
			ieLIs[i].onmouseover=function() {
				if(!/\bsfhover\b/.test(this.className))
					this.className+=" sfhover";
			}
			ieLIs[i].onmouseout=function() {
				if(!this.contains(event.toElement))
					this.className=this.className.replace(' sfhover', '');
			}
		}
	} else {
		// IE 5.0 doesn't support iframes so hide the select statements on hover and show on mouse out.
		// IE script to change class on mouseover
		var ieLIs = document.getElementById('nav').getElementsByTagName('li');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			ieLIs[i].onmouseover=function() {this.className+=" sfhover";hideSelects();}
			ieLIs[i].onmouseout=function() {this.className=this.className.replace(' sfhover', '');showSelects()}
		}
	}
}


/* -- Vendors Form -- opens /vendors.asp?username&password to submit to http://www.petrofac.co.ae/procurement/LoginProcessing.asp-- */

function formcheck(frm)
{
    var username;
    var password;
    var URL;

   if(document.aspnetForm.logon_name.value=="")
	{
	document.getElementById("VendorsFormErrors").innerHTML = "Username cannot <br />be left empty";
	
	//	alert("Username cannot be left empty");
		document.getElementById("Label_logon_name").style.color = "#9c1e3d"
		document.aspnetForm.logon_name.focus();		
		return false;
		
	} else{
	    document.getElementById("Label_logon_name").style.color = "#666666"
		document.getElementById("VendorsFormErrors").innerHTML = "";
		username = document.aspnetForm.logon_name.value;
	}
    
    if(document.aspnetForm.user_security_password.value=="")
	{
		document.getElementById("VendorsFormErrors").innerHTML = "Password cannot <br />be left empty";

		//alert("Password cannot be left empty");
		document.getElementById("Label_user_security_password").style.color = "#9c1e3d"
		document.aspnetForm.user_security_password.focus();		
		return false;
    }else{
	    document.getElementById("Label_user_security_password").style.color = "#666666"
	    document.getElementById("VendorsFormErrors").innerHTML = "";
		password = document.aspnetForm.user_security_password.value;
	}

    URL = "/vendors.asp?username=" + username + "&password=" + password + "";
    window.open(URL,'Petrofac Vendors')
    return false;
}


/* -- Location map -- */

 function getFlashMovie(movieName) {
 //alert('movieName' + movieName);
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }

 function moveTo(numX, numY) {
  
  var text = numX + ":" + numY; //document.htmlForm.sendField.value;


//alert('boo' + getFlashMovie("ExternalInterfaceExample")) 

  getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text);
  
  
  document.getElementById("opsMap").src = "/common/images/maps/map-"+numY+"-"+numX+".gif";
 } 
 
 function getTextFromFlash(str) {
  document.htmlForm.receivedField.value = "From Flash: " + str;
  return str + " received";
}

function getWidth() {
    var myWidth = 0;
    var ieAdjust = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        ieAdjust = 17;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    var divWidth = (myWidth - 467) + ieAdjust;

    if (divWidth > 815){
    divWidth = 815;
    }
    else if (divWidth < 550){
    divWidth = 550;
    }
 
    var divHight = divWidth * 0.90184;
    document.getElementById('Flash_Map_Holder').style.width = divWidth + "px";
    document.getElementById('Flash_Map_Holder').style.height = divHight + "px"
}

//this.href,'fixedscroll',550,750

var newWin = null;
 
function RNSpopUp(strURL) {
    if (newWin != null && !newWin.closed) 
        newWin.close(); 
    var strOptions="status,scrollbars,screenX=300,left=300,screenY=200,top=50,height=550,width=630"; 
    newWin = window.open(strURL, 'newWin', strOptions); 
    newWin.focus(); 
}

var browser = navigator.appName;
var ver = navigator.appVersion;
var thestart = parseFloat(ver.indexOf("MSIE"))+1;
var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7));
var lightboxKiller;

if ((browser=="Microsoft Internet Explorer") && (brow_ver < 6))
{
	lightboxKiller = true;
}else{
	lightboxKiller = false;
}