/* ---------------------------------------------------------------------------------------
HLC_StdLib.js
--------------------------------------------------------------------------------------- */

    /* -------------------------------------------------- */
    /* Function   : popWindowToScale
       Created By : Chris Andrade
       Created On : 12/22/2003	
       Description: Pops a new window to the specified width and height
       
       Arguments: page -> html,aspx page to open
       
				  winName -> identifier of the new 
							 window instance
				
				  width -> width of window
				
				  height -> height of window
    ----------------------------------------------------- */
		function popWindow(page, winName, width, height) 
		{
			var browser_name = navigator.appName;
			
			if (browser_name.indexOf("WebTV") != -1) return null;
			
			// Find the center position to launch the window to
			if (parseInt(navigator.appVersion) >= 4 )
			{
				xposition = (screen.width - width) / 2;
				yposition = (screen.height - height) / 2;
			}

			// Assign the window arguments
			args = "width=" + width + ",";
			args += "height=" + height + ",";
			args += "location=0" + ",";
			args += "menubar=0" + ",";
			args += "resizable=0" + ",";
			args += "scrollbars=0" + ",";
			args += "status=1" + ",";
			args += "titlebar=1" + ",";
			args += "toolbar=0" + ",";
			args += "hotkeys=0" + ",";
			args += "screenx=" + xposition + ",";
			args += "screeny=" + yposition + ",";
			args += "left=" + xposition + ",";
			args += "top=" + yposition;
			
			var new_window = window.open(page, winName, args);
			new_window.focus();
		}

    /* -------------------------------------------------- */
    /* Function   : popWindowNoStatusBar
       Created By : Chunyan Cao
       Created On : 1/8/2004	
       Description: Pops a new window to the specified width and height and with no status bar
       
       Arguments: page -> html,aspx page to open
       
				  winName -> identifier of the new 
							 window instance
				
				  width -> width of window
				
				  height -> height of window
    ----------------------------------------------------- */
		function popWindowNoStatusBar(page, winName, width, height) 
		{
			var browser_name = navigator.appName;
			
			if (browser_name.indexOf("WebTV") != -1) return null;
			
			// Find the center position to launch the window to
			if (parseInt(navigator.appVersion) >= 4 )
			{
				xposition = (screen.width - width) / 2;
				yposition = (screen.height - height) / 2;
			}

			// Assign the window arguments
			args = "width=" + width + ",";
			args += "height=" + height + ",";
			args += "location=0" + ",";
			args += "menubar=0" + ",";
			args += "resizable=0" + ",";
			args += "scrollbars=0" + ",";
			args += "status=0" + ",";
			args += "titlebar=0" + ",";
			args += "toolbar=0" + ",";
			args += "hotkeys=0" + ",";
			args += "screenx=" + xposition + ",";
			args += "screeny=" + yposition + ",";
			args += "left=" + xposition + ",";
			args += "top=" + yposition;
			
			var new_window = window.open(page, winName, args);
			new_window.focus();
		}

    /* -------------------------------------------------- */
    /* Function   : popWindowToScale
       Created By : Chris Andrade
       Created On : 10/30/2003	
       Description: Pops a new window to the specified scale percentage
       
       Arguments: page -> html,aspx page to open
       
									winName -> identifier of the new 
														 window instance
									
									scalePerc -> the scale percentange the 
															 window should open up to (ex. if 75%, enter 75) 
    ----------------------------------------------------- */
		function popWindowToScale(page, winName, scalePerc) 
		{
			var browser_name = navigator.appName;
			
			// Change scalePerc value to it's decimal equivalent
			var perc = scalePerc * .01;
			
			// Apply the scale ratio to both the width and height
			var width = Math.floor(screen.width * perc);
			var height = Math.floor(screen.height * perc);
			
			if (browser_name.indexOf("WebTV") != -1) return null;
			
			// Find the center position to launch the window to
			if (parseInt(navigator.appVersion) >= 4 )
			{
				xposition = (screen.width - width) / 2;
				yposition = (screen.height - height) / 2;
			}

			// Assign the window arguments
			args = "width=" + width + ",";
			args += "height=" + height + ",";
			args += "location=1" + ","
			args += "menubar=1" + ","
			args += "resizable=1" + ","
			args += "scrollbars=1" + ","
			args += "status=1" + ","
			args += "titlebar=1" + ","
			args += "toolbar=1" + ","
			args += "hotkeys=0" + ","
			args += "screenx=" + xposition + ",";
			args += "screeny=" + yposition + ",";
			args += "left=" + xposition + ",";
			args += "top=" + yposition;
			
			var new_window = window.open(page, winName, args);
			new_window.focus();
		}

    /* -------------------------------------------------- */
    /* Function   : ResetValidation
       Created By : Chris Christopher
       Created On : 09/23/2003	
       Description: The only thing this function does is return true.  Used to reset
                    custom validation controls whose error state is normally set via
                    code.
    ----------------------------------------------------- */
		function ResetValidation(strHTMLID) {
		  document.getElementById(strHTMLID).style.isvalid = "True";
		  return true;
		}


    /* -------------------------------------------------- */
    /* Function   : DisplayElement
       Created By : Chris Christopher
       Created On : 09/20/2003	
       Description: Dynamically hides/shows a HTML element based on the value
                    of a webform control, additionally it can enabled/disable an
                    associated webform validation control.
       
       Arguments  : strHTMLID	   - ID of the HTML element you wish to hide/show.
									  flgDisplay   - determines of the visibilty attribute is to be set
									                 to 'hidden' or 'visible'
									  flgIsDynamic - when true this causes the web page to be dynamically
									                 resized when the element is hidden/displayed. 
    ----------------------------------------------------- */
		function DisplayElement(strHTMLID, flgDisplay, flgIsDynamic) {
			
		  if(flgDisplay == true)
		    {
		      document.getElementById(strHTMLID).style.visibility = 'visible';
		      if(flgIsDynamic == true)
		        {document.getElementById(strHTMLID).style.display = '';}
		    }
		  else
		    {
		      document.getElementById(strHTMLID).style.visibility = 'hidden';
		      if(flgIsDynamic == true)
		        {document.getElementById(strHTMLID).style.display = 'none';}
		    }		    		  
		  return true;
		}
    
    /* -------------------------------------------------- */
    /* Function   : DisplayElement
       Created By : Chris Christopher
       Created On : 09/20/2003	
       Description: Originally intended to enable disable page validation controls
										when the input fields are hidden/displayed.
       
       Arguments  : strHTMLID	   - ID of the HTML element you wish to hide/show.
									  flgEnabled   - value to set the 'enabled' attribute to.
    ----------------------------------------------------- */
    function EnableElement(strHTMLID, flgEnabled) {
      if(flgEnabled == true)
		    {
          document.getElementById(strHTMLID).setAttribute('enabled', true);
		    }
		  else
		    {
  	      document.getElementById(strHTMLID).setAttribute('enabled', false);
		    }		    		  
		  return true;
		}


/* ------------------------------------------------------------------------------------ */


function formatCurrency(num) 
{
	var varnumformatted;

	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	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));
	if (sign)
		varnumformatted = '$' + num + '.' + cents;
	else
		varnumformatted = '($' + num + '.' + cents + ')';
	
	return  varnumformatted;//(((sign)?'':'-') + '$' + num + '.' + cents);
}

function isBlank(str)              
{
	if (str.length == 0)             // yes - nothing entered
	return true
	for (i=0; i<=str.length-1; i++)  // yes - all spaces
	if (str.charAt(i) != " ")
		return false
	return true                      // nope
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isIntegerPN (s)
{   var i, startPos;

	if (isBlank(s)) 
	return false;
	

	// Search through string's characters one by one
	// until we find a non-numeric character.
	// When we do, return false; if we don't, return true.

	if ( s.charAt(0) == "-" )
		startPos = 1;
	else
		startPos = 0;
		
	for (i = startPos; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);

		if (!isDigit(c)) return false;
	}

	// All characters are numbers.
	return true;
}

function isNumber( number )
{		
	number = removeCommas( number );
	if ( isIntegerPN(number) )
		return true;
	else
		return false
}

function removeCommas( strValue ) 
{
	var objRegExp = /,/g; //search for commas globally
		
	//replace all matches with empty strings
	return strValue.replace(objRegExp,'');
}

function format_number(n)
{
	if (!isNumber(n))
		return n;
		
	var isBlank = true; 
	var isNegative = false;
		if (n.length == 0)             // yes - nothing entered
		return "";
		for (i=0; i<=n.length-1; i++)  // yes - all spaces
		if (n.charAt(i) != " ")
			isBlank = false;
		if ( isBlank ) 
			return "";
		
	n = removeCommas(n);
	var arr=new Array('0'), i=0; 
		
	if ( n < 0 ) 
	{
		isNegative = true;
		n = n * -1;
	}
	while (n>0) 
		{arr[i]=''+n%1000; n=Math.floor(n/1000); i++;}
	arr=arr.reverse();
	for (var i in arr) if (i>0) //padding zeros
		while (arr[i].length<3) arr[i]='0'+arr[i];
		
	if ( isNegative ) 
		return "-" + arr.join();
	else
		return arr.join();
}
			
function setLabelToDefault()
{

	for (i = 0; i < Page_Validators.length; i++) {	
		var validator = Page_Validators[i];		
		var inputObj = document.getElementById(validator.controltovalidate);						
		var span1Obj = document.getElementById("span" + validator.controltovalidate);	
		var	span2Obj = document.getElementById("span2" + validator.controltovalidate);
		
		if (span1Obj)
		{	
			span1Obj.style["color"] = "#153564";
		}
		
		if (span2Obj)
		{	
			span2Obj.style["color"] = "#153564";
		}
		
		if (inputObj)
		{
			if (inputObj.type == "select-one")
			{
				inputObj.style.backgroundColor = "#FFFFFF";
				inputObj.style.color = "#153564";
			}
			else
			{
				inputObj.style.borderColor = "";
			}		
		}
	}
}

function LabelErrorInput()
{	
	setLabelToDefault();
	
	var validator; 
	var span1Obj, span2Obj;
	var inputObj;

	for (iVal = 0; iVal < Page_Validators.length; iVal++) {					
		ValidatorValidate(Page_Validators[iVal]);
		
		validator = Page_Validators[iVal];					
				
		if (!validator.isvalid)
		{
			span1Obj = document.getElementById("span" + validator.controltovalidate);	
			span2Obj = document.getElementById("span2" + validator.controltovalidate);
			inputObj = document.getElementById(validator.controltovalidate);		
		}
		
		if (span1Obj)
			span1Obj.style["color"] = "#FF0000";
		
		if (span2Obj)
			span2Obj.style["color"] = "#FF0000";
			
		if (inputObj)
		{
			if (inputObj.type == "select-one")
			{
				inputObj.style.backgroundColor = "#FF0000";
				inputObj.style.color = "#FFFFFF";
			}
			else
			{
				inputObj.style.borderColor = "#FF0000";
			}						
		}
	
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_callJS(jsStr)
{
	return eval(jsStr);
}
