

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
    var p, i, foundObj;
  
    if(!theDoc) theDoc = document;
    if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
    {
        theDoc = parent.frames[theObj.substring(p+1)].document;
        theObj = theObj.substring(0,p);
    }
    if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
    for (i=0; !foundObj && i < theDoc.forms.length; i++)
        foundObj = theDoc.forms[i][theObj];
    for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
        foundObj = findObj(theObj,theDoc.layers[i].document);
    if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
    return foundObj;
}

function MM_findObj(theObj, theDoc)
{
    var p, i, foundObj;
    if(!theDoc) theDoc = document;
    if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
    {
        theDoc = parent.frames[theObj.substring(p+1)].document;
        theObj = theObj.substring(0,p);
    }
    if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
    for (i=0; !foundObj && i < theDoc.forms.length; i++)
        foundObj = theDoc.forms[i][theObj];
    for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
        foundObj = findObj(theObj,theDoc.layers[i].document);
    if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
    return foundObj;
}

function sh_div(div_name){
    myObj=findObj(div_name);
    try{
        if(myObj.style.display=='none') myObj.style.display='block';
        else if(myObj.style.display=='block') myObj.style.display='none';
    }catch(err){
        alert(err);
    }
}


var req_flds=Array();

function modifica_form(tipo){

    //my_flds1=Array('nome_bill','cognome_bill','cf_bill');
    my_flds1=Array('cf_bill');
    my_flds2=Array('rag_soc_bill','iva_bill');

    if(tipo=='A'){//azienda
        req_flds=Array('rag_soc_bill','iva_bill','indirizzo_bill','citta_bill','cap_bill','prov_bill','stato_bill','mail_bill','security_code','tel_bill','bday','bmonth','byear','privacy');
        for(var i=0;i<my_flds1.length;i++){
            my_obj=MM_findObj(my_flds1[i]);
            my_obj.className = 'textboxdisabled';
            my_obj.disabled=true;
        }
        for(var i=0;i<my_flds2.length;i++){
            my_obj=MM_findObj(my_flds2[i]);
            my_obj.className = '';
            my_obj.disabled=false;
        }
    }
    else{
        if(tipo=='P'){//privato
            req_flds=Array('nome_bill','cognome_bill','indirizzo_bill','citta_bill','cap_bill','prov_bill','stato_bill','mail_bill','security_code','tel_bill','bday','bmonth','byear','privacy');
            for(var i=0;i<my_flds1.length;i++){
                my_obj=MM_findObj(my_flds1[i]);
                my_obj.className = '';
                my_obj.disabled=false;
            }
            for(var i=0;i<my_flds2.length;i++){
                my_obj=MM_findObj(my_flds2[i]);
                my_obj.className = 'textboxdisabled';
                my_obj.disabled=true;
            }
        }
    }
}

function check_pass(){
    var myErr='';var addErr=false;
    myObj1=MM_findObj('pass_registrazione');
    myObj2=MM_findObj('pass_registrazione2');
	
    if(myObj1.value=='' || myObj1.value!=myObj2.value){
        Err=true;
        myObj1.style.border='1px solid red';
        myObj2.style.border='1px solid red';
    }else{
        Err=false;
        myObj1.style.border='1px solid #7F9DB9';
        myObj2.style.border='1px solid #7F9DB9';
    }
    if (Err){
        errDiv=MM_findObj('error');
        errDiv.innerHTML='The two passwords should be identical!';
        errDiv.style.display='block';
    }
    document.MM_returnValue = !Err;
}
	
function check_form(lang){
    var myErr='';var addErr=false;
    backMsg=MM_findObj('back-msg');
    try{
        backMsg.style.display='none';
    }catch(err){}
	
    for(var i=0;i<req_flds.length;i++){
        myObj=MM_findObj(req_flds[i]);
        if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
            if (myObj.value.length==0){
                addErr=true
                }
        }
        else if (myObj.type=='textarea'){
            if(myObj.value.length<1){
                addErr=true
                }
        }
        else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
            if(myObj.selectedIndex==0){
                addErr=true
                }
        }
        if (addErr){
            myErr+='* Il campo '+req_flds[i]+' e vuoto!\n'; 
            addErr=false
            myObj.style.border='1px solid red';
        }else{
            myObj.style.border='1px solid #dfdfdf';
        }
    }
	
    if (myErr!=''){
        errDiv=MM_findObj('error');
        if(lang=="IT"){errDiv.innerHTML='Le informazioni richieste sono incomplete o contengono errori!<br/>Controlla i campi in rosso!';}
        else{
            if(lang=="FR"){errDiv.innerHTML='L\'information demandée est incomplète ou contient des erreurs!<br/>Veuillez vérifier les champs en rouge!';}
            else{
                errDiv.innerHTML='The required information is incomplete or contains errors!<BR>Please check the fields in red!';
            }
        }
        errDiv.style.display='block';
    }
    document.MM_returnValue = (myErr=='');
}


function WriteSwf(img,wsize,hsize,opt){
    document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+wsize+"\" height=\""+hsize+"\">");
    document.write("<param name=\"movie\" value=\""+img+"\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=wmode value=transparent>");

    if(opt != null){
        var params = opt.split("$");
        out='';
        for(var i=0;i<params.length;i++){
            var tmp = params[i];
            var paramss = tmp.split(">>");

            var strAtt = paramss[0];
            var strVal = paramss[1];

            out+="<param name="+strAtt+" value="+strVal+"> \n";

            strAtt="";
            strVal="";

        }
        document.write(out);
    }

    document.write("<embed src=\""+img+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+wsize+"\" height=\""+hsize+"\" wmode=\"transparent\"");
	
    if(opt != null){
        var params = opt.split("$$");
        out='';
        for(var i=0;i<params.length;i++){
            var tmp = params[i];
            var paramss = tmp.split(">>");

            var strAtt = paramss[0];
            var strVal = paramss[1];

            document.write(" "+strAtt+"=\""+strVal+"\"");

            strAtt="";
            strVal="";

        }
    } 
    document.write("></embed>");
    document.write("</object>");
}
function toggleLayer(id){
    document.getElementById(id).style.visibility='visible';
}
function hide(id){
    document.getElementById(id).style.visibility='hidden';
}


function showHideLogin(d) {
    if(d.length < 1) {
        return;
    }
    if(document.getElementById(d).style.display == "none") {
        document.getElementById(d).style.display = "block";
    }else{
        document.getElementById(d).style.display = "none";
    }
}

//function check_1024(){
//    if ((screen.width<=1024) || (screen.height<=768)){
//        $("li","#submenu").css({
//            "background-color": "red",
//            "font-size": "10px",
//            "margin-right": "0px"
//        })
//    }
//
//}
