var w3c=(document.getElementById)? true: false;
var ie5=(w3c && document.all)? true : false;

function findoptionindex(obj,matchvalue){
 for (var i=0;i<=obj.length-1;i++){
  if (obj.options[i].value==matchvalue){
   return i;
  }
 }
 return -1;
}
function autoselectlist(formfield,matchvalue){
 var obj;
 if (isobject(formfield))
  obj=formfield;
 else
  obj=eval('document.' + formfield);
 if (document.all) {
  var seli=findoptionindex(obj,matchvalue);
  if (seli>=0)
   obj.selectedIndex=seli;
 } else {
  if (obj)
   obj.value=matchvalue;
 }
}
function selectedvalue(x){
 if (!x)
  return '';
 if (document.all) {
  return x.options[x.selectedIndex].value;
 } else {
  return x.value;
 }
}
function selectedtext(x){
 return x.options[x.selectedIndex].text;
}
function isobject(x){
 return (typeof x == 'object' && !!x);
}
function changetext(objectid,text) {
 var obj;
 if (isobject(objectid))
  obj=objectid;
 else
  obj=getobj(objectid);
 if (obj!=null){
  obj.innerHTML=text;
 }
}
function gettext(objectid) {
 var obj;
 if (isobject(objectid))
  obj=objectid;
 else
  obj=getobj(objectid);
 return obj.innerHTML;
}
function getobj(objname){
 return document.getElementById?document.getElementById(objname):document.all?document.all[objname]:document.layers[objname];
}
function getattr(objectid,attributename) {
 var obj;
 if (isobject(objectid))
  obj=objectid;
 else
  obj=getobj(objectid)
 if (obj)
  return obj.getAttribute(attributename);
 return "";
}
function setattr(objectid,attributename,value) {
 var obj;
 if (isobject(objectid))
  obj=objectid;
 else
  obj=getobj(objectid)
 if (!obj)
  return;
 obj.setAttribute(attributename,value);
}
function uc(){
 alert('Under Construction. Please try again later.');
 return false;
}

function isdefined(x){
 return typeof(x)=='undefined'?false:true;
}
var ignoreclickid=false;
function ignoreclick(){
 ignoreclickid=true; 
}
function gourl(url,clickid){
 if (!ignoreclickid)
  document.location.href=url;
 ignoreclickid=false;
}
function moveit(obj,thisx,thisy){
 obj.style.x=thisx;
 obj.style.y=thisy;
 obj.style.left=thisx;
 obj.style.top=thisy;
}
function findpos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function hideobj(x){
 getobj(x).style.display='none';
}
function showobj(x){
 getobj(x).style.display='block';
}
function toggleobj(x){
 var obj=getobj(x);
 if (obj.style.display=='block')
  obj.style.display='none';
 else
  obj.style.display='block';
}
var windowWidth = 0, windowHeight = 0;
function getWindowSize() {
 if( typeof( window.innerWidth ) == 'number' ) {
  windowWidth = window.innerWidth;
  windowHeight = window.innerHeight;
 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  windowWidth = document.documentElement.clientWidth;
  windowHeight = document.documentElement.clientHeight;
 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  windowWidth = document.body.clientWidth;
  windowHeight = document.body.clientHeight;
 }
}
var scrollOffsetX = 0, scrollOffsetY = 0;
function getScrollXY() {
 if( typeof( window.pageYOffset ) == 'number' ) {
  scrollOffsetY = window.pageYOffset;
  scrollOffsetX = window.pageXOffset;
 } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
  scrollOffsetY = document.body.scrollTop;
  scrollOffsetX = document.body.scrollLeft;
 } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
  scrollOffsetY = document.documentElement.scrollTop;
  scrollOffsetX = document.documentElement.scrollLeft;
 }
}
function getpagewidth() {
 return document.body.scrollWidth;
}
function getpageheight() {
 return document.body.scrollHeight;
}
function getwidth(obj){
 if (document.all)
  return obj.scrollWidth
 return obj.scrollWidth
}
function getheight(obj){
 if (typeof(obj).type=='string')
  return obj.offsetHeight;
 if (document.all)
  return obj.scrollHeight
 return obj.scrollHeight
}
function hidealldropdowns(unhide){
 var ddls=document.getElementsByTagName("SELECT");
 for(i=0;i<ddls.length;i++){
  if (unhide==1)
   ddls[i].style.display="block";
  else
   ddls[i].style.display="none";
 }
}
function togglecontenttohide(unhide){
 var obj=getstyleruleobj('contenttohide');
 if (obj) {
  if (unhide==1)
   setopacity(obj,100);
  else
   setopacity(obj,0);
 }
 if (ie5)
  hidealldropdowns(unhide);
}
function getstyleruleobj(ruletext){
 var obj=null;
 if (document.styleSheets.item) {
  if (document.styleSheets[0].cssRules)
   obj=document.styleSheets.item(0).cssRules;
  else
   obj=document.styleSheets.item(0).rules;
 } else {
  if (document.styleSheets[0].rules)
   obj=document.styleSheets[0].rules.item;
  else
   obj=document.styleSheets[0].cssRules;
 }
 if (obj) {
  for (var i=0;i<=obj.length-1;i++) {
   if (obj[i].selectorText=='.'+ruletext)
    return obj[i];
  }
 }
 return null;
}
function setopacity(obj,perc){//perc - 0 to 100
 if(ie5){
  if (perc==100)
   obj.style.filter='';
  else{
   obj.style.filter='alpha(opacity='+perc+')';}
 } else {
  obj.style.MozOpacity=perc/100;
 }
}
function getopacity(obj){
 var op=0;
 if(ie5){
  var x=obj.style.filter;
  var pos1=x.indexOf('=');
  var pos2=x.indexOf(')');
  if(pos1<0 || pos2<0) return 0;
  op=x.substring(pos1+1,pos2);
 } else {
  op=obj.style.MozOpacity*100;
 }
 return op*1;
}

var onloadcom = new Array();
function addloadcommand(functtext){
 onloadcom[onloadcom.length]=functtext;
}
function bodyonload(){
 for (var i=0;i<onloadcom.length;i++){
  eval(onloadcom[i]);
 }
}
if (window.addEventListener)
 window.addEventListener("load", bodyonload, false);
else if (window.attachEvent)
 window.attachEvent("onload", bodyonload);
else if (document.getElementById)
 window.onload=bodyonload;


function getselectradio(obj){
 if (!obj)
  return '';
 for (var i=0; i<obj.length; i++){
  if (obj[i].checked)
   return obj[i].value;
 }
 return '';
}

function selectradio(obj,v){
 for (var i=0; i<obj.length; i++){
  if(obj[i].value==v){
   obj[i].checked=true;
  }
 }
}

function safeeval(js){
 if(js!='')
  eval(js);
}

function preloadlist(imglist){
 //format: abc.gif;def.jpg;ghi.gif
 var imgs=new Array();
 var imgarray=imglist.split(';');
 for (var i=0;i<=imgarray.length-1;i++){
  imgs[i]=new Image(); imgs[i].src=imgarray[i];
 }
}

function isnumeric(s) {
 if (!s) return false;
 var chars = "0123456789-.";
 for (var i=0;i<s.length;i++) {
  if (chars.indexOf(s.charAt(i))==-1)
   return false;
 }
 return true;
}

function mt(x){
 if (x==null) return true;
 if (x=="") return true;
 return false;
}

function getformfieldvalue(obj){
 if (!obj) return '';
 var type=obj.type;
 if (type=='text' || type=='textarea' || type=='hidden' || type=='password') {
  return obj.value;
 }
 if (type=='radio') {
  return getselectradio(obj);
 }
 if (type=='checkbox') {
  if (obj.checked) return obj.value;
  return 0;
 }
 if (type=='select-one' || type=='select-multiple') {
  return selectedvalue(obj);
 }
}
