function doSave(form) {
	form.varSave.value = "1";
	form.submit();
}

function doQA() {
	document.frmRFPs.varQA.value = "1";
	document.frmRFPs.submit();
}

function delRec(strItem,form) {
var cnfrm = confirm("Are you sure you wish to delete this "+strItem +"?");
if (cnfrm) {
	form.varDelete.value = "1";
	form.submit();
	}
return true;
}

function delLogo(strItem,form) {
var cnfrm = confirm("Are you sure you wish to remove this "+strItem +"?");
if (cnfrm) {
	form.varRemove.value = "1";
	form.submit();
	}
return true;
}

function addRec(form){
	form.varAdd.value = "1";
	form.submit();
return true;
}

function move(strPage,form) {
  for(var x=0; x < form.options.length;x++)  {
      if(form.options[x].selected) {
		var str = strPage + "?id=" + form.options[x].value;
		location.replace(str);
		break;
		}
 }
}

function moveYear(strPage) {
	for(var x=0; x < document.MeForm.dt.options.length;x++)  {
		if(document.MeForm.dt.options[x].selected) {
			var dt= document.MeForm.dt.options[x].value
		}
	}
	for(var x=0; x < document.MeForm.yr.options.length;x++)  {
		if(document.MeForm.yr.options[x].selected) {
		var str = strPage + "&dt=" + dt + "&yr=" + document.MeForm.yr.options[x].value;		
		location.replace(str);
		}
	}
}

//For Calendar Navigation
function moveMonth(strPage) {
	for(var x=0; x < document.MeForm.yr.options.length;x++)  {
		if(document.MeForm.yr.options[x].selected) {
			var yr= document.MeForm.yr.options[x].value;
		}
	}
	for(var x=0; x < document.MeForm.dt.options.length;x++)  {
		if(document.MeForm.dt.options[x].selected) {
		var str = strPage + "&dt=" + document.MeForm.dt.options[x].value + "&yr=" + yr;
		location.replace(str);
		}
	}
}

function openWin( windowURL, windowName, windowFeatures) { 
	return window.open( windowURL, windowName, windowFeatures);
}

function setUpdateID(form) {
	form.updateHdn.value = 1;
	form.submit();
}

function delQA() {
	var cnfrm = confirm("Are you sure you wish to delete these/this item(s)?");
	if(cnfrm) {
		document.frmQA.varDelete.value = "1";
		document.frmQA.submit();
	}
}

function addMeetingEvent(){
		document.frmEvents.varAdd.value = "1";
		document.frmEvents.eventtypeHdn.value = 0;
		document.frmEvents.submit();
return true;
}

function doOccurrence() {
	if(document.frmEvents.eventdate.value == "") {
		alert("You need to select a Date above before selecting the rate of occurrance.");
		return false;
	}
	else {
		document.frmEvents.varSetOccurrence.value = "1";
		//document.frmEvents.varAdd.value = 1;
		document.frmEvents.submit();
	}
}

function doSelect() {
	document.occurrence.varSelect.value = "1";
	document.occurrence.submit();
}

function setOccurrence() {
	window.opener.document.frmEvents.varAdd.value = 1;
	//window.opener.document.frmEvents.varReturn.value = 1;
	window.opener.document.frmEvents.eventtypeHdn.value = document.frmSetOccurrence.eventtypeHdn.value;
	window.opener.document.frmEvents.eventdateHdn.value = document.frmSetOccurrence.eventdateHdn.value;
	window.opener.document.frmEvents.numberHdn.value = document.frmSetOccurrence.number.value;
	window.opener.document.frmEvents.monthpositionHdn.value = document.frmSetOccurrence.monthposition.value;
	window.opener.document.frmEvents.submit();
	window.close();
}

function doCancel() {
	window.opener.document.frmEvents.varAdd.value = 1;
	window.opener.document.frmEvents.varReturn.value = 1;
	window.opener.document.frmEvents.eventtypeHdn.value = 0;
	window.opener.document.frmEvents.submit();
	window.close();
}


function emailCheck(emailStr) 
	{		
		/* The following pattern is used to check if the entered e-mail address
   		fits the user@domain format.  It also is used to separate the username
   		from the domain. */
		var emailPat=/^(.+)@(.+)$/;

		/* The following string represents the pattern for matching all special
   		characters.  We don't want to allow special characters in the address. 
   		These characters include ( ) < > @ , ; : \ Quotation . [ ]    */
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

		/* The following string represents the range of characters allowed in a 
   		username or domainname.  It really states which chars aren't allowed. */
		var validChars="\[^\\s" + specialChars + "\]";

		/* The following pattern applies if the "user" is a quoted string (in
   		which case, there are no rules about which characters are allowed
   		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   		is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";

		/* The following pattern applies for domains that are IP addresses,
   		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   		e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

		/* The following string represents an atom (basically a series of
   		non-special characters.) */
		var atom=validChars + '+';

		/* The following string represents one word in the typical username.
   		For example, in john.doe@somewhere.com, john and doe are words.
   		Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";

		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		/* The following pattern describes the structure of a normal symbolic
   		domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		/* Finally, let's start trying to figure out if the supplied address is valid. */

		/* Begin with the coarse pattern to simply break up user@domain into
   		different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat);

		if (matchArray==null)
		{
  		/* Too many/few @'s or something; basically, this address doesn't
   			even fit the general mould of a valid e-mail address. */
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}

		var user=matchArray[1];
		var domain=matchArray[2];

		// See if "user" is valid 
		if (user.match(userPat)==null)
		{
    	// user is not valid
    	alert("The username doesn't seem to be valid.");
   		return false;
		}

		/* if the e-mail address is at an IP address (as opposed to a symbolic
   		host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat);

		if (IPArray!=null)
		{
   		// this is an IP address
  		for (var i=1;i<=4;i++)
  		{
    		if (IPArray[i]>255)
    		{
       		alert("Destination IP address is invalid!");
					return false;
    		}
   		}
   		return true;
		}

		// Domain is symbolic name
		var domainArray=domain.match(domainPat);

		if (domainArray==null)
		{
			alert("The domain name doesn't seem to be valid.");
   		return false;
		}

		/* domain name seems valid, but now make sure that it ends in a
   		three-letter word (like com, edu, gov) or a two-letter word,
   		representing country (uk, nl), and that there's a hostname preceding 
   		the domain or country. */

		/* Now we need to break up the domain to get a count of how many atoms
   		it consists of. */
		var atomPat=new RegExp(atom,"g");
		var domArr=domain.match(atomPat);
		var len=domArr.length;

		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
    {
   		// the address must end in a two letter or three letter word.
   		alert("The address must end in a three-letter domain, or two letter country.");
   		return false;
		}

		// Make sure there's a host name preceding the domain.
		if (len<2)
		{
   		var errStr="This address is missing a hostname!";
   		alert(errStr);
   		return false;
		}

		// If we've gotten this far, everything's valid!
		return true;
	}

/*VALIDATE ZIP CODE ENTRY AND LENGTH
Date: 10/8/2002
functions included:	ValidZip() - allows only number,hyphen and backspace keys to be used
								ValidZipLength() - validates the zipcode's length if a 5 or 5 + 4 zipcode is used
*/

function ValidZip(e) {
	//only allow user to input numbers, hyphen and backspace(8)
	if (document.all) {
	//first check backspace
	if (event.keyCode==8){ return true; }
	//now check hyphen
	if (event.keyCode==45){ return true; }
	//lastly check for a number entry
	if (event.keyCode<48||event.keyCode>57) {
		return false;
	}
}
else {
	if (e.which==8){ return true; }
	if (e.which==45){ return true; }
	if (e.which<48||e.which>57) {
		return false;
	}
}		
}

function ValidZipLength(objZip) {
	if(objZip.value.length < 5) {
		alert("Please enter a complete zip code.");
		return false;
	}
	if(objZip.value.length > 5 && objZip.value.length < 10) {
		alert("Please enter a complete zip code.");
		return false;
	}
return true;
}

function numbersOnly(e) {
//only allow user to input numbers and backspace(8)
if (document.all) {
	//first check backspace
	if (event.keyCode==8){ return true; }
	if (event.keyCode<48||event.keyCode>57) {
		return false;
	}
}
else {
	if (e.which==8){ return true; }
	if (e.which<48||e.which>57) {
		return false;
		}
}		
}

/*VALIDATE PHONE NUMBER ENTRY AND FORMAT
Date: 10/8/2002
functions included:	getIt() - obtains the current key entry
								ValidatePhone() - validates the phone number by auto-formatting
															the entry in the (###)###-#### format
															(the "(" and ")" and "-" are automatically entered)
															
			***Use the NumbersOnly() function in the "Phone Number " field
				 to ensure only numbers are entered
*/

var n;
var p;
var p1;

function getIt(m){
n=m.name;
p1=m
ValidatePhone()
}

function ValidatePhone(){
p=p1.value
if(p.length==3){
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	p1.value="";
	p1.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		p1.value="";
		p1.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	p1.value="";
	pp="("+p13+")"+p14+p15;
	p1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
	pp=p19+p17+"-"+p18;
	p1.value="";
	p1.value=pp;
	}
}
setTimeout(ValidatePhone,100)
}

/*VALIDATE TIMES AND DATES for SQL SERVER
Date: 10/8/2002
functions included:	ValidTime() - used to ensure manual time entry matches correct format (hh:mm(:ss) AM/PM)
								ValidDate() - used to ensure manual date entry matches correct format (mm/dd/yyyy)
									isInteger() - subfunction of ValidDate()
									stripChars() - subfunction of ValidDate()
									daysInFebruary() - subfunction of ValidDate() - checks for Leap Year and adds a day
									DaysArray() - subfunction of ValidDate() - holds the days in a month (30,31,29)
								ValidDateChars() - allows only number and "/" keys to enter values to date field
								DateCompare() - compares 2 dates to each other and alerts negative result
*/
								
function ValidTime(strTime) { 
var timePart = /^(\d{1,2})(:(\d{2}))?(\s)?$/;
var matchArray = strTime.match(timePart);

	if (matchArray == null) {
		alert("Time is not in a valid format.\nPlease use HH:MM format.");
	return false;
	}

	var hour = matchArray[1];
	var minute = matchArray[3];

	if (hour < 0  || hour > 12) {
		alert("Hour must be between 1 and 12.");
		return false;
	}
	if (minute<0 || minute > 59) {
		alert ("Minute must be between 0 and 59.");
		return false;
	}
return true;
}

//valid date character
var dtCh= "/"; 

function ValidDate(dtStr){

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0){
		alert("Please enter a valid 4 digit year.");
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripChars(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
return true;
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripChars(s, chars){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in string, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (chars.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this;
}

function ValidDateChars(e) {
	//only allow user to input numbers, forward slash and backspace(8)
	if (document.all) {
	//first check backspace
	if (event.keyCode==8){ return true; }
	//now check for forward slash or number entry
	if (event.keyCode<47||event.keyCode>57) {
		return false;
	}
}
else {
	if (e.which==8){ return true; }
	if (e.which<47||e.which>57) {
	return false;
	}
}		
}

function DateCompare(date1,date2,ckfor) {
var d1 = new Date(date1)
var d2 = new Date(date2)
var ck = ckfor

	if(d1 > d2) {
		alert("The Start Date must be before the End Date.\nPlease enter a New Date/Time.");
		return false;
	}
	if(ck == 'yes') {
	var dif = 0;	
	dif = d1 - d2;
		if(dif == 0) {
			alert("The Start Date and the End Date are the same.\nPlease enter a New Date/Time.");
			return false;
		}
	}
	return true;
}

function ValidFileName(file) {
	invalidchars = "!@#$%^&*()+={}[];,"
	for (i = 0; i < file.length; i++) {
	    ch = file.substring(i, i + 1);
	    if (invalidchars.indexOf(ch,0) != -1) {
			return false;
	    }
	}
	return true;
}