
var oldLoad = window.onload;
var bplCCKDivAgency;
window.onload=function(){
  if(oldLoad){
    oldLoad();
  }
	try{
		var obj = document.getElementsByTagName('iframe')[0].nextSibling.nextSibling.nextSibling;
		if(obj.tagName=='TABLE' || obj.tagName=='table'){
		    obj = document.getElementsByTagName('iframe')[0].nextSibling.nextSibling;
		}
		//alert(obj.style.left);
		if(obj.style.left=='90px'){
			obj.style.left='400px';
		}
		//alert(obj.style.left);
	} catch (e) {
        //alert(e);
	}  
	try{
		bplCCKDivAgency=document.getElementById('divAlert');
		if(bplCCKDivAgency!=null){
		    visibilityDropDown();
		    setInterval ( "visibilityDropDown()", 250 );
		    window.onscroll = scrollEvent;
		    window.onresize = resizeEvent;
		}
	  
	}catch(g){
	    //alert(g);
	}
}
function scrollEvent() {
        bplCCKDivAgency.style.width=document.body.clientWidth+document.body.scrollLeft;
	    bplCCKDivAgency.style.height=document.body.clientHeight+document.body.scrollTop;
	    window.onresize = resizeEvent;
}

function resizeEvent() {
    bplCCKDivAgency.style.width=document.body.clientWidth;
	bplCCKDivAgency.style.height=document.body.clientHeight;
	window.onresize = scrollEvent;
}

function visibilityDropDown(){
   var list_select = document.getElementsByTagName('select');
   var visibilityDiv = bplCCKDivAgency.style.display;
   var visibilitySelect;
   if(visibilityDiv=='none'){
    visibilitySelect=true;
   }else{
    visibilitySelect=false;
   }
   for(i=0; i < list_select.length; i++){
    if(visibilitySelect==false){
        list_select[i].style.display='none';
    }else{
       list_select[i].style.display='' ;
   }
  }
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

// Questa funzione ritorna il trim della stringa passata in ingresso.
function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
		sString = sString.substring(1, sString.length);
	while (sString.substring(sString.length-1, sString.length) == ' ')
		sString = sString.substring(0,sString.length-1);
	return sString;
}

// Get current mouse x, y position
function getMouseXY(e) {
	if (document.body)
	{
		if (IE) {
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		} else {
			tempX = e.pageX;
			tempY = e.pageY;
		}  
		if (tempX < 0){tempX = 0};
		if (tempY < 0){tempY = 0}; 
	}
	return true;
}

// set visibility of zoomed images to visible, set the src of zoomed images
function ShowPhoto(url) {
	var layerPhoto = document.getElementById("divPhoto");
	var Ypos;
	if(layerPhoto != null) {
		Ypos=tempY-layerPhoto.offsetHeight;
		layerPhoto.style.left = tempX+'px';
		layerPhoto.style.top = Ypos+'px';
		var imgPhoto = document.getElementById("imgPhoto");
			if(imgPhoto != null) {
				imgPhoto.src = url;
			}
	}
	layerPhoto.style.visibility = 'visible';
}

function PrintDiv(spacerUrl, closeIcon){
	document.write("<DIV ID=\"divPhoto\" STYLE=\"Z-INDEX:1;VISIBILITY:hidden; WIDTH:200px; POSITION:absolute; HEIGHT:120px\">");
	document.write("<TABLE WIDTH=\"200\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#ffffff\">");
	document.write("<TR ALIGN=\"right\" BGCOLOR=\"#003399\">");
	document.write("<TD COLSPAN=\"3\"><A HREF=\"javascript:MM_showHideLayers('divPhoto','','hide');\"><IMG SRC=\""+closeIcon+"\" WIDTH=\"15\" HEIGHT=\"14\" BORDER=\"0\"></A></TD>");
	document.write("</TR><TR>");
	document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("<TD WIDTH=\"198\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("</TR><TR>");
	document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("<TD VALIGN=\"top\" STYLE=\"padding: 5px;\">");
	document.write("<IMG ID=\"imgPhoto\" width=\"194\" height=\"131\"></TD>");
	document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("</TR><TR>");
	document.write("<TD BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("<TD BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("<TD BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>");
	document.write("</TR></TABLE></DIV>");
}

function MakeHelpDiv(spacerUrl, closeIcon){
    document.write("<DIV ID=\"divHelp\" STYLE=\"position:absolute; z-index:1; visibility: hidden;\">")
    document.write("<TABLE WIDTH=\"250\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"#FFFFFF\">")
    document.write("<TR ALIGN=\"RIGHT\"  BGCOLOR=\"#003399\">")
    document.write("<TD COLSPAN=\"3\"><A HREF=\"#\" onClick=\"MM_showHideLayers('divHelp','','hide');return false\"><IMG SRC=\""+closeIcon+"\" WIDTH=\"15\" HEIGHT=\"14\" BORDER=\"0\"></A></TD>")
    document.write("</TR><TR>")
    document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("<TD WIDTH=\"118\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("</TR><TR>")
    document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("<TD VALIGN=\"TOP\" STYLE=\"padding: 5px;\" ID=\"helpDescriptionArea\"></TD>")
    document.write("<TD WIDTH=\"1\" BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("</TR><TR>")
    document.write("<TD BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("<TD BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("<TD BGCOLOR=\"#999999\"><IMG SRC=\""+spacerUrl+"\" WIDTH=\"1\" HEIGHT=\"1\"></TD>")
    document.write("</TR></TABLE></DIV>")
}

function ShowHelp(content) {
	var layerHelp = document.getElementById("divHelp");
	var Ypos;
	if(layerHelp != null) {
		Ypos=tempY-layerHelp.offsetHeight;
		layerHelp.style.left = (tempX+20)+'px';
		layerHelp.style.top = Ypos+'px';
		var contentHolder = document.getElementById("helpDescriptionArea");
			if(contentHolder != null) {
			    if(document.all){
                     contentHolder.innerText = content;
                } else{
                    contentHolder.textContent = content;
                }
			}
	}
	layerHelp.style.visibility = 'visible';
}

//----------------------------------- ACTIVE CONTENT SCRIPTS
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_GenerateObjectString(objAttrs, params, embedAttrs){
    var str = '<object ';
    
    for (var i in objAttrs)
        str += i + '="' + objAttrs[i] + '" ';
        
    str += '>';
    
    for (var i in params)
        str += '<param name="' + i + '" value="' + params[i] + '" /> ';
        
    str += '<embed ';
    
    for (var i in embedAttrs)
        str += i + '="' + embedAttrs[i] + '" ';
        
    str += ' ></embed></object>';
    
    return str;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var strObj = AC_GenerateObjectString(objAttrs, params, embedAttrs);
        
    document.write(strObj);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_FL_GetContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return AC_GenerateObjectString(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        //args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
function classChange(element,newclass) 
{
     document.getElementById(element).className = newclass;
}
function classChangeForLogIn(imputPwdName, element, newclass) 
{
	if (newclass == "box_login") {
		document.getElementById(imputPwdName).value = "password"
	} else {
		document.getElementById(imputPwdName).value = ""
	}
    document.getElementById(element).className = newclass;
}
var refSSDivTimeout;
var lastDiv;

function showSubItems(id)
{
    var elem = document.getElementById(id);
    if (!elem)
        return;
    if (lastDiv && lastDiv != elem)
	{				
			lastDiv.style.display = 'none';		
	}
    if(refSSDivTimeout) 
    {
        clearTimeout(refSSDivTimeout);
        refSSDivTimeout = null;       
    }
    elem.style.display = 'inline';
        
}
function hideSubItems(id)
{
    var elem = document.getElementById(id);
	if(!elem) return;    
	if(refSSDivTimeout) 
    {
		clearTimeout(refSSDivTimeout);
        refSSDivTimeout = null;							
    }
    refSSDivTimeout = setTimeout(function(){elem.style.display = 'none';}, 200);   		
	lastDiv = elem; 
}

//--------------------------------------
//  
// New HTML Dynamic Banners Scripts
//
// Ahmed Djobby
// 2008.03.03
//--------------------------------------

function GetTimeStamp(theDate) {
    var timeStamp = 0;
    
    if (theDate &&
        theDate.constructor == Date){
        var baseDate = new Date ();    
        baseDate.setFullYear(1970, 01, 01);    
    
        timeStamp = theDate - baseDate;
    }
    
    return timeStamp;
}

// Makes an Async HTML Banner Request.
// Ahmed Djobby
// 2008.03.03
function LoadBanner(url, additionalQueryString, containerID){   
    var xmlHTTPReq = null;
    var parentID = containerID;        
    
    if (window.XMLHttpRequest) {        
        xmlHTTPReq = new XMLHttpRequest();

        if (xmlHTTPReq.overrideMimeType)
            xmlHTTPReq.overrideMimeType("text/plain; charset=utf-8");                
    }     
    else if (window.ActiveXObject) {        
        try {
            xmlHTTPReq = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                xmlHTTPReq = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {
                xmlHTTPReq = null;
            }
        }
    }				
    
    if (xmlHTTPReq != null) {				
        xmlHTTPReq.onreadystatechange = function() {onReadyStateChanged(xmlHTTPReq, parentID);};
        
        //xmlHTTPReq.open("GET",url + "&AntiCache=" + GetTimeStamp(new Date()),true); // To be discussed.
        xmlHTTPReq.open("GET",url,true);
        xmlHTTPReq.setRequestHeader("Content-type", "text/plain; charset=utf-8");
        
        //-- For Test purposes we try to disable response caching
        //-- must (or may be not) activated for pro use
        /*xmlHTTPReq.setRequestHeader("Pragma", "no-cache");
        xmlHTTPReq.setRequestHeader("Cache-Control", "no-store");
        xmlHTTPReq.setRequestHeader("Cache-Control", "no-cache");*/
                
        xmlHTTPReq.send(additionalQueryString);        
    }			
}

// Handles the HTML Banner Async Response.
// Ahmed Djobby
// 2008.03.03
function onReadyStateChanged(xmlHTTPReq, containerID) {    
    if (!xmlHTTPReq)
        return;		        

    if (xmlHTTPReq.readyState!=4) 
        return;

    if( xmlHTTPReq.status!=200)			  
        return;

    var container = null;
    
    if (containerID && containerID != '')
        container = document.getElementById(containerID);
    
    if (container)
        container.innerHTML = xmlHTTPReq.responseText;
}


// New HTML Dynamic Banners Scripts: End
//--------------------------------------


//Funzione per effettuare il passaggio in SSL durante la login
//------------------------------------------------------------
var iStatusChangeSSLLogin = 0;
function ChangeSSLLogin() {
     if (iStatusChangeSSLLogin <= 0 && __CMS_CurrentUrl)
    {
        if(__CMS_CurrentUrl.indexOf('http://')==0)
            __CMS_CurrentUrl = __CMS_CurrentUrl.replace(/http:/i,'https:');
        else
            __CMS_CurrentUrl = 'https://'+window.location.hostname+__CMS_CurrentUrl;                                            
    }
    iStatusChangeSSLLogin++;
}

// -------------------------------------
// Enabling/Disabling element.
//
// Ahmed Djobby
// 2008.03.21
// -------------------------------------
function SetElementEnabledStatus(elemID, enabled){    
    var ddl = document.getElementById(elemID);    

    if (ddl) {        
        if (enabled == "false")
            ddl.disabled = true;
        else 
            ddl.disabled = false;
    }
}
// -------------------------------------

// -------------------------------------
// Issue 3280
//
// Ahmed Djobby
// 2008.06.16
// -------------------------------------

var FocusAlertEnabled = true;

// Give Focus to the AlertIcon defined by its controlId and its scrollTargetId
//
// Issue 3280
// Ahmed Djobby
// 2008.06.17
function FocusAlert(controlId, srollTargetId){
    if (srollTargetId &&
        controlId &&
        FocusAlertEnabled) {        
        var scrollTarget = document.getElementById(srollTargetId);        

        if (scrollTarget){   
            var coordinate = GetCoordinate(scrollTarget);

            if (coordinate && 
                coordinate.constructor == Coordinate &&
                !isNaN(coordinate.X) && !isNaN(coordinate.Y))               
                window.scrollTo(coordinate.X, coordinate.Y);
            else 
                window.location.hash = "#" + controlId;                                            
        }
        else 
            window.location.hash = "#" + controlId;
        
        FocusAlertEnabled = false;
        return false;
    }
}

// Coordinate Object Constructor Definition.
// Ahmed Djobby
// 2008.07.08
function Coordinate(x, y){
    this.X = x;
    this.Y = y;
}

// Gets the control coordinate (x, y)
// Ahmed Djobby
// 2008.07.08
function GetCoordinate(control){
    var result = null;
    
    if (control){        
        var xPos = control.offsetLeft;
        var yPos = control.offsetTop;        
        var tempEl = control.offsetParent;
        
        while (tempEl != null) {            
            xPos += tempEl.offsetLeft;
            yPos += tempEl.offsetTop;
            
            tempEl = tempEl.offsetParent;
        }
        
        result = new Coordinate(xPos, yPos);
    }
    
    return result;
}

function ResetFocusStatus(){
    FocusAlertEnabled = true;
}
// -------------------------------------

// -------------------------------------
// Simulate postback on Neter
//
// Ahmed Djobby feat. Emanuele Colo'
// 2008.06.27 
// -------------------------------------
function PostBackOnEnterKeyPress(strPostBackFunction, event){
    if (strPostBackFunction && strPostBackFunction != ''){
        var iKeyCode = null;
        
        if (window.event)
            iKeyCode = window.event.keyCode;
        else if (event)
            iKeyCode = event.keyCode;

        if (iKeyCode && iKeyCode == 13)
            eval(strPostBackFunction);
    }
}
// -------------------------------------


// -------------------------------------
// Gestione dei Coockie
// funzioni di creazione, lettura ed eliminazione di un cookie
//
// -- cdm 15.07.2008 
// -------------------------------------

// imposta il cookie Nome = Valore con il path path e per la durata di Giorni (se giorni non è un numero setta un cookies di sessione)
function setCookie(nome, valore, path, giorni)
{
	var expireDate = new Date()
	//set "expstring" to either an explicit date (past or future)
	if (typeof giorni == "number") { 
		//if set persistent cookie
		var expstring = expireDate.setDate(expireDate.getDate() + parseInt(giorni))
		document.cookie = nome + "=" + escape(valore) + "; expires=" + expireDate.toGMTString() + "; path=" + path;
	}
	else { 
		//else if this is a session only cookie setting
		document.cookie = nome + "=" + escape(valore) + "; path=" + path;
	}
}

// restituisce il valore del cookie Nome
function getCookie(nome)
{
	// utilizzo una RegularExp per cercare la copia nome/valore che mi interessa
	var re = new RegExp(nome + "=[^;]+", "i"); 
	if (document.cookie.match(re)) { 
		// se trovo il cookie restituisco il valore
		return unescape(document.cookie.match(re)[0].split("=")[1])
	}
	// se non esiste restituisco stringa vuota
	return "";
}

// rimuove un cookie
function delCookie(sNome) {
	setCookie(sNome, "");
}

// -------------------------------------

//Issue 3581
//Funzione che visualizza il div del changeCountry

function changeClassForChangeCountry()
{
    if(document.getElementById('changeCountryContainer').className=='changeCountryOff'){
        document.getElementById('changeCountryContainer').className = 'changeCountryOn';
        return;
    }
    document.getElementById('changeCountryContainer').className = 'changeCountryOff';
}
//Issue 3595
//Funzione che accende il div passato e spegne gli altri
function THISonTHAToff(code){
	divName = new Array();
	divName[0] = "onOff_americas";
	divName[1] = "onOff_europe";
	divName[2] = "onOff_scandinavia";
	divName[3] = "onOff_pacificasia";
	divName[4] = "onOff_middleeast";
	divName[5] = "onOff_africa";
	for(i=0; i < divName.length; i++){
		elem =  document.getElementById(divName[i]);
		if(divName[i]== code){
			elem.style.display="";
		}else{
			elem.style.display="none";	
		}

	}
}

function ChangeActionForm(strUrl){
    document.forms[0].action = strUrl;
    document.forms[0].submit();
    //return false;
}
