// JavaScript Document
var s=navigator.userAgent.toLowerCase();
var isIE8 = s.indexOf("msie 8.0")>0
var isIE7 = s.indexOf("msie 7.0")>0
var isIE6 = (s.indexOf("msie 6.0")>0) && (!isIE8) && (!isIE7)
var isIE = s.indexOf("msie")>0

function openWindow(pagina, x, y, bar){
	window.open(pagina,'','scrollbars='+bar+',screenX=150,screenY=50,left=0,top=0,resizable=0,menubar=0,toolbar=0,status=0,width='+x+',height='+y);
}
function setColor(color, hex){
	if(color != ""){
		$("colore_sel").value = "Colore selezionato: "+color;
		$("colore").value = hex
	}
}

function checkProdotto(col, tag){
	if(col>0){
		if($("colore").value == ""){
			alert("Selezionare il colore desiderato");
			return false
		}
	}
	if(tag>0){
		if($("taglia").value == ""){
			alert("Selezionare la taglia desiderata");
			$("taglia").focus();
			return false
		}
	}
	
	addItem('frm_prodotto', 'add_carrello.asp');
} 

function checkReg(f){
	if(f.nome.value == ""){
		alert("NOME obbligatorio");
		f.nome.focus();
		return false
	}
	if(f.cognome.value == ""){
		alert("COGNOME obbligatorio");
		f.cognome.focus();
		return false
	}	
	if(f.indirizzo.value == ""){
		alert("INDIRIZZO obbligatorio");
		f.indirizzo.focus();
		return false
	}
	if(f.provincia.value == "--"){
		alert("PROVINCIA obbligatoria");
		f.provincia.focus();
		return false
	}
	if(f.comune.value == "--"){
		alert("COMUNE obbligatorio");
		f.comune.focus();
		return false
	}
	if(f.cap.value == ""){
		alert("CAP obbligatorio");
		f.cap.focus();
		return false
	}
	if(f.telefono.value == ""){
		alert("TELEFONO obbligatorio");
		f.telefono.focus();
		return false
	}
	if(f.codfisc_piva.value == ""){
		alert("COD.FISC/P.IVA obbligatorio");
		f.codfisc_piva.focus();
		return false
	}
}
function checkSped(f){
	if(f.nome.value == ""){
		alert("NOME obbligatorio");
		f.nome.focus();
		return false
	}
	if(f.cognome.value == ""){
		alert("COGNOME obbligatorio");
		f.cognome.focus();
		return false
	}
	if(f.provincia.value == "--"){
		alert("PROVINCIA obbligatoria");
		f.provincia.focus();
		return false
	}
	if(f.comune.value == "--"){
		alert("COMUNE obbligatorio");
		f.comune.focus();
		return false
	}
	if(f.indirizzo.value == ""){
		alert("INDIRIZZO obbligatorio");
		f.indirizzo.focus();
		return false
	}
	if(f.cap.value == ""){
		alert("CAP obbligatorio");
		f.cap.focus();
		return false
	}
}

function checkContatti(f){
	if(f.nome.value == ""){
		alert("NOME obbligatorio");
		f.nome.focus();
		return false
	}
	if(f.cognome.value == ""){
		alert("COGNOME obbligatorio");
		f.cognome.focus();
		return false
	}
	Ctrl = f.email;
	result = false;
	space_tokens = Ctrl.value.split(" ");
	if(space_tokens.length == 1){
		at_tokens = Ctrl.value.split("@");
		if(at_tokens.length == 2)
		{
			if(at_tokens[1].length != 0)
			{
				right_dot_tokens = at_tokens[1].split(".");
				if(right_dot_tokens.length >= 2)
				{
					if (right_dot_tokens[1].length != 0)
					{
						result=true;
					}
				}
			}
		}
	}

	if (!result){
		errorString = "Inserisci un'indirizzo E-MAIL valido";
		alert(errorString);
		Ctrl.focus();
		return (result);
	}
}

function checkInvia(f){
	if(f.nome.value == ""){
		alert("NOME obbligatorio");
		f.nome.focus();
		return false
	}
	
	Ctrl = f.email;
	result = false;
	space_tokens = Ctrl.value.split(" ");
	if(space_tokens.length == 1){
		at_tokens = Ctrl.value.split("@");
		if(at_tokens.length == 2)
		{
			if(at_tokens[1].length != 0)
			{
				right_dot_tokens = at_tokens[1].split(".");
				if(right_dot_tokens.length >= 2)
				{
					if (right_dot_tokens[1].length != 0)
					{
						result=true;
					}
				}
			}
		}
	}

	if (!result){
		errorString = "Inserisci un'indirizzo E-MAIL valido";
		alert(errorString);
		Ctrl.focus();
		return (result);
	}
	f.action="inviaamico_submit.asp"
	f.submit()
}
function addItem(f, page){
	$(f).action = page;
	$(f).submit();
}

function Ajax_LoadSubSelect(ajax_page, targetSelect, selectedValue, pars) {
  	var url = ajax_page
	var obj = $(targetSelect);
	var pars = pars
		
	var myAjax = new Ajax.Request (
		url, 
		{
			method: "post", 
			parameters: pars,
			onComplete: function showResponse(originalRequest){
				//put returned XML in the textarea
				var resp = originalRequest.responseText;
				
				obj.options.length = 0;
				if(resp != ""){
					var arrOptions = resp.split(";");
					for(i = 0; i < arrOptions.length; i++){
						if(arrOptions[i] != ""){
							var arrId = arrOptions[i].split("|");
							if(arrId[0] == selectedValue){
								obj.options[obj.options.length] = 
								new Option(arrId[1], arrId[0], false, true);
							} else {
								obj.options[obj.options.length] = 
								new Option(arrId[1], arrId[0]);
							}
						}
					}
				}
			}
		});
} 

function verificaForm(frm) {
	if(frm.name=="frm_login"){
		if(frm.userid.value ==""){
			errorString = "Nome Utente OBBLIGATORIO";
			alert(errorString);
			frm.userid.focus();
			return false;	
		}
		if(frm.password.value ==""){
			errorString = "Password OBBLIGATORIA";
			alert(errorString);
			frm.password.focus();
			return false;	
		}
	} else if (frm.name=="frm_mod_profilo"){
		if(frm.password.value != ""){
			if(frm.new_pass.value == ""){
				alert("Indicare la nuova password");
				frm.new_pass.focus();
				return false;
			}
			else if(frm.new_pass2.value == ""){
				alert("Riscrivere la nuova password");
				frm.new_pass2.focus();
				return false;
			} 
			else if(frm.new_pass2.value != frm.new_pass.value){
				alert("Le nuove password non coincidono. Scrivere la stessa password nei campi appositi.");
				frm.new_pass.value = ""
				frm.new_pass2.value = ""
				frm.new_pass.focus();
				return false;
			}
		}	
	} else if(frm.name=="frm_registra"){
		if(frm.utente.value ==""){
			errorString = "Nome Utente OBBLIGATORIO";
			alert(errorString);
			frm.utente.focus();
			return false;	
		}
		Ctrl = frm.email;
		result = false;
		space_tokens = Ctrl.value.split(" ");
		if(space_tokens.length == 1){
			at_tokens = Ctrl.value.split("@");
			if(at_tokens.length == 2)
			{
				if(at_tokens[1].length != 0)
				{
					right_dot_tokens = at_tokens[1].split(".");
					if(right_dot_tokens.length >= 2)
					{
						if (right_dot_tokens[1].length != 0)
						{
							result=true;
						}
					}
				}
			}
		}
	
		if (!result){
			errorString = "Inserisci un'indirizzo E-MAIL valido";
			alert(errorString);
			Ctrl.focus();
			return (result);
		}
		
		if (frm.email.value != frm.email2.value){
			errorString = "Le email indicate non coincidono";
			alert(errorString);
			frm.email2.focus();
			return false;
		}
	}
}

function ShowCat(div, pulsante, action) {		
	var index_pulsante = $(pulsante).id.indexOf("closed")

	if (index_pulsante != -1){
		$(pulsante).id = $(pulsante).id.substr(0, index_pulsante) + "open";
		new Effect.BlindDown(div, {duration:0.7});
	} else {
		$(pulsante).id = $(pulsante).id.substr(0, $(pulsante).id.indexOf("open")) + "closed";
		new Effect.BlindUp(div, {duration:0.7});
	}
} 


function inoltra(f, msg, pagina){
	if(confirm(msg)){
		f.action = pagina;
		f.submit();
	}
}
