if($('div.sheet'))
{
	$(document).ready(function(){
	   $($('div.sheet')).corner('top');
	});
}

/***** IMPORTANTE: Le funzioni ivi contenute necessitano della libreria JQuery *****/
var holes;
var kind;
var name;
var surname;
var email;
var email2;
var country;
var phone;
var comment;

function checkform() {
    holes = new Array();
    kind=$(":radio[@name='c_k']:checked").val();
    name=$('#c_name').val();
    surname=$('#c_surname').val();
    email=$('#c_email').val();
    email2=$('#c_email_confirm').val();
    country=$('#c_country').val();
    phone=$('#c_phone').val();
    comment=$(":input[@id='c_comment']").val();
    // Popolo l'array 'holes' degli eventuali campi da corregere
    if(name=='')
        holes.push('c_name');
    if(surname=='')
        holes.push('c_surname');
    if(email=='')
        holes.push('c_email');
    if(email2=='')
        holes.push('c_email_confirm');
    if(country=='***')
        holes.push('c_country');
    if(comment=='')
        holes.push('c_comment');
    
    // Se l'array holes contiene campi da correggere, visualizzo gli asterischi
    if(holes.length!=0) {
        $('#ast_c_name').css("display","none");
        $('#ast_c_surname').css("display","none");
        $('#ast_c_email').css("display","none");
        $('#ast_c_email_confirm').css("display","none");
        $('#ast_c_country').css("display","none");
        $('#ast_c_comment').css("display","none");
        for(i in holes) 
            $('#ast_'+holes[i]).css("display","inline");
        alert(js_dic_ERRORFIELDS);
    } else if (emailControl(email) && emailControl(email2) && email==email2) {
        var struct = new Object();
        struct['kind']=kind;
        struct['name']=name;
        struct['surname']=surname;
        struct['email']=email;
        struct['country']=country;
        struct['phone']=phone;
        struct['comment']=comment;
        var json_struct = $.toJSON(struct);
        $('#loading').css("display","block");
        $.ajax({
            type: "POST",
            url: js_global_root_url+"mail_system/contact_cdb.php",
            dataType: "json",
            data: json_struct,
            success: function(res){
                $('#loading').css("display","none");
                if(res=='true') {
                    alert(js_dic_SUCCESS);
                } else alert(js_dic_FAIL);
            }
        });
        
        
    } else {
        $('#ast_c_email').css("display","inline");
        $('#ast_c_email_confirm').css("display","inline");
        alert(js_dic_EMAILNOTMATCH);
    }
        
    
}
