var w = 400;
var h = 250;
var l = Math.floor((screen.width-w)/2);
var t = Math.floor((screen.height-h)/2);


function getParam(paramName)  {
     var query = window.location.search;
     query = query.substring(1);
     var param = '';
     var ss = query.split("&");
     for (i=0; i < ss.length; i++) {
    	 var arr = ss[i].split('=');
         if (arr[0] == paramName){
              param = arr[1];
         }
     }
     return param;
}

function apri(url) {
	window.location = url + window.location.search;
}


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}



function apriFinestra(url, dimO, dimV) {
	window.open(url ,'lottomatica','width=' + dimO + ',height=' + dimV + ',toolbar=yes, location=no,status=yes,menubar=yes,scrollbars=no,resizable=no');
	
	
}


function setForm(){
	var rad_val = "";
	
	for (var i=0; i < document.contattiForm.tipoRichiedente.length; i++)
  {
   if (document.contattiForm.tipoRichiedente[i].checked)
      {
      	rad_val = document.contattiForm.tipoRichiedente[i].value;
      }
  }
  
  
	if (rad_val == "rivenditore"){
		document.contattiForm.oggettoRichiesta.options[document.contattiForm.oggettoRichiesta.options.length]=new Option("Problemi Tecnici","Problemi_tecnici", false, false);
		document.contattiForm.codiceAssistenza.disabled=false;
		
	}else {
		if (rad_val == "altro"){
			document.contattiForm.oggettoRichiesta.options.length=2;
			document.contattiForm.codiceAssistenza.disabled=true;
		}
	}
}

function checkMail(email){
	var ret = true;
	var position = email.indexOf('@');
	if (position > 0){
		email=email.substring(position+1, email.length);
		var pos1 = email.indexOf('.');
		if (pos1 > 1){
			email=email.substring(pos1+1,email.length);
			if ((email.length > 3) || (email.length < 2))
				ret = false;
		} 
		else ret = false; 
	}
		else ret = false;
 		
 	return ret	
}


function controlla(){
	var msg="";
	var msg1="";
	var ret=true;
	
	
	if (document.contattiForm.nome.value == "")
		msg = msg + "Nome\n";
	
	if (document.contattiForm.cognome.value == "")
		msg = msg + "Cognome\n";
	
	if (document.contattiForm.email.value == "")
		msg = msg + "E-Mail\n";
	else { 
		if (!checkMail(document.contattiForm.email.value))
			msg1 = msg1 + "L'indirizzo di e-mail non e' corretto!\n"; 
 	}
 		
	if (document.contattiForm.messaggio.value == "")
		msg1 = msg1 + "Inserire un messaggio\n";
    
    if(document.contattiForm.tipoRichiedente.type != "hidden") {
        for (var i=0; i < document.contattiForm.tipoRichiedente.length; i++) {
            if (document.contattiForm.tipoRichiedente[i].checked){
                rad_val = document.contattiForm.tipoRichiedente[i].value;
            }
        }
    }
    else {
         rad_val = document.contattiForm.tipoRichiedente.value;
    }
    

  	//if (rad_val == "rivenditore"){
		if (document.contattiForm.codiceAssistenza.value == "")
			msg = msg + "Codice Assistenza\n";
		else{
			if(isNaN(document.contattiForm.codiceAssistenza.value) || (document.contattiForm.codiceAssistenza.value < 600000 ) || (document.contattiForm.codiceAssistenza.value > 799999 ) )
				msg1 = msg1 + "il Codice IVR non e' valido\n";
		}
	//}
	
	if((msg != "") || (msg1 != "")){
		ret = false;
		if (msg!="")
			alert("i seguenti campi sono obbligatori:\n"+ msg + msg1);
		else if(msg1!="")
			alert(msg1);
	}
	
	return ret;
}




var lastdom=null; 
var lastris=null;
function showLevel(lyr) {
    if (lastdom) {lastdom.style.display='none'; }
    if (lastris) {
            lastris.style.className='off';  
    }

    var strA = "answer_" + lyr;

    if (document.getElementById(strA)) {
            lastdom=document.getElementById(strA);
            lastdom.style.display='block';  
    }
    var strF = "faq_" + lyr;

    if (document.getElementById(strF)) {
            lastris=document.getElementById(strF);
            lastris.style.className='on';   
    }
}


function apriCerca() {    

            window.open("http://www.puntolis.it/modulo.asp","Cerca", "menubar=no,width=580,height=250,toolbar=no,scrollbars=yes,left=" + l);

            //window.open("/servizi/ricerca_pdv/ricerca_popup.html","Cerca", "menubar=no,width=840,height=630,toolbar=no,scrollbars=no,");

            //window.open("/servizi/ricerca_pdv/ricerca_popup_temp.html","Cerca", "menubar=no,width=840,height=380,toolbar=no,scrollbars=no,");          

}



