// JavaScript Document
$(function(){	// shorthand for $(document).ready() BTW
												  
	$('.rounded').each(function() {
		$(this).corner({
			  tl: { radius: 8 },
			  tr: { radius: 8 },
			  bl: { radius: 8 },
			  br: { radius: 8 },
			  antiAlias: true,
			  autoPad: true,
			  validTags: ["div"] });
	});
	
	$('.roundedinner').each(function() {
		$(this).corner({
			  tl: { radius: 8 },
			  tr: { radius: 8 },
			  bl: { radius: 8 },
			  br: { radius: 8 },
			  antiAlias: true,
			  autoPad: true,
			  validTags: ["div"] });
	});
});
/*
$(function(){
      settings = {
          tl: { radius: 5 },
          tr: { radius: 5 },
          bl: { radius: 5 },
          br: { radius: 5 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }

	  var cornersObj = new curvyCorners(settings, "rounded");
	  cornersObj.applyCornersToAll();
  });*/
  // 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 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"; 
	}
}

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(){
    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');
        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=='');
}


