﻿function getDocumentHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getDocumentHeightWithoutScroll() {
        var D = document;
        return Math.max(D.body.scrollHeight,
        D.body.offsetHeight,
        D.body.clientHeight
    );
}

function getObjectHeight(objName) {
    var obj = document.getElementById(objName);
    return Math.max(
        obj.scrollHeight,obj.offsetHeight,obj.clientHeight
    );
}

function toggleDisplay(objID) {
    var obj = document.getElementById(objID);
    if (obj.style.display == 'none') obj.style.display = '';
    else obj.style.display = 'none'
}

function showDisplay(objID) {
    var obj = document.getElementById(objID);
    obj.style.display = '';
}

function hideDisplay(objID) {
    var obj = document.getElementById(objID);
    obj.style.display = 'none'
}

function confirmDelete() {
    var res = confirm("Are you sure you want to delete?");
    return res;
}

// Show & hide two div layers alternately
function ShowHideBlock(divToShow, divToHide) {
    var id = document.getElementById(divToShow);
    id.style.display = 'block';
    id.focus(); // works only in IE
    var id1 = document.getElementById(divToHide);
    id1.style.display = 'none';
}

function ShowBlock(divToShow) {
    var id = document.getElementById(divToShow);
    id.style.display = 'block';
    id.focus(); // works only in IE

}

function HideBlock(divToHide) {
    var id1 = document.getElementById(divToHide);
    id1.style.display = 'none';

} 
// Check the validity of the string for filename use
function IsValidForFileName(ctrID) {

    var obj = document.getElementById(ctrID);
  
    var parten = /^[^,.&*<>\/\\()"']*$/;
    if (obj != null) {
        if (parten.exec(obj.value))
            return true
        else {
        alert("Please input valid file name");
        obj.focus();
        return false;
        }
    }

}

function IsValidForName(str)
{
    var parten = /^[a-zA-Z]+$/;
    if (parten.test(str))
        return true;
    else
        return false;
}

function IsValidForPhoneNumber(str) {

    var parten = /^[0-9-#+]+$/;
    if (parten.test(str))
        return true;
    else
        return false;

}

function IsValidForNumberOnly(str) {
    var parten = /^[0-9.]+$/;
    if (parten.test(str))
        return true;
    else
        return false;
   
}

function IsValidForEmail(str) {

    var parten = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if (parten.test(str))
        return true;
    else
        return false;

}
//check whether the required fileds if null
//input argument is the webcontrol list that should be filled
function IsAllRequiredFieldsFilled(fileds) 
{
    alert(fileds);
    var ids = fileds.split("|");

    for (var ctr = 0; ctr < ids.length; ctr++) 
       {
           obj = document.getElementById(ids[ctr]);

        if (obj) 
        {
            if((obj.value == null) || obj.value == "")
            {
                alert("Please fill all required fields!");
                obj.focus();//work only by IE
                return false;
             }        
        }
    }   
}


// Scroll to the top of the page
function ScrollToTop() {
    if (window.parent)
        setTimeout('window.parent.scrollTo(0,100)', 50);
    else
        setTimeout('window.scrollTo(0,100)', 50);
    
}

// Scroll to the bottom of the page
function ScrollToBottom() {
    setTimeout('window.scrollTo(0,document.body.clientHeight)', 50);
}

function onCalendarShown(sender, args) {

    sender._switchMode("years", true);           
}


function OnEsc(e) {
    var esckey = 27;
    var key;

    if (typeof window.event != 'undefined' && typeof event.keyCode != 'undefined')
        key = event.keyCode;
    else if (typeof e != 'undefined' && typeof e.keyCode != 'undefined')
        key = e.which;
    else
        return false;

    return (key == esckey);
}

// Opens a URL on a new window
function NewWindow(url, windowname /*use empty str to allow multiple window*/, w, h, resizable, toAllowMultiple) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',screenY=' + wint + ',screenX=' + winl + ',scrollbars=no,toolbar=no,location=no,directories=no,status=no,copyhistory=no,resizable=' + resizable;
    var k = window.open(url, windowname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { k.window.focus(); }
}