function rotateImage(prod, num)
{
	var img;
	var newImg;
	newImg = "/media/products/" + prod + "_" + num + ".jpg";
	img = document.images("rotateView");
	img.src = newImg;
}

function replaceImage(status)
{
	if (status==1)
		document.images("powered").src="/media/rpt_powered_on.gif";
	else
		document.images("powered").src="/media/rpt_powered_off.gif";
}

var curMenu = null;
var mouseX;
var mouseY;

if (!document.all) 
{
    window.captureEvents(Event.MOUSEMOVE);
    window.onmousemove=mouse_move;
}

function MouseOverChangeClass(elem,strColor) 
{
	if (elem.className != strColor + "_click") 
	{
		elem.className = strColor + "_over";
	}

}

function MouseOutChangeClass(elem, strColor) 
{

	if (elem.className != strColor + "_click") 
	{
		elem.className = strColor + "_off";
	}
}

function drop_menu(oMenu)
{
	var IE = document.all?true:false
	
	if (curMenu != null)
		curMenu.style.display = "none";
		
	oMenu.style.display = "block";
	curMenu = oMenu;
}

function mouse_move(e)
{
	mouseX = e.pageX;
	mouseY = e.pageY;
}

function change_class(oElm, tClass, fClass)
{

	var iX = 0;
	var iY = 0;
	var ibX1, ibX2, ibY1, ibY2;
	var IE = document.all?true:false
	
	if (IE) 
	{
		iX = event.clientX + document.body.scrollLeft
		iY = event.clientY + document.body.scrollTop
	}
	else 
	{
		iX = mouseX;
		iY = mouseY;
	}  
	
	if (oElm != null)
	{
		ibX1 = parseInt(oElm.style.left);
		ibX2 = ibX1 + parseInt(oElm.style.width);
		ibY1 = parseInt(oElm.style.top);
		ibY2 = ibY1 + parseInt(oElm.style.height);
		
		if (((iX < ibX1 + 3 || iX > ibX2 - 3) || (iY < ibY1 + 3  || iY > ibY2 - 5)) || (isNaN(ibX1) || isNaN(ibY1)))
		{
			//window.status = iX + ":" + iY + "-" + ibX1 + "," + ibY1 + ":" + ibX2 + "," + ibY2;
			oElm.className = tClass;
		}
		else
		{
			oElm.className = fClass;
		}
	}
}

function hide_menu(oMenu)
{	

	var iX = 0;
	var iY = 0;
	var ibX1, ibX2, ibY1, ibY2;
	var IE = document.all?true:false
	
	if (IE) 
	{
		iX = event.clientX + document.body.scrollLeft
		iY = event.clientY + document.body.scrollTop
	}
	else 
	{
		iX = mouseX;
		iY = mouseY;
	}  
	
	if (oMenu != null)
	{
		ibX1 = calculate_absolute_X(oMenu);//parseInt(oMenu.style.left);
		ibX2 = ibX1 + parseInt(oMenu.style.width);
		ibY1 = calculate_absolute_Y(oMenu);//parseInt(oMenu.style.top);
		ibY2 = ibY1 + parseInt(oMenu.style.height);
		//alert(calculate_absolute_X(oMenu));
		//alert(calculate_absolute_(oMenu));

		//alert(iX + ":" + iY);
		//alert(ibX1 + "," + ibY1 + ":" + ibX2 + "," + ibY2);
		if (iX < ibX1 + 3 || iX > ibX2 - 3 || iY < ibY1 - 5  || iY > ibY2 ){
			oMenu.style.display = "none";
		}
	}	
}
var tables=0;
function calculate_absolute_X( theElement )
{
	var xPosition = 0;

	while ( ( theElement != null ))// && ( theElement.id != id ) )
	{
		xPosition += theElement.offsetLeft;
		theElement = theElement.offsetParent;
	}

	return xPosition + tables;
}

function calculate_absolute_Y( theElement )
{
	var yPosition = 0;

//	while ( theElement != null )
	while ( ( theElement != null ))
	{
		yPosition += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}

	return yPosition + tables;
}


function anyMask(event, sMask) 
{
	//var sMask = "**?##?####";
	var KeyTyped = String.fromCharCode(getKeyCode(event));
	var targ = getTarget(event);
	
	keyCount = targ.value.length;
	//alert(sMask.charAt(keyCount));
	
	if (sMask.charAt(keyCount) == '*')
 	   	return true;
 
	if (sMask.charAt(keyCount) == KeyTyped)
    	{
		return true;
	}
	
	if ((sMask.charAt(keyCount) == '#') && isNumeric(KeyTyped)) 
	   return true; 
	
	if ((sMask.charAt(keyCount) == 'A') && isAlpha(KeyTyped))
         return true; 
    
      if ((sMask.charAt(keyCount) == '?') && isPunct(KeyTyped))
         return true; 
	if (KeyTyped.charCodeAt(0) < 32) return true;
    
    return false;	   
   
	
}

 function getTarget(e) {
  // IE5
   if (e.srcElement) {
   	return e.srcElement;
   }
    if (e.target) {
   	return e.target;
   }	
 }

  function getKeyCode(e) {
 //IE5
 if (e.srcElement) {
 	return e.keyCode
 }
  // NC5
  if (e.target) {
   return e.which
  }
 }

 function isNumeric(c)
{
	var sNumbers = "01234567890";
	if (sNumbers.indexOf(c) == -1)
		return false;
	else return true;
	
}  

function isAlpha(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode >= 65 && lCode <= 122 )
 	  {	
		return true;
         }
	else 
	return false;
}  

function isPunct(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode >= 32 && lCode <= 47 )
 	  {	
		return true;
         }
	else 
	return false;

}
 

function phoneMask()
 {
	var sMask = "01234567890";
	var KeyTyped = String.fromCharCode(window.event.keyCode);
	var srcObject = window.event.srcElement;
	//alert(window.event.keyCode);
	if (window.event.keyCode != 8)
	{
	 if (sMask.indexOf(KeyTyped.toString()) == -1)
		{
		 		window.event.keyCode = 0;
				_ret = false;
		}
	}	 

   frigger = document.getElementById(window.event.srcElement.id);
   keyCount = frigger.value.length;
    var tmpStr = "(";
    
    keyEntered = KeyTyped;
    keyCount++;
    switch (keyCount)
    {
    case 2: 
      tmpStr += srcObject.value;
      srcObject.value = tmpStr;
      break;
    case 5:
      srcObject.value += ")";
      break;
    case 9:
      srcObject.value += "-";
      break;
      }
 }



function dateMask()
 {
	var sMask = "01234567890";
	var KeyTyped = String.fromCharCode(window.event.keyCode);
	var srcObject = window.event.srcElement;
	//alert(window.event.keyCode);
	if (window.event.keyCode != 8)
	{
	 if (sMask.indexOf(KeyTyped.toString()) == -1)
		{
		 		window.event.keyCode = 0;
				_ret = false;
		}
	}	 

   frigger = document.getElementById(window.event.srcElement.id);
   keyCount = frigger.value.length;
    var tmpStr = "";
    
    keyEntered = KeyTyped;
    keyCount++;
    switch (keyCount)
    {
    case 3: 
      srcObject.value += "/";
      break;
    case 6:
      srcObject.value += "/";
      break;
      }
 } 
 
 
 
 function ssnMask()
  {
	var sMask = "01234567890";
	var KeyTyped = String.fromCharCode(window.event.keyCode);
	var srcObject = window.event.srcElement;
	//alert(window.event.keyCode);
	if (window.event.keyCode != 8)
	{
	 if (sMask.indexOf(KeyTyped.toString()) == -1)
		{
		 		window.event.keyCode = 0;
				_ret = false;
		}
	}	 

   frigger = document.getElementById(window.event.srcElement.id);
   keyCount = frigger.value.length;
   
   if (keyCount>10)
		window.event.keyCode = 0;
   
    var tmpStr = "";
    
    keyEntered = KeyTyped;
    keyCount++;
    switch (keyCount)
    {
    case 2: 
      tmpStr += srcObject.value;
      srcObject.value = tmpStr;
      break;
    case 4:
      srcObject.value += "-";
      break;
    case 7:
      srcObject.value += "-";
      break;
      }
 }

function showHide(obj, oControl) 
{
		flipObj = document.getElementById(obj);
		if(flipObj.style.display=="" || flipObj.style.display=="block")
		{			
			flipObj.style.display="none";
			oControl.innerText = "[+] Show Documents";						
		}
		else
		{			
			flipObj.style.display="block";
			oControl.innerText = "[-] Hide Documents";			
		}
}

	function showMenu(id,currentSection){
		document.getElementById('drp1').style.display='none';
		document.getElementById('drp2').style.display='none';
		document.getElementById('drp3').style.display='none';
		document.getElementById('drp4').style.display='none';
		var a=document.getElementById('drp'+id);
		
		if (a!=null)
			a.style.display='';
			
		document.getElementById('m1').className='menuitem';
		document.getElementById('m2').className='menuitem';
		document.getElementById('m3').className='menuitem';
		document.getElementById('m4').className='menuitem';

		a=document.getElementById('m'+id);
		if (currentSection==null || currentSection=='undefined'){
			if (a!=null)
				a.className="menuitem-hover";
		}
		
	}
	
	function displayMenu(currentSection,currentMenu){
		if (currentMenu==null || currentMenu=='undefined'){
			showMenu(currentSection);
		}else{
			showMenu(currentMenu, currentSection);		
		}
		
	}
	
	
function newWindow(URL, width, height){

		window.open(URL, "Sub", "scrollbars=no,width=" + width + ",height=" + height + ",menubar=no,toolbar=no,titlebar=no,status=no");
	}
	
	
function trim(strText) {
   return ltrim(rtrim(strText));
}

function ltrim(strText) { 
    
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);   
   
   return strText;
}

function rtrim(strText) { 	
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
        
   return strText;
}


function formatCurrency(num) {
	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));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


var _OUTPUT=1; /* set to 1 to have the function output the result -return true if converted
                * set to 0 to have the function not output anything -returns the value
				*/
function formatPhone(num)
{ 
  var _return=false;
  /*
   * 7181238748 to 1(718)123-8748
   */ 

  num = replaceAll( num , " " , "" );
  num = replaceAll( num , "-" , "" );
  num = replaceAll( num , "." , "" );
  num = replaceAll( num , "(" , "" );
  num = replaceAll( num , ")" , "" );
  
  if(num.length != 10 ) { 
    /* 
     * if user did not enter 10 digit phone number then simply print whatever user entered 
     */ 
	_return=_OUTPUT?num:false;
  } 
  else
  { 
    /* formating phone number here */ 
	_return="(";
	var ini = num.substring(0,3);
	_return+=ini+")";
	var st = num.substring(3,6);
	_return+=st+"-";
	var end = num.substring(6,10);
	_return+=end;
  }
  return _return; 
} 

function replaceAll( sIn , sFind, sReplace){
	if ( sIn == null )
		return "";
		
	return sIn.split( sFind ).join( sReplace );
}