﻿var IP = '';
function init() {
    if(browserLbl == "IE")
    {
        if(browserVLbl == "6.0")
        {
            patchIE6CSS();
        }
    }
    ChangeCSSForLang();
    $("table.mainMenuDynamicitemStyle").each(setMenuItemsDivs); 
    $("img.internal").each(setImgsPath); 
    $("a").each(setLinksHref);     


    $("button").each(setButtonsLocation);     
    //    try
    //    {
    //        $.getJSON("http://jsonip.appspot.com?callback=?",function(data){
    //            IP = data.ip;
    //        });
    //    }
    //    catch(err)
    //    {
    //    }



    $("#languagesButton").click(languagesButtonClick)
    $("#LanguagesDDlistTable").mouseleave(closeLanguagePanel)
//    $("#CapitalButton").click(CapitalButtonClick)
//    $("#CapitalDDlistTable").mouseleave(closeLanguagePanel)
    $("input.numeric").each(setNumericIputs); 
    $("input.userNamePass").each(setUserNamePassIputs); 
    $("input.cancel").each(setCancelBtnConfirm);
    try
    {
        disableLogin(); 
    }
    catch(err)
    {
    }
    
    try
    {
        CheckSideMenu(); 
    }
    catch(err)
    {
    }
    document.getElementById(ScreenResolutionClientID).value = screen.width + "x" + screen.height;

    try
    {
        setHumanValidationIframe();
    }
    catch(err)
    {
    }
    try
    {
        setRefresh(); //dinamic refresh after changing interface
    }
    catch(err)
    {
    }
    try
    {
        if(translatorMode != "true")
        {
            initRates(LangLbl);
        }
    }
    catch(err)
    {
    }                
}
function languagesButtonClick() {
    if ($("#LanguagesDDlistTable").css("display") == "none") {
        $("#LanguagesDDlistTable").css("display", "block");
        $("#languagesButtonOn").css("display", "block");
        $("#languagesButtonOff").css("display", "none");
    } else {
        closeLanguagePanel();
    }
}
function closeLanguagePanel() {
    $("#LanguagesDDlistTable").css("display", "none");
    $("#languagesButtonOn").css("display", "none");
    $("#languagesButtonOff").css("display", "block");
}

function CapitalButtonClick() {
    if ($("#CapitalDDlistTable").css("display") == "none") {
        $("#CapitalDDlistTable").css("display", "block");
        $("#CapitalButtonOn").css("display", "block");
        $("#CapitalButtonOff").css("display", "none");
    } else {
        closeCapitalPanel();
    }
}
function closeCapitalPanel() {
    $("#CapitalDDlistTable").css("display", "none");
    $("#CapitalButtonOn").css("display", "none");
    $("#CapitalButtonOff").css("display", "block");
}
function setButtonsLocation() {
    if(typeof($(this).attr("onclick")) !== 'undefined' && $(this).attr("onclick") != null) 
    {
        var langPref = '';
        lang = '/'+LangLbl.replace(/^\s+|\s+$/g, '');
        if(lang.indexOf('/en') == 0)
        {
        }
        else if (lang.indexOf('/he') == 0) 
        {
        }
        else if(lang == '/')
        {
        }
        else
        {
            langPref = lang;
        }    
        
        var onclickScript = $(this).attr("onclick").toString();
        if(onclickScript.indexOf("location.href") > -1)
        {
            if(onclickScript.indexOf("http") == -1)
            {
                if(onclickScript.indexOf("\"") > -1)
                {
                    onclickScript = onclickScript.substring(onclickScript.indexOf("\"")+1);
                    onclickScript = onclickScript.replace("\"", "");
                }
                else if(onclickScript.indexOf("'") > -1)
                {
                    onclickScript = onclickScript.substring(onclickScript.indexOf("'")+1);
                    onclickScript = onclickScript.replace("'", "");
                }
                var addLang = true;
                if(onclickScript.indexOf(langPref+"/") > -1)
                {
                    addLang = false;
                }
                if(onclickScript.indexOf(BaseUrl) == -1)
                {
                    if(addLang)
                        onclickScript = BaseUrl+langPref+ onclickScript;
                    else
                        onclickScript = BaseUrl+onclickScript;
                }
                else if($(this).attr("onclick").indexOf(BaseUrl+langPref) == -1)
                {
                    if(addLang)
                        onclickScript = BaseUrl+langPref+ onclickScript.replace(BaseUrl, "");
                    else
                        onclickScript = BaseUrl+onclickScript.replace(BaseUrl, "");
                }
                onclickScript = onclickScript.replace("function onclick(event) {", "").replace("}", "").substring(onclickScript.indexOf(";"), "");

                $(this).unbind("click");
                $(this).removeAttr( "onclick" )
                $(this).click(function() {location.href = onclickScript;return false;});
            }
        }
    }
}

function ChangeCSSForLang()
{
    $("#menuDiv").addClass(LangLbl+'Menu');
    if(browserLbl == "IE")
    {
        if(browserVLbl != "6.0")
        {
            $("#divLogin").addClass(LangLbl+'DivLogin');
            $("#divLiveHelp").addClass(LangLbl+'DivLiveHelp');
        }
    }
    else
    {
        $("#divLogin").addClass(LangLbl+'DivLogin');
        $("#divLiveHelp").addClass(LangLbl+'DivLiveHelp');
    }
}

function TrimString(sInString)
{
    return sInString.replace(/(^\s+)|(\s+$)/g, "");
}

function CheckSideMenu()
{
    if(TrimString(document.getElementById("SideMenuDiv").innerHTML) == "")
    {
        document.getElementById("SideMenuDiv").style.display = "none";
    }else
    {
        document.getElementById("SideMenuDiv").style.display = "block";
    }
}

function setCancelBtnConfirm()
{
    $(this).bind('click',function(){ if (!window.confirm(CancelConfirm)){ return false; } else { return true; }});
}

function setMenuUnvisible()
{
    if(Mode != "Edit")
    {
        if($(this).css("display") != "none")
        {
            $(this).css("display", "none");
        }
    }
    else
    {
        $(this).css("display", "block");
        $(this).css("opacity", "0.7");
    }
}

function setUserNamePassIputs()
{
    $(this).bind("keypress", isUserNamePassSymbol);
}


function setNumericIputs()
{
    $(this).bind("keypress", isNumbers);
}

function setButtonLinks()
{
    if($(this).find("div").html() != null)
    {
    }
}

function setImgsPath()
{
    if($(this).attr("src").indexOf(BaseUrl) == -1)
    {
        $(this).attr("src",BaseUrl+$(this).attr("src"));
    }
}
function ButtonWindowOpen(URL)
{
    var langPref = '/'+LangLbl.replace(/^\s+|\s+$/g, '');        
    if(langPref.indexOf('/en') != 0 && langPref.indexOf('/he') != 0)
    {        
        window.open(langPref + URL);
    }
    else
    {
        window.open(URL);
    }
}
function setLinksHref()
{
    if (typeof ($(this).attr("href")) !== 'undefined' && $(this).attr("href") != null) 
    {
        var href = $(this).attr("href").toString();
        if(href.indexOf("#") > -1) {
            return;
        }
        if((href.indexOf("http") == -1) && (href.indexOf("mailto:") == -1) && (href.indexOf("javascript:") == -1))
        {
            var saveInnerHtml = false;
            var innerHtml = "";
            if(browserLbl == "IE")
            {
                if($(this).attr("href").indexOf("Mail") >= 0)
                {
                    innerHtml = $(this).html();
                    saveInnerHtml = true;
                }
            }
            var langPref = '';
            lang = '/'+LangLbl.replace(/^\s+|\s+$/g, '');
            if(lang.indexOf('/en') == 0)
            {
            }
            else if (lang.indexOf('/he') == 0) 
            {
            }
            else if(lang == '/')
            {
            }
            else
            {
                langPref = lang;
            }    
            var addLang = true;
            if(href.indexOf(langPref+"/") > -1)
            {
                addLang = false;
            }
            if($(this).attr("href").indexOf(BaseUrl) == -1)
            {
                if(addLang)
                    $(this).attr("href",BaseUrl+langPref+$(this).attr("href"));
                else
                    $(this).attr("href",BaseUrl+$(this).attr("href"));
            }
            else if($(this).attr("href").indexOf(BaseUrl+langPref) == -1)
            {
                if(addLang)
                    $(this).attr("href",BaseUrl+langPref+$(this).attr("href").replace(BaseUrl, ""));
                else
                    $(this).attr("href",BaseUrl+$(this).attr("href").replace(BaseUrl, ""));
            }
            if(browserLbl == "IE")
            {
                if(saveInnerHtml)
                {
                    $(this).html(innerHtml);
                }
            }
        }
    }
}

function setAllLinksToHttps()
{
    if($(this).attr("href") != null)
    {
        if($(this).attr("href").indexOf("https:") == -1)
        {
            var saveInnerHtml = false;
            var innerHtml = "";
            if(browserLbl == "IE")
            {
                if($(this).attr("href").indexOf("Mail") >= 0)
                {
                    innerHtml = $(this).html();
                    saveInnerHtml = true;
                }
            }
            var langPref = '';
            lang = '/'+LangLbl.replace(/^\s+|\s+$/g, '');
            if(lang.indexOf('/en') == 0)
            {
            }
            else if (lang.indexOf('/he') == 0) 
            {
            }
            else if(lang == '/')
            {
            }
            else
            {
                langPref = lang;
            }   
                  
            $(this).attr("href",$(this).attr("href").replace("http:","https:"));
            
            if(browserLbl == "IE")
            {
                if(saveInnerHtml)
                {
                    $(this).html(innerHtml);
                }
            }
        }
    }
}

function setLinksHrefForResources()
{
    var saveInnerHtml = false;
    var innerHtml = "";
    if(browserLbl == "IE")
    {
        if($(this).attr("href").indexOf("Mail") >= 0)
        {
            innerHtml = $(this).html();
            saveInnerHtml = true;
        }
    }

    $(this).attr("href",$(this).attr("href").replace(BaseUrl + "/", "/"));

    if(browserLbl == "IE")
    {
        if(saveInnerHtml)
        {
            $(this).html(innerHtml);
        }
    }
}

function setMenusVisible()
{
    $(this).css("display", "block");
    if($(this).find("a"))
    {
        href = $(this).find("a").attr("href")
        href = href.substring(href.lastIndexOf('/')+1)
        href = href.substring(0,href.lastIndexOf('.'));
        if(document.getElementById(pageName).innerHTML == href)
        {
            html = $(this).html();
            $(this).empty();
            $(this).html("<div>"+html+"</div>");
        }
    }
}

function showTreeView()
{
    if($("div.editorTreeView").css("width") == "0px")
    {
        $("div.editorTreeView").css("border-style","solid");
        $("div.editorTreeView").animate({width: "200"}, 300);
    }
    else
    {
        $("div.editorTreeView").animate({width: "0"}, 300);
        $("div.editorTreeView").css("border-style","none");
    }
}

function showBackUpsList()
{
    if($("div.resourceBackUpListDiv").css("height") == "0px")
    {
        var hiddenField = $get(triggerRun);
        if (hiddenField) 
        {
            __doPostBack(triggerRun,'');                        
        }
        $("div.resourceBackUpListDiv").css("border-style","solid");
        $("div.resourceBackUpListDiv").animate({height: "475"}, 300);
        
    }
    else
    {
        $("div.resourceBackUpListDiv").animate({height: "0"}, 300);
        $("div.resourceBackUpListDiv").css("border-style","none");
    }
}

function loadPopup()
{
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popup").fadeIn("slow");
        popupStatus = 1;
    }
}
function loadWaitBox() {
    $("#backgroundPopup").css({
        "opacity": "0.7"
    });
    $("#backgroundPopup").fadeIn(1500);
    $("#waitBox").fadeIn(1500);
}
function disablePopup()
{
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#popup").fadeOut("slow");
        popupStatus = 0;
    }
}

function centerPopup()
{
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popup").height();
    var popupWidth = $("#popup").width();
    $("#popup").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2 + document.documentElement.scrollTop,
        "left": windowWidth/2-popupWidth/2
    });
    $("#backgroundPopup").css({
        "height": windowHeight
    });
}
function centerWaitBox() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#waitBox").height();
    var popupWidth = $("#waitBox").width();
    $("#waitBox").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2 + document.documentElement.scrollTop,
        "left": windowWidth / 2 - popupWidth / 2
    });
    $("#backgroundPopup").css({
        "height": windowHeight
    });
}                

function setRefresh()
{
    if(refreshPage == "true")
    {
        window.location = window.location;                    
    } 
}

function ApplyScript() {
    try
    {
    }
    catch(err)
    {
    }
}

function normalizeTextForPage(text){
    var result = text;
    result = result.replace(/&lt;/gi, "<");
    result = result.replace(/&gt;/gi, ">");
    return result;
}

function normalizeTextForResources(text){
    var result = text;
    while (result.indexOf("src=\"" + BaseUrl + "/") >= 0)
    {
        result = result.replace("src=\"" + BaseUrl + "/", "src=\"/");
    }
    var script = '';
    var noscript = '';
    
    
    var scriptIndex = result.indexOf('<script');
    var noScriptIndex = result.indexOf('<noscript');
    if(scriptIndex > -1)
    {
        script = result.substring(result.indexOf('<script'),result.lastIndexOf('</script>')+9);
        result = result.substring(0,result.indexOf('<script')-1);
    }
    if(noScriptIndex > -1)
    {
        noscript = result.substring(result.indexOf('<noscript'),result.lastIndexOf('</noscript>')+11);
        result = result.substring(0,result.indexOf('<noscript')-1);
    }
    $("#ResultDiv").html(result);
    $("#ResultDiv a.internal").each(setLinksHrefForResources); 
    result = $("#ResultDiv").html();
    $("#ResultDiv").html("");
    result = result + script + noscript;
    while (result.indexOf("location=\"" + BaseUrl + "/") >= 0)
    {
        result = result.replace("location=\"" + BaseUrl + "/", "location=\"/");
    }
    result = result.replace(/</g, "&lt;");
    result = result.replace(/>/g, "&gt;");
    return result;
}


function showChangesOnSuccess(value, ctx, methodName) {
    document.getElementById(key).innerHTML = normalizeTextForPage(value);
} 

function showPopupOnSuccess(value, ctx, methodName) { 
    centerPopup();
    loadPopup();
    
    document.aspnetForm.TextBoxMeta.value = normalizeTextForPage(value);
    var oEditor = FCKeditorAPI.GetInstance(resTextID);
    oEditor.SetHTML(normalizeTextForPage(value));
    if(methodName == 'GetResourceBackUP')
    {
    }
    else if(methodName == 'GetResourceValue')
    {
        $("div.resourceBackUpListDiv").css("border-style","none");
        $("div.resourceBackUpListDiv").css("height","0px");
        $('#'+triggerRun).val(resourcesPath + ';' + fileName + ';' + lang + ';' + key);
        if((key.indexOf('PageResource1.Title') >= 0) || (key.indexOf('metaTagsTitleResource1.Text') >= 0))
        {
            $("#fckEditorHideDiv").css('display','none');
            $("#TextBoxMeta").css('display','block');
        }
        else
        {
            $("#fckEditorHideDiv").css('display','block');
            $("#TextBoxMeta").css('display','none');
        }
    }
}

function showWaitBox() {
//    centerWaitBox();// dima zmani
//    loadWaitBox();
    return true;
} 


function switchEditorMode() { 
    if($("#TextBoxMeta").css('display') == 'none')
    {
        $("#fckEditorHideDiv").css('display','none');
        $("#TextBoxMeta").css('display','block');
    }
    else
    {
        $("#fckEditorHideDiv").css('display','block');
        $("#TextBoxMeta").css('display','none');
    }
} 

function showPopupOnFailed(ex, ctx, methodName) { 
    try
    {
        alert('exceptionType = ' + ex.get_exceptionType()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('message = ' + ex.get_message()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('timedOut = ' + ex.get_timedOut()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('statusCode = ' + ex.get_statusCode()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('stackTrace = ' + ex.get_stackTrace()); 
    }
    catch(err)
    {
    }

} 

function showPopup(PresourcesPath,PfileName,Plang,Pkey) {                    
    resourcesPath = PresourcesPath;
    fileName = PfileName;
    lang = Plang;
    key = Pkey;
    var ctx = null;
    try
    {
        ResourcesWebService.GetResourceValue(BaseUrl,resourcesPath,fileName,lang,key,showPopupOnSuccess, showPopupOnFailed, ctx);
    }
    catch(err)
    {
        alertException(err);
    }
}


function getBackUp(resId)
{
    var ctx = null;
    ResourcesWebService.GetResourceBackUP(resId.toString(),showPopupOnSuccess, showPopupOnFailed, ctx);
}

function okPopupOnSuccess(value, ctx, methodName) 
{ 
} 

function okPopupOnFailed(ex, ctx, methodName) 
{ 
    alertException(ex);
} 
function alertException(ex)
{
    try
    {
        alert('name = ' + ex.name ); 
    }
    catch(err)
    {
    }
    try
    {
        alert('message = ' + ex.message ); 
    }
    catch(err)
    {
    }
    try
    {
        alert('description = ' + ex.description ); 
    }
    catch(err)
    {
    }
    try
    {
        alert('exceptionType = ' + ex.get_exceptionType()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('message = ' + ex.get_message()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('timedOut = ' + ex.get_timedOut()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('statusCode = ' + ex.get_statusCode()); 
    }
    catch(err)
    {
    }
    try
    {
        alert('stackTrace = ' + ex.get_stackTrace()); 
    }
    catch(err)
    {
    }
}

function okPopup() {
    var ctx = null;
    var textValue;
    if($("#TextBoxMeta").css('display') == 'block')
    {
        textValue = document.aspnetForm.TextBoxMeta.value;
    }
    else
    {
        var oEditor = FCKeditorAPI.GetInstance(resTextID);
        try
        {
            textValue = oEditor.GetHTML();
        }
        catch(err)
        {
            alertException(err);
        }
    }                    
    textValue = normalizeTextForResources(textValue);
    ResourcesWebService.SetResourceValue(RequestPath,BaseUrl,resourcesPath,fileName,lang,key,textValue,userIdLbl,okPopupOnSuccess, okPopupOnFailed, ctx);
    disablePopup();
}

function updateRates(lang)
{
    var ctx = null;
    ResourcesWebService.GetRatesTable(BaseUrl, GlobalResourcesPath,lang, getRatesOnSuccess, getRatesOnFailed, ctx);
    setTimeout("updateRates('"+lang+"')",15000);
} 
function getRatesOnSuccess(value, ctx, methodName) { 
    setRatesHTML(value);
} 
function getRatesOnFailed(ex, ctx, methodName) 
{ 
} 

function setBCGroundImageOnOver(obj)
{
    $(obj).css('background-image',$(obj).css('background-image').replace('.gif','_.gif'));
}

function setBCGroundImageOnOut(obj)
{
    $(obj).css('background-image',$(obj).css('background-image').replace('_.gif','.gif'));
}

function isNumbers(ev)
{
    var key;
    var keychar;

    if (window.event)
       key = window.event.keyCode;
    else if (ev)
       key = ev.which;
    else
       return true;
    keychar = String.fromCharCode(key);
    
    if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) )
       return true;
    else if ((("0123456789").indexOf(keychar) > -1))
       return true;
    else
       return false;                    
}

function isUserNamePassSymbol(ev)
{
    var key;
    var keychar;
    key = (window.event) ? event.keyCode : ev.which;
    if(key == 0 || key == 8)
    {
         return true;
    }
    keychar = String.fromCharCode(key);
    var re = new RegExp("[a-z]|[A-Z]|[0-9]");
    var OK = re.exec(keychar);

    if (!OK)
    {
      return false;  
    }
    else
    {
      return true;
    }
}

function HoverParents(id, parentSnake)
{
    try
    {
        var parents = parentSnake.toString().split(',');
        if(parentSnake == "ctl00_MainMenu_MainMenun")
        {
            Menu_HoverStatic(document.getElementById(id));
        }
        else
        {
            Menu_HoverDynamic(document.getElementById(id));


            for(i = 0;i < parents.length;i++)
            {
                if(parents[i] != '')
                {
                    Menu_HoverStatic(document.getElementById(parents[i]));
                }
            }
        }
    }
    catch(err)
    {
    }
    moveMenu(id,parentSnake);
}

function UnhoverParents(id, parentSnake)
{ 
    try
    {
        Menu_Unhover(document.getElementById(id));
       
        var parents = parentSnake.toString().split(',');
        for(i = 0;i < parents.length;i++)
        {
            if(parents[i] != '')
            {
                Menu_Unhover(document.getElementById(parents[i]));
            }
        }
    }
    catch(err)
    {
    }
    if(browserLbl == "IE")
    {
        if(browserVLbl != "6.0")
        {
            //$("#"+id+"Items").removeClass('mainMenuDynamicStyleFix');
        }
    }
}

function moveMenu(id,parentSnake)
{
    if(browserLbl == "IE")
    {
        if(browserVLbl == "6.0")
        {
            if(parentSnake.indexOf(",") > -1)
            {
                var parents = parentSnake.toString().split(',');
                moveMenuWithID(parents[0]);
            }
            else
            {
                moveMenuWithID(id);
            }
        }
        else
        {
            //moveMenuWithIDForIE(id);    
        }
    } 
    else if(browserLbl == "AppleMAC-Safari")
    {
        //alert(id);
    } 
    
}

function moveMenuWithIDForIE(id)
{
    itemsDivId = id + "Items";
    if(document.getElementById(itemsDivId) != null)
    {
        $("#"+itemsDivId).addClass('mainMenuDynamicStyleFix');
    }
    else
    {
        window.status = itemsDivId;
    }
}

function moveMenuWithID(id)
{
    itemsDivId = id + "Items";
    document.getElementById(itemsDivId).style.left = (document.getElementById(itemsDivId).style.left.replace("px", "") - 240 + Math.floor((1260 - document.documentElement.clientWidth)/2)) + "px";
}

function setMenuItemsDivs()
{
    var href = $(this).find("a").attr("href");
    $(this).find("td").bind("click", function(){
        window.location=href;
    });
}

function allDigits( str ) 
{
    var foo=str.split( '' ); 
    for( var idx=0; idx < foo.length; idx++ ) 
    {
        if( !isDigit(foo[idx]) ) 
        {
            return false;
        }
    }
    return true;
}    
function isDigit( s ) 
{
    if( s.length > 1 ) 
    {
        return false;
    }
    var nums='1234567890';
    if(nums.indexOf(s) != -1) 
    {
        return true;
    }
    else
    {
        return false;
    }
}    

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 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 );
}

function DaysArray(n) 
{
    for (var i = 1; i <= n; i++) 
    {
	    this[i] = 31
	    if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
	    if (i==2) {this[i] = 29}
    } 
    return this
}

function isDate(dtStr)
{
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    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)
    {
	    //alert("The date format should be : mm/dd/yyyy")
	    return false
    }
    if (strMonth.length<1 || month<1 || month>12)
    {
	    //alert("Please enter a valid month")
	    return false
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
    {
	    //alert("Please enter a valid day")
	    return false
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
    {
	    //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
	    return false
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || allDigits(stripCharsInBag(dtStr, dtCh))==false)
    {
	    //alert("Please enter a valid date")
	    return false
    }
    return true
}

$(document).ready(function() {
    (function($) {
        $.fn.reverseOrder = function() {
            return this.each(function() {
                $(this).prependTo($(this).parent());
            });
        };
    })(jQuery);

    adjustTotalWidth();
    $('li.headlink').hover(
        function() {
            if ($('ul', this).queue() != undefined) {
                var width = $(this).width();
                if ($('ul', this).queue().length == 0) {
                    $('ul', this).slideDown(0);
                    adjustMinWidth($('ul', this), width);
                }
                $(this).css('width', width);
            }
        },
        function() {
            $('ul', this).slideUp(0);
        }
    );

        if ($('li.headlink:first').css('direction') == 'rtl') {
            $('#mainManuDiv li.headlink').reverseOrder();
    }
});

var adjustMinWidth = function(element, minwidth) {
    //ie doesn't like min-width property so we have to do that.
    if ($.browser.msie) {
        var subMenuWidth = element.width();
        var headMenuWidth = minwidth;
        if (subMenuWidth < headMenuWidth) {
            element.css('width', minwidth);
        }
    }
    else {
        element.css('min-width', minwidth);
    }
}

var adjustTotalWidth = function() {
    var sumWidth = 0;
    var countLi = 0;
    $('li.headlink').each(function() {
        countLi += 1;
        sumWidth += $(this).width();
    });
    if ($('#headerDiv').width() != sumWidth) {
        var dif = $('#headerDiv').width() - sumWidth;
        var addWidth = Math.floor(dif / countLi);
        var temp = dif - addWidth * countLi;
        var i = 0;
        $('li.headlink').each(function() {
            i += 1;
            if (i == 1) {
                $(this).css('width', $(this).width() + addWidth + temp);

            }
            else {
                $(this).css('width', $(this).width() + addWidth);
                $(this).css('text-align', 'center');
            }
        });
    }
    $('#mainManuDiv').css('visibility', 'visible');
}



