//-- 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 hideAll(lyrId) { 

//document.getElementById(nr).style.

//}

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";
}





//Fade using script.aalishio.us (or however it is spelt)

var z = 3;
function fadein(div) {
	var k = document.getElementById(div).style;
	var x = z-1
	

	//alert("this z-index:" + k.zIndex + "\n counter:" + x);

	//if(k.zIndex != x){
	//	k.display = "none";
	//	k.visibility = "hidden";

	//	k.zIndex = z;
		setTimeout("Effect.Appear('"+ div+"');", 1500);
		//Effect.Appear(div);
	//	z++;
	//	document.getElementById("testCounter").innerHTML = "count = " + z;
	//	alert("z-index" + z);
	//}
	return false;
}

function fadeout(div) {
	var k = document.getElementById(div).style;
	var x = z-1
	

	//alert("this z-index:" + k.zIndex + "\n counter:" + x);

	//if(k.zIndex = x){
	//	k.display = "none";
	//	k.visibility = "hidden";

		//k.zIndex = z;
		setTimeout("Effect.Fade('"+ div+"');", 50);
		//Effect.Fade(div);
		//z++;
	//	document.getElementById("testCounter").innerHTML = "count = " + z;
	//	alert("z-index" + z);
	//}
	return false;
}


/* -- To Fix hover in IE6 and lower -- */

sfHover = function(){
	var sfEls = document.getElementById("navTopMenuID").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/* -- 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) {
  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;
  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"
}
