//*********************************************
//General Appliction Functions
//*********************************************
// if ((typeof (oId) != "undefined") && (oId != null)) {

//*********************************************
function HandleProgressBar(val, objId) {
    //alert(objId);
    var oId = document.getElementById(objId);
    //alert(val);
    //Check Ifnot null or undefined to avoid client script errors
    if ((typeof (oId) != "undefined") && (oId != null)) {
        //alert('success');
        if (val == 1) {
            oId.style.display = 'block';
        }
        else {
            oId.style.display = 'none';
            alert(oId.style.display);
        }
    }
}
//*********************************************
function LoadPageToIframe(url, iframeId) {
    var iframe = document.getElementById(iframeId);
    if (iframe != null && typeof (iframe) != 'undefined') {
        iframe.src = url;
    }
}
//*********************************************
function makeWindow(url, w, h, nme, s) {
    //alert(url + '***' + w + '***' + h);
    var sURL = url;
    var sName = nme;
    var data = "width=" + w + ",height=" + h + ",toolbar=no,scrollbars=" + s + ",left=15,top=15";
    window.open(sURL, sName, data);
}
//*********************************************
function OpenWindowFullScreen(url, name) {
    var w = (screen.width);
    var h = (screen.height);
    var data = "width=" + w + ",height=" + h + ",resizable=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,location=yes,top=0,left=0";
    window.open(url, name, data);
}
//*********************************************
function makeViewerWindow(url, nme, s) {
    var w = (screen.width * 0.79);
    var h = (screen.height * 0.79);
    var sURL = url;
    var sName = nme;
    var data = "width=" + w + ",height=" + h + ",toolbar=no,scrollbars=" + s + ",left=15,top=15";
    window.open(sURL, sName, data);
}
//*********************************************
function makeFullWindow(URL, Width, Height) {
    var Data = "width=" + Width + ",height=" + Height + ",resizable=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,location=no,top=20,left=20"
    var sURL = URL
    window.open(sURL, "self_made", Data)
}
//*********************************************
function OpenUserImage(URL, Width, Height) {
    var Data = "width=" + Width + ",height=" + Height + ",resizable=no,menubar=no,status=no,toolbar=no,scrollbars=no,location=no,top=20,left=20"
    var sURL = URL
    window.open(sURL, "userImage", Data)
}
//*********************************************
function isUndefined(a) {
    return typeof a == 'undefined';
}
//*********************************************
// scroll page to bottom of the page
function scrollToBottom() {
    setTimeout("scrollT0()", 500);
}
//*********************************************
function OpenToFullScreen() {
    window.self.scrollTo(0, 0);
    window.resizeTo(window.screen.width, window.screen.height);
}
//*********************************************
function scrollT0() {
    window.self.scrollTo(0, window.screen.height);
}
//*********************************************
function setImgSrc(obj, url) {
    obj.src = url;
}
//*********************************************
function DeleteSpaces(str, action) {
    var strLength = str.length;
    if (strLength == 0) return str;

    var newString = '';
    var pattern = / /g; // create a regular expression to handle ALL spaces

    if (action == 1) {
        newString = str.replace(pattern, "_");
    }
    if (action == 2) {
        //includes minus(-)
        //pattern = /\$|,|@|#|~|`|\%|\*|\^|\&amp;|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\&lt;|\&gt;|\?|\||\\|\!|\$|\./g;


        pattern = /\$|,|@|#|~|\%|\*|\^|\&amp;|\(|\)|\+|\=|\_|\]|\[|\}|\{|\;|\:|\&lt;|\&gt;|\?|\||\\|\!|\$|\./g;

        newString = str.replace(pattern, " ");
    }
    return newString;
}
//*********************************************
function GetParamFromUrl(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}
//*********************************************
///////////////////////////////////////////////
//string function
/////////////////
function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}
//*********************************************
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
//*********************************************
function whatLang(letter) {

    //identify letter: Hebraw or English?	
    //alert(letter + ' = letter');
    var asciiVal;
    asciiVal = letter.charCodeAt(0);
    //alert(asciiVal);

    //english:  (65 To 90)  (97 to 122)
    //hebraw: (224 To 250)

    if (((asciiVal >= 65) && (asciiVal <= 90)) || ((asciiVal >= 97) && (asciiVal <= 122)))
        res = 'eng';

    else if ((asciiVal >= 1498) && (asciiVal <= 1514))
        res = 'heb';

    else
        res = 'heb';

    return res;
}
//*********************************************
//shorten the string: Heb or Eng with cases
function makeShortJS(str, strLen) {
    //alert(str);alert(strLen);

    var len, ResStr, letter, res;
    len = str.length;

    if (len > strLen) {
        //Heb or Eng?
        letter = Right(str, 1);
        res = whatLang(letter.charAt(0)); //Test.charAt(i)
        //alert(res);

        if (res == 'heb') {
            ResStr = Left(str, strLen - 2);
            ResStr = ResStr + '...';

        }
        else if (res == 'eng') {
            ResStr = Left(str, strLen - 2);
            ResStr = '...' + ResStr;

        }
        else {
            return str;
        }

        return ResStr;

    }
    else
        return str;

}
//*********************************************
//set the value in a form radio buttons
function radioButtonSetCheckedValue(radioObj, newValue) {
    if (!radioObj)
        return;
    var rb = document.getElementsByTagName("input");
    for (var k = 0; k < rb.length; k++) {
        if (rb[k].name.indexOf(radioObj) >= 0) {
            if (rb[k].value == newValue)
                rb[k].checked = true;
        }
    }
}
//*********************************************
//get the selected value from a form radio buttons
function radioButtonGetCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var rb = document.getElementsByTagName("input");
    for (var k = 0; k < rb.length; k++) {
        if (rb[k].name.indexOf(radioObj) >= 0) {
            if (rb[k].checked)
                return rb[k].value;
        }
    }
    return "";
}
//*********************************************
//HP Cookie Functions 
//*********************************************
function nameDefined(ckie, nme) {
    var splitValues
    var i
    for (i = 0; i < ckie.length; ++i) {
        splitValues = ckie[i].split("=")
        if (splitValues[0] == nme) return true
    }
    return false
}
//*********************************************
function delBlanks(strng) {
    var result = ""
    var i
    var chrn
    for (i = 0; i < strng.length; ++i) {
        chrn = strng.charAt(i)
        if (chrn != " ") result += chrn
    }
    return result
}
//*********************************************-
function getCookieValue(ckie, nme) {
    var splitValues
    var i
    for (i = 0; i < ckie.length; ++i) {
        splitValues = ckie[i].split("=")
        if (splitValues[0] == nme) return splitValues[1]
    }
    return ""
}
//*********************************************
function testCookie(cname, cvalue) {  //Tests to see if the cookie 
    var cookie = document.cookie        //with the name and value 
    var chkdCookie = delBlanks(cookie)  //are on the client computer
    var nvpair = chkdCookie.split(";")
    if (nameDefined(nvpair, cname))  //See if the name is in any pair
    {
        tvalue = getCookieValue(nvpair, cname)  //Gets the value of the cookie
        if (tvalue == cvalue) return true
        else return false
    }
    else return false
}

//*********************************************
function CheckPreloaderCookie() {


    var sShowAd = 1;
    //sShowAd = <%=self_made.Main.GetGroupID("PreloaderCookie")%>

    if (sShowAd == 1) {

        if (testCookie("PreloaderCookie", "yes")) {
            //alert('yes');
            /*
            var futdate = new Date()
            var expdate = futdate.getTime()
            expdate += 1000 //expires in 1 sec, for testing
            futdate.setTime(expdate)
            var newCookie="PreloaderCookie=yes; path=/;"
            newCookie += " expires=" + futdate.toGMTString()
            window.document.cookie=newCookie
            */
            ChangeFrame("Preloader", "HomePage");

        }
        else {
            //alert('no');
            var futdate = new Date();
            var expdate = futdate.getTime();
            //expdate += 1000*60*1440  //expires in 24 hours(milliseconds)
            expdate += 1000 * 60 * 15; //expires in 15 min(milliseconds)
            futdate.setTime(expdate);
            var newCookie = "PreloaderCookie=yes; path=/;"
            newCookie += " expires=" + futdate.toGMTString();
            window.document.cookie = newCookie;

        }
    }
}
//*********************************************
//Date Handle Functions 
//*********************************************
function CompareDates(dateFromString, dateToString) {// format: dd/mm/yyyy
    if (dateFromString == '' && dateToString == '')
        return true;

    else if (dateFromString != '' && dateToString == '')
        return false;

    else if (dateFromString == '' && dateToString != '')
        return false;

    var fromArr = dateFromString.split("/");

    if (fromArr[0].indexOf("0") == 0)
        fromArr[0] = fromArr[0].substr(1);

    var fromD = parseInt(fromArr[0]);


    if (fromArr[1].indexOf("0") == 0)
        fromArr[1] = fromArr[1].substr(1);

    var fromM = parseInt(fromArr[1]);


    if (fromArr[2].indexOf("0") == 0)
        fromArr[2] = fromArr[2].substr(1);

    var fromY = parseInt(fromArr[2]);
    var dateFrom = new Date(fromY, fromM - 1, fromD);

    var toArr = dateToString.split("/");

    if (toArr[0].indexOf("0") == 0)
        toArr[0] = toArr[0].substr(1);

    var toD = parseInt(toArr[0]);

    if (toArr[1].indexOf("0") == 0)
        toArr[1] = toArr[1].substr(1);

    var toM = parseInt(toArr[1]);


    if (toArr[2].indexOf("0") == 0)
        toArr[2] = toArr[2].substr(1);

    var toY = parseInt(toArr[2]);
    var dateTo = new Date(toY, toM - 1, toD);

    if (dateFrom > dateTo)
        return false;

    return true;
}
//*********************************************
//General Page Functions
//*********************************************
function RefreshUpdatePanel() {
    //alert('RefreshGridViewInParent - dev');
    var iframe = document.getElementById("UcDragablePannel_containerIframe");
    if (iframe != null && typeof (iframe) != 'undefined') {
        //iframe is also the name...
        window.frames.iframe.RefreshUpdatePanel();
    }
}
//*********************************************
function CallRichTextPopup() {
    //alert('RefreshGridViewInParent - dev');
    var iframe = document.getElementById("UcDragablePannel_containerIframe");
    if (iframe != null && typeof (iframe) != 'undefined') {
        //iframe is also the name...
        window.frames.iframe.CallRichTextPopup();
    }
}
//*********************************************
function setPageUi() {
    var tdLeft = document.getElementById("tdLeft");
    var tdCenter = document.getElementById("tdCenter");
    var tdRight = document.getElementById("tdRight");
    if (tdCenter != null && typeof (tdCenter) != 'undefined') {
        if (tdLeft != null && typeof (tdLeft) != 'undefined') {
            if (tdRight != null && typeof (tdRight) != 'undefined') {
                var sWidth = tdCenter.style.width;
                var w = parseInt(sWidth.replace("px", ""));
                //alert(w);
                var sideWidth = (screen.width - w) / 2;
                //alert(sideWidth);
                tdLeft.style.width = sideWidth + "px";
                tdRight.style.width = sideWidth + "px";
            }
        }
    }
}
//*********************************************
