/* http://adtportugal.v9.sitekit.net */

ValidateJobApplication = function()
{

    if($("#SKFCE_1_UserInput").exists())
       $("#SKFCE_1_UserInput").addClass("validate[required,length[0,40]]");

    if($("#SKFCE_2_UserInput").exists())
       $("#SKFCE_2_UserInput").addClass("validate[required,custom[email],length[0,80]]");

    if($("#SKFCE_3_UserInput").exists())
       $("#SKFCE_3_UserInput").addClass("validate[required,length[0,40]]");

    if($("#SKFCE_11_UserInput").exists())
       $("#SKFCE_11_UserInput").addClass("validate[required,length[0,40]]");

    if($("#SKFCE_15_UserInput").exists())
       $("#SKFCE_15_UserInput").addClass("validate[length[0,40]]");

    if($("#SKFCE_19_UserInput").exists())
       $("#SKFCE_19_UserInput").addClass("validate[length[0,40]]");

    //if($("#SKFCE_6_UserInput").exists())
    //   $("#SKFCE_6_UserInput").addClass("validate[required,length[0,40]]");

    if($("#SKFCE_7_UserInput").exists())
       $("#SKFCE_7_UserInput").addClass("validate[required,length[0,10]]");

    if($("#SKFCE_8_UserInput").exists())
       $("#SKFCE_8_UserInput").addClass("validate[required,length[0,40]]");

    //if($("#SKFCE_9_UserInput").exists())
    //   $("#SKFCE_9_UserInput").addClass("validate[required,length[0,40]]");

    if($("#SKFCE_10_UserInput").exists())
       $("#SKFCE_10_UserInput").addClass("validate[required,length[0,40]]");

    if($("#SKFCE_14_UserInput").exists())
       $("#SKFCE_14_UserInput").addClass("validate[length[0,50]]");

    if($("#SKFCE_6_UserInput").exists())
       $("#SKFCE_6_UserInput").addClass("validate[optional,length[0,255]]");

    if($("#SKFCE_18_UserInput").exists())
       $("#SKFCE_18_UserInput").addClass("validate[optional,length[0,255]]");

    if($("#SKFCE_19_UserInput").exists())
       $("#SKFCE_19_UserInput").addClass("validate[optional,length[0,255]]");

    BindFormValidation('Sitekit_Form_423');
}


//Show form according to verticals
ShowQuickFillForm = function(branchId)
{
    $.validationEngine.closePrompt('.formError',true)
    if($("#frm-SalesForce").exists())
    {
        var frmGuid = jQuery.uuid();
        $("#instanceID").val(frmGuid);
        QuickfillForm_AddValidationToAllFields_SK();
        //QuickfillForm_RemoveValidationFromFields_SK(branchId); //apply if needed
        BindFormValidation('frmSalesforce');
        $("#frm-SalesForce").css('display',"");
    }
    
    $(".formError").css("display","");
}

//Add validation class to Quick Fill form
QuickfillForm_AddValidationToAllFields_SK = function()  //Saleforce
{
    if($("#first_name").exists()) //firstname
        $("#first_name").addClass("validate[required,length[0,40]]");

    if($("#last_name").exists()) //lastname
        $("#last_name").addClass("validate[required,length[0,40]]");
        
    if($("#email").exists())  //email      
        $("#email").addClass("validate[required,custom[email],length[0,80]]"); 

    if($("#company").exists()) //company
        $("#company").addClass("validate[required,length[0,40]]");
        
    if($("#SKFCE_6_UserInput").exists())  //position 
         $("#SKFCE_6_UserInput").addClass("validate[required,length[0,40]]");

    if($("#city").exists())  //city      
        $("#city").addClass("validate[required]");

    if($("#phone").exists())  //phone
         $("#phone").addClass("validate[required,length[0,40]]")

     //if($("#SKFCE_5_UserInput").exists())  //zip     
     //   $("#SKFCE_5_UserInput").addClass("validate[required,length[0,100]]"); 

     if($("#00N200000026841").exists())  //product interest    
        $("#00N200000026841").addClass("validate[required]");
}
/*
//Remove Or Change validation class to quick fill form 
QuickfillForm_RemoveValidationFromFields_SK = function(branchId) //SITEKIT
{
    switch(branchId)
    {
    case 1:
        if($("#company").exists())
        {
            $("#company").removeClass("validate[required,length[0,40]]");      
            $("#company").addClass("validate[optional,length[0,40]]");            
        }
        break;
    }
}
*/

//binding validation to defined form
BindFormValidation = function(formId)
{
    $.validationEngineLanguage.newLang();
    if($("#" + formId).exists())
    {
       $("#" + formId).validationEngine();
    }
}

// reset the defined form
ResetForm = function(formId)
{
    $('textarea','#' + formId).text('');
    $(':input','#' + formId).not(':button, :submit, :reset, :hidden, :radio, :checkbox').val('').removeAttr('checked').removeAttr('selected'); 
}


function AddOptions(ctrlid, arrValue)
{
    $('option',"#" + ctrlid).remove();
    var select = $('#' + ctrlid);  
    var options = select.attr('options'); 
    $.each(arrValue, function(val, text) {  
        options[options.length] = new Option(text, val);  
    }); 
}


//Show Main form according to options
ShowMainForm_SK = function()
{
    var frmGuid = jQuery.uuid();
    $("#instanceID").val(frmGuid);
    $.validationEngine.closePrompt('.formError',true)

//    if($("#SKFCE_13_ElementID_Ja:checked").exists())
//    {
//        var options = {"":"Bitte wählen Sie aus:","Fragen zu Rechnungen":"Fragen zu Rechnungen","Technsiche Hilfe":"Technsiche Hilfe","Allgemeine Frage":"Allgemeine Frage"};
//        AddOptions('SKFCE_14_UserInput', options);
//    }
//    else
//    {
//        var options = {"":"Bitte wählen Sie aus:","Rechnungen":"Rechnungen","Technischer Support":"Technischer Support","Allgemeine Frage":"Allgemeine Frage"};
//        AddOptions('SKFCE_14_UserInput', options);
//           
//    }
    
    MainForm_AddValidationToAllFields_SK();
//    MainForm_RemoveValidationFromFields_SK(); 
    BindFormValidation('Sitekit_Form_430');
}

//Add validation class to all fields
MainForm_AddValidationToAllFields_SK = function()
{
    if($("#SKFCE_0_UserInput").exists())//current account number
        $("#SKFCE_0_UserInput").addClass("validate[required]");

    if($("#SKFCE_3_UserInput").exists())//nature of inquiry
        $("#SKFCE_3_UserInput").addClass("validate[required]");

    if($("#SKFCE_10_UserInput").exists())//firstname
        $("#SKFCE_10_UserInput").addClass("validate[required]");

    if($("#SKFCE_1_UserInput").exists())//last name
        $("#SKFCE_1_UserInput").addClass("validate[required]");

    if($("#SKFCE_6_UserInput").exists())//telephone
        $("#SKFCE_6_UserInput").addClass("validate[required]");

    if($("#SKFCE_2_UserInput").exists())  //email      
        $("#SKFCE_2_UserInput").addClass("validate[required,custom[email],length[0,80]]"); 

    if($("#SKFCE_11_UserInput").exists())  //company      
        $("#SKFCE_11_UserInput").addClass("validate[required,length[0,100]]"); 
    
    //if($("#SKFCE_8_UserInput").exists()) //position
      //  $("#SKFCE_8_UserInput").addClass("validate[required]");

    //if($("#SKFCE_9_UserInput").exists())//town
      //  $("#SKFCE_9_UserInput").addClass("validate[required]");

    //if($("#SKFCE_10_UserInput").exists())//zip
      //  $("#SKFCE_10_UserInput").addClass("validate[required]");

    if($("#SKFCE_5_UserInput").exists())//comments
        $("#SKFCE_5_UserInput").addClass("validate[optional,length[0,400]]");


}

/*
//Remove or change validation class of the fields
MainForm_RemoveValidationFromFields_SK = function()
{

}
*/

//Show Main form according to options
ShowMainForm_SF = function() //Salesforce
{
    $.validationEngine.closePrompt('.formError',true)
    MainForm_AddValidationToAllFields_SF();
    //MainForm_RemoveValidationFromFields_SF(); 
    BindFormValidation('frmSalesforce');
}

//validate enquiry form for residential
MainForm_AddValidationToAllFields_SF = function()
{
    if($("#00N200000026841").exists())
        $("#00N200000026841").addClass("validate[required]");

    if($("#first_name").exists())
        $("#first_name").addClass("validate[required]");

    if($("#last_name").exists())
        $("#last_name").addClass("validate[required]");

    if($("#phone").exists())
        $("#phone").addClass("validate[required]");

    if($("#email").exists())        
        $("#email").addClass("validate[required,custom[email],length[0,80]]"); 

    if($("#company").exists())        
        $("#company").addClass("validate[required,length[0,100]]"); 

    //if($("#position").exists())        
      //  $("#position").addClass("validate[required,length[0,100]]"); 
    
    if($("#town").exists())
        $("#town").addClass("validate[required]");

   // if($("#zip").exists())
     //   $("#zip").addClass("validate[required]");

    if($("#description").exists())
        $("#description").addClass("validate[optional,length[0,400]]");
}

/*
//validate enquiry form for business
MainForm_RemoveValidationFromFields_SF = function()
{
 
}
*/

//checks for element exists
jQuery.fn.exists = function(){return jQuery(this).length>0;} 

/*
 * Usuage:
 * var frmGuid = jQuery.uuid();
 * $("#instanceID").val(frmGuid);
*/

/*
 Generate fragment of random numbers
*/

jQuery._uuid_default_prefix = '';
jQuery._uuidlet = function () {
	return(((1+Math.random())*0x10000)|0).toString(16).substring(1);
};

/*
 Generates random uuid
*/

jQuery.uuid = function (p) {
	if (typeof(p) == 'object' && typeof(p.prefix) == 'string') {
		jQuery._uuid_default_prefix = p.prefix;
	} else {
		p = p || jQuery._uuid_default_prefix || '';
		return(p+jQuery._uuidlet()+jQuery._uuidlet()+"-"+jQuery._uuidlet()+"-"+jQuery._uuidlet()+"-"+jQuery._uuidlet()+"-"+jQuery._uuidlet()+jQuery._uuidlet()+jQuery._uuidlet());
	};
};

 /* Functions to implement omniture tracking starts here*/
function DoRedirect(){
    if(document.formPost){
        //SEventForEnquiryForm();
        //SEventForCareerForm();
        window.location.href = document.formPost.SubmitAction.value;// + '?sEvent=' + $("#SEvent").val();  
        //document.formPost.action = document.formPost.SubmitAction.value + '?sEvent=' + $("#SEvent").val();  
        //document.formPost.submit();
    }
}
