//popup
function popup(url,title,w,h,r,s,m,t) {
	//if vars aren't provided, use these defaults
	if (title==null) {
		title = 'popup';
	} if (w==null) {
		w=600;
	} if (h==null) {
		h=400;
	} if (r==null) {
		r='yes';
	} if (s==null) {
		s='yes';
	} if (m==null) {
		m='no';
	} if (t==null) {
		t='no';
	}
	vars = 'width='+w+',height='+h+',resizable='+r+',scrollbars='+s+',menubar='+m+',toolbar='+t;
	var newWin = window.open(url,title,vars);
	newWin.focus();
	return false;
}


//open a print-friendly version
function printIt(pageLoc,show) {
	if(pageLoc != ''){
		var url = pageLoc;
	} else {
		var url = document.location.href
	}

	if (document.location.href.indexOf('?')!=-1) {
		var url = url + '\&layout=print';
	}
	else {
		var url = url + '?layout=print';
	}
	if(show != ''){
		var url = url + '&showTable=' + show;
	}

	var printView = window.open(url,'printView','width=680,height=450,location=no,menubar=yes,resize=yes,scrollbars=yes,toolbar=yes');
	printView.focus();
}
//REMOVE AFTER GREP FOR FUNCTION CALL
//open a print-friendly version of one table on a multi print tables page
//pass the id of the table to show to this function
function printItMulti(pageLoc,show) {
	if(pageLoc != ''){
		var url = pageLoc;
	} else {
		if (document.location.href.indexOf('?')!=-1) {
			var url = document.location.href + '\&layout=print&showTable=' + show;
		}
		else {
			var url = document.location.href + '?layout=print&showTable=' + show;
		}
	}
	var printView = window.open(url,'printView','width=680,height=450,location=no,menubar=yes,resize=yes,scrollbars=yes,toolbar=yes');
	printView.focus();
}

//if this is a print-friendly version, print it onload
function process() {
	if ((document.location.href.indexOf('layout=print')!=-1)&&(!document.layers)) {
		//window.print();
	}
}

//write print button right aligned with bottom padding of 10 to the page
function printButton(){
	if (document.location.href.indexOf('layout=print')!=-1) {
		document.write('<p id="printButton" align="right"><a href="#" onClick="window.print();"><img src="/prod_images/but_print.gif" border="0" width="67" height="17" alt="Print"></a></p>');
	}
}
	


//email validation script
function emailCheck(emailStr) {

	var specialChars      = "\\(\\)<>@,;:\\$" + "\\\\" + '\"' + "\\.\\[\\]";
	var validChars        = "[^\\s" + specialChars + "]";
	var quotedUser        = '("[^"]*")';
	var atom              = validChars + '+';
	var word              = "(" + atom + "|" + quotedUser + ")";
	var userPat           = new RegExp("^" + word + "(\\." + word + ")*$");

	//begin checking address
	var em = emailStr.split('@');
	if(em.length > 2){
    alert('Please check your Email Address -- you have too many \"@\" characters in it.');
		return false;
  }

	var matchArray        = emailStr.match(/^([^@]+)@([-\.\w\[\]]+)$/);

	if (matchArray == null) {
		if(emailStr.indexOf('@') == -1){
			alert('Please check your Email Address -- you are missing the \"@\" character.');
			return false;
		}
		else{
  	  if(em[0].search(userPat) == -1){
 	  		alert('Please check your Email Address -- your username (what\'s before the \"@\") is missing or invalid.');
				return false;
			}
			else{
				alert('Please check your Email Address -- your domain (what\'s after the \"@\") is missing or invalid.');
				return false;
			}
		}
	}

	user                  = new String(matchArray[1]);
	domain                = new String(matchArray[2]);

	if (user.search(userPat) == -1) {
    alert('Please check your Email Address -- your username (what\'s before the \"@\") is missing or invalid.');
		return false;
	}

	// verify the domain
	re1 = /^((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	
	if(domain.search(re1) == -1){
    alert('Please check your Email Address -- your domain (what\'s after the \"@\") is missing or invalid.');
		return false;
  }
	
	// If we've gotten this far, everything's valid!
	return true;
}

