﻿
//returns the ClientID of an ASP.NET server control using its ID
function GetClientId(strid) {
    var count = document.getElementsByTagName('*').length; //<-- gets all elements, instead of Forms as this only returns FORM elements
    var i = 0;
    var eleName;
    for (i = 0; i < count; i++) {
        eleName = document.getElementsByTagName('*')[i].id;
        pos = eleName.indexOf(strid);
        if (pos >= 0) break;
    }
    return eleName;
}

function queryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

//removes the specified class (t) from the provided element (e)
function removeClassName(e, t) {
    if (typeof e == "string") {
        e = xGetElementById(e);
    }
    //code to change and replace strings
    var ec = ' ' + e.className.replace(/^s*|s*$/g, '') + ' ';
    var nc = ec;
    t = t.replace(/^s*|s*$/g, '');
    //check if not already there
    if (ec.indexOf(' ' + t + ' ') != -1) {
        //found, so lets remove it
        nc = ec.replace(' ' + t.replace(/^s*|s*$/g, '') + ' ', ' ');
    }
    //return the changed text!
    e.className = nc.replace(/^s*|s*$/g, ''); //trimmed whitespace
    return true;
}

function showPhoto(txt) {

    PageMethods.AJAX_ShowImage(txt.value, show_image, onFailed);
}


/********************
*** AJAX Return methods
*********/

function onSucceeded(result, userContext, methodName) {
    //alert(result);
}
function onFailed(error, userContext, methodName) {
    alert("An error occurred during AJAX call:\n\r\n\r" + error + '\n\r\n\r' + methodName + '\r\n\r\n' + error.get_message());
}

function redirect(result, userContext, methodName) {
    window.location.href = result
}

function show_image(result, userContext, methodName) {
    //alert(result);
    var divPhoto = document.getElementById(GetClientId('divPhoto'))
    divPhoto.innerHTML = result;
}
