﻿// JScript File
var menu_status = new Array();
function showHide(theid) { if (document.getElementById) { var switch_id = document.getElementById(theid); if (menu_status[theid] != 'show') { switch_id.className = 'show'; menu_status[theid] = 'show'; setCookie(); } else { switch_id.className = 'hide'; menu_status[theid] = 'hide'; setCookie(); } } }
function setCookie() { s = new Array(); i = 0; for (key in menu_status) { if (menu_status[key] == 'show') { s[i] = key; i++; }; } Set_Cookie('activemenu', s.join("-"), '', '/', '', ''); }
function Set_Cookie(name, value, expires, path, domain, secure) { var today = new Date(); today.setTime(today.getTime()); if (expires) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + "=" + escape(value) + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : ""); }
function Get_Cookie(name) { var start = document.cookie.indexOf(name + "="); var len = start + name.length + 1; if ((!start) && (name != document.cookie.substring(0, name.length))) { return null; } if (start == -1) return null; var end = document.cookie.indexOf(";", len); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len, end)); }
function show_menu() { s = Get_Cookie('activemenu'); if (s != '') { a = s.split("-"); for (key in a) { showHide(a[key]); } } }

function __doUserLogin(userName, userPassword, userRemember) {
    var theform = document.Form1;
    theform.__LOGINREQ.value = 1;
    theform.__USRLOGIN.value = userName;
    theform.__USRPASSW.value = userPassword;
    theform.__USRPERST.value = userRemember;
    theform.submit();
}

function Is_IE5Up() { var agt = navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); var is_ie3 = (is_ie && (is_major < 4)); var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1)); return (is_ie && !is_ie3 && !is_ie4); }

function ShowDialog(URl) { ShowDialog(URL, 500, 600) }
function ShowDialog(URL, width, height) { if (Is_IE5Up()) { window.showModalDialog(URL, "", "dialogHeight: " + height + "px; dialogWidth: " + height + "px; dialogTop: px; dialogLeft: px;" + "edge: Raised; center: Yes; help: No; resizable: Yes; status: No;"); } else { window.open(URL, "Browser", "top=" + (screen.height - height) / 2 + ",left=" + (screen.width - width) / 2 + ",location=0,status=0,resizable=1,scrollbars=1,width=" + width + ",height=" + height); } }

function emailitem(URL) {
    emailwindow = window.open("EmailUrlLink.aspx?URL=" + URL, "emailwindow", "width=500,height=350,scrollbars=1,status=0,location=0,resizable=1");
}
function printitem(src) { window.print() }
function showGallopResults(params) {
    galobwin = window.open("ShowGallopResults.aspx?" + params, "galobwin", "width=500,height=500,scrollbars=1,status=0,location=0,resizable=1");
}

function proceed() { return confirm('WARNING: All changes you have done will be lost.\nPress Cancel to Save changes or OK to proceed.'); }
function delConfirm(val) { return confirm('Are you sure you want to delete this ' + val + '?'); }
function delListConfirm() { return confirm('Are you sure you want to delete this selected items'); }
function saveAndDelConfirm() { return confirm('On save, item(s) checked for deletion will be deleted too. Are you sure?'); }

function openWindow(URL, width, height, resize, scroll, location) { win = window.open(URL, "Browser", "top=" + (screen.height - height) / 2 + ",left=" + (screen.width - width) / 2 + ",location=" + location + ",status=0,resizable=" + resize + ",scrollbars= " + scroll + ",width=" + width + ",height=" + height); }
function openWin(URL) { openWindow(URL, 790, 500, 1, 1, 0); }
function newWin(URL) { win = window.open(URL); return false; }
function openPopUp(URL, width, height) { openWindow(URL, width, height, 0, 1, 0); }
function copyDropDownToTextBox(dd, tb) { tb.value = dd.options[dd.selectedIndex].text }
function openModuleAdd(tabId) { openWindow('/admin/AddModule.aspx?tabId=' + tabId, 780, 140, 1, 1, 0) }
function openPageSettings(tabId) { openWindow('/admin/PageSettings.aspx?p=' + tabId, 700, 400, 1, 1, 0) }

function openPrintWin() {

    var width = 700;
    var height = 600;
    var url = '/print.aspx';
    win = window.open(url, "Print", "top=" + (screen.height - height) / 2 + ",left=" + (screen.width - width) / 2 + ",location=1,status=0,resizable=1,scrollbars=1,width=" + width + ",height=" + height);
}

function openImageWin(pic, width, height, txt, txtStyle) {
    link = open("", "mphW", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=100,top=100,width=" + width + ",height=" + height);
    link.document.open();
    link.document.writeln("<html>");
    link.document.writeln("<head>");
    link.document.writeln("<title>Picture</title>");
    link.document.writeln("</head>");
    link.document.writeln("<body topmargin=\"0\" leftmargin=\"0\">");
    link.document.writeln("<img id=\"picture\" name=\"picture\" src=\"" + pic + "\">");
    if (txt != "") {
        link.document.writeln("<p style=\"" + txtStyle + "\">" + txt + "</p>");
    }
    link.document.writeln("</body>");
    link.document.writeln("</html>");
    link.document.close();
    link.focus();
}

// Set the horizontal and vertical position for the popup
PositionX = 100;
PositionY = 100;
// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth = 500;
defaultHeight = 500;
// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;
// Do not edit below this line...
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
    var isNN = (navigator.appName == "Netscape") ? 1 : 0;
    var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
}
var optNN = 'scrollbars=no,width=' + defaultWidth + ',height=' + defaultHeight + ',left=' + PositionX + ',top=' + PositionY;
var optIE = 'scrollbars=no,width=150,height=100,left=' + PositionX + ',top=' + PositionY;
function popImage(imageURL, imageTitle) {
    if (isNN) { imgWin = window.open('about:blank', '', optNN); }
    if (isIE) { imgWin = window.open('about:blank', '', optIE); }
    with (imgWin.document) {
        writeln('<html><head><title>Loading...</title><style type="text/css">body{margin:0px;background-color:#000}</style>');
        writeln('<script type="text/javascript">');
        writeln('var isNN,isIE;');
        writeln('if(parseInt(navigator.appVersion.charAt(0))>=4){');
        writeln('isNN=(navigator.appName=="Netscape")?1:0;');
        writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
        writeln('function reSizeToImage(){');
        writeln('if (isIE){');
        writeln('window.resizeTo(100,100);');
        writeln('width=100-(document.body.clientWidth-document.images[0].width);');
        writeln('height=100-(document.body.clientHeight-document.images[0].height);');
        writeln('window.resizeTo(width,height);}');
        writeln('if (isNN){');
        writeln('window.innerWidth=document.images["popimage"].width;');
        writeln('window.innerHeight=document.images["popimage"].height;}}');
        writeln('function doTitle(){document.title="' + imageTitle + '";}');
        writeln('</script>');
        if (!AutoClose) writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
        else writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
        writeln('<img alt="' + imageTitle + '" name="popimage" src=' + imageURL + ' style="display:block"></body></html>');
        close();
    }
}


function SetLeftColHeight() {
    l = document.getElementById("left")
    l.style.height = document.body.offsetHeight + "px"
}

function requiredField(tb, div, msg) {
    errMsg = document.getElementById(div);
    if (tb.value == "") {
        errMsg.innerHTML = msg;
        return false;
    } else {
        errMsg.innerHTML = "";
        return true;
    }
}

function selectGridItems(dgCnt, chk, aGridChk) {
    var prefix = aGridChk.substring(0, aGridChk.lastIndexOf('_') - 2);
    var suffix = aGridChk.substring(aGridChk.lastIndexOf('_'));

    for (i = 0; i < dgCnt; i++) {
        var chkId = prefix;
        if (i <= 9) { chkId += "0" + i } else { chkId += i }
        chkId += suffix;
        var dgChk = document.getElementById(chkId);
        dgChk.checked = chk.checked;
    }
}

function gridItemSelect(dgCnt, chk, aGridChk) {
    var prefix = aGridChk.substring(0, aGridChk.lastIndexOf('_') - 2);
    var suffix = aGridChk.substring(aGridChk.lastIndexOf('_'));
    var allChecked = true;
    for (i = 0; i < dgCnt; i++) {
        var chkId = prefix;
        if (i <= 9) { chkId += "0" + i } else { chkId += i }
        chkId += suffix;
        var dgChk = document.getElementById(chkId);
        if (!dgChk.checked) {
            allChecked = false;
            break;
        }
    }
    chk.checked = allChecked;
}


function chkListSelect(cnt, chkPrefix, val) {
    for (i = 0; i < cnt; i++) {
        var chk = document.getElementById(chkPrefix + "_" + i);
        chk.checked = val
    }
}


function chkAll(cnt, chkPrefix, chk) {
    for (i = 0; i < cnt; i++) {
        var lChk = document.getElementById(chkPrefix + "_" + i);
        if (lChk.id != chk.id && !lChk.checked) {
            chk.checked = false;
            return
        }
    }
    chk.checked = true;
}


function openFTPWin(fieldname, dir) {
    url = "Utils/FTP/FTP.aspx?";
    if (dir != "") url += "dir=" + dir + "&";
    url += "type=I&fieldname=" + fieldname;
    f = window.open(url, "browse", "location=0,status=0,resizable=1,scrollbars=1,width=700,height=400");
}
function openFTP(fieldname) { openFTPWin(fieldname, ""); }
function Browse(datafolder, fieldname) { openFTPWin(fieldname, datafolder); }

function openColorPicker(fieldname) { cp = window.open("Utils/ColorPicker.htm?fieldname=" + fieldname, "colorpicker", "location=0,status=0,resizable=0,scrollbars=0,width=460,height=280"); }
function openHtmlEditor(fieldname) { h = window.open("Utils/HtmlEditor.aspx?fieldname=" + fieldname, "browse", "location=1,status=0,resizable=1,scrollbars=1,width=700,height=400"); }

function imagePopUp(img) {
    url = img
    nameW = 'feature'
    height = 400
    width = 600
    if (navigator.appVersion.indexOf('4') != -1) {
        // Vars for centering the new window on Version 4 Browsers
        xTop = screen.width / 2 - (width / 2);
        yTop = screen.height / 2 - (height / 2);
        myWindow = window.open(url, nameW, 'height=' + height + ',width=' + width + ',scrollbars=0,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
        myWindow.document.title = "Image Preview - SpiderCMS 1.7 FTP"
    } else {
        myWindow = window.open(url, nameW, 'height=' + height + ',width=' + width + ',scrollbars=0,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=200');
        myWindow.document.title = "Image Preview - SpiderCMS 1.7 FTP"
    } //browser check
} //imagePopUp


function setCalendarView(calName) {
    var cal = document.getElementById(calName)

    if (cal.style.visibility == 'visible') {
        cal.style.visibility = 'hidden';
    } else {
        cal.style.visibility = 'visible';
    }
} //setCalendarView


function DatePicker(fieldname1, fieldname2) {
    openWindow("Utils/Calendar/CalendarPopUp.aspx?fieldname1=" + fieldname1 + "&fieldname2=" + fieldname2, 210, 170, 0, 0, 0)
    return false
} //DatePicker

function openW(URL) {
    var link = open("", "Amathus_Hotel");
    link.document.writeln("<img src=" + URL + " src_cetemp=" + URL + " src_cetemp=" + URL + " />");
    link.document.close();
    link.focus();
}

function swapImage(imgId, newImgSrc) {
    var img = document.getElementById(imgId)
    img.src = newImgSrc;
}

function swapImage(imgId, newImgSrc, divId, legend) {
    var img = document.getElementById(imgId)
    img.src = newImgSrc;

    var div = document.getElementById(divId)
    div.innerHTML = legend
}


function createPagePopUp(pageTitle, pageBody) {
    var NN = 'scrollbars=yes,width=' + defaultWidth + ',height=' + defaultHeight + ',left=' + PositionX + ',top=' + PositionY;
    var IE = 'scrollbars=yes,width=350,height=200,left=' + PositionX + ',top=' + PositionY;

    if (isNN) { win = window.open('about:blank', '', NN); }
    if (isIE) { win = window.open('about:blank', '', IE); }
    with (win.document) {
        writeln("<html><head><title>" + pageTitle + "</title></head><body>");
        writeln(pageBody);
        writeln("</body></html>");
    }
}

function showHideDiv(divId) {
    var div = document.getElementById(divId)
    if (div.style.display == 'block') {
        div.style.display = 'none'
        return 0;
    } else {
        div.style.display = 'block';
        return 1;
    }
}

function getYear() {
    var date = new Date();
    var yy = (date.getYear() < 1000) ? date.getYear() + 1900 : date.getYear();
    return yy
}

function getCurrentDate() {
    var date = new Date();

    var dd = (date.getDate() < 10) ? '0' + date.getDate() : date.getDate();
    var mm = (date.getMonth() < 9) ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
    var yy = (date.getYear() < 1000) ? date.getYear() + 1900 : date.getYear();

    var d = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    return d[date.getDay()] + ", " + dd + "/" + mm + "/" + yy
}

function getDateTime() {
    var date = new Date();

    var dd = (date.getDate() < 10) ? '0' + date.getDate() : date.getDate();
    var mm = (date.getMonth() < 9) ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
    var yy = (date.getYear() < 1000) ? date.getYear() + 1900 : date.getYear();
    var hours = date.getHours();
    var minutes = (date.getMinutes() < 10) ? '0' + date.getMinutes() : date.getMinutes();
    var seconds = (date.getSeconds() < 10) ? '0' + date.getSeconds() : date.getSeconds();

    var d = new Array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');

    document.getElementById("dt").innerHTML = d[date.getDay()] + ", " + dd + "/" + mm + "/" + yy + " " + hours + ":" + minutes + ":" + seconds
    setTimeout("getDateTime()", 1000)
}


function checkRadio(radio) {
    var x = document.forms[0].getElementsByTagName('input');
    for (var i = 0; i < x.length; i++)
        if (x[i].type == 'radio') x[i].checked = false;
    radio.checked = true;
}



function PreLoadImage(imgObj, imgSrc) {
    if (document.images) {
        eval(imgObj + ' = new Image()')
        eval(imgObj + '.src = " ' + imgSrc + '"')
    }
}

function ChangePreloadedImage(imgName, imgContainer) {
    if (document.images) {
        imgOn = eval(imgName + ".src");
        obj = document.getElementById(imgContainer);
        obj.src = imgOn;
    }
}

function gallopRadioButton(mid, groups) {
    var arrGroup = groups.split(";");
    var votes = "";

    for (i = 0; i < arrGroup.length; i++) {
        var radioObj = eval('document.forms[0].' + arrGroup[i]);
        for (var j = 0; j < radioObj.length; j++) {
            if (radioObj[j].checked) {
                votes += radioObj[j].value + ';';
            }
        }
    }
    galobwin = window.open("ShowGallopResults.aspx?mid=" + mid + "&votes=" + votes, "galobwin", "width=500,height=500,scrollbars=1,status=0,location=0,resizable=1");
}


function showHideBilling(chkBill, trBillStr) {
    var trBill = document.getElementById(trBillStr);
    if (chkBill.checked) {
        trBill.style.display = 'none';
    }
    else {
        trBill.style.display = 'block';
    }
}


function showHideElem(elemStr) {
    var elem = document.getElementById(elemStr);
    if (elem != null) {
        if (elem.style.display == 'none') {
            elem.style.display = 'block';
        }
        else {
            elem.style.display = 'none';
        }
    }
}

function adjustRatio(imgId) {

    var img = document.getElementById(imgId);
    var container = img.parentNode;
    var containerTagName = container.nodeName.toUpperCase();
    var cnt = 0;

    while (containerTagName != "DIV") {
        container = container.parentNode;
        containerTagName = container.nodeName.toUpperCase();
        cnt++;
        if (cnt > 2) {
            break;
        }
    }
    if (container.nodeName.toUpperCase() == "DIV") {
        var containerHeight = container.style.height.replace(/px/, "");
        var containerWidth = container.style.width.replace(/px/, "");

        if (containerHeight < img.height) {
            img.style.height = '100%';
            img.style.width = 'auto';
        } else if (containerWidth < img.width) {
            img.style.height = 'auto';
            img.style.width = '100%';
        } else if (containerWidth >= img.width && img.width <= img.height) {
            img.style.width = 'auto';
            img.style.height = containerHeight + 'px';
        } else if (containerWidth >= img.width && img.width >= img.height) {
            img.style.width = containerWidth + 'px';
            img.style.height = 'auto';
        } else {
            img.style.width = 'auto';
            img.style.height = 'auto';
        }
    }
}

//////Flickr and Picassa downloading/////////////
var selectedCnt = 0;
var uploadedCnt = 0;
var uploaFailCnt = 0;

function upload(gal, domainPart) {
    var x = document.forms[0].getElementsByTagName('input');
    for (var i = 0; i < x.length; i++) {
        if (x[i].type == 'checkbox' && x[i].checked == true) {
            postFile(x[i].id, gal, domainPart);
            selectedCnt++;
        }
    }

    return false;
} //upload

function postFile(idx, gal, domainPart) {
    var xmlhttp;
    var img = document.getElementById("img" + idx);
    var imgstat = document.getElementById("imgstat" + idx);

    var source = img.href;
    var word = /.flickr./gi;
    if (!source.match(word)) {
        source = source.substr(0, source.lastIndexOf("/")) + "/d" + source.substr(source.lastIndexOf("/"), source.length - 1);
    } else {
        source = img.getAttribute("originalurl")
        if (source == null || source.length == 0) {
            source = img.href;
        }
    }

    var url = domainPart + "ePhotos/Gallery/upload.aspx?img=" + encodeURIComponent(source) + "&gal=" + gal;

    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } //if

    xmlhttp.open("POST", url, true);
    //alert(url)
    xmlhttp.onreadystatechange = function () {
        switch (xmlhttp.readyState) {
            case 0:
                imgstat.innerHTML = "Error: The request is not initialized";
                uploaFailCnt++;
                getUploadProgress();
                break;
            case 1:
                imgstat.innerHTML = "Uploading...";
                imgstat.style.color = "blue";
                imgstat.style.fontWeight = "normal";
                break;
            case 4:
                imgstat.innerHTML = "UPLOADED";
                imgstat.style.color = "green";
                imgstat.style.fontWeight = "bold";
                uploadedCnt++;
                getUploadProgress();
                break;
        } //switch

    }         //onreadystatechange
    xmlhttp.send(null);
} //postFile

function getUploadProgress() {
    if (uploadedCnt + uploaFailCnt == selectedCnt) {
        alert("Upload completed.\n" +
                    uploadedCnt + " of " + selectedCnt + " images successfully uploaded.\n" +
                    uploaFailCnt + " of " + selectedCnt + " images fail to upload");
        uploadedCnt = 0;
        uploaFailCnt = 0;
        selectedCnt = 0;
        checkNone();
    }
} //checkUploadCompleted

function checkAll() {
    var x = document.forms[0].getElementsByTagName('input');
    for (var i = 0; i < x.length; i++)
        if (x[i].type == 'checkbox') x[i].checked = true;
} //checkAll

function checkNone() {
    var x = document.forms[0].getElementsByTagName('input');
    for (var i = 0; i < x.length; i++)
        if (x[i].type == 'checkbox') x[i].checked = false;
} //checkNone

function SelectOne(rdo, gridName) {
    /* Getting an array of all the "INPUT" controls on the form.*/
    all = document.getElementsByTagName("input");
    for (i = 0; i < all.length; i++) {
        if (all[i].type == "radio")/*Checking if it is a radio button*/
        {
            /*I have added '__ctl' ASP.NET adds '__ctl' to all 
            the controls of DataGrid.*/
            var count = all[i].id.indexOf(gridName + '_ctl');
            if (count != -1 && all[i] != null) {
                all[i].checked = false;
            }
        }
    }
    rdo.checked = true; /* Finally making the clicked radio button CHECKED */
} //SelectOne
