var popUpWin=0;
var disappeardelay=250;  //menu disappear delay
var enableanchorlink=0; //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1; //hide menu when user clicks within menu? (1=yes, 0=no)
var ie5=document.all;
var ns6=document.getElementById&&!document.all;
var width = 620;
var height = 640;
var left = (window.screen.width - width) / 2;
var top = 0;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validateEmail(theForm){
	if(theForm.address.value.length > 4 && theForm.address.value.indexOf('@', 0) > 0 && theForm.address.value.indexOf('.', 0) > 0){
		theForm.submit();
	}else{
		alert('Per favore inserisci un indirizzo email valido.');
		theForm.address.focus();
		theForm.address.select();		
		return false;
	}			
}

function GetThis(T, C, U, L)
{
    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)
    + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    window.open(targetUrl);
}

function showSideContents(cid){
	document.getElementById('main_content').style.visibility='hidden';
	document.getElementById('main_content').style.display='none';

	document.getElementById('catdet_'+cid).style.visibility='visible';
	document.getElementById('catdet_'+cid).style.display='block';
}
function hideSideContents(cid){
	document.getElementById('main_content').style.visibility='visible';
	document.getElementById('main_content').style.display='block';

	document.getElementById('catdet_'+cid).style.visibility='hidden';
	document.getElementById('catdet_'+cid).style.display='none';
}

function sendFeedback(){
	var theForm = document.service_form;
	theForm.field1.value = 'sendEmail';
	theForm.action = 'client_feedback.php?hd=client';
	theForm.submit();
}
function validate_form(){
	var theForm = document.service_form;

	if(theForm.email_firstname.value.length < 1){
		alert('Per favore specifica il tuo nome.');
		theForm.email_firstname.focus();
		theForm.email_firstname.select();		
		return false;
	}	
	if(theForm.email_lastname.value.length < 1){
		alert('Per favore specifica il tuo cognome.');
		theForm.email_lastname.focus();
		theForm.email_lastname.select();		
		return false;
	}

	if(theForm.email_town.value.length < 1){
		alert('Per favore specifica la tua città.');
		theForm.email_town.focus();
		theForm.email_town.select();		
		return false;
	}

	if(theForm.email_country.options[theForm.email_country.selectedIndex].value == '--'){
		alert('Per favore specifica il tuo paese.');
		theForm.email_country.focus();
		return false;
	}

	if(theForm.email_email.value.length > 4 && theForm.email_email.value.indexOf('@', 0) > 0 && theForm.email_email.value.indexOf('.', 0) > 0){
	}else{
		alert('Per favore specifica un indirizzo email valido.');
		theForm.email_email.focus();
		theForm.email_email.select();		
		return false;
	}

	if(theForm.email_enquirytype.options[theForm.email_enquirytype.selectedIndex].value == '--'){
		alert('Per favore specifica la tipologia della richiesta.');
		theForm.email_enquirytype.focus();
		return false;
	}

	theForm.field1.value = 'sendEmail';
	theForm.action = 'contact.php?hd=contact';
	theForm.submit();
}
function popUpWindow(URLStr, left, top, width, height){
	var screenleft = (window.screen.width/2)-(width/2);
	var screentop = 0;
	if(popUpWin){
    	if(!popUpWin.closed) popUpWin.close();
  	}
  	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+screenleft+', top='+screentop+'');
}

function launchDetailsWindow($orderid){	
	popUpWindow('client_order_details.php?oid=' + $orderid, 0, 0, 650, 600);
}

function updateCustomerDetails(server_url){
	var theForm = document.service_form;

	if(theForm.det_firstname.value.length < 3){
		alert('Per favore specifica per lo meno 3 caratteri per il tuo nome.');
		theForm.det_firstname.focus();
		theForm.det_firstname.select();		
		return false;
	}	
	if(theForm.det_lastname.value.length < 1){
		alert('Per favore specifica per lo meno 2 caratteri per il tuo cognome.');
		theForm.det_lastname.focus();
		theForm.det_lastname.select();		
		return false;
	}
	if(theForm.det_address1.value.length < 3){
		alert('Per favore specifica il tuo indirizzo.');
		theForm.det_address1.focus();
		theForm.det_address1.select();		
		return false;
	}
	if(theForm.det_county.value.length < 1){
		alert('Per favore specifica la tua provincia.');
		theForm.det_county.focus();
		theForm.det_county.select();		
		return false;
	}
	if(theForm.det_town.value.length < 1){
		alert('Per favore specifica la tua città.');
		theForm.det_town.focus();
		theForm.det_town.select();		
		return false;
	}
	if(theForm.det_postcode.value.length < 4){
		alert('Per favore specifica il tuo CAP.');
		theForm.det_postcode.focus();
		theForm.det_postcode.select();		
		return false;
	}
	if(theForm.det_country.options[theForm.det_country.selectedIndex].value == '--'){
		alert('Per favore specifica il tuo paese.');
		theForm.det_country.focus();
		return false;
	}

	if(theForm.det_telephone.value.length < 8){
		alert('Per favore specifica il tuo numero di telefono.');
		theForm.det_telephone.focus();
		theForm.det_telephone.select();		
		return false;
	}

	if(theForm.det_email.value.length > 4 && theForm.det_email.value.indexOf('@', 0) > 0 && theForm.det_email.value.indexOf('.', 0) > 0){
	}else{
		alert('Per favore specifica un indirizzo email valido.');
		theForm.det_email.focus();
		theForm.det_email.select();		
		return false;
	}

	if(theForm.det_password.value.length < 6){
		alert('Per favore specifica una password di almeno 6 caratteri.');
		theForm.det_password.focus();
		theForm.det_password.select();		
		return false;
	}

	if(theForm.det_confirm.value.length < 6){
		alert('Per favore specifica una password di conferma di almeno 6 caratteri.');
		theForm.det_confirm.focus();
		theForm.det_confirm.select();		
		return false;
	}else{
		if(theForm.det_confirm.value == theForm.det_password.value){
			
		}else{
			alert('La password e la conferma non hanno lo stesso valore.');
			theForm.det_confirm.focus();
			theForm.det_confirm.select();			
			return false;
		}
	}
	theForm.field1.value = 'update';
	theForm.action = 'client_summary.php?hd=client';
	theForm.submit();
}

function emailPsw(server_url){
	var theForm = document.service_form;
	if(theForm.emailpsw.value.length > 4 && theForm.emailpsw.value.indexOf('@', 0) > 0 && theForm.emailpsw.value.indexOf('.', 0) > 0){
		theForm.field1.value = 'email_password';
		theForm.action = server_url+'ita/checkout.php?hd=details';
		theForm.submit();		
	}else{
		alert('Per favore specifica un indirizzo email valido.');
		theForm.emailpsw.focus();
		theForm.emailpsw.select();
		return false;
	}
}
function login_client(server_url){
	var theForm = document.service_form;
	if(theForm.login_email.value.length > 4 && theForm.login_email.value.indexOf('@', 0) > 0 && theForm.login_email.value.indexOf('.', 0) > 0){
	}else{
		alert('Per favore specifica un indirizzo email valido.');
		return false;
	}

	if(theForm.login_password.value.length < 6){
		alert('Per favore specifica una password di almeno 6 caratteri.');
		return false;
	}	
	theForm.action = server_url+'ita/client_login.php?hd=client';
	theForm.submit();	
}

function goToPaypal(var_checkout){
      scroll(0,0);
      var outerPane = document.getElementById('FreezePane');
      var innerPane = document.getElementById('InnerFreezePane');
      if (outerPane) outerPane.className = 'FreezePaneOn';
      if (innerPane) innerPane.innerHTML = 'Attendi mentre ti trasferiamo al sito <p style=\"font-size:30px;\">Paypal&trade; </h1><p align=\"center\"><img src=\"images/external/loadinfo.net.gif\" width=\"48\" height=\"48\" alt=\"Attendi mentre loading ...\"></p>';

	var theForm = document.service_form;
	//alert('Upon clicking the [OK] button, you will be redirected to the Chiwit Design - Paypal Secure Checkout Form.\nPlease allow a few seconds for the Secure Paypal web page to appear.'); //\nPlease note that our secure certificate is provided by the Organization 3ix.org\nCommon Name jade.host-care.com.');
	//alert('Due to delivery restructuring, our online secure payment is temporarily off-line.\nWe will be opening Paypal Checkout again August 29 2008. Sorry for the inconvenience.\nEmail to team@chiwitdesign.com for further information or enquiries.');
	//return false;
	theForm.action = var_checkout;
	theForm.submit();
}
function goToSummary(server_url){
	var theForm = document.service_form;

	if(theForm.ship_firstname.value.length < 3){
		alert('Per favore specifica per lo meno 3 caratteri per il nome.');
		theForm.ship_firstname.focus();
		theForm.ship_firstname.select();
		return false;
	}	
	if(theForm.ship_lastname.value.length < 1){
		alert('Per favore specifica per lo meno 2 caratteri per il cognome.');
		theForm.ship_lastname.focus();
		theForm.ship_lastname.select();
		return false;
	}
	if(theForm.ship_address1.value.length < 3){
		alert("Per favore specifica un indirizzo per la spedizione.");
		theForm.ship_address1.focus();
		theForm.ship_address1.select();
		return false;
	}
	if(theForm.ship_county.value.length <1 ){
		alert('Per favore specifica la provincia.');
		theForm.ship_county.focus();
		theForm.ship_county.select();		
		return false;
	}
	if(theForm.ship_town.value.length < 1){
		alert('Per favore specifica la città.');
		theForm.ship_town.focus();
		theForm.ship_town.select();		
		return false;
	}
	if(theForm.ship_postcode.value.length < 4){
		alert('Per favore specifica il CAP.');
		theForm.ship_postcode.focus();
		theForm.ship_postcode.select();		
		return false;
	}
	theForm.field1.value = 'update';
	theForm.action = server_url+'ita/checkout_delivery.php?hd=delivery';
	theForm.submit();
}
function goToDelivery(server_url){
	var theForm = document.service_form;

	if(theForm.det_firstname.value.length < 3){
		alert('Per favore specifica per lo meno 3 caratteri per il tuo nome.');
		theForm.det_firstname.focus();
		theForm.det_firstname.select();		
		return false;
	}	
	if(theForm.det_lastname.value.length < 1){
		alert('Per favore specifica per lo meno 2 caratteri per il tuo cognome.');
		theForm.det_lastname.focus();
		theForm.det_lastname.select();		
		return false;
	}
	if(theForm.det_address1.value.length < 3){
		alert('Per favore specifica il tuo indirizzo.');
		theForm.det_address1.focus();
		theForm.det_address1.select();		
		return false;
	}
	if(theForm.det_county.value.length < 2){
		alert('Per favore specifica la tua provincia.');
		theForm.det_county.focus();
		theForm.det_county.select();		
		return false;
	}
	if(theForm.det_town.value.length < 1){
		alert('Per favore specifica la tua città');
		theForm.det_town.focus();
		theForm.det_town.select();		
		return false;
	}
	if(theForm.det_postcode.value.length < 4){
		alert('Per favore specifica il tuo CAP.');
		theForm.det_postcode.focus();
		theForm.det_postcode.select();		
		return false;
	}
	if(theForm.det_country.options[theForm.det_country.selectedIndex].value == '--'){
		alert('Per favore specifica il tuo paese.');
		theForm.det_country.focus();
		return false;
	}

	if(theForm.det_telephone.value.length < 8){
		alert('Per favore specifica il tuo numero di telefono.');
		theForm.det_telephone.focus();
		theForm.det_telephone.select();		
		return false;
	}

	if(theForm.det_email.value.length > 4 && theForm.det_email.value.indexOf('@', 0) > 0 && theForm.det_email.value.indexOf('.', 0) > 0){
	}else{
		alert('Per favore specifica un indirizzo email valido.');
		theForm.det_email.focus();
		theForm.det_email.select();		
		return false;
	}

	if(theForm.det_password.value.length < 6){
		alert('Per favore specifica per lo meno 6 caratteri per la tua password.');
		theForm.det_password.focus();
		theForm.det_password.select();		
		return false;
	}

	if(theForm.det_confirm.value.length < 6){
		alert('La password di conferma ha meno di 6 caratteri.');
		theForm.det_confirm.focus();
		theForm.det_confirm.select();		
		return false;
	}else{
		if(theForm.det_confirm.value == theForm.det_password.value){
			
		}else{
			alert('La password e la conferma non contengono lo stesso valore.');
			theForm.det_confirm.focus();
			theForm.det_confirm.select();			
			return false;
		}
	}
	theForm.field1.value = 'update';
	theForm.action = server_url+'ita/checkout.php?hd=details';
	theForm.submit();
}

function goToCheckout(server_url){
	var deliveryMethod = document.service_form.delivery;
	var selectedMethod = deliveryMethod.options[deliveryMethod.selectedIndex].value;
	var country = document.service_form.country;
	var selectedCountry = country.options[country.selectedIndex].value;
	if(selectedMethod.length > 0 && selectedMethod > 0){
		if(selectedCountry.length > 1){
			document.location.href=server_url+'ita/checkout.php?hd=details';
		}else{
			alert('Per favore scegli un paese di destinazione per il tuo ordine.');
			document.service_form.country.focus();
		}
	}else{
		alert('Per favore scegli un metodo di spedizione per il tuo ordine.');
		document.service_form.delivery.focus();
	}
}
function login(server_url){
	var theForm = document.service_form;
	if(theForm.loginemail.value.length > 4 && theForm.loginemail.value.indexOf('@', 0) > 0 && theForm.loginemail.value.indexOf('.', 0) > 0){
		if(theForm.loginpsw.value.length == 6){
			theForm.field1.value = 'login';
			theForm.action = server_url+'ita/checkout.php?hd=details';
			theForm.submit();
		}else{
			alert('La password deve essere per lo meno 6 caratteri.');
			theForm.loginpsw.focus();
			theForm.loginpsw.select();			
		}
	}else{
		theForm.loginemail.value = 'Indirizzo email invalido';
	}
}
function clearBasket(){
	if(!confirm('Stai per svuotare il contenuto del carrello acquisti.\nOK per confermare o CANCEL per continuare.')){
	return false;
	}
}

function addCode(strCode,strScript){
	if(strCode.length > 0){
		if(!confirm('Hai inserito il codice \'' + strCode.toUpperCase() + '\'.\nControlla bene prima di schiacciare OK o clicca su CANCEL per modificarlo.\nSolo un codice può essere accettato.\n')){
			return false;
		}else{
			document.service_form.field1.value = strCode.toUpperCase();
			document.service_form.action = strScript + '?hd=orderlist&action=6';
			document.service_form.submit();
			return false;
		}
	}else{
		alert('Hai un codice sconto?\nInseriscilo al lato e clicca sul bottone (+).');
		document.service_form.promo.style.backgroundColor = '#D7E300';
		return false;
	}
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden){
	if (ie5||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
	var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
	dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}else{
	var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
	var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
		if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
			edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}

function showmenu(obj, e, dropmenuID){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
var browserName=navigator.appName; 
if (browserName=="Microsoft Internet Explorer")
{
	dropmenuobj.x=getposOffset(obj, "left");
}else{
	dropmenuobj.x=getposOffset(obj, "left") + 1;
}
dropmenuobj.y=getposOffset(obj, "top");
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
