
//indirizzo sito
var sito = window.location.href ;
//sito
sito = sito.replace("http://",""); 
//ottengo strLivello
var arySito = sito.split(".");
var strLivello= arySito[0].toLowerCase();;

//in base al livello agisco in lingua
switch( strLivello )
	{
		case "www": //italiano

		  root  = "http://www.vertigomusic.it"
		  
		  eti01 = "E' necessario inserire un indirizzo e-mail !"
		  eti02 = "Indirizzo e-mail non valido!"
		  eti03 = "Inserisci un nominativo"
		  eti04 = "Inserisci le informazioni"
		  eti05 = "Contattaci"
		  
		  break;
		  
		case "en":  //inglese
		
		  root  = "http://en.vertigomusic.it"
		  
		  eti01 =  "You must enter an e-mail!";
		  eti02 =  "Wrong e-mail!"
		  eti03 =  "Enter a name"
		  eti04 =  "Enter information"
		  eti05 =  "Contact Us"
		  
		  break;
	}
	
//xmlhttpPost
function xmlhttpPost(strURL,formname,responsediv,responsemsg) {
    var xmlHttpReq = false;
    var self = this;
    // Xhr per Mozilla/Safari/Ie7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // per tutte le altre versioni di IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			// Quando pronta, visualizzo la risposta del form
            updatepage(self.xmlHttpReq.responseText,responsediv);
        }
		else{
			// In attesa della risposta del form visualizzo il msg di attesa
			updatepage(responsemsg,responsediv);

		}
    }
    self.xmlHttpReq.send(getquerystring(formname));
}

function getquerystring(formname) {
    var form = document.forms[formname];
	var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }
	
	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "IMAGE"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}

function updatepage(str,responsediv){
    document.getElementById(responsediv).innerHTML = str;
}


//form newsletter
function newsletter_submit(){ 
	if (document.getElementById('ute_email').value ==  "")
	{ 
		alert( eti01 );
		document.getElementById('ute_email').focus()
		return ;
	}
	
	var emailadd = document.getElementById('ute_email').value;
	if (emailadd.indexOf('@', 0) == -1 || emailadd.indexOf('.', 0) == -1)
	 { 
			alert(  eti02 );
			document.getElementById('ute_email').focus();
			return ;
	  }
	  
	xmlhttpPost( root + '/subsave.asp', 'form_newsletter', 'newsletter', '<p class="title_ns">Newsletter</p><p class=loading><img src='+root+'/img/loading.gif lign=middle> loading</p>'); 
	return ;

}



//form contatto
function contact_submit(){ 

	if (document.getElementById('cnt_nome').value ==  "")
	{ 
		alert( eti03 );
		document.getElementById('cnt_nome').focus()
		return ;
	}

	if (document.getElementById('cnt_mail').value ==  "")
	{ 
		alert( eti01 );
		document.getElementById('cnt_mail').focus()
		return ;
	}
	
	var emailadd = document.getElementById('cnt_mail').value;
	if (emailadd.indexOf('@', 0) == -1 || emailadd.indexOf('.', 0) == -1)
	 { 
			alert(  eti02 );
			document.getElementById('cnt_mail').focus();
			return ;
	  }
	  

	if (document.getElementById('cnt_info').value ==  "")
	{ 
		alert( eti04 );
		document.getElementById('cnt_info').focus()
		return ;
	}
    
	xmlhttpPost( root + '/subsave.asp', 'form_contact', 'contattaci', '<p class="title_cnt">' + eti05 + '</p><p class=loading ><img src='+root+'/img/loading.gif align=middle> loading</p>'); 
	
	return ;

}



//condividi su twitter
function shareTw(){
	  var u;
	  var t;
	  var url4Share;
	  u=self.location.href;
	  t=document.title;
	  u=encodeURIComponent(u);
	  t=encodeURIComponent(t);
	  url4Share="http://twitter.com/share?url="+u+"&text="+t
	  window.open( url4Share );

}
