// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var DOM=document.getElementById?true:false;
var IE =window.navigator.appName.indexOf('Microsoft')==-1?false:true;

function OpenLink(url,w,h)
{
    var caratteristiche;
    caratteristiche="height="+h+", width="+w+", ";
    caratteristiche+="resizable=yes, location=no, menubar=no, scrollbars=yes, status=no, toolbar=no";
    window.open(url,'',caratteristiche);
    return false;
}

function check() {
    if (setNotice("user_company_name","company_name")) return false;
    if (setNotice("user_name","name")) return false;
    if (setNotice("user_surname","surname")) return false;
	if (setNotice("user_fiscal_code","fiscal_code")) return false;
	var mail = document.getElementById("user_mail");
    if (mail) {
        text = document.getElementById("mail");
        if(text.value == "") {            
            if (text) text.style.color = '#F00';
			showErrorMessage();
            return false;
        } else { 
            if (text) {
                text.style.color = '#222'; 
                var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
                if (!espressione.test(mail.value)) {
                    text.style.color = '#F00';
                    return false;
                    alert("Mail errata\nMail wrong!");
                }                
            }            
        }
    }
	if (setNotice("user_telephone","telephone")) return false;
	if (setNotice("user_vat","vat")) return false;
    if (setNotice("user_address","address")) return false;
    if (setNotice("user_city","city")) return false;
	if (setNotice("user_zip","zip")) return false;
    if (setNotice("user_country","country")) return false;
    if (setNoticeAccept("accept","accept")) return false;
    return true;
}

function setNotice(element,id) {
    var tag = document.getElementById(element);
    if (tag) {
        text = document.getElementById(id);					
        if(tag.value == "") {            
            if (text) text.style.color = '#F00';
			showErrorMessage();
            return true;
        } else { 
            if (text) text.style.color = '#222';
        }
    }
    return false;
}
function setNoticeNum(element,id) {
    var tag = document.getElementById(element);
    if (tag) {
        text = document.getElementById(id);
        if(tag.value == "") {            
            if (text) text.style.color = '#F00';
			showErrorMessage();
            return true;
        } else { 
            if (text) {
                text.style.color = '#222';
                if(isNaN(tag.value) || parseInt(tag.value)<0) {
                    text.style.color = '#F00';
                    alert("Deve essere numerico\nMust be numeric!");
                    return true;                    
                }
            }                
        }
    }  
    return false
}

function setNoticeAccept(element,id) {
    var tag = document.getElementById(element);
    if (tag) {
        text = document.getElementById(id);
        if(!tag.checked){
            text.style.color = '#F00';
            alert('devi accettare la condivisione dati');
            return true;
        }
    }
    return false
}

function check_choiche_1(){
  var fisso     = document.getElementById('fisso');
  var on_demand = document.getElementById('on_demand');
  if (fisso && on_demand){
    text = document.getElementById('choiche_1');
    if(!fisso.checked && !on_demand.checked){
      text.style.color = '#F00';
      alert('devi scegliere fisso, on demand o entrambi');
      return true;
    }
  }
  return false;
}

function check_choiche_2(){
  var euro     = document.getElementById('euro');
  var dollari  = document.getElementById('dollari');
  if (euro && dollari){
    text = document.getElementById('choiche_2');
    if(!euro.checked && !dollari.checked){
      text.style.color = '#F00';
      alert('devi scegliere euro, dollari o entrambi');
      return true;
    }
  }
  return false;
}

function checkJVM() {
    JVM = navigator.javaEnabled();
    alert("Per visualizzare il grafico è' necessario la <a href=\"http://http://www.java.com/it/download/index.jsp\">Java Virtual Machine</>");
}

function check_request(){
    if (setNotice("info_company_name","company_name"))return false;
    if (setNotice("info_name","name"))return false;
    if (setNotice("info_surname","surname"))return false;
    if (setNotice("info_address","address"))return false;
    if (setNotice("info_zip","zip"))return false;
    if (setNotice("info_city","city"))return false;
    if (setNotice("info_country","country"))return false;
    if (setNotice("info_state","state"))return false;
    var mail = document.getElementById("info_mail");
    if (mail) {
        text = document.getElementById("mail");
        if(text.value == "") {
            if (text) text.style.color = '#F00';
            return false;
        } else {
            if (text) {
                text.style.color = '#222';
                var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
                if (!espressione.test(mail.value)) {
                    text.style.color = '#F00';
                    return false;
                    alert("Mail errata\nMail wrong!");
                }
            }
        }
    }
    if (setNotice("info_telephone","telephone"))return false;
    return true;
}

function check_sms(){
  if(setNotice("sms_user_company_name","company_name"))return false;
  if(setNotice("sms_user_name","name"))return false;
  if(setNotice("sms_user_surname","surname"))return false;
  if(setNotice("sms_user_address","address"))return false;
  if(setNotice("sms_user_zip","zip"))return false;
  if(setNotice("sms_user_city","city"))return false;
  if(setNotice("sms_user_country","country"))return false;
  if(setNotice("sms_user_vat","vat")) return false;
  if(setNotice("sms_user_fiscal_code","fiscal_code")) return false;
  var mail = document.getElementById("sms_user_mail");
  if (mail) {
    text = document.getElementById("mail");
     if(text.value == "") {
      if (text) text.style.color = '#F00';
        return false;
      } else {
        if (text) {
          text.style.color = '#222';
          var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
          if (!espressione.test(mail.value)) {
            text.style.color = '#F00';
            return false;
            alert("Mail errata\nMail wrong!");
          }
        }
      }
  }
  if (setNotice("sms_user_telephone","telephone")) return false;
  if (setNotice("sms_request_cellphone","cellphone")) return false;
  if (check_choiche_1()) return false;
  if (check_choiche_2()) return false;
  if (setNoticeAccept("accept","accept")) return false;  
  return true;
}

function check_wpm(){
    if(setNotice("wmp_company_name","company_name"))return false;
    if(setNotice("wmp_name","name"))return false;
    if(setNotice("wmp_surname","surname"))return false;
    if(setNotice("wmp_position","position"))return false;
    if(setNotice("wmp_telephone","telephone"))return false;
    var mail = document.getElementById("wmp_email");
    if (mail) {
        text = document.getElementById("email");
        if(text.value == "") {
            if (text) text.style.color = '#F00';
            return false;
        } else {
            if (text) {
                text.style.color = '#222';
                var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
                if (!espressione.test(mail.value)) {
                    text.style.color = '#F00';
                    return false;
                    alert("Mail errata\nMail wrong!");
                }
            }
        }
  }
  return true;
}

function showErrorMessage(){
	var tag = document.getElementById("errorMessage");
	if(tag)
		tag.style.display = "block";
}

function open_eur(){
    var dollar = document.getElementById('quotation-usd');
	dollar.style.display='none';
    var euro = document.getElementById('quotation-eur');
	euro.style.display='block';
	
	var radio1 = document.getElementById('radio-six');
	radio1.checked = "checked";
	var radio2 = document.getElementById('radio-eight');
	radio2.checked = "checked";
}
function open_usd(){
    var dollar = document.getElementById('quotation-usd');
	dollar.style.display='block';
    var euro = document.getElementById('quotation-eur');
	euro.style.display='none';
	
	var radio1 = document.getElementById('radio-one');
	radio1.checked = "checked";
	var radio2 = document.getElementById('radio-three');
	radio2.checked = "checked";
}
