// JavaScript Document
var firstErrorArray = new Array();

function openPDFWindow(theURL, winName, features, thePDF) {
	if (features == "") features = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=600';
	var newWin;
	
	theURL = unescape(theURL);
	thePDF = unescape(thePDF);
	if (thePDF != "") {		
		// extract current location
		var currentLoc = location.href;
		for (var x=currentLoc.length; x > 1; x--) {
			if (currentLoc.substring(x,(x-1)) == "/") {
				var currentLoc = currentLoc.substring(x,0);
				break;
			}
		}
		thePDF = '../../pdfviewer.htm?redir=' + currentLoc + thePDF;
		newWin = window.open(thePDF,winName,features);
	} else {
		newWin = window.open(theURL,winName,features);
	}	
	newWin.focus();
}

// registration form functions
function resetErrorFields(arrayCheck) {
	// this will changes all fields if they were red back to white
	firstErrorArray = new Array();
	 for (i = 0; i < arrayCheck.length; i++) {
	 	divError(arrayCheck[i], 1);
 	}
}

function divError(divID, returnState) {
	// this function will change the field to a red color to show an error	
  if (document.getElementById(divID)) {
	if (returnState) {
		document.getElementById(divID).style.background = "#FFFFFF"
	} else {
		firstErrorArray.push(divID);
		document.getElementById(divID).style.background = "#FFCCFF"
	}
  }
}

function findPosY(obj) {
    var curtop = 0;
   if(!obj) {
	 return 0
   } else {
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
	if (curtop) {
   	 return curtop-50;
	} else {
	 return curtop;
	} 	
  }
}


function validateTypes(formValue, vType, alertMessage) {
  var validReturn = 1;
  if (formValue) {
   if (formValue != "") {
	if (vType == "email") {
		var emailExp=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
		if(!emailExp.test(formValue)) {
	 		validReturn = 0;
		}
	} else if (vType == "number") {
		if(isNaN(formValue)){
			validReturn = 0;
		}
	} else if (vType == "zip") {
		// Check for correct zip code
		
		//sep = this.setArg( sep, "- " );
		//var regex = new RegExp( "^[0-9]{5}(|[" + sep.toPattern() + "][0-9]{4})?$" );

     	var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 		if(!reZip.test(formValue)) {
			validReturn = 0;
		}
	 }
    }	
  }
  
  if (alertMessage) {
	  if (!validReturn) {
	  	alert(alertMessage);
	  }
  } else {
  	return validReturn;
  }
}

function removeAllTabs() {
	for (var j=0; j<=document.form.length; j++) {
	  if (document.form[j]) {	
		if (document.form[j].value) {
			textString = document.form[j].value;
			if (textString.indexOf("\t") != -1) {
				textString = textString.replace(/\t/g, "    ");
				document.form[j].value = textString
			}
		}	
	 }
  }
}

function currentYear() {
	try {
		var theDate = new Date();
		var theYear = theDate.getFullYear();
		return theYear;		
	} catch (exceptionobj) {
		;
	}
}

function displayCurrentYear() {
	try {
		document.writeln(currentYear()); 
	} catch (exceptionobj) {
		;
	}
}