function crea_http_req() {
	var req = false;
	if (window.XMLHttpRequest){
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject){
	  req=new ActiveXObject("Microsoft.XMLHTTP")
	}
	 return req;
}

function svuota_div(obj) {
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function clearDIV(obj) {
  obj.style.visibility="hidden";
  obj.style.display="none";
}

function rimuovi_div(master,ele){
  document.getElementById(master).removeChild(document.getElementById(ele));
}

function hide(div) {
    setTimeout(function(){clearDIV(document.getElementById(div))},5000);
}

function nascondi() {
    setTimeout(function(){pulisciDIV(document.getElementById("login_avviso"))},3000);
}

function pulisciDIV(obj) {
  var nObj="";
	nObj = obj.cloneNode(false);
	obj.parentNode.insertBefore(nObj,obj);
	obj.parentNode.removeChild(obj);
}
  
function svuota_errore(obj){
	var nObj =obj.cloneNode(false);
	obj.parentNode.insertBefore(nObj,obj);
	obj.parentNode.removeChild(obj);
}

function check_register(modulo){
  var required_fields=new Array("contact_title","contact_first_name","contact_last_name","contact_address1","contact_city","contact_postcode","contact_country","contact_phone","contact_email","contact_email2","security_password","security_password2","security_question","security_answer");
  var required_name_fields=new Array("enter a title","enter a first name","enter a last name","enter an address","enter a town","enter a postcode","enter a country","enter a phone number","enter an email address","confirm an email address","enter your password","confirm your password","choose a security question","enter a security answer");
  var error=0;
  var frase="";
  if(!document.getElementById(modulo).contact_privacy.checked){
    frase="Please ensure the Terms and Conditions field is checked.";
    error++;
  }
  if(document.getElementById("contact_email").value!=document.getElementById("contact_email2").value){
    frase="Error. Two different email addresses have been inserted in your submission.";
    error++;
  }
  
  if(document.getElementById("security_password").value!=document.getElementById("security_password2").value){
    frase="Error. Two different passwords have been inserted in your submission."
    error++;
  }
  
  for(var a=required_fields.length-1;a>=0;a--){
    if(document.getElementById(required_fields[a]).value.length<1){
      document.getElementById(required_fields[a]).style.border="solid 2px #F47611";
      error++;
      frase="Please "+required_name_fields[a];
    }
  }
  
  if(error>0){
    svuota_errore(document.getElementById("notify"));
    svuota_errore(document.getElementById("notify2"));
    img=document.createElement("img");
    img.setAttribute("src","img/punto_escl.gif");
    img.setAttribute("alt","");
    img.setAttribute("class","punto_esclamativo");
    img2=document.createElement("img");
    img2.setAttribute("src","img/punto_escl.gif");
    img2.setAttribute("alt","");
    img2.setAttribute("class","punto_esclamativo");
    document.getElementById("notify").appendChild(document.createTextNode(frase));
    document.getElementById("notify").appendChild(img);
    document.getElementById("notify").className="notify";
    document.getElementById("notify2").appendChild(document.createTextNode(frase));
    document.getElementById("notify2").appendChild(img2);
    document.getElementById("notify2").className="notify";
    return false;
  } else {
    document.getElementById(modulo).submit();
    document.getElementById("t_checkout").disabled=true;
    return true;
  }
}

function check_profile(modulo){
  var required_fields=new Array("contact_title","contact_first_name","contact_last_name","contact_address1","contact_city","contact_postcode","contact_country","contact_phone","contact_email","contact_phone","security_question","security_answer");
  var error=0;
  for(var a=0;a<required_fields.length;a++){
    if(document.getElementById(required_fields[a]).value.length<1){
      document.getElementById(required_fields[a]).style.border="solid 1px #F47611";
      error++;
    }
  }
  if(document.getElementById("contact_email2").value!="" && (document.getElementById("contact_email").value!=document.getElementById("contact_email2").value)){
    error++;
  }
  if((document.getElementById("security_password").value!="" || document.getElementById("security_password2").value!="") && document.getElementById("security_password").value!=document.getElementById("security_password2").value){
    error++;
  }
  if(error>0){
    svuota_errore(document.getElementById("notify"));
    document.getElementById("notify").appendChild(document.createTextNode("Please ensure all required information is complete. See above for details"));
    document.getElementById("notify").className="notify";
    return false;
  } else {
    document.forms[modulo].submit();
    return true;
  }
}

function check_shipping(modulo){
  var required_fields=new Array("shipping_first_name","shipping_last_name","shipping_address1","shipping_city","shipping_zip","shipping_country");
  var error=0;
  for(var a=0;a<required_fields.length;a++){
    if(document.getElementById(required_fields[a]).value.length<1){
      document.getElementById(required_fields[a]).style.border="solid 1px #F47611";
      error++;
    }
  }
  
  if(error>0){
    svuota_errore(document.getElementById("notify"));
    document.getElementById("notify").appendChild(document.createTextNode("Please ensure all required information is complete. See above for details"));
    document.getElementById("notify").className="notify";
    return false;
  } else {
    document.forms[modulo].submit();
    return true;
  }
}

function openlogin(){
  document.getElementById("log").className="log";
  document.getElementById("openlogin").className="nascondi";
}

function login(){
if(document.getElementById("login_mail").value.length!=0){
    document.getElementById("login_button").disabled=false;
  }
}

function check_ricerca(){
  if(document.getElementById("srch").value.length<2){
  return false;
  }
  return true;
}

function svuota_campi(){
  document.getElementById("shipping_first_name").value="";
  document.getElementById("shipping_last_name").value="";
  document.getElementById("shipping_company").value="";
  document.getElementById("shipping_address1").value="";
  document.getElementById("shipping_address2").value="";
  document.getElementById("shipping_address3").value="";
  document.getElementById("shipping_city").value="";
  document.getElementById("shipping_county").value="";
  document.getElementById("shipping_zip").value="";
  document.getElementById("shipping_country").value="";
  document.getElementById("billing_first_name").value="";
  document.getElementById("billing_last_name").value="";
  document.getElementById("billing_company").value="";
  document.getElementById("billing_address1").value="";
  document.getElementById("billing_address2").value="";
  document.getElementById("billing_address3").value="";
  document.getElementById("billing_zip").value="";
  document.getElementById("billing_city").value="";
  document.getElementById("billing_county").value="";
  document.getElementById("billing_country").value="";
  document.getElementById("samedates").checked=0;
}

function copy_data(){
  document.getElementById("billing_first_name").value=document.getElementById("shipping_first_name").value;
  document.getElementById("billing_last_name").value=document.getElementById("shipping_last_name").value;
  document.getElementById("billing_company").value=document.getElementById("shipping_company").value;
  document.getElementById("billing_address1").value=document.getElementById("shipping_address1").value;
  document.getElementById("billing_address2").value=document.getElementById("shipping_address2").value;
  document.getElementById("billing_address3").value=document.getElementById("shipping_address3").value;
  document.getElementById("billing_zip").value=document.getElementById("shipping_zip").value;
  document.getElementById("billing_city").value=document.getElementById("shipping_city").value;
  document.getElementById("billing_county").value=document.getElementById("shipping_county").value;
  document.getElementById("billing_country").value=document.getElementById("shipping_country").value;
}

