//Copyright� 1998. ZYX Productions. All rights reserved.
//**Start Encode**
var touched=-1
var mesg="", confirmMesg=""

var ns4=document.layers;	//document(input);
var ie4=document.all;		//document.all(input); document.all.item(input); document.getElementById(input);
var ns6=document.getElementById&&!document.all;		//document.getElementById;
function getElm(elementID){
	if (ie4){
	return document.all(elementID);
	}
	if (ns4){
	return document.elementID;
	}
	if (ns6){
	return document.getElementById(elementID);
	}
}
function getElms(elementID){
	if (ie4){
	return document.getElementsByName(elementID);
	}
	if (ns4){
	return document.elementID;
	}
	if (ns6){
	return document.getElementsByName(elementID);
	}
}
function expandOrCollapse(pageID,eventObj){
	if (getElm(pageID).style.display=="none"){
	getElm(pageID).style.display="block";
	//eventObj.src="images/minus.gif";
	eventObj.className="close";
	}
	else{
	getElm(pageID).style.display="none";
	//eventObj.src="images/plus.gif";
	eventObj.className="expand";
	}
}
//SubV: sets one input value and submits the whole corresponding form with all previously set values
//security is build in for user priviledge verification and denial of specific services
function SubV(IDname,IDvalue) {
		getElm(IDname).value = IDvalue;
//		getElm(IDname).parentElement.submit();
		getElm(IDname).form.submit();
}
//SetV: sets one input value of its corresponding form
function SetV(IDname,IDvalue) {
		getElm(IDname).value = IDvalue;
}
//SebF: submit form
function SubF(IDform){
getElm(IDform).submit();
}
//confirmDelete: pops confirmation box whenever "delete" is requested
function confirmDelete(IDname,IDvalue,IDtype)
{
	 var conf= confirm("Click OK will permanently delete\n" +"this " + IDtype + "!");
	 if (conf== true)
	 {
	  SubV(IDname,IDvalue);
	 }
	 else
	 {
	  return false;
	 }
}
//confirmDelete: pops confirmation box whenever "delete" is requested
function confirmDel(IDtype)
{
	 var conf= confirm("Click OK will permanently delete\n" +"this " + IDtype + "!");
	 if (conf== true)
	 {
	  return true;
	 }
	 else
	 {
	  return false;
	 }
}
//confirm action: pops confirmation box whenever a note worthy action is requested
function confirmAct(mesg)
{
	 var conf= confirm(mesg);
	 if (conf!= true)
	 {
	  return false;
	 }
}
//alert message
function alertMesg(mesg){
alert(mesg);
}
//display indicated item and hide previously selected item
function displayThis(touchID)
{
	if (touched!=-1){
	getElm(touched).style.display='none';
	touched=touchID;
	}
	else {
	touched=touchID;
	}
getElm(touchID).style.display='inline';
}

// Check if string s is empty or whitespace characters only.
function isWhitespace(s)
{   var i;
	var whitespace = " \t\n\r";
    // Is s empty?
    if (isEmpty(s)) return true;
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);
	if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
//man, more checks, this is on radio values
function radioValue(s){
var selectedValue="";
for (i=0; i<s.length; i++){
	if (s[i].checked) selectedValue=s[i].value;
}
return selectedValue;
}
//this is on checkBox values
function checkBoxValue(s){
var selectedValue="";
for (i=0; i<s.length; i++){
	if (s[i].checked) selectedValue+=s[i].value + ", ";
}
selectedValue=selectedValue.substr(0, selectedValue.length-2);
return selectedValue;
}
function checkBoxTitle(s){
var selectedValue="";
for (i=0; i<s.length; i++){
	if (s[i].checked) selectedValue+=s[i].title + "\n";
}
//selectedValue=selectedValue.substr(0, selectedValue.length-2);
return selectedValue;
}
//return form check error mesg
function returnError(mesg,confirmMesg){
	if (mesg=="") {
		if (confirmMesg=="")
		return true;
		else{
		var conf= confirm(confirmMesg+"\n");
		if (conf==false) return false; 
		}
	return true;
	}
	else
	{
	alert(mesg);
	return false;
	}
}
//fileUploadFormCheck
function fileUploadFormCheck(){
var mesg="", confirmMesg=""
	if (isWhitespace(getElm("description").value)==true) mesg+="Description is empty\n";
	if (isWhitespace(getElm("fileName").value)==true) mesg+="File Name is empty\n";
return returnError(mesg,confirmMesg);
}

// Check form value
function formValueCheck(s,checkMethod,methodOption){ //s is input object
var mesg=""
	switch (checkMethod){
	   case "number":
	   		if (isFinite(s.value)==false) mesg="Numbers only\n";
				break;
	   case "alpha":
		 		if (/[^A-Za-z\s]+/.test(s.value)==true) mesg="Alphabets only\n";
				break;
	   case "string":
		 		if (isWhitespace(s.value)==true) mesg="Value cannot be empty\n";
				break;
	   case "email":
		 		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(s.value)) && !(isWhitespace(s.value))) mesg="Not a valid email\n";
				break;
	   case "phone":
		 		switch (methodOption){
				case "allNum":
					if (!(/^\d{10}$/.test(s.value)) && !(isWhitespace(s.value))) {mesg="Phone number must be 10 digits in the following formats:\nxxxxxxxxxx";};
					break;
				case "dash":
					if (!(/^\d{3}-\d{3}-\d{4}$/.test(s.value)) && !(isWhitespace(s.value))) {mesg="Phone number must be in the following format:\nxxx-xxx-xxxx";};
					break;
				case "max":
					var re; 
					re = new RegExp("\\d{"+s.maxLength+"}","ig");
					if (re.test(s.value)==false && !(isWhitespace(s.value))) {mesg="This requires " +s.maxLength +" numbers"};
				default:
					break;
				}
				break;
	   default: 
	   		break;
	}
	
	if (mesg!="") {
	s.focus();
	s.select();
	return returnError(mesg,"");
	return false;
	}
}

// General check for required fields of all inputs enclosed in a form
function generalFormCheck(s){ // s is a form object, the trick is in the alt
var formInputs=s.elements, mesg="", postFocus=""
for (i=0; i<formInputs.length; i++){
	if (isEmpty(formInputs[i].alt)==false && isWhitespace(formInputs[i].value)==true){
	mesg+=formInputs[i].alt +" is required\n";
		if (postFocus=="") postFocus=formInputs[i];
	}
}
	if (mesg!="") {
	postFocus.focus();
	return returnError(mesg,"");
	return false;
	}
}
//General check for matching values such as password and email entries, require alt attribute in input field
function checkMatch(s,t){
var mesg="", postFocus=""
if (getElm(s).value!=getElm(t).value){
mesg+=getElm(s).alt + " and " + getElm(t).alt + " must be the same.\n"
	if (postFocus=="") postFocus=getElm(s);
}
	if (mesg!="") {
	postFocus.focus();
	return returnError(mesg,"");
	return false;
	}
}
//folowing is unstable
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}	
function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
	return found;
}
function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
		return index;
	}
	return true;
}
function formFiller(pageName,windowName,winWidth,winHeight){
windowName=window.open(pageName,windowName,'toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no,width='+winWidth+',height='+winHeight+',screenX=0,left='+(screen.width-winWidth)/2+',screenY=0,top='+(screen.availHeight-winHeight)/2+'');
windowName.focus();
}
function winOpener(pageName,windowName,winWidth,winHeight){
windowName=window.open(pageName,windowName,'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable,alwaysRaised,dependent,titlebar=no,width='+winWidth+',height='+winHeight+',screenX=0,left='+(screen.width-winWidth)/2+',screenY=0,top='+(screen.availHeight-winHeight)/2+'');
windowName.focus();
}
/*
<SCRIPT language="jscript" RUNAT="Server">
var cityStr;
cityStr=decodeURI(request.querystring("city"));
</SCRIPT>
*/
// Your code goes here.