/// <reference path="jquery-1.3.2-vsdoc2.js" />

function gId(objID){return document.getElementById(objID);}
function newWinFull(url)
{
    w=screen.availWidth;
    h=screen.availHeight;
    settings="width="+ w + ",height="+ h + ",top=0, left=" + w + ", resizable=yes,scrollbars=yes";
    win=window.open(url, "name", settings);
}
function newWinHalfFull(url)
{
    w=screen.availWidth/2;
    h=screen.availHeight;
    settings = "width=" + w + ",height=" + h + ",top=0,left=" + w + ",resizable=yes,scrollbars=yes";
    win=window.open(url, "name", settings);
}
function newWinFull2(url)
{
    w=screen.availWidth;
    h=screen.availHeight;
    settings="width="+ w + ",height="+ h + ",top=0,left=0,directories=yes,menubar=yes,toolbar=yes,status=yes,location=yes,scrollbars=yes,resizable=yes";
    win=window.open(url, "name", settings);
}
function newWindow(w,h,url)
{
    var l = (screen.availWidth - w) / 2;
    var t = (screen.availHeight - h) / 2;
    settings="width="+ w + ",height=" + h + ",top=" + t + ",left=" + l + ",resizable=yes,scrollbars=yes";
    win=window.open(url, "name", settings);
}
function onLoadRun()
{
    if(typeof(onLoadExt) != 'undefined') onLoadExt();
}

function addbookmark(){ 
var url = location.href; 
var title = document.title; 
try{ 
    window.external.addFavorite(url, title); 
}catch (e){ 
    try{ 
        window.sidebar.addPanel(title, url, ""); 
       }catch (e){ 
            alert("Add favorite failed, please add it manually!"); 
        } 
    } 
}

function trim(str) {
    if (!str) return "";
    return str.replace(/(^\s*)|(\s*$)/g, "");     
}  

// turn off right click menu
// document.oncontextmenu=new Function("event.returnValue=false;");

//Select or deselect designated check box
function select_deselectAll (objId, objVal) {
    if(objVal == null || objId == null) return;
    var chkVal = objVal.checked;
    var idVal = objId.id;
    if (idVal.indexOf('DeleteThis') != -1 && gId(idVal) != null) { // only single check box
        gId(idVal).checked = !gId(idVal).checked;
        return;
    } else if(idVal.indexOf ('CheckAll') != -1) {
        var frm = document.forms[0];
        // Loop through all elements
	    for (i=0; i<frm.length; i++) {
		    // Look for our Header Template's Checkbox
		    if (frm.elements[i].type == "checkbox") {
			    // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
			    if(chkVal == true) {
				    frm.elements[i].checked = true;
			    } else {
				    frm.elements[i].checked = false;
			    }
		    // Work here with the Item Template's multiple checkboxes
		    }
	    }
    }
}
//End of select_deselectAll

function changeImg() {
    var img = gId("imgCode");
    img.src = img.src + '?';
}

// deal with url
function replaceUrl(hostName) {
    $("a").each(function() {
        var href = $(this).attr("href");
        if (href.indexOf("http://") == 0 || href.indexOf("https://") == 0 || href.indexOf("javascript:") == 0) return;
        if (href.indexOf("/") == 0) href = hostName + href.substring(1);
        else
            href = hostName + href;
        $(this).attr("href", href);
    });
}

function znChangeForm(action, method)
{
    var theForm = document.forms[0];
    theForm.action = action;
    theForm.method = method;
    theForm.submit();
}
