// JavaScript Document


function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = "";
}


function resetDefault(el) {
  if (el.value == "") el.value = el.defaultValue;
}


///////////// Pop-up Window Code /////////////////////////////////////
	
function loadPage(url, winHeight, winWidth) {
 
 if (!window.gallery) {
		// has not yet been defined, open window
		gallery = window.open(url, 'gallery', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+winWidth+',height='+winHeight+'');
 		// call function to test for pop-up blocking
 		popUp_test(gallery, url);
 }
 else {
	// has been defined
	if (!gallery.closed) {
		// still open, close open
		gallery.close();
		gallery = window.open(url, 'gallery', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+winWidth+',height='+winHeight+'');
		// call function to test for pop-up blocking
 		popUp_test(gallery, url);
	}
	else {
		//open window
		gallery = window.open(url, 'gallery', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+winWidth+',height='+winHeight+'');
		// call function to test for pop-up blocking
 		popUp_test(gallery, url);
	}
 }
}

// function to test for pop-up blocking
function popUp_test(popWin, URLStr) {
	try {
		// test for open window 
		var obj = popWin.name;
		// If successfull, Popup blocker NOT detected
		// You can do something at this point, or not
	}
	catch(e){
		//System has been blocked by POP-UP BLOCKER
		// Redirect main browser window to pop-up URL
		location.href = URLStr + "?popUp=no";
		
	} 
 }
 
function getValue(s) {
 var x = document.location.search;
 var xend = 0;
 if (x.indexOf(s) != -1) {
  x = x.substr(x.indexOf(s) + s.length);
  xend = x.indexOf("&");
  if (xend > 0) { x = x.substr(0,xend); }
 } else {
  x = "";
 }
 return x;
}

function replaceChar(s,c1,c2) { // search string s for c1 and replace with c2
 if (s != null && s.length > 0) {
  while (s.indexOf(c1) != -1) {
   p = s.indexOf(c1);
   s = s.substring(0,p) + c2 + s.substring(p+1,s.length);
  }
 }
 return s;
}

// function that returns whether or not an email address is actually potentially valid
function _MW_validate_email(address) {
		// if the length is zero, return true...need to specify other validation to catch this error
		// this allows validation if something is entered, but allows blanks in the event that no entry is allowed
		if (address.length == 0) return true;
	
		var atPosition = address.indexOf('@');
		var dotPosition = address.lastIndexOf('.');
		var addressLength = address.length;

		if (addressLength < 5)  // definitely bad here!
			return false;
		else if (atPosition < 1)
			return false;
		else if ((dotPosition < 3) ||
				(dotPosition <= (atPosition + 1)))
			return false;

		return true;
}
