/**************************************
 * warranty.js
 * Sajith MS
 * 6/26/06
 *
 * Validations for Warranty Works
 ***************************************/

/**
 * Sajith MS
 * 6/26/06
 * cart validations
 **/

function validateCheckBox()
 {
    objForm = document.cartViewForm;
    alert(":::"+objForm.cartID.checked);
    if(!objForm.cartID.checked)
        {
        alert("Please make a Selection");
        } else {
        objForm.submit();
    }
 }

/**
 * Manju
 * 6/26/06
 * validations for contact us
 **/

function ValidateForm() {
    objForm = document.contact;
    if(objForm.txtEmail.value == "")
    {
        alert("Please enter the  Email Address.");
        objForm.txtEmail.focus();
        return false;
    }
    if(objForm.txtComment.value	== "") 
    {
        alert("Please enter the Comments");
        objForm.txtComment.focus();
        return false;
    }
}

/**
 * Sajith MS
 * 6/26/06
 * validations in registering tradefriend
 **/

function ValidateRegisterFriendForm()
  {
    objForm = document.userRegistration;
    if(objForm.txtYrName.value == "") 
    {
        alert("Please enter the Your Name.");
        objForm.txtYrName.focus();
        return false;
    }
    if(objForm.txtName.value == "") 
    {
        alert("Please enter the Friends Name.");
        objForm.txtName.focus();
        return false;
    }
    if(objForm.txtEmail.value == "") 
    {
        alert("Please enter the Trade Users Email Address.");
        objForm.txtEmail.focus();
        return false;
    }
  }

/**
 * Sajith MS
 * 6/26/06
 * validations in registering trade users
 **/

function setAffDiscRate(combo) 
{
    var custDiscRate = combo.options[combo.options.selectedIndex].value;
    objForm = document.userRegistration;
    objForm.txtAffDiscount.value = 15 - custDiscRate;
}

/**
 * Sajith MS
 * 6/26/06
 * validations in registeration form
 **/

function ValidateUserRegistraionForm() 
{
        objForm = document.userRegistration;    
        if(objForm.txtDiscVoucherPhrase && 
        Trim(objForm.txtDiscVoucherPhrase.value) == "") 
        {
            alert("Please enter the Discount Voucher Phrase Name.");
            objForm.txtDiscVoucherPhrase.focus();
            return false;
        }
    if(objForm.txtDiscount && Trim(objForm.txtDiscount.value) == "") 
    {
        alert("Please enter the Discount % For Customers.");
        objForm.txtDiscount.focus();
        return false;
    }
    if(objForm.txtDiscount && Trim(objForm.txtDiscount.value) >	10 )
    {
        alert("The Discount % For Customers should not be greater than 10.");
        objForm.txtDiscount.focus();
        return false;
    }
    if(Trim(objForm.txtBussinessName.value) == "") 
    {
        alert("Please enter the Business Name.");
        objForm.txtBussinessName.focus();
        return false;
    }
    if(Trim(objForm.cboBussinessType.
        options[objForm.cboBussinessType.selectedIndex].value) == "") 
    {

        alert("Please enter the trade bussiness type.");
        objForm.cboBussinessType.focus();
        return false;
    }
    if(Trim(objForm.txtName.value) == "") 
    {
        alert("Please enter the Trade Users Name.");
        objForm.txtName.focus();
        return false;
    }
    if(Trim(objForm.txtAddress1.value) == "") 
    {
        alert("Please enter the Trade Users Street 1.");
        objForm.txtAddress1.focus();
        return false;
    }
    if(Trim(objForm.txtTown.value) == "") 
    {
        alert("Please enter the Trade Users Town.");
        objForm.txtTown.focus();
        return false;
    }
    if(Trim(objForm.postcode.value) == "") 
    {
        alert("Please enter the Trade Users Postcode.");
        objForm.postcode.focus();
        return false;
    }
    if(!IsEmail(Trim(objForm.txtEmail.value))) 
    {
        alert("Please enter a valid Trade Users Email.");
        objForm.txtEmail.focus();
        return false;
    }
    if(Trim(objForm.txtPhone.value) == "") 
    {
        alert("Please enter the Trade Users Phone Number.");
        objForm.txtPhone.focus();
        return false;
    }
    if(Trim(objForm.txtLogin.value) == "") 
    {
        alert("Please enter the login name.");
        objForm.txtPhone.focus();
        return false;
    }
    objForm.submit.value = "true";
}

/**
 * Sajith MS
 * 6/26/06
 * Script to trim a string
 **/

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);
}

/**
 * Sajith MS
 * 6/26/06
 * validations for Email
 **/

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 orientWindow()
{
     window.toolbars=0
         window.resizeTo(520,480)
     window.moveTo(50,50)
 
}*/

/**
 * Sajith MS
 * 6/26/06
 * validations in Bussiness Type
 **/

function funOtherBussinessType() 
{
    if(document.userRegistration.cboBussinessType.
        options[document.userRegistration.cboBussinessType.
        selectedIndex].value == "Other") 
        {
        document.getElementById("otherbussinessType").innerHTML = 
        '<table  border="0" cellspacing="0" cellpadding="0"><tr>' + 
        '<td align="left" width="30%" class="td_content">&nbsp;If Other' + 
        ',<br>&nbsp;please specify<br>&nbsp;Business Type&nbsp;&nbsp;&nbsp;' + 
        '</td><td><input name="txtOtherBussinessType" type="text" size="40" ' + 
        'value=""><span class="required">*</span></td></tr></table>';
        } else {
        document.getElementById("otherbussinessType").innerHTML = "";
        }
}

/**
 * Sajith MS
 * 6/26/06
 * script for showing the window in key up for the voucher code
 **/

function OnKeyUpPopUpWindow() 
{
    var strValue = "";    
    if(document.invoiceDetailsForm.txtVoucherNumber.value != "") 
    {

        strValue = document.invoiceDetailsForm.txtVoucherNumber.value;        
        strValue = strValue.toUpperCase();

        if(strValue == "TEACHER") 
        {     
                window.open("registerTrade.jsp","_blank",
                "toolbar=no, scrollbars=yes, status=yes," + 
                "resizable=no, width=520, height=480");
        }
        if(strValue == "AFFILIATE") 
        {
                window.open("registerTrade.jsp","_blank",
                "toolbar=no,scrollbars=yes,status=yes," +
                "resizable=no,width=520, height=480");
                    
        }
    }

}
