/**************************************
 * login.js
 * Manju
 * 9/28/06
 *
 * Validations for Warranty Works
 ***************************************/

/**
 * Manju
 * 9/28/06
 * Customer Details
 **/

function checkLogin(objForm)
{        
    var objElement = objForm.listCustomerType;
    var reportType = objElement.options[objElement.selectedIndex].value;
    if(reportType == "Yes")
    {
            
        document.getElementById('tradeCustomer').style.display='block';
       
	

    }
 if(reportType == "No")
    {
            
       document.getElementById('tradeCustomer').style.display='none';
       

    }
    
}

function loginSubmit(objForm)
{

if ( Trim(objForm.txtContactName.value) == null || Trim(objForm.txtContactName.value) == "") 
                {
                    alert("Please enter Name");
                    return false;
                }

 if ( objForm.txtEmail.value == null || objForm.txtEmail.value == "") 
                {
                    alert("Please enter E-Mail");
                    return false;
                } else {
                    if(!IsEmail(Trim(objForm.txtEmail.value))) 
                         {
                             alert("Please enter a valid Email.");
                             objForm.txtEmail.focus();
                             return false;
                         }
                }   
if ( objForm.txtPhone.value == null || objForm.txtPhone.value == "") 
                {
                    alert("Please enter Phone Number");
                    return false;
                }

if ( objForm.txtLoginName.value == null || objForm.txtLoginName.value == "") 
                {
                    alert("Please enter Login Name");
                    return false;
                }

var loginName=objForm.txtLoginName.value; 
var loginName_array=loginName.split(" "); 

if ( loginName_array.length > 1 )
{
     alert("Spaces are not allowed in Login Name");
     return false;
}

if ( objForm.txtPassword.value == null || objForm.txtPassword.value == "") 
                {
                    alert("Please enter Password");
                    return false;
                }

var passwordName=objForm.txtPassword.value; 
var passwordName_array=passwordName.split(" "); 

if ( passwordName_array.length > 1 )
{
     alert("Spaces are not allowed in Password");
     return false;
}
if ( objForm.txtConfirmPassword.value == null || 
objForm.txtConfirmPassword.value == "") 
                {
                    alert("Please enter Confirm Password");
                    return false;
                }

var confirmPassword=objForm.txtConfirmPassword.value; 
var confirmPassword_array=confirmPassword.split(" "); 

if ( confirmPassword_array.length > 1 )
{
     alert("Spaces are not allowed in Confirm Password");
     return false;
}


var password = objForm.txtPassword.value;
var confirmPassword = objForm.txtConfirmPassword.value;

if ( password != confirmPassword ) 
    {
        alert("Password Mismatch");
        return false;
    }

var objElement = objForm.listCustomerType;
    var reportType = objElement.options[objElement.selectedIndex].value;
    if(reportType == "Yes")
    {

            
        if ( objForm.txtBussinessName != null )
        {

            if ( objForm.txtBussinessName.value == null ||
                objForm.txtBussinessName.value == "") 
                {
                    alert("Please enter bussiness name");
                    return false;
                }
        }

if ( objForm.listBussinessType != null )
        {

            if ( objForm.listBussinessType.value == 0 )
                {
                    alert("Please enter bussiness type");
                    return false;
                }
        }

        if ( objForm.txtMobile != null )
        {

            if ( objForm.txtMobile.value == null ||
                objForm.txtMobile.value == "") 
                {
                    alert("Please enter mobile number");
                    return false;
                }
        }
        if ( objForm.rdoTradeUsers != null )
        {
        
        if(objForm.rdoTradeUsers[0].checked == false && 
        objForm.rdoTradeUsers[1].checked == false)
        {
            alert("Please check the radio button for Motor/Non Motor traders");
            return false;
           
        }

    }


     return true;
}
}
/**
 * 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);
}




