function checkTextAreaInput(obj,max){

   var result = true;

   var rem = obj.value.length - max;



   if (obj.value.length >= max){

      alert("Please enter "+max+" characters or less!");

      stripped = obj.value.substring(0, rem);

      obj.value = stripped;

      result = false;

   }



   if (window.event)

      window.event.returnValue = result;



   return result;

}



function checkrequired(which) {

	var pass=true;

	if (document.images) {

		for (i=0;i<which.length;i++) {

			var tempobj=which.elements[i];

			if (tempobj.name.substring(0,8)=="required") {

				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&

					tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&

					tempobj.selectedIndex==0)||(tempobj.type=="checkbox"&&tempobj.checked==false)) {

						pass=false;

						break;

         	}

      	}

   	}

	}

	if (!pass) {

		//shortFieldName=tempobj.name.substring(8,100).toUpperCase();

		shortFieldName=tempobj.name.substring(8,100).toLowerCase();



		//Sub - to _ for the sundry_code

		out = "_"; // replace this

		add = " "; // with this

		temp = shortFieldName; // temporary holder



		while (temp.indexOf(out)>-1) {

		   pos= temp.indexOf(out);

		   temp = "" + (temp.substring(0, pos) + add +

		   temp.substring((pos + out.length), temp.length));

		}



		shortFieldName = temp;

		//End of substitution.



		alert("Please enter "+shortFieldName+"!");

		//alert("The "+shortFieldName+" field is required!");

		return false;

	}

	else

		return true;

}

function checklabTourRequired(which) {

	var pass=true;

	if (document.images) {

		for (i=0;i<which.length;i++) {

			var tempobj=which.elements[i];

			if (tempobj.name.substring(0,8)=="required") {

				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&

					tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&

					tempobj.selectedIndex==0)) {

						pass=false;

						break;

         	}

      	}

   	}

	}

	if (!pass) {

		//shortFieldName=tempobj.name.substring(8,100).toUpperCase();

		shortFieldName=tempobj.name.substring(8,100).toLowerCase();



		//Sub - to _ for the sundry_code

		out = "_"; // replace this

		add = " "; // with this

		temp = shortFieldName; // temporary holder



		while (temp.indexOf(out)>-1) {

		   pos= temp.indexOf(out);

		   temp = "" + (temp.substring(0, pos) + add +

		   temp.substring((pos + out.length), temp.length));

		}



		shortFieldName = temp;

		//End of substitution.



		alert("Please enter "+shortFieldName+"!");

		//alert("The "+shortFieldName+" field is required!");

		return false;

	}

	else

		return true;

}

function NewWindow(mypage, myname, w, h, scroll) {

   var winl = (screen.width - w) / 2;

   var wint = (screen.height - h) / 2;

   mypage = mypage+'?'+self.location.href;

   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'

   win = window.open(mypage, myname, winprops)

   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}

function ImageManagerWindow(mypage, myname, w, h, scroll) {

   var winl = (screen.width - w) / 2;

   var wint = (screen.height - h) / 2;

   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'

   win = window.open(mypage, myname, winprops)

   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}



function dodacheck(val) {

	var mikExp = /[$\\\\#%\^\&\*\[\]\+\_\{\}\<\>\?\!\:\;\,\`\~\=\|]/;

   var strPass = val.value;

   var strLength = strPass.length;

   var lchar = val.value.charAt((strLength) - 1);

   if(lchar.search(mikExp) != -1) {

      //var tst = val.value.substring(0, (strLength) - 1);

      //val.value = tst;

      alert("Sorry, but the following characters\n\r\n\r $ % ^ & * # < > [ ] \\ { + } ` ~ =  | : ; ? !\n\r\n\rare not allowed!\n");

      val.focus();

      return false;

   }

}



function checkEmail(whichfield) {

   //alert(whichfield);

   if (whichfield.value == ""){

      return (true)

   }

   if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(whichfield.value)){

      return (true)

   }

   alert("Invalid E-mail Address! Please re-enter.")

   //myForm.Email_Address.value = "";

   whichfield.focus();

   whichfield.value = "";

   return (false)

}



function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {

   var i, j;

   var prompt;

   // empty existing items

   for (i = selectCtrl.options.length; i >= 0; i--) {

      selectCtrl.options[i] = null;

   }

   prompt = (itemArray != null) ? goodPrompt : badPrompt;

   if (prompt == null) {

      j = 0;

   }

   else {

      selectCtrl.options[0] = new Option(prompt);

      j = 1;

   }

   if (itemArray != null) {

      // add new items

      for (i = 0; i < itemArray.length; i++) {

         selectCtrl.options[j] = new Option(itemArray[i][0]);

         if (itemArray[i][1] != null) {

            selectCtrl.options[j].value = itemArray[i][1];

         }

         if (itemArray[i][2] != null) {

            selectCtrl.options[j].selected = true;

         }

         j++;

      }

      // select first item (prompt) for sub list

      // selectCtrl.options[0].selected = true;

   }

}