/*
function isEmpty(str){return (str.replace(/\s/g,"").length==0)}
function _mail(str){return str.search(/^([\w\.\-])+@(([\w\-]{2,})+\.)+([a-z0-9]{2,})+$/i)!=-1}
function checkForm(frm){
	var freeFieldsName = "nome utente forum#tipo attivita#come ci ha conosciuto altro#nome del provider#sito web esempio#rr tipo azienda#rr citta#rr provincia#rr nome#rr cognome#rr telefono#";
	var chkIVA = false;
	var ivaNCharacter = 0;
	var chkPersonCode = false;
	var chkCAP = false;
	var naz = frm.elements["country"];
	if(naz)
		naz = ( naz.options[naz.selectedIndex].value||"" ).toUpperCase();
	
	var idDitta = frm.elements["userTypeID"];
	if(idDitta){
		idDitta = idDitta.options[idDitta.selectedIndex].value||"";
		switch(naz){
			case "I": case "IT": case "ITA":
				chkIVA = idDitta.charAt(0)=="1";
				ivaNCharacter = 11;
				chkCAP = true;
				chkPersonCode = idDitta.charAt(1)=="1";
			break;
			case "SM": case "RSM":
				chkIVA = idDitta.charAt(0)=="1";
				ivaNCharacter = 5;
				chkCAP = true;
				chkPersonCode = idDitta.charAt(1)=="1";
			break;
		}
	}
	
	for(var i=0,fldName='';i<frm.elements.length;i++){
		if(frm.elements[i].disabled) continue;
		
		fldName = (frm.elements[i].name||"").toLowerCase();
		
		switch(fldName){
			case "companycode":
				if(!chkIVA)
					continue;
			break;
			case "personcode":
				if(!chkPersonCode)
					continue;
			break;
		}
		
		// campo obbligatorio
		if(freeFieldsName.indexOf("#"+fldName+"#")==-1){
			if( frm.elements[i].type=="select-one" && frm.elements[i].selectedIndex==0 ){
				alert(window.fillField+": "+(window[fldName]||fldName));
				frm.elements[i].focus();
				return false;
			}else if( (frm.elements[i].type=="text"||frm.elements[i].type=="password") && isEmpty(frm.elements[i].value) ){
				alert(window.fillField+": "+(window[fldName]||fldName));
				frm.elements[i].focus();
				return false;
			}
		}
	}
	
	// controllo pIVA e cap per Italia e San Marino
	if(frm.elements["country"]){
		if(chkIVA && !frm.companyCode.disabled ){
			var re = eval("/^\\d{"+ivaNCharacter+"}$/");
			if(frm.companyCode.value.search(re)==-1){
				alert(window.erratedValue+": "+window.companycode);
				frm.companyCode.focus();
				frm.companyCode.select();
				return false;
			}
		}
		if( chkCAP && frm.postalCode && !frm.postalCode.disabled && frm.postalCode.value.search(/^\d{5}$/)==-1 ){
			alert(window.erratedValue+": "+window.postalcode);
			frm.postalCode.focus();
			frm.postalCode.select();
			return false;
		}
	}
	
	var mail = frm["checkField_1"]||frm.email;
	
	if(mail && !_mail(mail.value)){
		alert(window.erratedValue+": "+window.mail);
		mail.focus();
		mail.select();
		return false
	}
	return true;
}
*/

function isEmpty(str){str = str||""; return (str.replace(/\s/g,"").length==0)}
function isDate(str){str = str||""; return str.search(/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/)!=-1}
function isMail(str){str = str||""; return str.search(/^([\w\.\-])+@(([\w\-]{2,})+\.)+([a-z0-9]{2,})+$/i)!=-1}
function cryptString(s,bDecrypt){
	s = s||"";
	var newString = "";
	bDecrypt = !!bDecrypt;
	var cryptPrefix = "$";
	var krypt1 = "23BuvC_67X5Zab-fg8mYD4pRdhi.M9AEQPlNjk01/FTGJwxHIyK LceOqrstSVUWzno";
	var krypt2 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-. /";
	if(bDecrypt){
		if( s.indexOf(cryptPrefix)!=0 )
			return s;
		var temp = krypt1;
		krypt1 = krypt2;
		krypt2 = temp;
		s = s.substr(1);
	}else
		newString += cryptPrefix;
	for(var i=0,reg,index;i<s.length;i++){
		reg = new RegExp(s.charAt(i));
		index = krypt2.search(reg);
		newString += krypt1.charAt(index);
	}
	return newString;
}
function decryptString(s){
	return cryptString(s,true);
}

function checkRegistrationForm(frm){
	// campi che terminano con __*   => Campi obbligatori
	// campi che iniziano con $		 => Campi crittati	
	var tmpName;
	var naz = "";
	tmpName = "country";//cryptString("country");
	var oCountry = frm[tmpName] || frm[tmpName+"__*"];
	if(oCountry)
		naz = (oCountry.options[oCountry.selectedIndex].value||"").toUpperCase();
	
	var userTypeID = "";
	tmpName = "userTypeID";//cryptString("userTypeID");
	var oUserType = frm[tmpName] || frm[tmpName+"__*"];
	if(oUserType)
		userTypeID = oUserType.options[oUserType.selectedIndex].value||"";
	
	var pIVA = "";
	tmpName = "companyCode";//cryptString("companyCode");
	var oPIVA = frm[tmpName] || frm[tmpName+"__*"];
	if(oPIVA)
		pIVA = oPIVA.value||"";
	
	var emptyFields = [];
	var wrongFields = [];
	var bEmptyField;
	var bWrongField;
	for(var i=0,fldName='',requiredField,disabledField;i<frm.elements.length;i++){
		fldName = frm.elements[i].name;
		disabledField = frm.elements[i].disabled;
		if(!fldName || disabledField) 
			continue;
		
		fieldChecked(frm.elements[i]);
		requiredField = fldName.split("__*").length==2;
		bEmptyField = false;
		bWrongField = false;
		fldName = frm.elements[i].name.replace(/__\*$/,"");
		fldName = decryptString(fldName);
		
		switch(fldName){
			case "companyCode":
				requiredField = requiredField || userTypeID.charAt(0)=="1";
				if( requiredField || frm.elements[i].value.length )
					bWrongField = checkFldIVA(frm.elements[i],naz);
			break;
			case "personCode":
				requiredField = requiredField || userTypeID.charAt(1)=="1";
				if( requiredField || frm.elements[i].value.length )
					bWrongField = checkFldPersoneCode(frm.elements[i],naz,pIVA);
			break;
			case "postalCode":
				if( requiredField || frm.elements[i].value.length )
					bWrongField = checkPostalCodeFld(frm.elements[i],naz);
			break;
			case "birthDate":
				if( requiredField || frm.elements[i].value.length )
					bWrongField = !isDate(frm.elements[i].value);
			break;
			case "checkField_1":// mail
				if( requiredField || frm.elements[i].value.length )
					bWrongField = !isMail(frm.elements[i].value);
			break;
			case "checkField_1Confirm": case "pwdConfirm":
				if( requiredField || frm.elements[i].value.length )
					bWrongField = frm.elements[i].value!=frm.elements[i-1].value;
			break;
			case "customField1":
				if( requiredField || frm.elements[i].value.length )
					bWrongField = frm.elements[i].value>5;
			break;
			// LIBERI SEMPRE
			case "cmd_OK": case "cmd_RESET":
				requiredField = false;
			break;
		}
		
		// se il campo so gia' che e' errato lo aggiungo all'elenco e proseguo
		if( bWrongField ){
			fieldChecked(frm.elements[i],true);
			wrongFields.push(frm.elements[i]);
			continue;
		}
		
		if( requiredField ){
			switch(frm.elements[i].type){
				case "checkbox":
				case "radio":
					var checked = false;
					var list = frm[frm.elements[i].name];
					if(list && list.length){
						for(var r=0;r<list.length;r++){
							checked = list[r].checked;
							if(checked)
								break;
						}
					}else
						checked = frm.elements[i].checked;
					bEmptyField = !checked;
				break;
				case "select-one":
					bEmptyField = frm.elements[i].selectedIndex==0;
				break;
				default:
					bEmptyField = isEmpty(frm.elements[i].value);
				break;
			}
			if(bEmptyField){
				fieldChecked(frm.elements[i],true);
				emptyFields.push(frm.elements[i]);
			}
		}
	}
	
	if(emptyFields.length || wrongFields.length){
		alert(window["formFieldsErrorMessage"]);
		if( emptyFields[0] )
			emptyFields[0].focus();
		else if( wrongFields[0] )
			wrongFields[0].focus();
		return false
	}else
		return true;
}

function checkFldIVA(fld,naz){
	var bWrongField = false;
	switch(naz){
		case "SM": case "RSM":
			//var re = eval("/\\d{5}$/i");
			var re = /^(sm)*\d{5}$/i;
			bWrongField = fld.value.search(re)==-1;
		break;
		case "I": case "IT": case "ITA":
			bWrongField = !ControllaPIVA(fld.value);
		break;
	}
	return bWrongField;
}

function checkFldPersoneCode(fld,naz,pIVA){
	var bWrongField = false;
	switch(naz){
		case "I": case "IT": case "ITA":
			bWrongField = !ControllaCF(fld.value) && fld.value!=pIVA;
		break;
	}
	return bWrongField;
}
function checkPostalCodeFld(fld,naz){
	var bWrongField = false;
	switch(naz){
		case "I": case "IT": case "ITA":
		case "SM": case "RSM":
			var re = eval("/^\\d{5}$/");
			bWrongField = fld.value.search(re)==-1;
		break;
	}
	return bWrongField;
}

function fieldChecked(fld,bWrong){
	bWrong = !!bWrong;
	var checkOK = "ReadySkins/normal/images/ico_ball_green2.gif";
	var checkKO = "ReadySkins/normal/images/ico_ball_red2.gif";
	var icoID = fld.name+"_check";
	var icoCheck = document.getElementById(icoID);
	// metto a verde solo i cami che erano stati segnalati
	if(!bWrong && icoCheck){
		fld.style.border = "1px solid #ccc";
		icoCheck.src = checkOK;
	}
	if(bWrong){
		if(!icoCheck){
			icoCheck = new Image();
			icoCheck.setAttribute("id",icoID);
			icoCheck.setAttribute("hspace",5);
			insertAfter(icoCheck,fld);
		}
		fld.style.border = "1px solid #ff0000";
		icoCheck.src = checkKO;
	}
}
function insertAfter(new_node, existing_node) {
	// if the existing node has a following sibling, insert the current
	// node before it. otherwise appending it to the parent node
	// will correctly place it just after the existing node.
	
	if (existing_node.nextSibling) {
	// there is a next sibling. insert before it using the mutual
	// parent's insertBefore() method.
		existing_node.parentNode.insertBefore(new_node, existing_node.nextSibling);
	} else {
	// there is no next sibling. append to the end of the parent's
	// node list.
		existing_node.parentNode.appendChild(new_node);
	}
}
function ControllaCF(cf){
	var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  return true;
    cf = cf.toUpperCase();
    if( cf.length != 16 )
		return false;
		/*
        return "La lunghezza del codice fiscale non ?\n"
        +"corretta: il codice fiscale dovrebbe essere lungo\n"
        +"esattamente 16 caratteri.\n";
		*/
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )
          return false;
		   /*
		    return "Il codice fiscale contiene un carattere non valido `" +
                cf.charAt(i) +
                "'.\nI caratteri validi sono le lettere e le cifre.\n";
		*/
    }
    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
    s = 0;
    for( i = 1; i <= 13; i += 2 )
        s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    for( i = 0; i <= 14; i += 2 )
        s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
       return false;
	   /*
	    return "Il codice fiscale non ? corretto:\n"+
            "il codice di controllo non corrisponde.\n";
		*/
    return true;
}

function ControllaPIVA(pi){
    if( pi == '' )  return true;
    if( pi.length != 11 )
     	return false;
	   /*
	    return "La lunghezza della partita IVA non ?\n" +
            "corretta: la partita IVA dovrebbe essere lunga\n" +
            "esattamente 11 caratteri.\n";
		*/
    validi = "0123456789";
    for( i = 0; i < 11; i++ ){
        if( validi.indexOf( pi.charAt(i) ) == -1 )
           return false;
		   /*
		    return "La partita IVA contiene un carattere non valido `" +
                pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
			*/
    }
    s = 0;
    for( i = 0; i <= 9; i += 2 )
        s += pi.charCodeAt(i) - '0'.charCodeAt(0);
    for( i = 1; i <= 9; i += 2 ){
        c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
        if( c > 9 )  c = c - 9;
        s += c;
    }
    if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
        return false;
		/*
		return "La partita IVA non ? valida:\n" +
            "il codice di controllo non corrisponde.\n";
		*/
    return true;
}

function submitRegistrationForm(){
	var formRegistration = document.forms.frmRegistration;
	var registrationCorrect = checkRegistrationForm(formRegistration);
	var formVisura = document.forms.frmVisura;
	if(registrationCorrect){
		if(formVisura){
			var sFileName = formVisura.sellerVisura.value||"";
			if(sFileName){
				formRegistration.sellerVisuraTypeFile.value = sFileName.substr(sFileName.lastIndexOf(".")+1);
				formVisura.submit();
			}
		}
		formRegistration.submit();
	}
	return false;
}


function checkRequestForm(frm){
	if(isEmpty(frm.maskedField1.value)){
		alert(window.fillField+": "+window.refname);
		frm.maskedField1.focus();
		frm.maskedField1.select();
		return false;
	}
	if(isEmpty(frm.maskedField2.value)){
		alert(window.fillField+": "+window.mail);
		frm.maskedField2.focus();
		frm.maskedField2.select();
		return false;
	}
	if(frm.maskedField2&&!_mail(frm.maskedField2.value)){
		alert(window.erratedValue+": "+window.mail);
		frm.maskedField2.focus();
		frm.maskedField2.select();
		return false;
	}
	return true;
}



function checkOrderForm(frm){
	if(frm.courierID){
		if(frm.courierID.type=="select-one"){
			if(!(frm.courierID.options[frm.courierID.selectedIndex].value>>0)){
				alert(window.courier);
				frm.courierID.focus();
				return false;
			}
		}
		else if(frm.courierID.type=="radio"||frm.courierID.length){
			// elenco di radio
			if(frm.courierID.length){
				for(var i=0,courierChecked=false;i<frm.courierID.length;i++)
					if(frm.courierID[i].checked){
						courierChecked = true;
						break;
					}
				var radioToCheck = frm.courierID[0];
			}
			// radio singolo
			else{
				var courierChecked = frm.courierID.checked;
				var radioToCheck = frm.courierID;
			}
			if(!courierChecked){
				alert(window.courier);
				radioToCheck.focus();
				return false;
			}
		}
	}
	if(!(frm.paymentID.options[frm.paymentID.selectedIndex].value>>0)){
		alert(window.payment);
		frm.paymentID.focus();
		return false;
	}
	frm.action = "default.asp?cmd=sendOrder";
	return true;
}
function showHideCat(o){
	var list = o.parentNode.getElementsByTagName("ul");
	o.className = o.className=="open"?"folder":"open";
	for(var i=0;i<list.length;i++)
		if(o.parentNode==list[i].parentNode)
			list[i].style.display = list[i].style.display=="none"?"block":"none";
	return false;
}
function showTransp(){
	var arrDim = getWinDim();
	var arrPos = getScrollXY();
	var t = arrPos[1]+arrDim[1]/2;
	var transpObj = document.getElementById("myTransparentDiv");
	if(transpObj){
		transpObj.style.width = document.body.clientWidth+"px";
		transpObj.style.height = document.body.clientHeight+"px";
		transpObj.style.display = "block";
		transpObj.firstChild.style.top = (t-30)+"px";
	}
}

function openPopUp(sPath,w,h){
	w = w>>0;
	h = h>>0;
	showTransp();
	switch(w>0&&h>0){
		case true:
			designPopUP(sPath,w,h);
		break;
		default:
			var img = new Image();
			img.onload = function(){
				designPopUP(sPath,this.width+20,this.height+35);
			}
		var imgPath = sPath.split("=");
		imgPath = imgPath[1].split("&");
		img.src = imgPath[0];
		break;
	}	
}

function designPopUP(sPath,w,h,obj){
	var arrDim = getWinDim();
	var arrPos = getScrollXY();
	var l = arrDim[0]/2;
		l -= w/2;
	var t = arrPos[1]+arrDim[1]/2;
	t -= h/2;
	
	var transpObj = document.getElementById("myTransparentDiv");
	transpObj.onclick = hidePopUp;
	
	window.iFrame = document.getElementById("myIFrame");
	window.iFrame.setAttribute("src",sPath);
	window.iFrame.style.top = t+"px";
	window.iFrame.style.left = l+"px";
	window.iFrame.setAttribute("width",w);
	window.iFrame.setAttribute("height",h);
	
	window.iFrame.onreadystatechange = function(){
		if(this.readyState=="complete")
			showIFrame();
	}
	window.iFrame.onload = function(){
		showIFrame();
	}
	transpObj.onclick = hidePopUp;
	return false;
}

function showIFrame(){
	setTimeout('window.iFrame.style.display = "block";',1000);
}

function hidePopUp(){
	var iFrame = document.getElementById("myIFrame");
	var transpObj = document.getElementById("myTransparentDiv");
	if( iFrame && iFrame.style.display=="block" ){
		transpObj.style.display = "none";
		iFrame.style.display = "none";
	}
	return false;
}

function getWinDim() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  return [myWidth,myHeight];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}




function expandNode(id){
	var obj = document.getElementById("lnk_"+id);
	obj.innerHTML=obj.innerHTML=="+"?"-":"+";
	obj=document.getElementById("row_"+id);
	obj.style.display=obj.style.display=="none"?"":"none";
	return false;
}

window.onload = function(){
					var mainContent = document.getElementById("colMid");
					var box = document.getElementById("newsBox");
					if(!box)
						box = document.getElementById("downloadBox");
					if(mainContent&&box){
						if(mainContent.childNodes.length>0)
							mainContent.insertBefore(box,mainContent.childNodes[0]);
						else
							mainContent.appendChild(box);
					}
					
					// perche' nn scada la sessione
					window.setInterval("renewSession();",1200000);
					
				}
function renewSession(){
	document.images["renewSession"].src = "renewSession.asp?par="+Math.random();
}