/*Cambia dimensione testo*/
window.onerror = HandleError;function HandleError() {return true}

function textsize(misura) {
if (!document.getElementsByTagName) {return}
var standard = "s";
var misure_ = {
	"s": "10px",
	"m": "11px",
	"l": "13px"
};
if (!misura) {
	var cookie = readCookie("textsize");
	misura = cookie ? cookie : standard;
}
document.getElementsByTagName('body')[0].style.fontSize = misure_[misura];
createCookie("textsize", misura, 365);
	for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
		if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')) {
			if(a.getAttribute('title') == "skin") a.disabled = true;
      	if(a.getAttribute('title') == "skin") a.disabled = false;
		}
	} /* questo ciclo for serve a disattivare e riattivare il foglio di stile della skin, non so perché ma evita un problema nel ridimensionamento dei caratteri con Opera 7 */
}

window.onload = function(e) {
  textsize();
}
textsize();

/* Estrazione casuale di immagini */

function random_image(sec){
	setta_img()
	cambia_img()
	a = setInterval(cambia_img,sec)
}

function image() {
};

function setta_img(){
immagini = new image();
number = 0;
// array di immagini
immagini[number++] = "<a href='/mkt_services/mkt_services_5_form.html?i=1' id='doc1'><img src='/images/mkt_1.jpg'></a>"
immagini[number++] = "<a href='/mkt_services/mkt_services_5_form.html?i=2' id='doc2'><img src='/images/mkt_2.jpg'></a>"
immagini[number++] = "<a href='/mkt_services/mkt_services_5_form.html?i=3' id='doc3'><img src='/images/mkt_3.jpg'></a>"
immagini[number++] = "<a href='/mkt_services/mkt_services_5_form.html?i=4' id='doc4'><img src='/images/mkt_4.jpg'></a>"
immagini[number++] = "<a href='/mkt_services/mkt_services_5_form.html?i=5' id='doc5'><img src='/images/mkt_5.jpg'></a>"
immagini[number++] = "<a href='/mkt_services/mkt_services_5_form.html?i=6' id='doc6'><img src='/images/mkt_6.jpg'></a>"
}

function cambia_img(){
estratto = Math.floor(Math.random() * number);
document.getElementById("random_img").innerHTML = immagini[estratto]
}

/*Switch tab box home page*/

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


function showTabPress()
{
	MM_showHideLayers('press','','show');
	MM_showHideLayers('events','','hide');
	document.getElementById("tabpress").className='presson';
	document.getElementById("tabevents").className='eventsoff';
}

function showTabEvents()
{
	MM_showHideLayers('press','','hide');
	MM_showHideLayers('events','','show');
	document.getElementById("tabpress").className='pressoff';
	document.getElementById("tabevents").className='eventson';
}

/*Popup*/

function openPopup(loc, w, h)

{
window.open(loc,"popup","width=" + w + ",height=" + h + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=5,left=5");
} 

function openPopup2(loc, w, h)

{
window.open(loc,"popup","width=" + w + ",height=" + h + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=5,left=5");
} 

function openNewPopup(loc, nwin, w, h)

{
window.open(loc,nwin,"width=" + w + ",height=" + h + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=5,left=5");
} 

/*Stampa scheda*/
function printCountry(ID)

{
document.getElementById(ID).display='block';
alert(ID);
window.print();
} 

/*Mostra paese*/

function doToggle(ID){    

		if (document.getElementById(ID).style.display!="block"){
			for(var i=1; i<26; i++){
				document.getElementById("country"+i).style.display='none';
			}
			document.getElementById(ID).style.display="block";
		}else{
				document.getElementById(ID).style.display="none";
		}
	}

function doToggle2(ID){    

		if (document.getElementById(ID).style.display!="block"){
			for(var i=1; i<13; i++){
				document.getElementById("boxita"+i).style.display='none';
				document.getElementById("titboxita"+i).className='close';
			}
			document.getElementById(ID).style.display="block";
			document.getElementById("tit"+ID).className='open';
		}else{
				document.getElementById(ID).style.display="none";
				document.getElementById("tit"+ID).className='close';
		}
	}
	
/*Apri e chiudi*/
function openClose(ID) {
var el = document.getElementById(ID);
var display = el.style.display;
el.style.display = (display == "block") ? "none" : "block";
	if (el.style.display == "block"){
		document.getElementById(ID+ "tit").className= "open";
	}else{
		document.getElementById(ID+ "tit").className= "";
	}
}

function openCloseAuto(prefix,amount,toopen) {
for(var n=1; n<=amount; n++){
var el = document.getElementById(prefix+n);
var display = el.style.display;

if( (display == "none" || display == "") && el.id == prefix+toopen){  
el.style.display = "block";
document.getElementById(prefix+n+ "tit").className= "open";
}else{
el.style.display = "none";	
document.getElementById(prefix+n+ "tit").className= "";
}

}
}

// Validazione e-mail

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
					    alert("E-mail address is not valid")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  		    alert("E-mail address is not valid")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   		    alert("E-mail address is not valid")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   		    alert("E-mail address is not valid")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    		    alert("E-mail address is not valid")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("E-mail address is not valid")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("E-mail address is not valid")
		    return false
		 }

 		 return true					
	}

function controlla_mail(form){

var errori = false

var emailID=form.email

if ((emailID.value==null)||(emailID.value=="")){
  alert("Please fill in your email address")
  emailID.focus()
  errori = true 
 }else if (echeck(emailID.value)==false){
  emailID.value=""
  emailID.focus()
 errori = true
 }
 
if(errori == true){
return false
}else{
form.submit()
}

}

function controlla(form){
var errori = false

var emailID=form.email

if ((emailID.value==null)||(emailID.value=="")){
  alert("Please fill in your email address")
  emailID.focus()
  errori = true 
 }else if (echeck(emailID.value)==false){
  emailID.value=""
  emailID.focus()
 errori = true
 }
 
 var paeseID=form.paese
 
 if ((paeseID.value=="---") || paeseID.value == ""){
  alert("Please fill in your country")
  paeseID.focus()
  errori = true
 }

if(errori == true){
return false
}else{
form.submit()
}

}


// --- legge l'eventuale parametro country passato in querystring alla pagina
// --- e lo utilizza per accendere il livello di quel country
function contactOnload() {
	hrefString=self.location.href;
	posuguale=hrefString.indexOf('=');
	if (posuguale != -1) {
		posfinale = hrefString.length;
		countryStr = hrefString.substring(posuguale+1,posfinale);
		countryNumber = parseInt(countryStr);
		doToggle('country'+countryNumber);
	}
}