﻿function checkFileExtensionForJpgAndGif(elem) {
    var filePath = elem.value;

    if (filePath.indexOf('.') == -1)
        return false;

    var validExtensions = new Array();
    var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

    validExtensions[0] = 'jpg';
    validExtensions[1] = 'jpeg';
    validExtensions[2] = 'gif';
    //validExtensions[3] = 'png';

    for (var i = 0; i < validExtensions.length; i++) {
        if (ext == validExtensions[i])
            return true;
    }

    alert('Τα αρχεία ' + ext.toUpperCase() + ' δεν υποστηρίζονται!');
    elem.value = '';
    return false;
}
function checkFileExtensionForSwf(elem) {
    var filePath = elem.value;

    if (filePath.indexOf('.') == -1)
        return false;

    var validExtensions = new Array();
    var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

    validExtensions[0] = 'swf';
    //validExtensions[1] = 'jpeg';
    //validExtensions[2] = 'gif';
    //validExtensions[3] = 'png';

    for (var i = 0; i < validExtensions.length; i++) {
        if (ext == validExtensions[i])
            return true;
    }

    alert('Τα αρχεία ' + ext.toUpperCase() + ' δεν υποστηρίζονται!');
    elem.value = '';
    return false;
}
function checkFileExtensionForSwfOrJpgOrGif(elem) {
    var filePath = elem.value;

    if (filePath.indexOf('.') == -1)
        return false;

    var validExtensions = new Array();
    var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

    validExtensions[0] = 'swf';
    validExtensions[1] = 'jpeg';
    validExtensions[2] = 'gif';
    validExtensions[3] = 'jpg';

    for (var i = 0; i < validExtensions.length; i++) {
        if (ext == validExtensions[i])
            return true;
    }

    alert('Τα αρχεία ' + ext.toUpperCase() + ' δεν υποστηρίζονται!');
    elem.value = '';
    return false;
}
function numbersonly(e) {
    var unicode = e.charCode ? e.charCode : e.keyCode;

    //if the key isn't the backspace key (which we should allow)
    if (unicode != 8) {
        //if not a number
        if (unicode < 48 || unicode > 57) {
            //disable key press
            return false;
        } //end if
        else {
            // enable keypress
            return true;
        } //end else
    } //end if
    else {
        // enable keypress
        return true;
    } //end else
} //end function

function GetSynchronousJSONResponse(url, postData) {
    var xmlhttp = null;
    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();
    else if (window.ActiveXObject) {
        if (new ActiveXObject("Microsoft.XMLHTTP"))
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        else
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    // to be ensure non-cached version of response
    url = url + "?rnd=" + Math.random();

    xmlhttp.open("POST", url, false); //false means synchronous
    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    xmlhttp.send(postData);
    var responseText = xmlhttp.responseText;
    return responseText;
}
//Global Fail Web Service Call Back
function GlobalFailWebServiceCallBack(error, userContext, methodName) {
    alert("Stack Trace: " + error.get_stackTrace() + "/r/n" + "Error: " + error.get_message() + "/r/n" + "Status Code: " + error.get_statusCode() + "/r/n" + "Exception Type: " + error.get_exceptionType() + "/r/n" + "Timed Out: " + error.get_timedOut());
}
/// functions for visuals & UI

/************************* Font resizer **********************************/
var min = 16;
var max = 24;
function increaseFontSize(target) { //Increase font
    //resize text
    var elem = document.getElementById(target);
    if (elem) {
        if (elem.style.fontSize) {
            var size = parseInt(elem.style.fontSize.replace("px", ""));
        } else {
            size = 14;
        }
        if (size <= max) {
            size += 4;
        }
        elem.style.fontSize = size + "px";
    }
    //resize links
    var a = elem.getElementsByTagName('a');
    for (i = 0; i < a.length; i++) {
        if (a[i].style.fontSize) {
            var asize = parseInt(a[i].style.fontSize.replace("px", ""));
        } else {
            var asize = 14;
        }
        if (asize <= max) {
            asize += 4;
        }
        a[i].style.fontSize = asize + "px"
    }

}

function decreaseFontSize(target) { //Decrease font
    //resize text
    var elem = document.getElementById(target);
    if (elem) {
        if (elem.style.fontSize) {
            var size = parseInt(elem.style.fontSize.replace("px", ""));
        } else {
            size = 14;
        }
        if (size >= min) {
            size -= 4;
        }
        elem.style.fontSize = size + "px";
    }
    //resize links
    var a = elem.getElementsByTagName('a');
    for (i = 0; i < a.length; i++) {
        if (a[i].style.fontSize) {
            var asize = parseInt(a[i].style.fontSize.replace("px", ""));
        } else {
            var asize = 14;
        }
        if (asize >= min) {
            asize -= 4;
        }
        a[i].style.fontSize = asize + "px"
    }

}

/************************* Google search **********************************/
function GoogleSearch(domain, TextBoxId) {     //Input1: domain, Input2: search textbox id
    var txtQ = document.getElementById(TextBoxId);
    var q = txtQ.value;
    window.location = "http://www.google.com/custom" + "?q=" + q + "&domains=" + domain + "&sitesearch=" + domain;
}

/************************* Input check ************************************/
function checkInput(obj) {
    //var invalidChars = /["'\\'<>]/gi
    var invalidChars = /[<>]/gi
    if (invalidChars.test(obj.value)) {
        //alert("Invalid characters.");
        obj.value = obj.value.replace(invalidChars, "");
    }
}

/************************** Open PopUp window ******************************/
function wopen(url, name, w, h) {
    // Fudge factors for window decoration space.
    // In my tests these work well on all platforms & browsers.
    w += 32;
    h += 96;
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    // IE5 and other old browsers might allow a window that is
    // partially offscreen or wider than the screen. Fix that.
    // (Newer browsers fix this for us, but let's be thorough.)
    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }
    var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=yes, resizable=yes');
    // Just in case width and height are ignored
    win.resizeTo(w, h);
    // Just in case left and top are ignored
    win.moveTo(wleft, wtop);
    win.focus();
}


function RoundContainerDefault() {
    $("div.RoundContainerDefault").wrap('<div class="dialog">' +
'<div class="bd">' +
'<div class="c">' +
'<div class="s">' +
'</div>' +
'</div>' +
'</div>' +
'</div>');
    $('div.dialog').prepend('<div class="hd">' +
'<div class="c"></div>' +
'</div>')
.append('<div class="ft">' +
'<div class="c"></div>' +
'</div>');

}

function RoundContainerWhite() {
    $("div.RoundContainerWhite").wrap('<div class="dialogwhite">' +
'<div class="bd">' +
'<div class="c">' +
'<div class="s">' +
'</div>' +
'</div>' +
'</div>' +
'</div>');
    $('div.dialogwhite').prepend('<div class="hd">' +
'<div class="c"></div>' +
'</div>')
.append('<div class="ft">' +
'<div class="c"></div>' +
'</div>');

}



function bookmark() {
    bookmarkurl = "http://www.λιποαναρροφηση.gr/"
    bookmarktitle = "λιποαναρροφηση.gr"
    if (window.sidebar) {
        window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
    } else if (document.all) {
        if (document.all)
            window.external.AddFavorite(bookmarkurl, bookmarktitle)
    } else if (window.opera && window.print) {
        return true;
    }
}

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 
