// Validator Used on ChooseUser.asp
function Username_Validator(theForm)
{

  if (theForm.username.value == "")
  {
    alert("Please enter a value for the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  if (theForm.username.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  if (theForm.username.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
  var checkStr = theForm.username.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and digit characters in the \"User Name\" field.");
    theForm.username.focus();
    return (false);
  }

  if (theForm.password.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }

  if (theForm.password.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }

  if (theForm.password.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }

  
  var checkStr = theForm.password.value;
  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }

  }
  if (!allValid)
  {
    alert("Please enter only letter and digit characters in the \"Password\" field.");
    theForm.password.focus();
    return (false);
  }


  if (theForm.confirmpass.value == "")
  {
    alert("Please enter a value for the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

  if (theForm.confirmpass.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

  if (theForm.confirmpass.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

  if (theForm.confirmpass.value != theForm.password.value )
    {
      alert("Please re-enter your password correctly.");
      theForm.confirmpass.focus();
      return (false);
  }

  
  var checkStr = theForm.confirmpass.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and digit characters in the \"Confirm Password\" field.");
    theForm.confirmpass.focus();
    return (false);
  }

	  return (true);
}

// Email Validator
function Validate_Email(theForm)
{


  if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
  var checkStr = theForm.email.value;
  var allValid = true;
  var bDotPresent = false;
  var bRatePresent = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      	break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }

    if (j == checkOK.length - 1  )
	    {
	    	bDotPresent = true;

	    }

	    if (j == checkOK.length -2 )
	    {
	    	bRatePresent = true;
	    }

  }

  if (!allValid)
  {
    alert("Please enter only letter, digit and \"-_@.\" characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  if ((!bDotPresent) || (!bRatePresent) )

    {
    	alert ("Please enter a valid email address");
    	theForm.email.focus();
    	return(false);
    }

	  return (true);
}

// Open PopUp Window
function openPopUp (winURL, winName, winFeatures){
	newWindow = window.open(winURL,winName,winFeatures);
	newWindow.focus();
}

// New Gallery Window
function newGalleryWindow(galleryURL, galleryWinName, galleryFeatures){
	window.open(galleryURL, galleryWinName, galleryFeatures);
}

// Display WIndow
function displayWindow (url, width, height){
		var Win = window.open (url,"displayWindow",'width=' + width + ',height=' +
		height + ',resizable=0,scrollbars=no,menubar=no,status=yes');
		Win.focus();
}

// Form Validator
function validateIt(theForm)
 {
  if(theForm.categoryid.value != '')
	{
	theForm.submit()
	}
  else
     	{
     	return false
     	}
 }

// Clear Text
function doClear(theText) {
	if (theText.value == theText.defaultValue) {
	  theText.value = ""
	}
}

// Change Password (I think)
function password(){
	self.name = "Parent_Window"; 
	window.open('/portal/user/send_pass.asp','EmailLoginInfo','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=260');
}

// Button Over and Active states for IE

//startList = function() {
	//if (document.all&&document.getElementById) {
		// alert("function triggered");
		//inputArray = document.getElementsByTagName("Input");
		//for (i=0; i<inputArray.length; i++) {
			// alert("inside loop");
			//node = inputArray[i];
			//if (node.className=="button") {
				//node.onmouseover=function() {
					//this.className+=" over";
					// alert("if triggered");
				//}
				//node.onmousedown=function() {
					//this.className=this.className.replace(" over", " active");
				//}
				//node.onmouseout=function() {
					//this.className=this.className.replace(" over", "");
					//this.className=this.className.replace(" active", "");
				//}
			//}
		//}
	//}
//}
//window.onload=startList;

// Table row Over state for IE

startList = function() {
	if (document.all&&document.getElementById) {
		//alert("function triggered");
		inputArray = document.getElementsByTagName("TR");
		for (i=0; i<inputArray.length; i++) {
			// alert("inside loop");
			node = inputArray[i];
			if (node.className=="Row") {
				node.onmouseover=function() {
					this.className+=" over";
					// alert("if triggered");
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
			if (node.className=="altRow") {
				node.onmouseover=function() {
					this.className+=" altOver";
					// alert("if triggered");
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" altOver", "");
				}
			}
		}
	}
}
window.onload=startList;
