﻿function getObj(o) {
  if (document.getElementById) {
    return document.getElementById(o);
  }
  else if (document.all) {
    return document.all(o);
  }
  else if (document.layers) {
    return document.layers(o);
  }
}
function hide(o)
{
    getObj(o).style.display='none';
    getObj(o).style.visibility='hidden';
}
function display(o)
{
    getObj(o).style.display='';
    getObj(o).style.visibility='visible';
}

function Go(url) 
{
    window.location.href = url;
}

function confirmDelete(item) 
{
    return confirm('Are you sure you want to delete this ' + item + '?');
}

function Print(path) 
{
	openWindow(path + 'resources/utilities/print.aspx', 680, 620, 'yes');
}

function openWindow(loc,wdt,hgt,scroll, resizable) 
{	
	window.open(loc, 'win', 'height=' + hgt + ',width=' + wdt + ',top=120,left=100' + ',toolbar=yes,scrollbars=' + scroll + ',resizable=' + resizable);
}

function pageWidth() 
{
    return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

function pageHeight() 
{
    return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

function posLeft()
{
    return typeof window.pageXOffset != "undefined" ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft:document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function posTop()
{
    return typeof window.pageYOffset != "undefined" ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function posRight()
{
    return posLeft()+pageWidth();
}

function posBottom()
{
    return posTop()+pageHeight();
}

function DisableEnter(field, event, cmd) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		DoSubmit(cmd);
		return false;
	} 
	else
	return true;
}

function DoSubmit(cmd) {
    getObj(cmd).click();
}

function CheckBoxChange(cb) 
{

	var frm = cb.form, i = 0;
	
	while (i < frm.length) {
	
		if (frm[i].type == 'checkbox') {
		
			frm[i].checked = cb.checked;
		
		}
		
		i++;

	}

}

function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}