﻿
function getView(actionMethod, data, callback, args) {

    return jQuery.ajax(
    {    
        type: (data == null) ? "GET" : "POST",
        url: actionMethod,
        cache: false,
        data: data,
        dataType: "html",
        complete: function(result, resultDesc) {
            callback(result, args);
        }
    });

}

function submitForm(formId, actionMethod, callback, args) {
    
    var options = {
        url: actionMethod,
        dataType: 'html',
        complete: function(result, resultDesc) {
            callback(result, args);
        }
    };
        
    return jQuery(formId).ajaxSubmit(options);
}

/*Misc js moved from the IndexPage*/
function isDefined(variable)
{
    return (typeof(variable) == "undefined") || (variable == null) ? false : true;
}

function showhide(element)
{
    if(!isDefined(element))
	    return;
	
    if (element.style.display=="none") 
    {
	    element.style.display=""; 
    } 
    else 
    {   
	    element.style.display="none";
    }
}	

function show(element)
{
    showhide(element);
}	

function hide(element)
{
    showhide(element);
}


function refresh() {
    window.location.replace('/');
    /*setTimeout('refresh()', 15000);*/
}
function chUnCh(element) {
    var frmName = element.form, z = 0;
    for (z = 0; z < frmName.length; z++) {
        if (frmName[z].type == 'checkbox' && frmName[z].name != 'checkall') {
            frmName[z].checked = element.checked;
        }
    }
}

/*Images pre-loading*/
function JDL_swapImgRestore() { //v3.0
        var i, x, a = document.JDL_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
    }

    function JDL_preloadImages() { //v3.0
        var d = document; if (d.images) {
            if (!d.JDL_p) d.JDL_p = new Array();
            var i, j = d.JDL_p.length, a = JDL_preloadImages.arguments; for (i = 0; i < a.length; i++)
                if (a[i].indexOf("#") != 0) { d.JDL_p[j] = new Image; d.JDL_p[j++].src = a[i]; } 
        }
    }
    function JDL_findObj(n, d) { //v4.01
        var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
            d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
        }
        if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
        for (i = 0; !x && d.layers && i < d.layers.length; i++) x = JDL_findObj(n, d.layers[i].document);
        if (!x && d.getElementById) x = d.getElementById(n); return x;
    }
    function JDL_swapImage() { //v3.0
        var i, j = 0, x, a = JDL_swapImage.arguments; document.JDL_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
            if ((x = JDL_findObj(a[i])) != null) { document.JDL_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }
    
    
    function runOnLoad()
    {
            var winW = 753, winH = 570;

            if (parseInt(navigator.appVersion) > 3) {
                if (navigator.appName == "Netscape") {
                    /*winW = window.innerWidth-0;*/
                    winH = window.innerHeight - 200;
                }
        //        if (navigator.appName.indexOf("Microsoft") != -1) {
        //            /*winW = document.body.offsetWidth-0;*/
        //            winH = document.body.offsetHeight - 200;
        //        }
            }
            
            
            _editor_url = '/../../Media/HtmlEditor/';                     // URL to htmlarea files
            var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
            if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
            if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
            if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
            
            if (win_ie_ver >= 5.5) 
            {
                //do nothing as script is already loaded !
                //document.write('<script src="' +_editor_url+ '<%=GetScriptPath("js/editor.js")%>"');
                //document.write(' language="javascript" type="text/javascript"></script>');  
            } 
            else 
            { 
                document.write('<script>function editor_generate() { return false; }</script>'); 
            }
    }