
// ==========================================================================
// UNOBSTRUSIVE POPUP 
var popupLinkConfig = new Array;
   var w = 530;
   var h = 400;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
// popupLinkConfig["classname"] = new Array ( "targetname", "width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
popupLinkConfig["popup"]    = new Array ( "popup", "scrollbars=yes,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);


//window.onload = initPage;  
// Note: Make sure that no other javscripts assign a fuction to window.onload
// There can be only one function tied to window.onload at a time.

function initPage() {
  initPopupLinks();
  // place here any other code you wish to run when the page loads.
}

function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

// ==========================================================================


function setmyquery() { //v2.0
  window.open('http://search.bosch.com/www_bosch_it_formula/search.asp?ct=www_bosch_it_formula&qu=' + document.form1.qu.value,'searchpopup','status=yes,width=400,height=423');
}
				function displayDate() {
				    
					theDate = new Date();
				 	var year = theDate.getYear();
				 	var month = (theDate.getMonth())+1;
				 	var day = theDate.getDate();
				 	if (year < 1000) year+=1900;  
				 	if (day  < 10) day="0"+day;
				 	if (month < 10) month="0"+month;
					
					var myDate = "day/month/year";
					
					myDate = myDate.replace(/day/,day);
					myDate = myDate.replace(/month/,month);
					myDate = myDate.replace(/year/,year);
					if(document.getElementById){
						if(document.getElementById("hsDate")){
				 			document.getElementById("hsDate").innerHTML=myDate;
				 		}
				 	}
				}
				
				function openWebassistant(q){
					var path="http://www.bosch.it/content/service/wa/index.asp";
					if (typeof(q) != "string") q = "";
					if(path.indexOf("?") < 0){
						path+="?lang=it";
						
					}else{
						if(path.indexOf("lang=") < 0){
							path+="&lang=it";
						}
					}
					path+="&query="+q;
					
					
					window.open(path,"wa","width=564,height=508,toolbar=no,location=no,directories=no,scrollbars=no,status=no,menubar=no,resizable=no");
				}
				function openContactEmail(e){
					openContact("","","","",e);
				}
	

function openContact(igb,ioption1,ioption2,ioption3,iemail){
					if (((typeof(iemail)== "undefined")||iemail=="")&&((typeof(email)== "undefined")||email=="")){
						iemail="";
						igb=((typeof(igb)== "undefined") || (igb == ""))?(typeof(gb)=="undefined")?(typeof(business_division)=="undefined")?"":business_division:gb:igb;
						ioption1=((typeof(ioption1)== "undefined") || (ioption1 == ""))?(typeof(option1)=="undefined")?(typeof(sub_division1)=="undefined")?"":sub_division1:option1:ioption1;
						ioption2=((typeof(ioption1)== "undefined") || (ioption2 == ""))?(typeof(option2)=="undefined")?(typeof(sub_division2)=="undefined")?"":sub_division2:option1:ioption1;
						ioption3=((typeof(ioption1)== "undefined") || (ioption3 == ""))?(typeof(option3)=="undefined")?(typeof(sub_division3)=="undefined")?"":sub_division3:option1:ioption1;
					
					}else{
						igb="";ioption1="";ioption2="";ioption3="";
						if((typeof(iemail)== "undefined")||iemail==""){iemail=email;email="";}
					}
					
					
					myurl = "http://www.bosch.it/content/service/contact/index.asp";
					if ((typeof(myurl) != "undefined") && (myurl != "")) {
						if(myurl.indexOf("?")>0){
							if(myurl.indexOf("lang=") < 0){
								myurl = myurl+"&lang=it"
							}
							myurl = myurl+"&gb=" + escape(igb.toUpperCase()) + "&option1=" + escape(ioption1.toUpperCase()) + "&option2=" + escape(ioption2.toUpperCase()) + "&option3=" + escape(ioption3.toUpperCase()) + "&email=" + escape(iemail)+"&opener=" + escape(self.location.href) + escape("###") + escape(document.referrer); 
						}else{
							
								
							myurl = myurl+"?lang=it&gb=" + escape(igb.toUpperCase()) + "&option1=" + escape(ioption1.toUpperCase()) + "&option2=" + escape(ioption2.toUpperCase()) + "&option3=" + escape(ioption3.toUpperCase()) + "&email=" + escape(iemail)+"&opener=" + escape(self.location.href) + escape("###") + escape(document.referrer); 
    						}
		    			window.open(myurl, "contact", "width=564,height=508,toolbar=no,location=no,directories=no,scrollbars=no,status=no,menubar=no,resizable=no");
					}
				}

			
				
				function openSource(igb){
					var path="http://www.bosch.it/content/service/supplier/index.asp";
					igb=((typeof(igb)== "undefined") || (igb == ""))?(typeof(gb)=="undefined")?(typeof(business_division)=="undefined")?"":business_division:gb:igb;
					if(path.indexOf("?") < 0){
						path+="?lang=it";
					}else{
						if(path.indexOf("lang=") < 0){
							path+="&lang=it";
						}
					}
					window.open(path+"&gb="+igb+"&opener=" + escape(self.location.href) + escape("###") + escape(document.referrer),"dealer","width=564,height=508,toolbar=no,location=no,directories=no,scrollbars=no,status=no,menubar=no,resizable=no");
				}
				function openCountryLocator(){
					var path="";
					if(path.indexOf("?") < 0){

						path+="?lang=it";
					}else{
						if(path.indexOf("lang=") < 0){
							path+="&lang=it";
						}
					}
					window.open(path,"cl","");
				}
				function openMyBosch(){
					var path="http://www.bosch.it/content/service/mb/index.asp";
					if(path.indexOf("?") < 0){
						path+="?lang=it";
					}else{
						if(path.indexOf("lang=") < 0){
							path+="&lang=it";
						}
					}
					window.open(path,"mybosch","");
				}
				function openImpressum(){
					var path="http://www.bosch.it/content/language1/html/1062.htm";
					if(path.indexOf("?") < 0){
						
							path+="?lang=it";
						
					}else{
						if(path.indexOf("lang=") < 0){
							path+="&lang=it";
						}
					}
					window.open(path,"imprint","width=440,height=418,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no,resizable=no");
				}
			
/* 
MENU AD ALBERO PRINCIPALE
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 

 * ul2finder
 * written by Christian Heilmann (http://icant.co.uk)
 * turns the nested list with the ID "mainmenu" into a dynamic list
 * uses the CSS classes defined in the variables
 */
function ul2finder()
{
	// Define variables used and classes to be applied/removed
	var i,uls,als,finder;
	var parentClass='parent';
	var showClass='shown';
	var hideClass='hidden';
	var openClass='open';

	// check if our finder list exists, if not, stop all activities
	finder=document.getElementById('mainmenu');
	if(!finder){return;}
	

	// add the class domenabled to the body
	cssjs('add',document.body,'domenabled')
	// loop through all lists inside finder, position and hide them 
	// by applying the class hidden
	uls=document.getElementById('mainmenu').getElementsByTagName('ul');
	for(i=0;i<uls.length;i++)
	{
		cssjs('add',uls[i],hideClass);
	}	
	// loop through all links of inside finder
	lis=document.getElementById('mainmenu').getElementsByTagName('li');
	;
	for(i=0;i<lis.length;i++)
	{
		// if the li containing the link has no nested list skip this one
		if(!lis[i].getElementsByTagName('ul')[0])
		{				
			continue;
		}
		
		var newa=document.createElement('a');
		newa.href='#';
		newa.appendChild(document.createTextNode(lis[i].firstChild.nodeValue));
		lis[i].replaceChild(newa,lis[i].firstChild);
		
		// otherwise apply the parent class
		cssjs('add',newa,parentClass);
		
		if (lis[i].getElementsByTagName('ul')[0].className.indexOf('shown')>0)
		{
			cssjs('remove',newa,parentClass);
			cssjs('add',newa,openClass);
		}
			
		// if the user clicks on the link
		lis[i].getElementsByTagName('a')[0].onclick=function()
		{
		// loop through all lists inside finder
			for(var i=0;i<uls.length;i++)
			{
				// avoid the list connected to this link
				var found=false;
				for(j=0;j<uls[i].getElementsByTagName('ul').length;j++)
				{
					if(uls[i].getElementsByTagName('ul')[j] == 		
						this.parentNode.getElementsByTagName('ul')[0])
					{
						found=true;
						break;
					}
				}
				// and hide all others
				if(!found)
				{
					
					cssjs('add',uls[i],hideClass)
					cssjs('remove',uls[i],showClass)
					cssjs('remove',uls[i].parentNode.getElementsByTagName('a')[0],openClass)
					cssjs('add',uls[i].parentNode.getElementsByTagName('a')[0],parentClass)	
				}
			
			}	
			// change the current link from parent to open 	
			cssjs('swap',this,parentClass,openClass)
			// show the current nested list 
			cssjs('add',this.parentNode.getElementsByTagName('ul')[0],showClass)

			// don't follow the real HREF of the link
			return false;
	
	}
	}	
	/*
	 * cssjs
	 * written by Christian Heilmann (http://icant.co.uk)
	 * eases the dynamic application of CSS classes via DOM
	 * parameters: action a, object o and class names c1 and c2 (c2 optional)
	 * actions: swap exchanges c1 and c2 in object o
	 *			add adds class c1 to object o
	 *			remove removes class c1 from object o
	 *			check tests if class c1 is applied to object o
	 * example:	cssjs('swap',document.getElementById('foo'),'bar','baz');
	 */
	function cssjs(a,o,c1,c2)
	{
		switch (a){
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
		}
	}
}

// Check if the browser supports DOM, and start the script if it does.
//if(document.getElementById && document.createTextNode)
//{
	//window.onload=ul2finder;
//}

// FUNZIONE JQUERY PER EVIDENZIARE ULTIMA VOCE DI MENU (richiede jquery.js)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function evidenzia(){ 
$("ul.sottolivello li:last-child",document.getElementById("mainmenu")).addClass("jquery");
	  }
//$(document).ready(evidenzia);

// CARICAMENTO DELLE FUNZIONI TUTTE INSIEME ONLOAD
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function LoadFuncs() {
ul2finder()
initPage()
evidenzia()
}
window.onload=LoadFuncs;
