/**************************************
 * customerDetails.js
 * Manju
 * 9/28/06
 *
 * Validations for Warranty Works
 ***************************************/

/**
 * Manju
 * 9/28/06
 * Customer Details
 **/



function checkLoginType(objForm) {

    var objElem = objForm.listLogin;
    var searchBy = objElem.options[objElem.selectedIndex].value;
    
    if(searchBy == 1){
        objForm.action ="login.jsp";
        objForm.method = "post";
        objForm.submit();
    } if(searchBy == 2){
        objForm.action ="userRegistration.jsp";
        objForm.method = "post";
        objForm.submit();
    }if(searchBy == 3){     
    
        objForm.garage_name.value = objForm.ownname.value;        
        objForm.garage_address1.value = objForm.owner_address1.value;
        objForm.garage_address2.value = objForm.owner_address2.value;
        objForm.garage_city.value = objForm.owner_city.value;
        objForm.garage_post.value = objForm.owncode.value;
        objForm.garage_email.value = objForm.owner_email.value;
        objForm.garage_phone.value = objForm.owner_phone.value;        
        
        document.getElementById('postcode_search2').style.display = 'none';
        document.getElementById('garage_name').style.display = 'none';
        document.getElementById('garage_address1').style.display = 'none';        
        document.getElementById('garage_address2').style.display = 'none';
        document.getElementById('garage_city').style.display = 'none';
        document.getElementById('garage_post').style.display = 'none';
        document.getElementById('garage_email').style.display = 'none';
        document.getElementById('garage_phone').style.display = 'none';  
        document.getElementById('tblCustTable').style.display = 'none'; 
        

    }if(searchBy == 0){

        objForm.garage_name.value="";
        objForm.garage_address1.value ="";
        objForm.garage_address2.value = "";
        objForm.garage_city.value = "";
        objForm.garage_post.value = "";
        objForm.garage_email.value = "";
        objForm.garage_phone.value = "";
        
        document.getElementById('postcode_search2').style.display = 'none';
        document.getElementById('garage_name').style.display = 'none';
        document.getElementById('garage_address1').style.display = 'none';        
        document.getElementById('garage_address2').style.display = 'none';
        document.getElementById('garage_city').style.display = 'none';
        document.getElementById('garage_post').style.display = 'none';
        document.getElementById('garage_email').style.display = 'none';
        document.getElementById('garage_phone').style.display = 'none';    
}
if(searchBy == 4){

        objForm.garage_name.value="";
        objForm.garage_address1.value ="";
        objForm.garage_address2.value = "";
        objForm.garage_city.value = "";
        objForm.garage_post.value = "";
        objForm.garage_email.value = "";
        objForm.garage_phone.value = "";
        
        document.getElementById('postcode_search2').style.display = 'block';
        document.getElementById('garage_name').style.display = 'block';
        document.getElementById('garage_address1').style.display = 'block';        
        document.getElementById('garage_address2').style.display = 'block';   
        document.getElementById('garage_city').style.display = 'block';
        document.getElementById('garage_post').style.display = 'block';
        document.getElementById('garage_email').style.display = 'block';
        document.getElementById('garage_phone').style.display = 'block';  
        document.getElementById('tblCustTable').style.display = 'block'; 
}

}

/**
 * Manju
 * 3/12/07
 * Customer Details
 **/

function defaultKeepersAddress(objForm) {

    var objElem = objForm.listDefaultKeepers;
    var searchBy = objElem.options[objElem.selectedIndex].value;

if (searchBy == 1) {
         objForm.garage_name.value = objForm.ownname.value;
        objForm.garage_address1.value = objForm.owner_address1.value;
        objForm.garage_address2.value = objForm.owner_address2.value;
        objForm.garage_city.value = objForm.owner_city.value;
        objForm.garage_post.value = objForm.owncode.value;
        objForm.garage_email.value = objForm.owner_email.value;
        objForm.garage_phone.value = objForm.owner_phone.value;
    } if (searchBy == 0) {
        objForm.garage_name.value="";
        objForm.garage_address1.value ="";
        objForm.garage_address2.value = "";
        objForm.garage_city.value = "";
        objForm.garage_post.value = "";
        objForm.garage_email.value = "";
        objForm.garage_phone.value = "";
}
}



/**
 * Manju Joseph
 * 11/12/06
 * Validation for numeric values.
 **/

function isNumeric(n)
{
    dpos = n.indexOf(".");
    if (isNaN(n)){ return false; }
    else if(dpos > 0){return false;}
    return true;
}
function IsEmail(sEmail) 
{
    sEmail = Trim(sEmail);
    sEmailRegExp = /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/i;
    
    if (sEmail.search(sEmailRegExp) == -1)
        return false;
    
    return true;
}
function Trim(sStringToTrim) 
{
    sStringToTrim = "" + sStringToTrim;
    var iLen = sStringToTrim.length;
    var iFront;
    var iBack;
    for(iFront = 0; iFront < iLen && (sStringToTrim.charAt(iFront) == ' ' ||
            sStringToTrim.charAt(iFront) == '\n' || 
            sStringToTrim.charAt(iFront) == '\r' ||
            sStringToTrim.charAt(iFront) == '\t'); iFront++);
    for(iBack = iLen; iBack > 0 && iBack > iFront &&
            (sStringToTrim.charAt(iBack - 1) == 
                    ' ' || sStringToTrim.charAt(iBack - 1) == '\n' ||
                    sStringToTrim.charAt(iBack - 1) == '\r' || 
                    sStringToTrim.charAt(iBack - 1) == '\t');
    iBack--);
    
    return sStringToTrim.substring(iFront, iBack);
}
