var lastMouseX;
var lastMouseY;
var currentPOPWindow = null;
var buttonsArray = new Array();
var menusArray = new Array();
var submenusArray = new Array();
var pageIsReady = false;

function wait(msecs)
{
  var start = new Date().getTime();
  var cur = start
  while(cur - start < msecs)
  {
  cur = new Date().getTime();
  }
}

function submitForm(formName)
{
	var myform = document[formName]
	if (validateForm(myform)) myform.submit();
}

function createButtonImages(id)
{
	var buttonArray = new Array();
	buttonArray[0]=wbpr('n'+id+'.gif');
	buttonArray[1]=wbpr('o'+id+'.gif');
	buttonArray[2]=wbpr('c'+id+'.gif');
	buttonsArray[id] = buttonArray;
}

// for reg buttons
function wbe(id)
{
  if (!pageIsReady) return;
  x=id.substring(0,id.length-1);
  y=id.substring(id.length-1);
  var buttonArray = buttonsArray[x]
  document['btn'+x].src=buttonArray[y].src
}

function wbpr(im){
  var i=new Image();
  i.src='/static/image/button/img'+im;
  return i;
}

// for menu buttons
function createMenuImages(id)
{
	var buttonArray = new Array();
	buttonArray[0]=wmpr('n'+id+'.gif');
	buttonArray[1]=wmpr('o'+id+'.gif');
	buttonArray[2]=wmpr('c'+id+'.gif');
	
	menusArray[id] = buttonArray;
}

function wme(id)
{
  if (!pageIsReady) return;

  x=id.substring(0,id.length-1);
  y=id.substring(id.length-1);
  var buttonArray = menusArray[x]
  if (y == 2)
  {
  	resetwme();	
  }
  else if (y == 0)
  {
//    if (document.getElementById("submenugrp"+x))
//      document.getElementById("submenugrp"+x).style.display = 'none'

  }
  else if (y == 1)
  {
//    alert(x+"-"+document.getElementById("submenugrp"+x)+"-"+pageIsReady)
    if (document.getElementById("submenugrp"+x) && pageIsReady){
        document.getElementById("submenugrp"+x).style.display = 'none'
        document.getElementById("submenugrp"+x).style.display='block'
    }
  }
  if (document['btn'+x].src.indexOf("imgc"+x+".gif") == -1)
  { 
    document['btn'+x].src=buttonArray[y].src
  }
}

function wmpr(im){
  var i=new Image();
  i.src='/static/image/menu/img'+im;
  return i;
}

function resetwme()
{
  if (!pageIsReady) return;
  for (var i=0; i<menusArray.length; i++)
  {
    var buttonArray = menusArray[i]
    if (buttonArray != null)
    {
        if (document['btn'+i] != null){
          document['btn'+i].src=buttonArray[0].src
        }
    }
  }
}

// for sub menu buttons
function createSubMenuImages(id)
{
	var buttonArray = new Array();
	buttonArray[0]=wsmpr('n'+id+'.gif');
	buttonArray[1]=wsmpr('o'+id+'.gif');
	buttonArray[2]=wsmpr('c'+id+'.gif');

	submenusArray[id] = buttonArray;
}

function wsme(id)
{
  x=id.substring(0,id.length-1);
  y=id.substring(id.length-1);
  var buttonArray = submenusArray[x]
  if (y == 2)
  {
	  resetwsme();
  }
  if (document['submenu'+x].src.indexOf("imgc"+x+".gif") == -1)
  {
    document['submenu'+x].src=buttonArray[y].src
  }
}

function wsmpr(im){
  var i=new Image();
  i.src='/static/image/submenu/img'+im;
  return i;
}

function resetwsme()
{
  for (var i=0; i<submenusArray.length; i++)
  {
    var buttonArray = submenusArray[i]
    if (buttonArray != null)
    {
        if (document['submenu'+i] != null)
        document['submenu'+i].src=buttonArray[0].src
    }
  }  
}

function formatNumber(num, showComma, fractDigits) {
	num = num.toString().replace(/\$|\,/g,'');

	if(isNaN(num)) return "0";

	var sign = (num == (num = Math.abs(num)));
	var d = Math.pow(10,fractDigits);
//alert('d='+d)	
	num = Math.floor(num*d+0.50000000001);
//alert('num='+num)	
	fract = num%d;
//alert('fract='+fract)	
	num = Math.floor(num/d).toString();
//alert('num='+num)	
	while (fract.toString().length < fractDigits)
	{
		fract = "0" + fract;
//alert('now...fract='+fract)	
	}
	if (showComma){
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	return (((sign)?'':'-') +  num + '.' + fract);
}

function compareOptionValues(a, b){ 
	var sA = parseInt( a.value, 36 );  
	var sB = parseInt( b.value, 36 );  
	return sA - sB;
}

function compareOptionText(a, b) { 
	var sA = parseInt( a.text, 36 );  
	var sB = parseInt( b.text, 36 );  
	return sA - sB;
}
function listBoxSort(box)  
{
	var temp_opts = new Array();
	var temp = new Object();
	for(var i=0; i<box.options.length; i++)  
	{
		temp_opts[i] = box.options[i];
	}

	for(var x=0; x<temp_opts.length-1; x++)  
	{
		for(var y=(x+1); y<temp_opts.length; y++)  
		{
			if(temp_opts[x].text > temp_opts[y].text)  
			{
				temp = temp_opts[x].text;
				temp_opts[x].text = temp_opts[y].text;
				temp_opts[y].text = temp;
				temp = temp_opts[x].value;
				temp_opts[x].value = temp_opts[y].value;
				temp_opts[y].value = temp;
			}
	   }
	}
	
	for(var i=0; i<box.options.length; i++)  
	{
		box.options[i].value = temp_opts[i].value;
		box.options[i].text = temp_opts[i].text;
   }
	return;
}

function showhide(what){
	if (what.style.display=='none'){
		what.style.display='';
	}else{
		what.style.display='none';
	}
}	

function detectBrowser(){
	if (navigator.appName == "Microsoft Internet Explorer")
   		strSheet ="<LINK href=\"../utils/css/optimizer.css\" media=screen rel=StyleSheet type=text/css>";
	 else	strSheet ="<LINK href=\"../utils/css/net_optimizer.css\" media=screen rel=StyleSheet type=text/css>";
	document.writeln(strSheet);
}

function secondWinOpen(strUrl,strName,str3, winWidth,winHeight) {
  window.open(strUrl, "strName",
	"alwaysRaised=yes,location=no,status=no,scrollbars=yes,autosize=yes,resizable=yes,width="+winWidth+",height="+ winHeight+", left=300,top=300,screenX=200,screenY=300,toolbar=no,directories=no, locationbar=no, statusbar=no, menubar=no");
}

function limitPicSize(imgId, maxWidth, maxHeight)
{
  var img = document.getElementById(imgId);
	var newimg = new Image();
	newimg.src = img.src;

	var w=newimg.width;
	var h=newimg.height;

	if (newimg.width > maxWidth){
	  w=maxWidth
	  h=(maxWidth/newimg.width)*newimg.height
	}
	if (h> maxHeight){
	  w=(maxHeight/h)*w
	  h=maxHeight
	}
	img.width=w;
	img.height=h;
}


function winOpen(str,str1,str2,winWidth,winHeight) {
	var properties = "";
  	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
 		
	if(navigator.appName == "Microsoft Internet Explorer") {
   		screenY = document.body.offsetHeight;
   		screenX = window.screen.availWidth;
 	}else {
   		screenY = window.outerHeight
   		screenX = window.outerWidth
 	}
 	
	var leftvar = (screenX - winWidth) / 2;
	var rightvar = (screenY - winHeight) / 2;
	if(navigator.appName == "Microsoft Internet Explorer") {
		leftprop = leftvar;
		topprop = rightvar+100;
	}else {
		leftprop = (leftvar - pageXOffset);
		topprop = (rightvar - pageYOffset);
   	}
	win=window.open(str, str2,
"alwaysRaised=yes,location=no,status=no,scrollbars=no,autosize=no,resizable=yes,width="+winWidth+",height="+ winHeight+", left="+leftprop+",top="+topprop+",toolbar=" + str1 +",toolbar=no,directories=no, locationbar=no, statusbar=no, menubar=no");
}

function winPrintOpen(str,str1,str2,winWidth,winHeight) {
  var properties = "";
  	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
 		
	if(navigator.appName == "Microsoft Internet Explorer") {
   		screenY = document.body.offsetHeight;
   		screenX = window.screen.availWidth;
 	}else {
   		screenY = window.outerHeight
   		screenX = window.outerWidth
 	}
 	
	var leftvar = (screenX - winWidth) / 2;
	var rightvar = (screenY - winHeight) / 2;
	if(navigator.appName == "Microsoft Internet Explorer") {
		leftprop = leftvar;
		topprop = rightvar+100;
	}else {
		leftprop = (leftvar - pageXOffset);
		topprop = (rightvar - pageYOffset);
   	}
	win=window.open(str, str2,
"alwaysRaised=yes,location=yes,status=no,scrollbars=yes,autosize=yes,resizable=yes,width="+winWidth+",height="+ winHeight+", left="+leftprop+",top="+topprop+",toolbar=yes,directories=no, locationbar=yes, statusbar=no, menubar=yes");
}

function winHiddenOpen(str,str1,str2,winWidth,winHeight) {
	var properties = "";
  	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;

	if(navigator.appName == "Microsoft Internet Explorer") {
   		screenY = document.body.offsetHeight;
   		screenX = -1000;
 	}else {
   		screenY = window.outerHeight
   		screenX = -1000;
 	}

	var leftvar = (screenX - winWidth) / 2;
	var rightvar = (screenY - winHeight) / 2;
	if(navigator.appName == "Microsoft Internet Explorer") {
		leftprop = leftvar;
		topprop = rightvar+100;
	}else {
		leftprop = (leftvar - pageXOffset);
		topprop = (rightvar - pageYOffset);
   	}
	win=window.open(str, str2,
"alwaysRaised=yes,location=yes,status=no,scrollbars=yes,autosize=yes,resizable=yes,width="+winWidth+",height="+ winHeight+", left="+leftprop+",top="+topprop+",toolbar=yes,directories=no, locationbar=yes, statusbar=no, menubar=yes");
}

function winRedirectOpen(str,str1,str2,winWidth,winHeight) {
	var properties = "";
  	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
 		
	if(navigator.appName == "Microsoft Internet Explorer") {
   		screenY = document.body.offsetHeight;
   		screenX = window.screen.availWidth;
 	}else {
   		screenY = window.outerHeight
   		screenX = window.outerWidth
 	}
 	
	var leftvar = (screenX - winWidth) / 2;
	var rightvar = (screenY - winHeight) / 2;
	if(navigator.appName == "Microsoft Internet Explorer") {
		leftprop = leftvar;
		topprop = rightvar+100;
	}else {
		leftprop = (leftvar - pageXOffset);
		topprop = (rightvar - pageYOffset);
   	}
	win=window.open(str, str2,
"alwaysRaised=yes,location=yes,status=yes,scrollbars=yes,autosize=yes,resizable=yes,width="+winWidth+",height="+ winHeight+", left="+leftprop+",top="+topprop+",toolbar=yes,directories=yes, locationbar=yes, statusbar=yes, menubar=yes");
}

function compareDate(dateStart, dateEnd){
	if (isNull(dateStart)||isNull(dateEnd))	return 0; 
	else{
		if(trim(dateStart)<trim(dateEnd))			return -1;
		else if (trim(dateStart)==trim(dateEnd))	return 0;
		else			return 1;
	}
}

function toTime(s)
{
	return new Date(s.substr(6, 4),(s.substr(0, 2))-1,s.substr(3, 2),s.substr(11, 2),s.substr(14, 2),0)
}

function toDate(s)
{
	return new Date(s.substr(6, 4),(s.substr(0, 2))-1,s.substr(3, 2))
}

function validateText (input, min, max, canBeNull,dName,isSpecialRequired)
{
  validateText(input, min, max, canBeNull, dName, isSpecialRequired,true)  
}
function validateText (input, min, max, canBeNull,dName,isSpecialRequired,moveFocus)
{
	var returnStr = "";
	if(!canBeNull){
		if (isNull(input.value)) {
			//alert(dName+" is required. Please enter a value. ");
			if (moveFocus) input.focus();
      input.style.border="2px solid red"
      return dName+" is required. Please enter a value. ";
		}
	}
	
	if (!isNull(input.value)){
		if (isSpecialRequired){
			if (isSpecialCharacter(input.value)) {
//				alert("  \', \%, \+ , \& are not permitted in " + dName);
				if (moveFocus) input.focus();
        input.style.border="2px solid red"
				return false;
			}
		}else{	
			if(isinvalid(input.value)){
				//alert(">,< are not permitted in" + dName +".Please use another character or word");
				if (moveFocus) input.focus();
        input.style.border="2px solid red"
				return ">,< are not permitted in" + dName +".Please use another character or word";
			}
		}
	
		if (!isSize(input.value, min, max)) {
			//alert("Only character input between "+min+" and "+max+" allowed for "+dName+".");
			if (moveFocus) input.focus();
      input.style.border="2px solid red"
			return ">,< are not permitted in" + dName +".Please use another character or word";
		}
	}
  input.style.border=""
	return "";

}

function validateText_bkp (input, min, max, canBeNull,dName,isSpecialRequired) {
	if(!canBeNull){
		if (isNull(input.value)) {
			alert(dName+" is required. Please enter a value. ");
			input.focus();
			return false;
		}
	}
	
	if (!isNull(input.value)){
		if (isSpecialRequired){
			if (isSpecialCharacter(input.value)) {
				alert("  \', \%, \+ , \& are not permitted in " + dName);
				input.focus();
				return false;
			}
		}else{	
			if(isinvalid(input.value)){
				alert(">,< are not permitted in" + dName +".Please use another character or word");
				input.focus();
				return false;
			}
		}
	
		if (!isSize(input.value, min, max)) {
			alert("Only character input between "+min+" and "+max+" allowed for "+dName+".");
			input.focus();
			return false;
		}
	}
	return true;

}

function isNull(s) {
	s = trim(s);
	if(s==null||s.length==0)	return true;
	else  			return false;
}

function isSize(s, min, max) {
	if (s.length < min || s.length > max)  return false;
	else	return true;
}

function isSpecialCharacter(s, dName) {
	for (var i=0; i< s.length;i++){
		var c = s.charAt(i);
		//if ((c==' ')||(c=='"')||(c==';')||(c=='%')||(c=='+')||(c=='&'))	return true;
		if ((c==' ')||(c=='#')||(c=='"')||(c=='\'')||(c==';')||(c=='%')||(c=='+')||(c=='&')) return true;
	}
  	return false;
}


function isinvalid(s) {
	for (var i=0; i< s.length;i++){
		var c = s.charAt(i);
		if ((c=='>')||(c=='<'))	return true;
	}
	return false;
}

function isNumber(s) {
	numdecs = 0;
	var d;
	var ds = stripChars(s,",");
	d = stripChars(ds, "-");
	for (i = 0; i < d.length; i++) {
		mychar = d.charAt(i);
		if ((mychar >= "0" && mychar <= "9") || mychar 
				== ".") {
				if (mychar == ".")
					numdecs++;
		}else 	return false;
	}
	if (numdecs > 1) return false;
	return true;
}
function stripChars(str, chars) {
	var i;
	var newstring = "";
	for (i = 0;  i < str.length; i++) {
		mychar = str.charAt(i);
		if(mychar!=chars) newstring +=mychar;
	}
	return newstring;
}

function isInRange(str, min, max) {
	var i = parseInt(str);
	return((i >= min) && (i <= max));

}

function isInt(argvalue) {
  for (var n = 0; n < argvalue.length; n++)
    if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
      return false;
  return true;
}


function isUpperCase(argvalue) {
  for (var n = 0; n < argvalue.length; n++)
    if (argvalue.substring(n, n+1) < "A" || argvalue.substring(n, n+1) > "Z")
      return false;
  return true;
}

function isLowerCase(argvalue) {
  for (var n = 0; n < argvalue.length; n++)
    if (argvalue.substring(n, n+1) < "a" || argvalue.substring(n, n+1) > "z")
      return false;
  return true;
}

function isAlphaNumeric(argvalue) {
  retValue = true;
  for (var n = 0; n < argvalue.length; n++){
    if (argvalue.substring(n, n+1) >= "a" && argvalue.substring(n, n+1) <= "z" ||
	argvalue.substring(n, n+1) >= "A" && argvalue.substring(n, n+1) <= "Z" ||
	argvalue.substring(n, n+1) >= "0" && argvalue.substring(n, n+1) <= "9")
      	retValue = true;
    else {
	retValue = false;
	break;
    }
  }


  return retValue;
}


function isInteger(s) {
	if (s.indexOf(".") == -1) return true;
	return false;
}
	
function isfloat(argvalue) {
  if (argvalue.length == 0)
    return false;
  var cnt = 0;
  for (var n = 0; n < argvalue.length; n++) {
    if (argvalue.substring(n, n+1) != ".") {
      if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
        return false;
    }
    else
      cnt = cnt + 1;
  }
  if (cnt > 1)
    return false;
  return true;
}



function isSpecialCharacter(s) {
  for (var i=0; i<s.length;i++){
	var c = s.charAt(i);
	if ((c==' ')||(c=='#')||(c=='"')||(c=='\'')||(c==';')||(c=='%')||(c=='+')||(c=='&')) return true;
//	if ((c=='\'')||(c=='%')||(c=='+')||(c=='&')) 	return true;
//	if ((c=='"')||(c=='#')||(c=='\'')||(c=='%')||(c=='+')||(c=='&')) {		
//		return true;
//	}
  }
  return false;
}

function isSpecialCharacterForID(s) {
  for (var i=0; i< s.length;i++){
	var c = s.charAt(i);
	if ((c=='"')||(c=='\'')||(c=='&')||(c=='+')) {
		return true;
	}
  }
  return false;
}

function isSpecialCharacterForPayTerm(s) {
  for (var i=0; i< s.length;i++){
	var c = s.charAt(i);
	if ((c=='"')||(c=='\'')||(c==' ')||(c=='&')||(c=='+')) {
		return true;
	}
  }
  return false;
}


function isSpecialCharacterForAddress(s){
   for (var i=0; i< s.length;i++){
	var c = s.charAt(i);
	if ((c=='#')||(c=='%')||(c=='+')) {
		
		return true;
	}
  }
  return false;
}



function isInDoubleRange(str, min, max) {
	var i = parseFloat(str);
	return((i >= min) && (i <= max));
}

function trimNumber(numValue,decimalPosition){
	if (numValue.indexOf(".")>-1){
		anIndex = numValue.indexOf(".");
		newStr = numValue.substring(0,anIndex)+"."+numValue.substring(anIndex+1,anIndex+1+decimalPosition);
		return parseFloat(newStr);
	}else return parseInt(numValue+"");	
	
}

function isInDecimal(s, decs) {
	if (isblank(s))
		return true;

	bind = s.indexOf(".");
	if (bind >=0 && (s.length - bind -1) > decs)  return false;
	else		return true;

}

function trim(argvalue){
  if (argvalue == null || argvalue.length < 1) return argvalue;
  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }
  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }
  return argvalue;
}

function padWithZero(num) {
  	if (num<10)     rtn = "0"+num;
  	else                   rtn = num;
   	return rtn;
}
function isblank(str){
	if (str==null ||trim(str).length > 0)  return false;
	else return true; 
}

function validateAddress(input, min, max, canBeNull,dName,isSpecialRequired) {
	if(!canBeNull){
		if (isNull(input.value)) {
			alert(dName+" is required. Please enter a value. ");
			input.focus();
			return false;
		}
	}
	
	if (!isNull(input.value)){
		if (isSpecialRequired){
			if (isSpecialCharacterForAddress(input.value)) {
				alert("\%, \+ , \# are not permitted in " + dName);
				input.focus();
				return false;
			}
		}else{	
			if(isinvalid(input.value)){
				alert(">,< are not permitted in" + dName +".Please use another character or word");
				input.focus();
				return false;
			}
		}
	
		if (!isSize(input.value, min, max)) {
			alert("Only character input between "+min+" and "+max+" allowed for "+dName+".");
			input.focus();
			return false;
		}
	}
	return true;

}

function clean(){
	top.frames[4].location = "./navBot.jsp?status=clean";
}

function validateInteger(input, canBeNull, min, max, dName) {
	if (canBeNull && isblank(input.value))
		return true;

	if (!canBeNull && isNull(input.value)) {
			alert(dName+" is required. Please enter a value");
			input.focus();
			return false;
	}
	
	if (!isnum(trim(input.value)) || !isInteger(input.value)) {
		alert("This is not a valid integer for "+dName+".");
		input.focus();	
		return false;
	}
	if (!isInRange(input.value, min, max)){
		alert(dName + ": "+input.value + " is out of range, min: "+ min+", max: "+max);
		input.focus();
		return false;
	}
	
	return true;
}

function validateDouble(input, canBeNull, min, max, decimal, dName) {
	if (canBeNull && isblank(input.value))
		return true;

	if (!canBeNull && isNull(input.value)) {
			alert(dName+" is required. Please enter a value");
			input.focus();
			return false;
	}
	if (!isNumber(trim(input.value))) {
		alert("This is not a valid number for "+dName+".");
		input.focus();
		return false;
	}
	
	if (!isInDecimal(trim(input.value), decimal)) {
		alert("Only "+decimal+" decimal places allowed for "+dName+".");
		input.focus();
		return false;
	}


	if (!isInDoubleRange(trim(input.value), min, max)){
		alert(dName + ": "+input.value + " is out of range:"+ min+","+max);
		input.focus();
		return false;
	}
	
	return true;
}

function isValidDate(datestr)
{
   // Regular expression used to check if date is in correct format
   var pattern = new RegExp("0|1[0-9]/[0-3][0-9]/19|20[0-9][0-9]");
 //  var pattern = new RegExp([0-3][0-9][0-1][0-9][19-20][0-9][0-9]);
   if(datestr.match(pattern))
   {
      var date_array = datestr.split('/');

      // Attention! Javascript consider months in the range 0 - 11
      var month = date_array[0] - 1;
      var day = date_array[1];
      var year = date_array[2];

      // This instruction will create a date object
      source_date = new Date(year,month,day);

      if(year != source_date.getFullYear())
      {
//         alert('Year is not valid!');
         return false;
      }

      if(month != source_date.getMonth())
      {
//         alert('Month is not valid!');
         return false;
      }

      if(day != source_date.getDate())
      {
//         alert('Day is not valid!');
         return false;
      }
   }
   else
   {
//      alert('Date format is not valid!');
      return false;
   }

   return true;
}
function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
	alert("Time is not in a valid format.");
	return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
	alert("Hour must be between 0 and 23.");
	return false;
}
/*** for AM/PM input
if (hour <= 12 && ampm == null) {
	if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
		alert("You must specify AM or PM.");
		return false;
   }
}
if  (hour > 12 && ampm != null) {
	alert("You can't specify AM or PM for military time.");
	return false;
}
****/
if (minute<0 || minute > 59) {
	alert ("Minute must be between 0 and 59.");
	return false;
}
if (second != null && (second < 0 || second > 59)) {
	alert ("Second must be between 0 and 59.");
	return false;
}
return true;
}

//==
function setLastMousePosition(e) {
    if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
    lastMouseX = e.screenX;
    lastMouseY = e.screenY;
}
function positionPopWindow(url,pWidth,pHeight,windowName,options){
    if (lastMouseX - pWidth < 0) {
        lastMouseX = pWidth;
    }
    if (lastMouseY + pHeight > screen.height) {
        lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
    }
    lastMouseX -= pWidth;
    lastMouseY += 10;
    var features = ",screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
     if (!currentPOPWindow || currentPOPWindow.closed || currentPOPWindow.name != windowName ) {
      	currentPOPWindow=window.open(url,windowName,options+features,false);
     } else{
      	currentPOPWindow.focus();
     }
}
function getRValue()
{
	return "&r="+Math.round(Math.random()*1000);
}
//RESETS THE PAGE VALUE
function resetPage(formName, newPageValue)
{
	document[formName].page.value = newPageValue;
	reloadPage(formName);
}
//RESETS THE SORT VALUE
function resetSort(formName, newSortValue)
{
	document[formName].sort.value = newSortValue;
	reloadPage(formName);
}

function checkAll(formName, checkBoxName)
{
	for(i=0;i< document[formName].elements.length;i++ ){
		if(document[formName].elements[i].name == checkBoxName){
			if(document[formName].elements[i].checked == true)
			{
				document[formName].elements[i].checked = false;
			}
			else
			{
				document[formName].elements[i].checked = true;
			}
   	}
	}
	return;
}
function showApliconAlert(subject,content) {
	// Reset layer incase it is already open
	apliconAlertContainer.style.visibility='hidden';
	var verticalCenter;
	var hroizontalCenter;
	var popupOffsetWidth;
	var popupOffsetHeight;

	horizontalCenter = document.body.clientWidth / 2;
	verticalCenter = document.body.clientHeight / 2;
	popupOffsetWidth = apliconAlertContainer.offsetWidth / 2;
	popupOffsetHeight = apliconAlertContainer.offsetHeight / 2;

	// Position layer
	apliconAlertContainer.style.left = horizontalCenter - popupOffsetWidth;
	apliconAlertContainer.style.top = verticalCenter - popupOffsetHeight - 50;

	if (isNull(subject)) {
		subject = 'General Aplicon Alert';
	}
	if (isNull(content)) {
		content = 'No alert details.';
	}
	apliconAlertSubject.innerText = subject;
	apliconAlertContent.innerHTML = content;
	apliconAlertContainer.style.visibility='visible';
	
}
function validateNumeric(event)
{
    var retVal = true
	var keyCode;
  var firefox = navigator.appVersion.indexOf("firefox") != -1;
	var msie = navigator.appVersion.indexOf("MSIE") != -1;

	if (msie) {
		keyCode = window.event.keyCode;
	  }
	else if (firefox) {
		var keyCode;
		if (window.event) keycode = window.event.keyCode;
		else if (event) keyCode = event.which;
	  }
	else {
//		keyCode = window.event.keyCode;
		return true;
	  }

  if (!  ((keyCode >= 48 && keyCode <= 57) || (keyCode==45) || (keyCode==46)))
  {
	retVal = false
  }
//	alert(keyCode)
	// tab key	
	if (keyCode == 0 || keyCode == 8) return true;

	return retVal
}

function allEve(e){
	alert(ev)
	var ev= (window.event)? window.event: e;
	if(!ev || !ev.type) return false;
	var ME= ev;
	
	if(ME.type.indexOf('key')!= -1){
		if(iz('ie') || ME.type.indexOf('keypress')!= -1){
			ME.key= (ev.keyCode)? ev.keyCode: ((ev.charCode)? ev.charCode: ev.which);
		}
		else ME.key= ev.charCode;
		if(ME.key) ME.letter= String.fromCharCode(ME.key);
	}
	return ME;
}

function validateNoSpecialChars()
{
  var retVal = true

  var e = window.event
  if(window.event) // IE
  {
    keynum = e.keyCode
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
    keynum = e.which
  }
  
  var c = String.fromCharCode(keynum)
  if ((c=='#')||(c=='"')||(c=='\'')||(c==';')||(c=='%')||(c=='+')||(c=='&')) return false;

  return retVal
}

function validateAddress(myform)
{
/*
	if (!validateText(myform.address1, 1, 50, false, "address1", false))	
		return false;
	if (!validateText(myform.address2, 1, 50, true, "address2", false))	
		return false;
	if (!validateText(myform.city, 1, 50, false, "city", false))	
		return false;
	if (!validateText(myform.state, 1, 2, true, "state", false))	
		return false;
	if (!validateText(myform.zipCode, 1, 10, false, "zipCode", false))	
		return false;
	if (!validateText(myform.country, 1, 2, false, "country", false))	
		return false;
//			if (!validateText(myform.phone, 1, 20, true, "phone", false))	
//				return false;
//			if (!validateText(myform.fax, 1, 20, true, "fax", false))	
//				return false;
//			if (!validateText(myform.mobile, 1, 20, true, "mobile", false))	
//				return false;
*/
//			myform.action="register.jsp";	
	return true;
}

function resetValues(aForm){
		
	if (aForm.addressID.value == 0)
	{
		aForm.label.value = '';
		aForm.line1.value='';
		aForm.line2.value='';
		aForm.city.value='';
		aForm.zipcode.value='';
		aForm.state.value='';
		aForm.canadianProvince.value = '';
		aForm.canadianPostalCode.value = '';
		aForm.province.value = '';
		aForm.postalCode.value = '';
	}
}

function showAddressFields(aForm){
	if (aForm.country.value == "US"){
		//show US fields, hide canadian and int
		aForm.zipcode.style.display = 'block';
		document.getElementById('zipLabel').style.display = 'block';
		aForm.state.style.display = 'block';
		document.getElementById('stateLabel').style.display = 'block';
		
		aForm.canadianProvince.style.display = 'none';
		document.getElementById('provCanadaLabel').style.display = 'none';
		aForm.canadianPostalCode.style.display = 'none';
		document.getElementById('codeCanadaLabel').style.display = 'none';	
		aForm.canadianProvince.value = '';
		aForm.canadianPostalCode.value = '';
		
		aForm.province.style.display = 'none';
		document.getElementById('provIntLabel').style.display = 'none';
		aForm.postalCode.style.display = 'none';
		document.getElementById('codeIntLabel').style.display = 'none';
		aForm.province.value = '';
		aForm.postalCode.value = '';
		
//		document.getElementById('usa_icon').style.display = 'block';
//		document.getElementById('can_icon').style.display = 'none';
//		document.getElementById('int_icon').style.display = 'none';
		
//		document.getElementById('int_disclaimer').style.display = 'none';
		

	}else if(aForm.country.value == "CA"){
		
		aForm.zipcode.style.display = 'none';
		document.getElementById('zipLabel').style.display = 'none';
		aForm.state.style.display = 'none';
		document.getElementById('stateLabel').style.display = 'none';
		aForm.zipcode.value='';
		aForm.state.value='';

		aForm.canadianProvince.style.display = 'block';
		document.getElementById('provCanadaLabel').style.display = 'block';
		aForm.canadianPostalCode.style.display = 'block';
		document.getElementById('codeCanadaLabel').style.display = 'block';	


		aForm.province.style.display = 'none';
		document.getElementById('provIntLabel').style.display = 'none';
		aForm.postalCode.style.display = 'none';
		document.getElementById('codeIntLabel').style.display = 'none';
		aForm.province.value = '';
		aForm.postalCode.value = '';
		
//		document.getElementById('usa_icon').style.display = 'none';
//		document.getElementById('can_icon').style.display = 'block';
//		document.getElementById('int_icon').style.display = 'none';
		
//		document.getElementById('int_disclaimer').style.display = 'block';
	
		
	}else if (aForm.country.value != "XX")
	{
		aForm.zipcode.style.display = 'none';
		document.getElementById('zipLabel').style.display = 'none';
		aForm.state.style.display = 'none';
		document.getElementById('stateLabel').style.display = 'none';
		aForm.zipcode.value='';
		aForm.state.value='';
		
		aForm.canadianProvince.style.display = 'none';
		document.getElementById('provCanadaLabel').style.display = 'none';
		aForm.canadianPostalCode.style.display = 'none';
		document.getElementById('codeCanadaLabel').style.display = 'none';	
		aForm.canadianProvince.value = '';
		aForm.canadianPostalCode.value = '';

		aForm.province.style.display = 'block';
		document.getElementById('provIntLabel').style.display = 'block';
		aForm.postalCode.style.display = 'block';
		document.getElementById('codeIntLabel').style.display = 'block';

//		document.getElementById('usa_icon').style.display = 'none';
//		document.getElementById('can_icon').style.display = 'none';
//		document.getElementById('int_icon').style.display = 'block';
//		
//		document.getElementById('int_disclaimer').style.display = 'block';
	
	}
}								
function formatCurrency(amt)
{
	return formatNumber(amt, true, 2)
}

function setAdSize()
{
  if (document.getElementById('ad1'))
  {
    var ad = document.getElementById('ad1');
    var dimension = document.getElementById('ad1_dimension').value;

    var indx = dimension.indexOf("x")
    var maxWidth=dimension.substring(0, indx)
    var maxHeight=dimension.substring(indx+1)

    limitPicSize('ad1', maxWidth, maxHeight)
  }
}

// round corners
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

function Rounded(selector,wich,bk,color,opt){
var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;

if(color=="transparent"){
    cn=cn+"x";
    ecolor=bk;
    bk="transparent";
    }
else if(opt && opt.indexOf("border")>=0){
    var optar=opt.split(" ");
    for(i=0;i<optar.length;i++)
        if(optar[i].indexOf("#")>=0) ecolor=optar[i];
    if(ecolor=="") ecolor="#666";
    cn+="e";
    edges=true;
    }
else if(opt && opt.indexOf("smooth")>=0){
    cn+="a";
    ecolor=Mix(bk,color);
    }
if(opt && opt.indexOf("small")>=0) cn+="s";
prefixt=cn;
prefixb=cn;
if(wich.indexOf("all")>=0){t=true;b=true}
else if(wich.indexOf("top")>=0) t="true";
else if(wich.indexOf("tl")>=0){
    t="true";
    if(wich.indexOf("tr")<0) prefixt+="l";
    }
else if(wich.indexOf("tr")>=0){
    t="true";
    prefixt+="r";
    }
if(wich.indexOf("bottom")>=0) b=true;
else if(wich.indexOf("bl")>=0){
    b="true";
    if(wich.indexOf("br")<0) prefixb+="l";
    }
else if(wich.indexOf("br")>=0){
    b="true";
    prefixb+="r";
    }
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    if(edges) AddBorder(v[i],ecolor);
    if(t) AddTop(v[i],bk,color,ecolor,prefixt);
    if(b) AddBottom(v[i],bk,color,ecolor,prefixb);
    }
}

function AddBorder(el,bc){
var i;
if(!el.passed){
    if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){
        var t=el.firstChild.nodeValue;
        el.removeChild(el.lastChild);
        var d=CreateEl("span");
        d.style.display="block";
        d.appendChild(document.createTextNode(t));
        el.appendChild(d);
        }
    for(i=0;i<el.childNodes.length;i++){
        if(el.childNodes[i].nodeType==1){
            el.childNodes[i].style.borderLeft="1px solid "+bc;
            el.childNodes[i].style.borderRight="1px solid "+bc;
            }
        }
    }
el.passed=true;
}

function AddTop(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingTop=0;
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateEl(x){
if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x));
else return(document.createElement(x));
}

function getElementsBySelector(selector){
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];

if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    f=document.getElementById(fs[1]);
    if(f) return(f.getElementsByTagName(s[1]));
    return(objlist);
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    f=document.getElementById(selid);
    if(f) objlist.push(f);
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className.indexOf(selclass)>=0){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    }
return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));
}

