﻿var ctrlToFocus=null;
var divErrorControl = '';
var divNewErrorDiv = null;
function CheckNumericOnBlur(Src)
{
    var RegExPattern = /^\d{10}$/;
    if(!Src.value.indexOf('<'))
    {
        for(var Count=0;Count<Src.value.length;Count++)
        {            
           Src.value= Src.value.replace('<','');
        }
    }
}


function RemoveToolTip()
{
    var browserName = navigator.appName;
    if(browserName=="Netscape" )
    { 
        var tdArry=document.getElementsByTagName('td');
        for(var i=0;i<tdArry.length;i++)
        {
            tdArry[i].title="";                         
        }    
    }                
    else
    {          
        var divArry=document.getElementsByTagName('div');
        for(var i=0;i<divArry.length;i++)
           divArry[i].title="";
     }        
}

function SetTabPosition()
{
     var ScreenWidth=document.documentElement.clientWidth;
     var TabLeft=((ScreenWidth*1)-document.getElementById('ulMenutab').offsetWidth)/2;
     document.getElementById('ulMenutab').style.left=TabLeft+"PX";
}
function OpenOMB_Form(Src)
{
    if(Src.selectedIndex!="0")
        window.open(Src.options[Src.selectedIndex].value);
    return false;
}

function CloseErrorSummary(divError)
{
   //UnFreezeScreen('');
   //$.modal.close();
   document.getElementById(divError).style.display="none";
   //document.getElementById(divError).style.visibility="hidden";

   if(ctrlToFocus!=null)
        document.getElementById(ctrlToFocus).focus();
   divErrorControl='';
}


var ControlValue='';
function SetPostBackControlId(valId)
{
    ControlValue=valId;
}
 
function BlockandDrag(divId)
{
    divErrorControl=divId;
    
   /* $('#'+divId).modal({
      overlayCss: {
        backgroundColor: '#000',
        cursor: 'default'
      },
      opacity:0,
      position:['25%','25%'],
      persist:true
    });


    $('#'+divId).ppdrag();   */

    if (divNewErrorDiv != null)
        divNewErrorDiv.remove();
    //divNewErrorDiv = $('#' + divId).clone().prependTo('.FormBorder').show("slow");
    
    var prefix = document.getElementById('ctrlPrefix').value;
    if ($('#' + prefix + 'dvShowReports').length > 0) {

        if ($('#' + prefix + 'dvShowReports').is(':visible')) {

            divNewErrorDiv = $('#' + divId).clone().prependTo('.FormBorder').show("slow");
        }
        else if ($('#' + prefix + 'FormSortPlantListing').is(':visible')) {
            divNewErrorDiv = $('#' + divId).clone().prependTo('.FormBorderNoScript2').show("slow");
        }
        else if ($('#' + prefix + 'dvShowFilter').is(':visible')) {
            divNewErrorDiv = $('#' + divId).clone().prependTo('.FormBorderNoScript1').show("slow");
        }

    }
    else if ($('#' + 'divLogin').length > 0) {
        divNewErrorDiv = $('#' + divId).clone().prependTo('#' + 'divLogin').show("slow");
    }
    else if ($('#' + prefix + 'divAddNewAbbreviation').length > 0) {
    divNewErrorDiv = $('#' + divId).clone().prependTo('#' + prefix + 'divAddNewAbbreviation').show("slow");
    }
    else if ($('#' + 'divLockboxSet').is(':visible')) {
        divNewErrorDiv = $('#' + divId).clone().prependTo('.FormBorderNoScript').show("slow");
    }
        else {

        divNewErrorDiv = $('#' + divId).clone().prependTo('.FormBorder').show("slow");
    }
    if (ctrlToFocus != null)
        document.getElementById(ctrlToFocus).focus();
    divErrorControl = '';
}

function OpenErrorSummary(val,text)
{

    var inputValid = true;
    if (typeof(Page_ClientValidate) == 'function')
            inputValid = Page_ClientValidate(val);
   
    if(inputValid)
    {
        document.getElementById('divErrorSummary').style.display="none";
    }
    else
    {
            var ctrlValidator;
            
           
            for(i=0;i < Page_Validators.length; i++)
            {
                ctrlValidator = Page_Validators[i];
                if(ctrlValidator.validationGroup == val || (ctrlValidator.validationGroup == undefined && val==""))
                {
                   
                    //ValidatorEnable(ctrlValidator);        
                    if(!ctrlValidator.isvalid)
                    {
                        ctrlToFocus=ctrlValidator.controltovalidate;
                        break;  
                        
                    }
                }
                
            }

       //document.getElementById('divErrorSummary').style.display="block";
       //document.getElementById('divErrorSummary').style.visibility="visible";
       BlockandDrag('divErrorSummary');
        //FreezeScreen('FreezePane');
       scroll(0, 0);
       Page_ValidationActive = false;
    }
    return inputValid;
}


function OpenClientSummary(text)
{
        //document.getElementById('divErrorMessageClient').style.display="block";
        //document.getElementById('divErrorMessageClient').style.visibility="visible";
        var elem = document.getElementById("spnErrorMessage");
        if (typeof(elem.textContent) != "undefined")
            elem.textContent = text;
        else
            elem.innerText = text;
        BlockandDrag('divErrorMessageClient');
        scroll(0, 0); 
       //     FreezeScreen('FreezePaneErrorClient');
}

function OpenSummary(text)
{
        //document.getElementById('divErrorMessageClient').style.display="block";
        //document.getElementById('divErrorMessageClient').style.visibility="visible";
        var elem = document.getElementById("ulError");
        elem.innerHTML = text;
        BlockandDrag('divErrorMessageClient');
        scroll(0, 0); 
       //     FreezeScreen('FreezePaneErrorClient');
}


function CheckEnter(e)
{
    var element;
    if (e.target) element = e.target;
	else if (e.srcElement) element = e.srcElement;
    if(element.tagName.toLowerCase()=="input" && element.type.toLowerCase()=="text" && element.id.indexOf('Find')==-1)
    {
        if(e.which && e.which==13 || e.which==60 || e.which==62)
         return false;
        if(e.keyCode && e.keyCode==13 || e.keyCode==60 || e.keyCode==62)
        {
            window.event.returnValue = false;
            return false;
         }
     }
     return true;
}

function SpaceTrim(e) {
    if (e.keyCode || e.which) {
        if (e.keyCode == 32) {
            if (window.event != null)
                window.event.returnValue = false;
            return false;
        }
        else if (e.which == 32) {
            return false;
        }
    }
    return true;
}

//validation fo numeric without decimal point
function NumericOnly(e) {

    if (e.keyCode || e.which) {

        if ((e.keyCode >= 48 && e.keyCode <= 57) || e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 39 || e.keyCode == 46 || e.keyCode == 37 || e.keyCode == 35 || e.keyCode == 36) {
          /*  if (String.fromCharCode(e.keyCode) == "#" || String.fromCharCode(e.keyCode) == "$" || String.fromCharCode(e.keyCode) == "%")
                return false;*/
            return true;
        }
        else if ((e.which >= 48 && e.which <= 57) || e.which == 8 || e.which == 9 || e.which == 39 || e.which == 46 || e.which == 37 || e.which == 35 || e.which == 36) {
        /*if (String.fromCharCode(e.which) == "#" || String.fromCharCode(e.which) == "$" || String.fromCharCode(e.which) == "%")
            return false;*/
           
            return true;
        }
        else {
            if (window.event != null)
                window.event.returnValue = false;
            return false;
        }
    }
    return false;
}
function VarNumericOnly(e) {
    if (e.keyCode || e.which) {

        if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 39 || e.keyCode == 46 || e.keyCode == 37 || e.keyCode == 35 || e.keyCode == 36) {
            /*if (String.fromCharCode(e.keyCode) == "#" || String.fromCharCode(e.keyCode) == "$" || String.fromCharCode(e.keyCode) == "%") {
                window.event.returnValue = false;
                return false;
            }*/
                
            return true;
        }
        else if ((e.which >= 48 && e.which <= 57) || (e.which >= 65 && e.which <= 90) || (e.which >= 97 && e.which <= 122) || e.which == 8 || e.which == 9 || e.which == 39 || e.which == 46 || e.which == 37 || e.which == 35 || e.which == 36) {
       /* if (String.fromCharCode(e.which) == "#" || String.fromCharCode(e.which) == "$" || String.fromCharCode(e.which) == "%")
            return false;*/
            
            return true;
        }
        else {
            if (window.event != null)
                window.event.returnValue = false;
            return false;
        }
    }
    return false;
}
       
 
 function escapeError(e)
 {
        if (e.keyCode)
        {
            if(e.keyCode==27)
            {
            if(divErrorControl!='')
               CloseErrorSummary(divErrorControl);
               
            }
            return true;
        }
        else if (e.which) 
        {
            if(e.which==27)
            {
                if(divErrorControl!='')
                  CloseErrorSummary(divErrorControl);
            }
            return true;
        }
 }
 
 function CheckEnterPress(e) {
    if (e.keyCode) {
        if (e.keyCode == 13) {
        
            document.getElementById(document.getElementById('ctrlPrefix').value + "btnFind").click();
        
            
            return false;
        }
    }
    else if (e.which) {
        if (e.which == 13) {
            //document.getElementById(document.getElementById('ctrlPrefix').value + "btnFind").click();
            __doPostBack(document.getElementById(document.getElementById('ctrlPrefix').value + "btnFind").id,'');
            return false;
        }
        //__doPostBack(document.getElementById(document.getElementById('ctrlPrefix').value + "btnFind").id,'');

    }


}

function DisableBackspaceKey(e)
{ 
   if(e.keyCode==8 || e.which==8)
     return false;
   else
    return true;

}

function validateDate(source, args) {
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var txtDateSource = source.parentNode.getElementsByTagName('input')[0];
    if (txtDateSource != null) {
        var dateArray = txtDateSource.value.split('/');
        if (((!txtDateSource.value.match(RegExPattern)) && (txtDateSource.value != '')) || (txtDateSource.value == '')) {

            args.IsValid = false;
            return false;
        }

        else if (dateArray.length == 3 && dateArray[2].length != 4) {
            args.IsValid = false;
            return false;
        }
    }
}

function validateDateFormat(source, args) {
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var txtDateSource = source.parentNode.getElementsByTagName('input')[0];
    if (txtDateSource != null) {
        var dateArray = txtDateSource.value.split('/');
        if (((!txtDateSource.value.match(RegExPattern)) && (txtDateSource.value != ''))) {

            args.IsValid = false;
            return false;
        }
        else
            return true;
    }
}

function trim(str) {
    return str.replace(/^\s+|\s+$/g, "");
}
function FormatText(value) {
    var Length = value.length;
    var Num = 10 - Length * 1
    return FinalValue = zeroPad(value, Num);
}
function zeroPad(num, count) {
    var numZeropad = num;
    while (count > 0) {

        numZeropad = "0" + numZeropad;
        count = count - 1;
    }
    return numZeropad;
}

function zeroPad(num) {
    var numZeropad = '';
    var count = 10 - num.length;
    var indexZero = 0;
    while (indexZero < count) {
        if (numZeropad.length == 0) {
            numZeropad = "0";
        }
        else {
            numZeropad = "0" + numZeropad;
        }
        indexZero = indexZero + 1;
    }
    return numZeropad + num;
}

function ValidateReportDate(reportDate) {

    if (reportDate.length != 0) {
        var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
        if (!reportDate.match(RegExPattern)) {

            return false;
        }
        else {
            return true;
        }

    }
}
function ValidateZipExpression(ZipCode) {

    if (ZipCode.length != 0) {
        var RegExPattern = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
        if (!ZipCode.match(RegExPattern)) {

            return false;
        }
        else {
            return true;
        }

    }
}

function LabelNumericOnly(e) {

    if (e.keyCode) {
        if ((e.keyCode >= 48 && e.keyCode <= 57) || e.keyCode == 8 || e.keyCode == 9) {
            return true;
        }
        else {
            return false;
        }
    }
    else if (e.which) {
        if ((e.which >= 48 && e.which <= 57) || e.which == 8 || e.which == 9) {
            return true;
        }
        else {
            return false;
        }

    }
    // key = window.event.which;
}

function FormatDateString(stringdate) {
    var returnDate = "";
    var Datevalue = stringdate.split('/');
    if (Datevalue.length == 3)
        returnDate = Datevalue[1] + "/" + Datevalue[2] + "/" + Datevalue[0]
    return returnDate;
}


function showdivOnLoad(val) {
    /*SetTabPosition();*/
    if (val == 0)
        showdiv(0);
    if (val == 1)
        showdiv(1);
    if (val == 2)
        showdiv(2);
    if (val == 3)
        showdiv(3);
    if (val == 4)
        showdiv(4);
    if (val == 5)
        showdiv(5);
    if (val == 6)
        showdiv(6);
    if (val == 7)
        showdiv(7);
    if (val == 8)
    {
        showdiv(8);
        ShowMhiDiv(0); 
    }    
    if (val == 9)
    {
        showdiv(8);
        ShowMhiDiv(1); 
    }          

}
//window.onload=;
//-----------------------------For Tabs
var LnkArray = new Array("lnkUser", "lnkUserType", "lnkIpia", "lnkManufacturer", "lnkPlant",
"lnkResetPassword", "lnkAuditTrail", "lnkGeneralSettings","lnkMHI");
var ActiveArray = new Array("tabuser_active", "lnkUserType", "tabipia_active", "tabmanufacturer_active", "tabplant_active",
"tabresetPasswrd_active", "tabauditTrial_active", "tabgeneralSettings_active","tabretailerAsso_active");
var NormalArray = new Array("tabuser_normal", "lnkUserType", "tabipia_normal", "tabmanufacturer_normal", "tabplant_normal",
"tabresetPasswrd_normal", "tabauditTrial_normal", "tabgeneralSettings_normal","tabretailerAsso_normal");
//window.onload=showdivOnLoad;
function showdiv(No) {

    document.getElementById(document.getElementById('ctrlPrefixAdminMaster').value + 'hdnDivID').value = No;
    for (var DivNo = 0; DivNo < LnkArray.length; DivNo++) {
        if (DivNo != No) {
            document.getElementById(LnkArray[DivNo]).style.backgroundImage = "url( ../../Resources/Images/Icons/" + ActiveArray[DivNo] + ".gif)";
            //document.getElementById(LnkArray[DivNo]).style.borderbottom="solid 1px #fff";
            // document.getElementById(LnkArray[DivNo]).style.color ="#FFFFFF" ;
        }
        else {
            document.getElementById(LnkArray[DivNo]).style.backgroundImage = "url(../../Resources/Images/Icons/" + NormalArray[DivNo] + ".gif)";
            document.getElementById(LnkArray[DivNo]).style.borderBottom = "solid 1px #fff";
        }
    }
    return false;
}
var MhiLnkArray=new Array("lnkdealer","lnkCity");
var MhiActiveArray=new Array("tabDealerMapping_normal","tabCityMapping_normal");
var MhiNormalArray=new Array("tabDealerMapping_active","tabCityMapping_active");
function ShowMhiDiv(No) {
    document.getElementById(document.getElementById('ctrlPrefixAdminMaster').value + 'hdnDivID').value = No;
    for (var DivNo = 0; DivNo < MhiLnkArray.length; DivNo++) {
        if (DivNo != No) {
             document.getElementById(MhiLnkArray[DivNo]).style.backgroundImage = "url( ../../Resources/Images/Icons/" + MhiActiveArray[DivNo] + ".gif)";
             document.getElementById(MhiLnkArray[DivNo]).style.borderBottom = "solid 1px #fff";
        }
        else {
            document.getElementById(MhiLnkArray[DivNo]).style.backgroundImage = "url( ../../Resources/Images/Icons/" + MhiNormalArray[DivNo] + ".gif)";
           // document.getElementById(MhiLnkArray[DivNo]).style.borderBottom = "solid 1px #fff";
        }
    }
    return false;
}

var IconArray=new Array("lnkAdmin","lnkForm101","lnkForm301","lnkForm302","lnkOMBForms",
                        "lnkUpdate","lnkAdjust","lnkSearch","lnkPlantHistory","lnkLockBox",
                        "lnkAbbreviations","lnkLabelList","lnkReports","lnkPlantList","lnkIPIAList"
                        ,"lnkHQUpdate","lnkHQAdjust");
                        
var IconActiveArray=new Array("icn_admin_active","icn_f101_active","icn_f301_active","icn_f302_active","icn_obm_active",
                        "icn_update_active","icn_adjust_active","icn_search_active","icn_PHist_active","icn_Lbox_active",
                        "icn_abbre_active","icn_Llist_active","icn_reports_active","icn_Plist_active","icn_Ilist_active",
                        "icn_updateHQ_active", "icn_adjustHQ_active");
                        
/*var IconNormalArray=new Array("icn_admin","icn_f101_dactive","icn_f301_dactive","icn_f302_dactive","icn_obm_dactive",
                        "icn_update_dactive","icn_adjust_dactive","icn_search_dactive","icn_PHist_dactive","icn_Lbox_dactive",
                        "icn_abbre_dactive","icn_Llist_dactive","icn_reports_dactive","icn_Plist_dactive","icn_Ilist_dactive",
                        "icn_adjustHQ_dactive","icn_updateHQ_dactive");*/
                        

                        
function HighlightIcon(No) {
var IconPRefix=document.getElementById('ctrlPrefixMaster').value;
     document.getElementById(IconPRefix + 'hdnIconId').value = No;
    for (var DivNo = 0; DivNo < IconArray.length; DivNo++) {
        if (DivNo != No) {
            if(document.getElementById(IconPRefix+IconArray[DivNo])!=null)
                document.getElementById(IconPRefix+IconArray[DivNo]).className=IconArray[DivNo];
        }
        else {
            if(No==0)
            {
                 if(document.getElementById(IconPRefix+IconArray[DivNo])!=null)
                    document.getElementById(IconPRefix+IconArray[DivNo]).style.backgroundImage = "url( ../../Resources/Images/Icons/" + IconActiveArray[DivNo] + ".gif)";
            }
            else
            {
                if (document.getElementById(IconPRefix + IconArray[DivNo]) != null)
                    document.getElementById(IconPRefix+IconArray[DivNo]).style.backgroundImage = "url( ../Resources/Images/Icons/" + IconActiveArray[DivNo] + ".gif)";
             }
        }
    }
    return false;
}

// JScript File

var lastRowSelected=null; 
function setClickEvent(element,rowIndex) { 
    if( document.getElementById("ctl00_ctl00_DefaultMaster_DefaultAdminLayout_hdnIndex")!=null)
        document.getElementById("ctl00_ctl00_DefaultMaster_DefaultAdminLayout_hdnIndex").value = rowIndex;
    else
        document.getElementById("ctl00_DefaultMaster_hdnIndex").value = rowIndex; 
    if (lastRowSelected != element) 
    { 
        if (lastRowSelected !=null) 
        { 
            lastRowSelected.style.backgroundColor = originalColor; 
            lastRowSelected.style.color = 'Black' 
            lastRowSelected.style.fontWeight = 'normal'; 
        } 
    originalColor = element.style.backgroundColor 
    element.style.backgroundColor= '#CBE6F7' 
    element.style.color = 'black' 
    lastRowSelected = element; 
    } 
} 
function setMouseOverColor(element) 
{ 
    element.style.cursor='pointer'; 
    
} 

function setMouseOutColor(element) 
{ 
    element.style.textDecoration='none'; 
}


var myimages = new Array()
function preloadimages() {
    for (i = 0; i < preloadimages.arguments.length; i++) {
        myimages[i] = new Image(40,33);
        myimages[i].src = "../Resources/Images/Icons/" + preloadimages.arguments[i];
    }
}


function NumericOnlyForZipCode(e) {

    if (e.keyCode || e.which) {

        if ((e.keyCode >= 48 && e.keyCode <= 57) || e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 39 || e.keyCode == 46 || e.keyCode == 37 || e.keyCode == 35 || e.keyCode == 36 || e.keyCode == 45) {
            /*  if (String.fromCharCode(e.keyCode) == "#" || String.fromCharCode(e.keyCode) == "$" || String.fromCharCode(e.keyCode) == "%")
            return false;*/
            return true;
        }
        else if ((e.which >= 48 && e.which <= 57) || e.which == 8 || e.which == 9 || e.which == 39 || e.which == 46 || e.which == 37 || e.which == 35 || e.which == 36 || e.which == 45) {
            /*if (String.fromCharCode(e.which) == "#" || String.fromCharCode(e.which) == "$" || String.fromCharCode(e.which) == "%")
            return false;*/
            return true;
        }
        else {
            if (window.event != null)
                window.event.returnValue = false;
            return false;
        }
    }
    return false;
}
//Added By Anish on 15/01/2010
function ChangePasswordEnterPress(e) {
    if (e.keyCode) {
        if (e.keyCode == 13) {

            document.getElementById(document.getElementById('ctrlPrefix').value + "btnChangePassword").click();


            return false;
        }
    }
}

//Added By Anish on 10/Mar/2010
function HidePasswordBox() {
    document.getElementById(document.getElementById('ctrlPrefix').value + "divMainPasswordBox").style.display = "none";
}