/****************************************************************************************
Product:	  PowerVolt Inc.
Copyright:	  PowerVolt Inc., All rights reserved.
File Type:	  JavaScript File (.js)
Source:		  common.js
Created Date: 12/09/2008
Author:		  Justin Arun
Version:	  1.0.0
Description:  JavaScript file for common validator function


CR / Issue No      Modified By       Modified On       Version         Reason
****************************************************************************************/

var firstErrorControl;
var errMsg;
var clientID;
var ASCXClientID;
var masterclientID;

// Sets the prefix clientID for each page
function SetClientID(ID) {
    if (ID.lastIndexOf("_") > 0)
        clientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return clientID;
}

// Gets the prefix clientID for Grid Control's GridRow
function SetMasterClientID(ID) {
    

    if (ID.lastIndexOf("_") > 0)
        masterclientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return masterclientID;
}


// Gets the prefix clientID for Grid Control's GridRow
function GetGridRowClientID(ID) 
{
    var gridRowClientID;

    if (ID.lastIndexOf("_") > 0)
        gridRowClientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return gridRowClientID;
}

// Sets the prefix accordion2ClientID for each page
function SetAccordion1ClientID(ID) {
    if (ID.lastIndexOf("_") > 0)
        accordion1ClientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return accordion1ClientID;
}

// Sets the prefix accordion2ClientID for each page
function SetAccordion2ClientID(ID) {
    if (ID.lastIndexOf("_") > 0)
        accordion2ClientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return accordion2ClientID;
}

// Sets the prefix accordion3ClientID for each page
function SetAccordion3ClientID(ID) {
    if (ID.lastIndexOf("_") > 0)
        accordion3ClientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return accordion3ClientID;
}

// Gets the prefix clientID for Grid Control's GridRow
function GetASCXClientID(ID) 
{
    if (ID.lastIndexOf("_") > 0)
        ASCXClientID = ID.substring(0, ID.lastIndexOf("_") + 1);
    return ASCXClientID;
}

// Required Field validation
function ValidateRequired(controlName, errorMessage) 
{
    //var errorCode=true;
    var controlID = clientID + controlName;
    var controlObject = document.getElementById(controlID);

    errorCode = IsEmpty(controlObject); 

    if (!errorCode) {
        if (firstErrorControl == '')
            firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
      SetErrorColor(controlID, true);

    return true;
}


// Checks if the control has got any value
function IsEmpty(controlID) {
    var textVal = controlID.value;
    var count = 0;

    for (i = 0; i <= textVal.length - 1; i++) {
        var textValValid = textVal.charAt(i);
        if (textValValid == " ")
            count += 1;
    }

    if (count == textVal.length)
        return false;
    else
        return true;
}


//Special characters validation
function ValidateSpecialChars(controlName, errorMessage, condition) {
    var nonValidCharsRegEx = "`'~!@#$%^\&*()-_+{\"}|:<>?/=[];,.\\";
    var nonValidCityCharsRegEx = "'~!@#$%^\&*()-_+{\"}|:<>?/=[];,\\";
    var nonValidUserIdRegEx = "'~!@#$%^\&*()-_+{\"}|:<>?/=[];,\\";
    var nonValidNameRegEx = "'~!@#$%^\&*()-_+{\"}|:<>?/=[];,\\1234567890";
    var nonValidCompanyRegEx = "~!@#$%^\&*()-_+{\"}|:<>?/=[];,\\";
    var nonValidEmailCharsRegEx = "`'~!#$%^\&*()+{\"}|:<>?/=[];,\\";
    var nonValidOthersCharsRegEx = "`'~!@#$%^\&*()_+{\"}|:<>?/=[];\\1234567890";
    var nonValidShipperRegEx = "~!@#$%^\&*()-_+{\"}|:<>?/=[];,\\1234567890";
    var nonValidTitleRegEx = "`'~!@#$%^\*()-_+{\"}|:<>?=[];,\\";
    var nonValidPasswrodRegEx = "<>";
    var nonValidNumberDecimalRegEx = "~!@#$%^\&*()-_+{\"}|:<>?/=[];,\\ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    var nonValidPrimaryVoltageRegEx = "~!@#$%^\&*()-_+{\"}|:<>?=[];,\\ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    var controlID = clientID + controlName;
    var charValue = document.getElementById(controlID).value;
    var charRegEx = "";
    var finalTxtVal = "";

    switch (condition) {
        case "all": charRegEx = nonValidCharsRegEx;
            break;
        case "dot": charRegEx = nonValidCityCharsRegEx;
            break;
        case "userid": charRegEx = nonValidUserIdRegEx;
            break;
        case "name": charRegEx = nonValidNameRegEx;
            break;
        case "company": charRegEx = nonValidCompanyRegEx;
            break;
        case "email": charRegEx = nonValidEmailCharsRegEx;
            break;
        case "others": charRegEx = nonValidOthersCharsRegEx;
            break;
        case "shipper": charRegEx = nonValidShipperRegEx;
            break;
        case "title": charRegEx = nonValidTitleRegEx;
            break;
        case "password": charRegEx = nonValidPasswrodRegEx;
            break;
        case "numberdecimal": charRegEx = nonValidNumberDecimalRegEx;
            break;
        case "primaryvoltage": charRegEx = nonValidPrimaryVoltageRegEx;
            break;            
            
    }


    for (i = 0; i < charValue.length; i++) {
        Char = charValue.charAt(i);
        if (!(charRegEx.indexOf(Char) == -1)) {
            if (firstErrorControl == '') firstErrorControl = controlID;
            errMsg += GetErrorRow(controlID, errorMessage);
            SetErrorColor(controlID, false);
            return false;
        }
        else {
            SetErrorColor(controlID, true);
        }
    }
    return true;
}


// Dropdown validation
function ValidateDropDown(controlName, errorMessage) {
    //var errorCode=true;
    var controlID = clientID + controlName;
    var dropdown = document.getElementById(controlID);
    var selectedIndex = dropdown.selectedIndex;
    if (selectedIndex == 0) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
    }
    else
        SetErrorColor(controlID, true);
}


function CheckMaxlength(controlName, maxLengthValue, errorMessage) {

    //var controlID = clientControlID(clientIDDetail,controlName); 
    var controlID = clientID + controlName;
    var controlObject = document.getElementById(controlID).value;

    if (controlObject.length > maxLengthValue) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
    }
    else
        SetErrorColor(controlID, true);
}


function CheckMinlength(controlName, minLengthValue, errorMessage) {

    //var controlID = clientControlID(clientIDDetail,controlName); 
    var controlID = clientID + controlName;
    var controlObject = document.getElementById(controlID).value;

    if (controlObject.length < minLengthValue) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
    }
    else
        SetErrorColor(controlID, true);
}


//Email Validation
function ValidateEmail(controlName, errorMessage) {
    if (ValidateSpecialChars(controlName, errorMessage, "email")) 
    {
        //var controlID = clientControlID(clientIDDetail,controlName);
        var controlID = clientID + controlName;
        var emailValue = document.getElementById(controlID).value;
        var spaceValCheck = 0;

        //////////////////////////////////////////// for checking space while validating
        for (z = 0; z < emailValue.length; z++) {
            var Char = emailValue.charAt(z);
            if (Char == ' ') {
                spaceValCheck++;
                break;
            }
        }
        ///////////////////////////////////////////

        var atTheRate = emailValue.indexOf("@");
        var atTheRateCheck = emailValue.substring(atTheRate + 1, emailValue.length).indexOf("@");
        var dot = emailValue.lastIndexOf(".");
        var domain = emailValue.length - 1;
        if (atTheRate < 1 || dot - atTheRate < 2 || domain - dot > 3 || domain - dot < 2 || atTheRateCheck != -1 || spaceValCheck != 0) {
            //Handle error message and display of error messages here
            if (firstErrorControl == '') firstErrorControl = controlID;
            errMsg += GetErrorRow(controlID, errorMessage);
            SetErrorColor(controlID, false);
            return false;
        }
        else {
            //handle else part of error messages.
            SetErrorColor(controlID, true);
            return true;
        }
    }
}


// Zip validation
function ValidateZip(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    errorCode = IsZip(controlID);
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
    }
    else
        SetErrorColor(controlID, true);
}

//checks whether the control with the given id has a valid zip
function IsZip(control) {
    var controlObject = document.getElementById(control);
    var isNumber = zipRegEx.test(controlObject.value);
    if (!isNumber)
        return false;
    else
        return true;
}


//Phone, Mobile, Fax validation
function ValidatePhone(controlName, errorMessage) {
    var nonValidPhoneCharsRegEx = "`~@{}!#$%^\&*{\"}|:<>?=[];,\\ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";    
    var controlID = clientID + controlName;
    var charValue = document.getElementById(controlID).value;
        var check = false;
        for (var i = 0; i < charValue.length; i++) {
            Char = charValue.charAt(i);                
            //if (!(nonValidPhoneCharsRegEx.indexOf(Char) == -1) || noalpha.test(Char)) {
            if (!(nonValidPhoneCharsRegEx.indexOf(Char) == -1)) {                 
                check = true;
                break;                
            }
            }            
            if(check)
            {
                if (firstErrorControl == '') firstErrorControl = controlID;
                    errMsg += GetErrorRow(controlID, errorMessage);
                    
                SetErrorColor(controlID, false);
                return false;
            }
            else {
                SetErrorColor(controlID, true);
                return true;            
            }
}

// Phone Length validation
function ValidatePhoneLength(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    var controlObject = document.getElementById(controlID);
    var phoneLength = controlObject.value;    
    if (parseInt(phoneLength.length) < 10 )
        errorCode = false;
    else
        errorCode = true;
    
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
        SetErrorColor(controlID, true);
    return true;
}

// ZipCode Length validation
function ValidateZipCodeLength(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    var controlObject = document.getElementById(controlID);
    var zipCodeLength = controlObject.value;    
    if (parseInt(zipCodeLength.length) < 5 )
        errorCode = false;
    else
        errorCode = true;
    
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
        SetErrorColor(controlID, true);
    return true;
}
// Numeric validation
function ValidateNumbers(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    errorCode = IsNumber(controlID);
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
        SetErrorColor(controlID, true);
    return true;
}


//checks whether the control with the given id is numeric
function IsNumber(control) {
    //var controlID = clientControlID(clientIDDetail,control);
    //var controlID = clientID + control;
    var controlObject = document.getElementById(control);
    var isNumber = numRegEx.test(controlObject.value);
    if (!isNumber)
        return false;
    else
        return true;
}


// Decimal validation
function ValidateDecimal(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    errorCode = IsDecimal(controlID);
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
        SetErrorColor(controlID, true);
    return true;
}


//checks whether the control with the given id has a valid decimal
function IsDecimal(control) {
    var controlObject = document.getElementById(control);
    var isNumber = twoDecimalRegEX.test(controlObject.value);
    if (!isNumber)
        return false;
    else
        return true;
}

// Two Decimal validation
function ValidateSevenTwoDecimal(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    errorCode = IsSevenTwoDecimal(controlID);
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
        SetErrorColor(controlID, true);
    return true;
}

// Three Decimal validation
function ValidateSevenThreeDecimal(controlName, errorMessage) {
    var errorCode = true;
    var controlID = clientID + controlName;
    errorCode = IsSevenThreeDecimal(controlID);
    if (!errorCode) {
        if (firstErrorControl == '') firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
    else
        SetErrorColor(controlID, true);
    return true;
}


//checks whether the control with the given id has a valid decimal
function IsSevenTwoDecimal(control) {
    var controlObject = document.getElementById(control);
    var isNumber = seventwoDecimalRegEX.test(controlObject.value);
    if (!isNumber)
        return false;
    else
        return true;
}

//checks whether the control with the given id has a valid decimal
function IsSevenThreeDecimal(control) {
    var controlObject = document.getElementById(control);
    var isNumber = seventhreeDecimalRegEX.test(controlObject.value);
    if (!isNumber)
        return false;
    else
        return true;
}

// Sets the Error Color for the specified control
function SetErrorColor(controlID, isCss) {
    var controlToSet = document.getElementById(controlID);
    if (controlToSet)
        if (isCss)
    //controlToSet.className = 'validclass';
        controlToSet.style.backgroundColor = "";
    else
        controlToSet.style.backgroundColor = "#FEE407";
    //controlToSet.className = 'errorclass';        
}

// Gets the Error Row in HTML format
function GetErrorRow(controlID, errorMessage) {
    return "<tr><td onclick=\"SetControlFocus('" + controlID + "')\" ><span class='hand'>" + errorMessage + "</span></td></tr>";
}

// Sets focus on the specified control id
function SetControlFocus(controlID) {
    var controlToFocus = document.getElementById(controlID);
    if (controlToFocus)
        controlToFocus.focus();
}

/////////////////////////////////////////
//form button click recognition
function clickButton(e, buttonid) {

    var bt = document.getElementById(buttonid);
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

// Checks the date format as mm/dd/yyyy
function CheckDateFormat(controlName, errorMessage, clientIDDetail) {
    var controlID1 = clientID + controlName;
    var date = document.getElementById(controlID1).value;
    var controlID = controlID1;
    var checkDate = isDateValid(date);

    if (checkDate != "invalidYear") {
        if (!checkDate) {
            if (firstErrorControl == '')
                firstErrorControl = controlID;
            errMsg += GetErrorRow(controlID, errorMessage);
            SetErrorColor(controlID, false);
            return false;
        }
        else {
            SetErrorColor(controlID, true);
            return true;
        }
    }
    else {
        if (firstErrorControl == '')
            firstErrorControl = controlID;
        errMsg += GetErrorRow(controlID, errorMessage);
        SetErrorColor(controlID, false);
        return false;
    }
}


// Checks if the input is a Valid date
function isDateValid(dtStr) {
    var daysInMonth = new Array("31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
    var dtCh = "/";

    var pos1 = dtStr.indexOf(dtCh);
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1);

    var strDay = dtStr.substring(pos1 + 1, pos2);
    var strMonth = dtStr.substring(0, pos1);
    var strYear = dtStr.substring(pos2 + 1);

    strYr = strYear;

    if (strDay.charAt(0) == "0" && strDay.length > 1)
        strDay = strDay.substring(1);

    if (strMonth.charAt(0) == "0" && strMonth.length > 1)
        strMonth = strMonth.substring(1);

    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1)
            strYr = strYr.substring(1);
    }
    month = parseInt(strMonth);
    day = parseInt(strDay);
    year = parseInt(strYr);
    if (pos1 == -1 || pos2 == -1) {
        return false;
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        return false;
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month - 1]) {
        return false;
    }
    if (strYear.length != 4 || year == 0) {
        if ((parseInt(strYear) < 1900) || (parseInt(strYear) > 2100))
            return "invalidYear";
        else
            return false;
    }
    else {
        if ((parseInt(strYear) < 1900) || (parseInt(strYear) > 2100))
            return "invalidYear";
    }

    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || !isInteger(stripCharsInBag(dtStr, dtCh))) {
        return false;
    }
    return true;
}


// Gets the number of days in february
function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}

// Checks if the passed in value is an integer
function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
            return false;
    }
    // All characters are numbers.
    return true;
}

// Strips a specified character in a string
function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1)
            returnString += c;
    }
    return returnString;
}


function confirmDeletion() {
    return confirm('Are you sure to delete?')
}

//function for comparing todates
function DateComparision(controlName1, controlName2, errorMessage) 
{
    var controlID1 = clientID + controlName1;
    var date1 = document.getElementById(controlID1).value;
    var controlID2 = clientID + controlName2;
    var date2 = document.getElementById(controlID2).value; 

    var dateObj1 = new Date(date1);
    var dateObj2 = new Date(date2);
    if (dateObj1.valueOf() > dateObj2.valueOf()) {
        if (firstErrorControl == '')
            firstErrorControl = controlID2;
        errMsg += GetErrorRow(controlID2, errorMessage);
        SetErrorColor(controlID2, false);
        return false;
    }
    else {
        SetErrorColor(controlID2, true);
        return true;
    }
}

function divProductChkBoxList(checked) {    
    if (checked == true) {
        document.getElementById(clientID + 'divProductLt').style.display = "block";
    } else {        
        document.getElementById(clientID + 'divProductLt').style.display = "none";
    }
}
function divSalesChkBoxList(checked) {
    if (checked == true) {
        document.getElementById(clientID + 'divSales').style.display = "block";
    } else {
        document.getElementById(clientID + 'divSales').style.display = "none";
    }
}

function getLayerWidth(getId)
{
    var str = window.location.toString();        
    
    if(str.toUpperCase().indexOf("/EN/")!=-1)
    {
        if(getId=="register")
            return "420";
        else if(getId=="friend")
            return "637";
        else if(getId=="pricing")
            return "780";               
    }
    else if(str.toUpperCase().indexOf("/ES/")!=-1)
    {
        if(getId=="register")
            return "420";
        else if(getId=="friend")
            return "635";
        else if(getId=="pricing")
            return "780";
    }
    else if(str.toUpperCase().indexOf("/FR/")!=-1)
    {
        if(getId=="register")
            return "420";
        else if(getId=="friend")
            return "635";
        else if(getId=="pricing")
            return "780";
    }
    else if(str.toUpperCase().indexOf("/PT/")!=-1)
    {
        if(getId=="register")
            return "420";
        else if(getId=="friend")
            return "635";
        else if(getId=="pricing")
            return "780";
    }
    else
    {
        if(getId=="register")
            return "420";
        else if(getId=="friend")
            return "635";
        else if(getId=="pricing")
            return "780";
    }
}

function getLayerHeight(getId)
{
    var str = window.location.toString();        
    
    if(str.toUpperCase().indexOf("/EN/")!=-1)
    {
        if(getId=="register")
            return "220";
        else if(getId=="friend")
            return "449";
        else if(getId=="pricing")
            return "600";
    }
    else if(str.toUpperCase().indexOf("/ES/")!=-1)
    {
        if(getId=="register")
            return "220";
        else if(getId=="friend")
            return "505";
        else if(getId=="pricing")
            return "600";
    }
    else if(str.toUpperCase().indexOf("/FR/")!=-1)
    {
        if(getId=="register")
            return "210";
        else if(getId=="friend")
            return "475";
        else if(getId=="pricing")
            return "600";
    }
    else if(str.toUpperCase().indexOf("/PT/")!=-1)
    {
        if(getId=="register")
            return "210";
        else if(getId=="friend")
            return "455";
        else if(getId=="pricing")
            return "600";
    }
    else
    {
        if(getId=="register")
            return "200";
        else if(getId=="friend")
            return "442";
        else if(getId=="pricing")
            return "600";
    }
}

function layerCheckRegister(year) 
{
    layerVal = "Register.aspx?yr=" + year;
    if (GB_CURRENT == null)
        return GB_showCenter(lyrRegister, layerVal, parseInt(getLayerHeight('register')), parseInt(getLayerWidth('register')));
}

function layerCheckProduct() 
{
    layerVal = "Register.aspx";
    if (GB_CURRENT == null)
        return GB_showCenter(lyrProduct, layerVal, parseInt(getLayerHeight('register')), parseInt(getLayerWidth('register')));
}

function layerReferFriend() 
{
    layerVal = "ReferFriend.aspx";
    if (GB_CURRENT == null)
        return GB_showCenter(lyrReferFrnd, layerVal, parseInt(getLayerHeight('friend')), parseInt(getLayerWidth('friend')));
}

function layerPricing(queryStrDetails) 
{
    layerVal = "Pricing.aspx" + queryStrDetails;
    if (GB_CURRENT == null)
        return GB_showCenter("Check Price", layerVal, parseInt(getLayerHeight('pricing')), parseInt(getLayerWidth('pricing')));
}

function layerOrderPreview() 
{
    layerVal = "OrderPreview.aspx";
    if (GB_CURRENT == null)
        return GB_showCenter("Preview Order", layerVal, parseInt(getLayerHeight('pricing')), parseInt(getLayerWidth('pricing')));
}

function layerPrintOrder() {
    layerVal = "PrintOrder.aspx";
    if (GB_CURRENT == null)
        return GB_showCenter("Print Order", layerVal, parseInt(getLayerHeight('printOrder')), parseInt(getLayerWidth('printOrder')));
}

function layerClose()
{
    parent.parent.GB_hide();	
}
function layerCloseRedirect()
{
    //parent.parent.GB_hide();
    parent.parent.window.location="QuoteItems.aspx";
}
function Loaderimage()
{    
    //parent.parent.GB_hide();
    document.getElementById('img').style.display = "block";
}
function childSubmit() 
{
    __doPostBack(document.getElementById('btnRegister').name, '');
}

function fnNewFullWindow(strUrl, strTarget) {
    window.open(strUrl, strTarget, "status=no,toolbar=no,top=180,left=230,scrollbars=1,chrome=yes,menubar= no,location=top,resizable=yes");
}

function KeyPressNumeric() {
    if ((event.keyCode < 48) || (event.keyCode > 57)) {
        event.keyCode = 0;
    }
}

function reqQuantityQuantity(controlID) {
    if ((document.getElementById(controlID).value == "") || (parseInt(document.getElementById(controlID).value) == 0)) {        
        document.getElementById(controlID).value = 1; 
    }
    else if (isNaN(document.getElementById(controlID).value)) {        
        document.getElementById(controlID).value = 1; 
    }
}

function ExcelExport() {
    layerVal = "ExceltoDBUpload.aspx";
    if (GB_CURRENT == null)
        return GB_showCenter(importMsg, layerVal, 250, 415);
}

function fnNewWindow(strUrl, strtarget) {
    window.open(strUrl, strtarget, "width=530,height=420,left=0,top=0,status=no,toolbar=no,scrollbars=yes,chrome=yes,menubar= no,resizable=yes");
}

////////////////////////to reset session time using AJAX //////////////////////
//Add to cart ajax code to write to a temproray XML document
var xmlHttp;
function CreateXMLHTTP()
{
    try
    {   
         // Firefox, Opera 8.0+, Safari    
        xmlHttp=new XMLHttpRequest();    
    }
    catch (e)
    {    
        // Internet Explorer    
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
            }                
            catch (e)
            {
                alert(browserNotSupport);        
                return false;
            }
        }    
     }    
}
function sessionResetAjax(action)
{
    var actionVal = action; 
    var langVal = 'en'; //document.getElementById(masterclientID+'ddlLanguage').value;       
    CreateXMLHTTP();
    if(xmlHttp)
    {       
        var requestURL = "../AjaxService.aspx?";
            requestURL += "UserID=";
            requestURL += actionVal;
            requestURL += "&UserIdVal=";
            requestURL += langVal;
            var tempDate = new Date();
            var tempDay = tempDate.getDate();
            var tempMonth = tempDate.getMonth();
            var tempYear = tempDate.getFullYear();
            var tempHour = tempDate.getHours();
            var tempMin = tempDate.getMinutes();
            var tempSec = tempDate.getSeconds();
            var tempMil = tempDate.getMilliseconds();

            var tempDateString = tempDay + ":" + tempMonth + ":" + tempYear + ':' + tempHour + ':' + tempMin + ':' + tempSec + ':' + tempMil;

            requestURL += "&timeStamp=";
            requestURL += tempDateString;

            xmlHttp.onreadystatechange = sessionResetAjaxResponse;
            xmlHttp.open("GET", requestURL, true);
            xmlHttp.send(null);
     }     
}
//add to cart ajax code to remove href attribute for an item from temporary xml document
function sessionResetAjaxResponse()
 { 
    // 0 The request is not initialized 
    // 1 The request has been set up 
    // 2 The request has been sent 
    // 3 The request is in process 
    // 4 The request is complete 
    
    if(xmlHttp.readyState==4 || xmlHttp.readyState == 'complete')
    {
        if(xmlHttp.status == 200)
        {
            var result = xmlHttp.responseText;            
            return true;
        }
        else
        {
            alert(ajaxError);
            return false;
        }
    }
 } 
 ////////////////////////////////////////////////////////////////////////////
 
//////////////////// For Success message fade out /////////////////
//fades layer out
opac2 = 100;                    
function fadeOut(getId) 
{  
    if(opac2 > 0)
    {       
        opac2-=10;
        if(BrowserDetect.browser=="Explorer") 
            document.getElementById(getId).filters.alpha.opacity = opac2;                            
        else if(BrowserDetect.browser=="Chrome") 
            document.getElementById(getId).style.KhtmlOpacity = opac2/100;                            
        else if(BrowserDetect.browser=="Firefox") 
            document.getElementById(getId).style.MozOpacity = opac2/100;
        setTimeout("fadeOut('"+getId+"')", 0);
    }
    else
    {
        document.getElementById(getId).style.display="none";
    }
}
function fadeTotalOut(getId)
{
    fadeOut(getId);
}
////////////////////////////////////////////////////

//////// State and Country Dropdownlist onChange event Logic starts ///////////////////
//added by :: John Aneston
//Date on  :: 10/27/2009

var otherStateId="598";
var otherStateRowId="trOtherState";
var usaCountryId="100";
var defaultValue="0";
var stateControl="";
var countryControl="";
function StateChange(getValue, getSectionId)
{   
    if(getSectionId=='bill')
    {
        stateControl = document.getElementById(clientID+'ddlBillState');
        countryControl = document.getElementById(clientID+'ddlBillCountry');
        otherStateRowId = "trBillOtherState";
    }
    else if(getSectionId=='ship')
    {
        stateControl = document.getElementById(clientID+'ddlShipState');
        countryControl = document.getElementById(clientID+'ddlShipCountry');
        otherStateRowId = "trShipOtherState";
    }
    else
    {
        stateControl = document.getElementById(clientID+'ddlState');
        countryControl = document.getElementById(clientID+'ddlCountry');
    }
    
    if(getValue==otherStateId)
    {
        document.getElementById(clientID+otherStateRowId).style.display="";
        countryControl.value=defaultValue;
    }
    else
    {
        document.getElementById(clientID+otherStateRowId).style.display="none";
        if(getValue==defaultValue)
            countryControl.value=defaultValue;
        else
            countryControl.value=usaCountryId;
    }
}

function CountryChange(getValue, getSectionId)
{
    if(getSectionId=='bill')
    {
        stateControl = document.getElementById(clientID+'ddlBillState');
        countryControl = document.getElementById(clientID+'ddlBillCountry');
        otherStateRowId = "trBillOtherState";
    }
    else if(getSectionId=='ship')
    {
        stateControl = document.getElementById(clientID+'ddlShipState');
        countryControl = document.getElementById(clientID+'ddlShipCountry');
        otherStateRowId = "trShipOtherState";
    }
    else
    {
        stateControl = document.getElementById(clientID+'ddlState');
        countryControl = document.getElementById(clientID+'ddlCountry');
    }
    
    if(getValue==usaCountryId)
    {
        document.getElementById(clientID+otherStateRowId).style.display="none";
        if(stateControl.options[stateControl.selectedIndex].value==otherStateId)
            stateControl.value=defaultValue;
    }
    else
    {
        document.getElementById(clientID+otherStateRowId).style.display="";
        stateControl.value=otherStateId;
    }
}
//////// State and Country Dropdownlist onChange event Logic ends ///////////////////

//////// Print Order Starts///////////////////
//added by :: Saravanan
//Date on  :: 10/31/2009
//For Print & Close links visible hidden in printing

function fnPrintOrder(orderBtn, closeBtn, contactUsLink)
{    
    document.getElementById(orderBtn).style.visibility = 'hidden';
    document.getElementById(closeBtn).style.visibility = 'hidden';    
    document.getElementById(contactUsLink).style.color = '#000';
    window.print();    
    document.getElementById(orderBtn).style.visibility = 'visible';
    document.getElementById(closeBtn).style.visibility = 'visible';    
    document.getElementById(contactUsLink).style.color = '';
}

//////// Print Order Ends///////////////////
