function Load() {

    doResize(); 
    LoadFlash();
    InitDropDownList();
    
	$(window).bind('resize', function() {
	        doResize();
    });
    
    $(".maincontent").each(function(){
        if ( $(".mainpic").height() >= $(this).height()  ) {
            $(this).css("height", $(".mainpic").height() - 80);
        }
    });
    
    $(".focusempty").each(function(){$(this).focusEmpty()});
    
    $("*[rel=jsabox_img]").click(function() {
        
        $("#jsaboxcontent").html("<div class='lightboxcontent'><img src='Images/close.png' class='close' /><img src='" + $(this).attr("href") + "' /></div>");
        
        $(".lightboxcontent").click(function(){return false;});
        $(".lightboxcontent .close").click(function(){CloseItem();});

        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsabox_swf]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");        
        $("#jsabox").show();
        LoadFlash();
        return false;
    });

    $("*[rel=jsabox_html]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");        
        $("#jsabox").show();
        LoadFlash();
        return false;
    });
    
    $("*[rel=jsaBox_html]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsaBox_map]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='mapcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsaBox_flash]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent' style='width:600px;height:180px;'><img src='Images/close.jpg' class='close' />" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });

    $("#jsabox").click(function() {CloseItem();});
    
    $("*[rel=jsabox_video]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' class='lightboxcontents' src='Flash/VideoPlayer.swf?pvideo=" + $(this).attr("href") + "' width='303px' height='235px'></div>");
        LoadFlash();
        $("#jsabox").show();
        return false;
    });
    
    $(".Phone").mask("9(999) 999-9999");
    $(".Date").mask("99/99/9999").blur(function(){
        if (! DateControl($(this).val()) ) {
            $(this).val("");
        }
    });
    
    $(".Year").mask("9999");
    $(".TC").mask("99999999999");
    $(".TaxNumber").mask("9999999999");
    $(".Hour").mask("99:99").blur(function(){
        if ( parseInt($(this).val().replace(":","")) > 2359 ) {
            $(this).val("");
        }
    });
    
    $(".Number").keyup(function(){
        if (! IsNumeric($(this).val()) ) {
            $(this).val(ConvertNumeric($(this).val()));
        }
    });
    $(".FakeUpload").change(function(){
        $(this).parent().find(".fakeupload").val($(this).val());
    });
    
}

function InitDropDownList() {
    var Browser = $.browser;
    if (!(Browser.msie && Browser.version == "6.0") ) {
        $(".inputdrp").each(function(){
            if ( $(this).attr("isdrp") != "true" ) {
                $(this).attr("isdrp",true);
                $(this).parent().addClass("inputdrpParent").each(function () {$(this).html("<span class='inputdrpText'>" + $(this).find("option[selected=true]").text() + "</span>" + $(this).html());});
            }
        })
        $(".inputdrp").change(function () {$(this).parent().find(".inputdrpText").html($(this).find("option[selected=true]").text());});
    }
}


function CloseItem() {
    $("#jsaboxcontent").slideUp(250);
    setTimeout(function(){ $("#jsabox").hide(); $("#jsaboxcontent").show(); },250);
}

function openImage(fileUrl) {
    $("#jsaboxcontent").hide().html("<div class='qualtycontent' id='showflash'></div>")
    $("#jsabox").show();
    $("#showflash").GenerateFlash({ src: "Flash/LightBox.swf?urlPic=" + fileUrl , width: "420px", height: "573px" });
    setTimeout(function(){
    $("#jsaboxcontent").slideDown(300);
    },200);    
}

function ShowParent($this, StopItem) {
    $this.parent().find("li").show();
    if ( $(StopItem).attr("id") != $this.attr("id") ) {
        ShowParent($this.parent(),StopItem);
    }
}

function doResize() {
    if ( $(window).height() > 140 ) {
        $("#container").css("min-height", ($(window).height() - 140)).css("height", ($(window).height() - 140));
    }
}

function DateControl(fld) {
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    if ((fld.match(RegExPattern)) && (fld != '')) {
        return true;
    } else {
        return false;
    }
}

function IsNumeric(Text) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < Text.length && IsNumber == true; i++) {
        Char = Text.charAt(i);
        if (ValidChars.indexOf(Char) == -1) { IsNumber = false; };
    }
    return IsNumber;
}

function ConvertNumeric(Text) {
    var ValidChars = "0123456789.";
    var Char = "";

    for (i = 0; i < Text.length; i++) {
        if (ValidChars.indexOf(Text.charAt(i)) != -1) {
            Char = Char + Text.charAt(i);
        }
    }
    return Char;
}
