function getElement(name)
{
  var ctrl = null;
	if ( document.getElementById ){
		ctrl = document.getElementById(name);
	}else if (document.all){
		ctrl = document.all[name];
	}else if (document.layers){
		ctrl = document.layers[name];
	}
	//if(ctrl==null){window.alert(name+" not found!!");}
	return ctrl;
}

function openDefaultWindow(url , height , width )
{
  return openDefaultWindow(url , height , width, "newWindow" )
}
function openDefaultWindow(url , height , width, name )
{
	var win = window.open(url , name, "height=" + height + ",width=" + width + ",scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no,location=no");
	win.focus() ;
	return win ; 
}

function openToolbarWindow(url , height , width )
{
	var win = window.open(url , "newWindow", "height=" + height + ",width=" + width + ",scrollbars=yes,resizable=yes,toolbar=yes,status=no,menubar=no,location=no");
	win.focus() ;
	return win ; 
}

function refreshPage(){
  if((form=getElement("Form1"))){
    form.submit();
  }else if(document.forms[0]){
    document.forms[0].submit();
  }
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/"; // This may need to change later
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


var _pageSizeVal = 0;
function setPageFontSize(){
  var pageSize = readCookie("pageSize");
  if(pageSize!=null){
    _pageSizeVal=parseInt(pageSize);
    fontSize(_pageSizeVal);
  }
}

function toggleFontSize(){
  var newPageSizeVal = _pageSizeVal + 1;
  if(newPageSizeVal>2){
    newPageSizeVal=0;
  }
  fontSize(newPageSizeVal);
}

function forceFontSize(pageSize){
  if(pageSize>=0&&pageSize<=2){
    fontSize(pageSize);
  }
}

function fontSize(pageSize){
/*  var i, css, cssObjs = document.getElementsByTagName("LINK");
  var test = "styleSize" + pageSize.toString();
  for(i=0;i<cssObjs.length;i++){
    if((css=cssObjs[i])&&css.title.indexOf("styleSize")==0){
      css.disabled=true;
      if(css.title==test){
        css.disabled=false;
      }
    }
  }*/
  document.body.className = "bodysize"+pageSize.toString();
  _pageSizeVal = pageSize;
  createCookie("pageSize",pageSize.toString(),365);
}

function onPickListItemClicked(ctrl){
  var txt = getElement(ctrl.id.replace("_chkPick","_txtValue"));
  if(txt){
    txt.disabled=!ctrl.checked;
  }
}

function displayHelp(virroot,id,jobid){
	var helpwin = openDefaultWindow(virroot + 'help.aspx?helpId=' + id + '&jobId=' + jobid, 550 , 600, "helpwin") ;
	helpwin.focus();
}

// Click a button prgramatically
function clickButton(ctrlName){
  var lnkCtrl;
  if(ctrlName!=""&&(lnkCtrl=getElement(ctrlName))){
    if(lnkCtrl.click){
      lnkCtrl.click();
    }else{
      eval(lnkCtrl.href);
    }
  }
}

function dateFocus(ctrl){
  if(ctrl&&ctrl.value == 'dd/mm/yyyy'){
	  ctrl.value = '';
  }
}
function dateFocusShort(ctrl){
  if(ctrl&&ctrl.value == 'mm/yyyy'){
	  ctrl.value = '';
  }
}
function dateBlur(ctrl){
  if(ctrl&&ctrl.value == ''){
	  ctrl.value = 'dd/mm/yyyy';
  }
}
function dateBlurShort(ctrl){
  if(ctrl&&ctrl.value == ''){
	  ctrl.value = 'mm/yyyy';
  }
}
