<!-- Used to hide Javascript for older browsers
/*
 * FILENAME:   module.js
 * PURPOSE:    Enable/Disable form componets in Internet Explorer
 * USE:               <SCRIPT src="forms.js"></SCRIPT>
 *                          <INPUT id="id" name="name" type="type" onkeyup=changeall(this)>
 *                          <INPUT disabled type="submit" name="submit">
 *
 * FUNCTION:   validate_form ()
 * PURPOSE:    Check particular fields with the form for certain criteria.
 * USE:        <FORM ... onsubmit="return validate_form()">
 *
 * FUNCTION:   MaskPhoneNumber()
 * PURPOSE:    Prevent users from entering in invalid text, particularly letters into anumeric field.
 * USE:        <INPUT ... onkeypress="return MaskNumber(this, event)">
 */

function redir(username,level)
{
   newlocation = "register.php?menu_username=" + username + "&menu_selected=" + level;
   self.location = newlocation;
}

function MaskNumber(field,event) {
   /* TODO: Copy/Paste will allow unwanted characters in field. */
	var key, keychar;

	if (window.event) key = window.event.keyCode;
	else if (event) key = event.which;
	else return true;

	keychar = String.fromCharCode(key);

	// Check for special characters like backspace
	// then check for numbers.
	if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27)) return true;
	else if ((("0123456789").indexOf(keychar) > -1)) {
		window.status = "";
		return true;
	} else {
		window.status = "Field excepts numbers only";
		return false;
	}
}

function TestJavaScriptLoad () {
   alert('Test Complete!');
}

function IsEmpty(s) {
	var whitespace = " \t\n\r";
	var i;
	if ((s == null) || (s.length == 0))
		return true;

	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1)
			return false;
	}
	return true;
}

function openWin (winHeight, winWidth, picSrc ) {
   newWin = window.open ('', '', 'height=' + winHeight + ', width=' + winWidth + 'toolbar=no, titlebar=no, scrollbars=no' );
   newWin.document.write ("<HEAD><TITLE>" + "PVC FENCING" + "</TITLE></HEAD>");
   newWin.document.write ("<P align='center'>");
   newWin.document.write ("<IMG src=" + picSrc + ">");
   newWin.document.write ("<BR><FORM><CENTER><INPUT type='button' value='Close' onclick='JavaScript:window.close()'>");
   newWin.document.write ("</FORM></CENTER></P>");
}


function validate_form () {

	var aryCheckFields = [
	  [ document.new_registration.FNAME.value,   "Please specify your First Name."   ],
	  [ document.new_registration.LNAME.value,   "Please specify your Last Name."    ],
	  [ document.new_registration.ADDR1.value,   "Please specify a valid Address."   ],
	  [ document.new_registration.CITY.value,    "Please specify a City."            ],
	  [ document.new_registration.STATE.value,   "Please select a State."            ],
	  [ document.new_registration.EMAIL.value,   "Please Specify an email address."  ],
	  [ document.new_registration.USERNAME.value,"Please specify a username."        ]
   ];

   /* Check to make sure there is something in the field. */
   for (var index = 0; index < aryCheckFields.length; index++) {
      if (aryCheckFields[index][0].length == 0) {
         alert(aryCheckFields[index][1]);
         return false;
      }
   }

   /* Verify number fields separately. */
	var s;
	s = document.new_registration.PHONE.value;
	if (s.length != 10) { alert('That is not a valid Phone Number.'); return false; }

	s = document.new_registration.FAX.value;
	if (s.length != 10) { alert('That is not a valid Fax Number.'); return false; }

	s = document.new_registration.ZIP.value;
	if (s.length != 5 && s.length != 9) { alert('That is not a valid Postal Code.'); return false; }

	/* Verify Password fields separately */
	if ( IsEmpty ( document.new_registration.PASSWORD.value ) ) {
	  alert('You must specify a password.');
	  return false;
	} else {
	   s = document.new_registration.PASSWORD.value;
	   c = document.new_registration.CONFIRM.value;

	   if ( s.length != c.length ) {
	     alert("Passwords don't match!");
	     return false;
	   }

	   for ( i=0; i < s.length; i++ ) {
	     if ( s.charAt(i)!=c.charAt(i) ) {
	        alert("Passwords don't match!");
	        return false;
	     }
	   }
	}
	/* Verify Email Address */
}


(document.layers) ? layerobject=true : layerobject=false;
/* Internet Explorer */
(document.all) ? allobject=true : allobject=false;
/* Netscape */
(document.getElementById) ? dom=true : dom=false;

opera = navigator.userAgent.toLowerCase().indexOf('opera') != -1;

function getElement (layerName, parentLayer) {
   if (layerobject) {
      //alert('document.layers');
      parentLayer = (parentLayer) ? parentLayer : self;
      layerCollection = parentLayer.document.layers;
      if (layerCollection[layerName])
         return layerCollection[layerName];

      for (i=0; i < layerCollection.length;)
         return (getElement(layerName, layerCollection[i++]));
   }

   if (allobject) {
      //alert('document.all');
      return document.all[layerName];
   }
   if (dom) {
      //alert('document.getElementById');
      return document.getElementById(layerName);
   }
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
	   
		while (obj.offsetParent)
		{
		   //alert (obj.offsetParent);
		   //alert ('offsetTop: '+obj.offsetTop);
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) 
	{
	   //alert('Y:'+obj.y);
	   curtop += obj.y;
	}
		
	return curtop;
}

var timer;
var curLayer;

function resetTimer(layerName) {
   clearTimeout(timer);
   timer = setTimeout('hide(\''+layerName+'\')', 3000);
}

function showMenu ( layerName, origin, offsetX, offsetY ) {
   if (curLayer)
      hide(curLayer);
   curLayer = layerName;
   var theLayer = getElement(layerName);
   if (layerobject)
      theLayer.visibility = 'show';
   else
      theLayer.style.visibility = 'visible';

   /* Set x and y using coordinates from origin object. */
   if (origin) {
      setX (layerName, findPosX(origin)+offsetX);
      setY (layerName, findPosY(origin)+offsetY);
   }
   timer = setTimeout('hide(\''+layerName+'\')', 3000);
}



function show ( layerName, origin, offsetX, offsetY ) {
   var theLayer = getElement(layerName);
   if (layerobject)
      theLayer.visibility = 'show';
   else
      theLayer.style.visibility = 'visible';

   /* Set x and y using coordinates from origin object. */
   if (origin) {
      setX (layerName, findPosX(origin)+offsetX);
      setY (layerName, findPosY(origin)+offsetY);
   }
}

function hide ( layerName ) {
   if ( curLayer == layerName ) {
      curLayer = null;
   }
   var theLayer = getElement(layerName);
   if (layerobject)
      theLayer.visibility = 'hide';
   else
      theLayer.style.visibility = 'hidden';
}

function setX (layerName, x) {
   var theLayer = getElement(layerName);
   if (layerobject)
      theLayer.left = x;
   else if (opera)
      theLayer.style.pixelLeft = x;
   else
      theLayer.style.left = x + "px";
}

function setY (layerName, y) {
   var theLayer = getElement(layerName);
   if (layerobject)
      theLayer.top = y;
   else if (opera)
      theLayer.style.pixelTop = y;
   else
      theLayer.style.top = y + "px";
}
-->