﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="jquery.selectboxes.min.js" />
/// <reference path="jquery.scrollTo-min.js" />
/*************************************************Prototyping*********************************************************************/
Array.prototype.contains = function(element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
}
Array.prototype.clean = function(val) {
    var a;
    for (a = 0; a < this.length; a++) {
        if (this[a] == val) {
            this.splice(a, 1);
            a--;
        }
    }
    return this;
};

Array.prototype.AddElements = function(arrToAdd) {
    var a;
    for (a = 0; a < arrToAdd.length; a++) {
        //if value does not exist then add it
        if (!this.contains(arrToAdd[a])) {
            this.push(arrToAdd[a]);
        }
    }
    //remove empty elements
    return this.clean("");
};
Array.prototype.RemoveElements = function(arrToRemove) {
    var a;
    for (a = 0; a < arrToRemove.length; a++) {
        //if value does exist then remove it
        if (this.contains(arrToRemove[a])) {
            //remove element
            this.clean(arrToRemove[a]);
        }
    }
    //remove empty elements
    return this.clean("");
};
/*
var selectedKommuner = $("#hfKommuner").val().split(',');
var arrKommuner = kommuner.split(',');
//iterate through the passed values
for (var i = 0; i < arrKommuner.length; i++) {
    //if value does not exist then add it
    if (!selectedKommuner.contains(arrKommuner[i])) {
        selectedKommuner.push(arrKommuner[i]);
    }
}
//remove empty elements
selectedKommuner.clean();
//return the updated string
selectedKommuner.join(',');
*/
/******************************************************Region************************************************************************/
//loads all regions to and adds them to a dropdownlist
function RegionsLoadAllSelect(select) {
    AddItemsToSelect(select, regionsList, true);
}
function RegionsLoadAll() {
    var tmp = null;
    regionproxySync.invoke("LoadAll", {}, function(result) {
        tmp = result;
    })
    return tmp;
}
function RegionsLoadAllRdo(div,name,onclick) {
    CreateRadioButtonList(div, regionsList, name, onclick);
}
//Creates a list of all checkboxes
function RegionsLoadAllChk(div, name, onclick, checkuncheckOnClick) {
    CreateCheckBoxList(div, regionsList, name, onclick, checkuncheckOnClick, 0, false);
}
//Loads a region by id
function RegionLoadById(regionId) {
    var region = null;
    $(regionsList).each(function(i, item) {
        if (item.Id == regionId) {
            region = item;
        }
    });
    return region;
}
//Loads a region by id
function RegionLoadByMapName(mapName) {
    var region = null;
    $(regionsList).each(function(i, item) {
    if (item.MapName == mapName) {
            region = item;
        }
    });
    return region;
    /*
     var region = null;
    regionproxySync.invoke("LoadByMapName", { mapName: mapName }, function(result) {
        region = result;
    });
    return region;*/
}
/******************************************************Kommune************************************************************************/
//Loads all kommuner and adds them to a select
function KommuneLoadAllSelect(select) {
    AddItemsToSelect(select, kommunerList, true);
}
function KommuneLoadAll() {
    var tmp = null;
    kommuneproxySync.invoke("LoadAll", {}, function(result) {
        tmp= result;
    })
    return tmp;
}

//Loads alle kommuner in a particular region
function KommuneLoadByRegion(regionId) {
    var tmp = []; 
    $(kommunerList).each(function(i, item) {
    if (item.RegionId == regionId) {
            tmp.push(item);
        }
    });
    return tmp;
}
//Loads alle kommuner in a particular region
function KommuneLoadByRegions(regions) {
    var tmp = [];
    if (regions == '') {
        return kommunerList;
    }
    else {
        var arr = regions.split('');
        $(kommunerList).each(function(i, item) {
            if (arr.contains(item.RegionId)) {
                tmp.push(item);
            }
        });
        return tmp;
    }
}
//Loads all kommuner and adds them to a select list
function KommuneLoadByRegionSelect(select, regionId, isCheckBoxSelect,selected) {
    AddItemsToSelect(select, KommuneLoadByRegion(regionId), true, false, selected);
        //the select control should be displayed with checkboxes
        if (isCheckBoxSelect) {
            RefreshCheckBoxWidget(select, "kommuner");
        }
}
//Loads all kommuner and adds them to a select list
function KommuneLoadByRegionAddList(div, regionId, parentLink) {
    AddItemsToList(div, KommuneLoadByRegion(regionId), 1, parentLink);
}
//Loads all kommuner and adds them to a select list based on a commaseperated list of regions
function KommuneLoadByRegionsSelect(select, regions, isCheckBoxSelect) {
    $(select).children().remove();
    AddItemsToSelect(select, KommuneLoadByRegions(regions), false);
        //the select control should be displayed with checkboxes
        if (isCheckBoxSelect) {
            RefreshCheckBoxWidget(select, "regioner");
        }
}
//Creates a list of all checkboxes
function KommuneLoadByRegionChk(div, name, regions, onclick, showcheckuncheck, rows, divstyle, checked, simulateOnclick) {
    $(div).children().remove();
    CreateCheckBoxList(div, LoadByRegions(regions), name, onclick, showcheckuncheck, rows, divstyle, "kommuner", checked, simulateOnclick);
}
/******************************************************Retskredse************************************************************************/
//Loads all Retskredse and adds them to a select
function RetskredsLoadAllSelect(select) {
    AddItemsToSelect(select, retskredseList, true);

}
//Loads All retskredse
function RetskredseLoadAll() {
    var tmp;
    retskredsproxySync.invoke("LoadAll", {}, function(result) {
        tmp = result;
    });
    return tmp;
}
//Loads all retskredse by region
function RetskredseLoadByRegion(regionId) {
    var tmp = [];
    $(retskredseList).each(function(i, item) {
        if (item.RegionId == regionId) {
            tmp.push(item);
        }
    });
    return tmp;
}
//Loads all retskredse by regions
function RetskredseLoadByRegions(regions) {
    var tmp = [];
    if (regions == '') {
        return retskredseList;
    }
    else {
        var arr = regions.split('');
        $(retskredseList).each(function(i, item) {
            if (arr.contains(item.RegionId)) {
                tmp.push(item);
            }
        });
        return tmp;
    }
}
//Loads all Retskredse and adds them to a dropdownlist
function RetskredsLoadByRegionSelect(select, regionId, isCheckBoxSelect) {
    $(select).children().remove()
    AddItemsToSelect(select, RetskredseLoadByRegion(regionId), true);
        //the select control should be displayed with checkboxes
        if (isCheckBoxSelect) {
            RefreshCheckBoxWidget(select, "retskredse");
        }
}
function RetskredsLoadByRegionAddList(div, regionId, parentLink) {
    AddItemsToList(div, RetskredseLoadByRegion(regionId), 2, parentLink);
}
//Creates a list of all checkboxes
function RetskredsLoadByRegionChk(div, name, regions, onclick, showcheckuncheck, rows, divstyle, checked, simulateOnclick) {
    $(div).children().remove();
    CreateCheckBoxList(div, RetskredseLoadByRegions(regions), name, onclick, showcheckuncheck, rows, divstyle, "retskredse", checked, simulateOnclick);
}
/******************************************************Zipcode************************************************************************/
//Adds zipcodes to a select
function ZipCodesAddToSelect(select,zipCodes) {
    $(select).addOption("", "Vælg her", false);
    $(zipCodes).each(function(i, item) {
    $(select).addOption(item.Id, item.Id, false);
    })
}
function ZipCodeLoadAll() {
    var zipCodes = null;
    zipcodeproxySync.invoke("LoadAll", {}, function(result) {
        zipCodes = result;
    });
    return zipCodes;
}
/**********************************************************Category************************************************************************/
//Loads all Category and adds them to a select
function CategoryLoadAllSelect(select, isCheckBoxSelect, selected) {
    AddItemsToSelect(select, categoryList, true, false, selected);
        //the select control should be displayed with checkboxes
        if (isCheckBoxSelect) {
            RefreshCheckBoxWidget(select,"kategorier");
        }
}
//Loads all Category 
function CategoryLoadAll() {
    var tmp;
    categoryproxySync.invoke("LoadAll", {}, function(result) {
        tmp = result;
    });
    return tmp;
}
//Creates a list of all checkboxes
function CategoryLoadAllChk(div, name, onclick, showcheckuncheck, rows, divstyle, checked, simulateOnclick) {
    CreateCheckBoxList(div, categoryList, name, onclick, showcheckuncheck, rows, divstyle, "kategorier", checked, simulateOnclick);
}
/**************************************************Control functions ************************************************************/
function AddItemsToSelect(select, data, addSelectAll, addSelectHere, selected) {
    //remove existing items
    $(select).removeOption(/./);
    if (addSelectAll) {
        //if any values has been selected
        //alert($(select).selectedValues().Length);
        $(select).addOption("", "Alle", selected);
    }
    if (addSelectHere) {
        $(select).addOption("", "Vælg her", selected);
    }
    $(data).each(function(i, item) {
    $(select).addOption(item.Id, item.Name, selected);
    });
}
function AddItemsToList(div, data,type, parentLink) {
    $(div).children().remove();
    //create the onclickevent
    var onclick = "";

    var listOfId = "";
    var tmp = [];
    tmp[0] = '<div>';
   for (var i = 0; i < $(data).length; i++) {
       var item = $(data)[i];
       onclick = " onclick='" + GetOnclick(type).replace("'Ids'", "\"" + item.Id + "\"") + "' ";
       //Show remove button
       if (type == 3 || type == 4) {
           tmp.push("<a  class='imglink' href='#' " + onclick + "><img src='" + root + "Style/Images/skraldespand.gif' /></a>&nbsp;");
       }

       tmp.push("<a class='normal' href='#' " + onclick + ">" + item.Name + "</a><br/>");
        listOfId = listOfId+","+item.Id
    }
     tmp[tmp.length] = "</div>";
     $(div).append(tmp.join(''));
     //remove current onclick
     $(parentLink).unbind('click');
    //add onclick to parent
     $(parentLink).bind('click', { listOfId: listOfId, type: type }, function fn(event) {
     setTimeout(GetOnclick(event.data.type).replace("Ids", event.data.listOfId), 00);
     //Prevents default link behavior
     return false;
    }
    );
    //save the selected list of items
    if (type == 3) {
        $("#hfKommuner").val(listOfId);
    } else if (type == 4) {
    $("#hfRetskredse").val(listOfId);
    }
}

function GetOnclick(type) {
    var onclick = "";
    if (type == 1) {
        onclick = "AddKommuner('Ids',true)";
    }
    else if (type == 2) {
    onclick = "AddRetskredse('Ids',true)";
    }
    else if (type == 3) {
    onclick = "RemoveKommuner('Ids',true)";
    }
    else if (type == 4) {
    onclick = "RemoveRetskredse('Ids',true)";
    }
    return onclick;
}
function RefreshCheckBoxWidget(select, firstItemText) {
    //destroy the original widget
    $(select).dropdownchecklist("destroy");
    //create a new consisting of the updated data
    $(select).dropdownchecklist({ firstItemChecksAll: true, maxDropHeight: 250, width: 200,firstItemText:firstItemText,
    customFirstItemClick: function(chk, lbl) {
    var checked = chk.attr("checked");
    if (!checked) {
        $(lbl).text("Alle " + firstItemText);
            }
            else {
                $(lbl).text("Fravælg alle " + firstItemText);
            }
        }
    });
   }
///Creates a radio button list
function CreateRadioButtonList(div, data, name, onclick) {
    var tmp = [];
    tmp[0] = '<div>';
    for (var i = 0; i < $(data).length; i++) {
        var item = $(data)[i]
        tmp[i + 1] = "<label><input type='radio' name='" + name + "' id='" + name + item.Id + "' value='" + item.Id + "' onclick='" + onclick + "' />" + item.Name + "</label><br/>";
    }
    tmp[tmp.length] = "</div>";
    $(div).append(tmp.join(''));
}
function ShowLabelText(name, text,div) {
    //resize label
    $("#lbl" + name).width($('#' + div).width()-25);
   // var all
    if ($("input:checkbox[name='" + name + "']:not(:checked)").length == 0) {
        $("#lbl" + name).text("Alle "+ text);
    }
    else {
        $("#lbl" + name).text(GetSelectedCheckBoxNames(name));
    }
}
//creates a list of checkboxes
function CreateCheckBoxList(div, data, name, onclick, showcheckuncheck, rows, divstyle, text, checked,simulateOnclick) {
    var tmp = [];
    var textFn = "ShowLabelText(\"" + name + "\",\"" + text + "\",\"" + $(div).attr("id") + "\");";
   
     tmp.push('<div style="' + divstyle + '">');
    //$(":checkbox[name='boxes[]']:checked")
    //tmp.push("<label><input type='checkbox' name='" + name + "CheckAll' id='" + name + "' onclick='CheckUnCheckAll(\"" + name + "\",\"" + name + "\");" + checkuncheckOnClick + "' />Vælg/fravælg alle</label><br/>");
     if (showcheckuncheck) {
         tmp.push("<div style='height:19px;'><a href='#' class='lnkSmall' onclick='CheckAll(\"" + name + "\");" + textFn + "" + onclick + "' >Alle</a>&nbsp;<a href='#' class='lnkSmall' onclick='UnCheckAll(\"" + name + "\");" + textFn + "" + onclick + "' >Ingen</a></div>");
     }
    
    for (var i = 0; i < $(data).length; i++) {
        //add new div
        if (parseInt(rows) > 0 && i >0 &&(i+1) %  rows == 0) {
            tmp.push('</div><div style="' + divstyle + '">');
        }
        var checkedstring = (checked) ? "checked" : "";
        var item = $(data)[i]
        tmp.push("<label><input type='checkbox' " + checkedstring + " name='" + name + "' id='" + name + item.Id + "' value='" + item.Id + "' onclick='" + onclick + "" + textFn + "' />" + item.Name + "</label><br/>");
          
    }
    tmp[tmp.length] = "</div>";
    $(div).append(tmp.join(''));
    ///makes sure that the checkbox string is displayed
    ShowLabelText(name, text, $(div).attr("id"));
}
///resets a selectbox
function resetSelectBox(id) {
    //unselect all items
    $("#" + id).selectOptions(/./, false);
    //sort the selected options
    $("#" + id).sortOptions();
    $("#" + id).scrollTop(0);
}

/**********************************************************************Dialogs **************************************************************************************/
function SetupDialog(id, width, height) {
    if (typeof (height) == 'undefined') {
        height = 500;
    }
    if (typeof (width) == 'undefined') {
        height = 800;
    }
    $(id).dialog({
        bgiframe: false,
        resizable: true,
        autoOpen: false,
        modal: true,
        width: width,
        height:height,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            Luk: function() {
            $(this).dialog('close'); 
                resizeContent();
            }
        }
    });
    //append to form to ensure postback
    $(id).parent().appendTo($("form:first"));
}
function SetUpCreateAuction() {
    $("#dialog").dialog({
        bgiframe: true,
        resizable: true,
        autoOpen: false,
        height: 475,
        width: 525,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            Luk: function() {
                $(this).dialog('close');
            }
        }
    });

}
function ShowCreateAuction() {
    //$('#iCreateAuction').attr("src", root+"Auction/Pages/CreateAuction.aspx?mode=modal")
    $('#dialog').dialog('open');
}
/**********************************************************************Usefull functions*****************************************************************************/
///Redirects the user to a page
function Goto(url) {
    location.href = root + url;
}
///Redirects the user to a page
function GotoParent(url) {
    //location.href = root + url;
    parent.location.href = root + url;
    return false;
}
function ShowPaymentWindow() {
    ShowWindow( root+'various/pages/PaymentForm.aspx', 'betaling', 500, 500);
  }
 
function refreshPage() {
    var URL = unescape(window.location.pathname);
    location.href = URL;

}
function refreshParentPage() {
    var URL = unescape(window.opener.location.pathname);
    window.opener.location.href = URL;

}
function refreshParentIframePage(qry) {
    var URL = unescape(parent.location.pathname);
    parent.location.href = URL + qry;
    return false;
}

///returns true if the user is logged in
function IsLoggedIn() {
    var loggedin = false;
    userproxySync.invoke("IsLoggedIn", {},
    function(result) 
    {
        loggedin = result;
    }
    );
    return loggedin;
}
///returns true if the user is paying
function IsPayingUser() {
    var paying = false;
    userproxySync.invoke("IsPayingUser", {},
    function(result) {
        paying = result;
    }
    );
    return paying;
}
///returns true if the user is paying
function IsLawyer() {
    var islawyer = false;
    userproxySync.invoke("IsLawyer", {},
    function(result) {
    islawyer = result;
    }
    );
    return islawyer;
}


////Shows a popup window
function ShowWindow(url, title, width, height) {
   var v = window.open(url, title, "width=" + width + ",height=" + height + ",statusbar=yes,resizable=yes,scrollbars=yes");
    v.focus();
    return false;
}
function ShowSimpleWindow(url) {
    var v = window.open(url, "", "statusbar=yes,resizable=yes,scrollbars=yes");
    v.focus();
}
///Shows a simple window
function ShowSimpleWindow2(url) {
    var v = window.open(root + url,"", "width=700,height=600,statusbar=yes,resizable=yes,scrollbars=yes");
    v.focus();
}
///Shows a picture
function ShowPicture(Id) {
    if (parseInt(Id) > 0) {
        var v = window.open(root + "Various/Pages/ShowPicture.aspx?id=" + Id, "", "width=500,height=400,statusbar=yes,resizable=yes,scrollbars=yes");
        v.focus();
    }
}
///Shows a auction on the map
function ShowOnCard(lbnr) {
    var v = window.open(root + "Google/Pages/ShowMap.aspx?type=3&lbnr=" + lbnr, "", "width=500,height=400,statusbar=yes,resizable=yes,scrollbars=yes");
    v.focus();
}
function ShowAuctionWindow(lbnr) {
    aw1 = open(root + "Auction/pages/auction.aspx?lbnr=" + lbnr, '', 'width=830,height=760,resizable=yes,scrollbars=yes,toolbar=no');
    aw1.focus();
}
function ShowAuctionPictureWindow(lbnr) {
    if (parseInt(lbnr) > 0) {
        aw1 = open(root + "Auction/pages/auction.aspx?lbnr=" + lbnr + "#2", '', 'width=830,height=760,resizable=yes,scrollbars=yes,toolbar=no');
        aw1.focus();
    }
}

function ShowEmailAgent(id, tab) {
    if (IsLawyer() || IsPayingUser()) {
        $('#dialogEmailAgent').dialog('open');
        $('#iEmailAgent').attr("src", root + "Various/pages/EmailAgentPage.aspx?id=" + id + "&tab=" + tab);
    } else {
    Goto('User/Pages/Register.aspx?msg=Du skal have et betalings abonnement for at kunne bruge denne funktion.')
    }
}
//Checks all check boxes on page
function CheckAllPage(btn) {
    if ($(btn).attr("value") == "Fravælg alle") {
        $(":checkbox").attr('checked', false);
        //Change text on button
        $(btn).attr("value", "Vælg alle");
    }
    else {
        $(":checkbox").attr('checked', true);
        //$(btn).live('click', function() { alert(1); UnCheckAllPage(this); });
        //Change text on button
        $(btn).attr("value", "Fravælg alle");
    }
    
}
//Checks all check boxes on page
function UnCheckAllPage(btn) {
    $(":checkbox").attr('checked', false);
    //Change text on button
    $(btn).attr("value", "Vælg alle");
    //Change onclick event
    $(btn).bind('click', function() { CheckAllPage(this); });
    return false;
    
}
//checks or unchecks all items in
function CheckUnCheckAll(id, name) {
    $("input:checkbox[name='" + name + "']").attr('checked', $('#' + id).is(':checked'));
}
//checks all items
function CheckAll(name) {
    $("input:checkbox[name='" + name + "']").attr('checked',true);
}
function UnCheckAll(name) {
    $("input:checkbox[name='" + name + "']").attr('checked',false);
}
//Returns a list of selected checkbox values 
function GetSelectedCheckBoxValues(name) {
    var values="";
    $("input:checkbox[name='"+name+"']:checked").each(function() {
         var currentValue = $(this).val();
        if (currentValue != '')
        values += currentValue + ",";
    });
    return values.substring(0, ((values.length == 0) ? 0 : values.length - 1));
}
//Returns a list of selected checkbox names 
function GetSelectedCheckBoxNames(name) {
    var values = "";
    $("input:checkbox[name='" + name + "']:checked").each(function() {
        var currentValue = $(this).parent("label").text();
        if (currentValue != '')
            values += currentValue + ",";
    });
    return values.substring(0, ((values.length == 0) ? 0 : values.length - 1));
}
//Returns a list of selected checkbox values
function SetSelectedCheckBoxesByValues(name, values) {
    if (values != null && values != '') {
        var valArr = values.toString().split(',');
        $("input:checkbox[name='" + name + "']").each(function() {
            $(this).attr('checked', valArr.contains($(this).val()));
        });
    }
}
//Returns a list of selected checkbox values 
function GetSelectedListBoxValues(id) {
    var values = "";
    $(id).children().each(function() {
        var currentValue = $(this).val();
        if (currentValue != '')
            values += currentValue + ",";
        //INPUT[name=" + name + "][type='checkbox']
    });
    return values.substring(0, ((values.length == 0) ? 0 : values.length - 1));
}
//Returns a list of selected checkbox values
function SetSelectedListBoxValues(id, values) {
    if (values != null && values != '') {
        var valArr = values.split(',');
        $(id).children().each(function() {
            $(this).attr("selected", valArr.contains($(this).val()));
        });
    }
}
//Tests input and makes sure that only integers are entered
function IsValidInt(f) {
    if (!/^\d*$/.test(f.value)) {
        f.value = f.value.replace(/[^\d]/g, "");
    }
}
//Returns a display value for a textbox or similar
function GetCleanValue(val) {
    if (typeof (val) == "undefined" || val.toString() == "0") {
        return "";
    }
    return val;
}
//Returns a display value for a textbox or similar
function GetDateValue(val) {
    if (typeof (val) == "undefined" || val.toString() == "0") {
        return "";
    }
    return val.toString().substring(6,8)+"-"+val.toString().substring(4,6)+"-"+ val.toString().substring(0,4);
}
function resizeContent() {
    if (isRunningIE6OrBelow) {
      /*  alert($(window).height());
        alert($(document).height());
        alert($("body").height());*/
    }
    else {
        var width = (document.body.clientWidth >= 1024) ? 1024 : document.body.clientWidth - 30;
        var columnWidth = ((document.body.clientWidth - width)/2);
        $('#tdLeft').width(columnWidth);
        $('#tdRight').width(columnWidth);
        $('#content').width(width)
        
      
        $('#divTop').width($('#content').width());
        $('#menu').width($('#content').width());
        //alert($('div').tallestSize());
        //set content wrap height
        if ($('#content').height() < $(window).height()) {
            $('#content').height($(window).height() - $('#header-wrap').height());
        }
        //if 
        if ($('#content').height() < $("#innerContent").height()) {
            $('#content').height($("#innerContent").height());
        }
         //if ($('#content').height() < $('#innerContent').height()) {
        //    $('#innerContent').height($('#innerContent').height());
        //}
         //$('#content').height($('#contentTd').height())
        //alert();
        //alert();
        //alert($(document).outerHeight());
        //$('#content').height($(document).height());
        //alert("clientHeight" + document.documentElement.clientHeight);
        //alert("scrollHeight" + document.documentElement.scrollHeight);
        //alert(document.body.scrollHeight);
        //var width = (document.body.clientheight >= 1024) ? 1024 : document.body.clientWidth;
        //Resize the content div to the window size
       // $('#content').height($(document).height()-4);
        //if the innercontent is bigger than the content div then resize it
       /* if ($('#content').height() < $('#innerContent').outerHeight()) {
            $('#content').height($('#innerContent').outerHeight());
        }
        else if ($('#content').height() < $(document).height()) {
            $('#content').height($(document).height());
        }*/
        
    }
}
///Shows a progress window
function ShowProgress() {
    $.blockUI({ message: '<label class="header"><img src="' + root + 'Style/images/busy.gif" /> Vent venligst...</label>' });
}
//removes the progress
function RemoveProgress() {
    $.unblockUI();
}
function WaitForIFrame(id) { if (document.getElementById(id).readyState != "complete") { setTimeout("WaitForIFrame('" + id + "');", 200); } else { RemoveProgress(); } }

function ShowCheckBoxDiv(div, height) {
    //change class
    $(div).addClass("dropdownlist-active");
    //show the actual checkdiv
     $(div).children("div:first").css("height", height);
    $(div).children("div:first").css("left", $(div).offset().left);
    $(div).children("div:first").css("top", $(div).offset().top+20);
    $(div).children("div:first").css("width", $(div).width());
    $(div).children("div:first").show();
   
}
function HideCheckBoxDiv(div) {
    //show the actual checkdiv
    $(div).children("div:first").hide();
    $(div).removeClass("dropdownlist-active");
     //$(div).stop().animate({ height: '20px' }, { queue: false, duration: 150 });
}
/********************************************************************Images preload********************************************************************************/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
var images = new Array()
function preloadImages() {
    for (i = 0; i < preloadImages.arguments.length; i++) {
        images[i] = new Image()
        images[i].src = preloadImages.arguments[i]
    }
}
