/*
==========================================================
InnerLoop Creative Solutions - Javascript function library
Date Created: 22 Dec 2004 - Last Modified: 05 Arp 2006

Notes: This library contains all javascript functions we use, and is included
in the top of the page at the same place as the stylesheets.

TO INCLUDE:
<script type="text/javascript" src="../Javascript/ScriptLibrary.js"></script>
==========================================================
*/

// Pop up a new window (customizable)
function popUpWindow(URLStr, left, top, width, height, resize, scrolling) {
	
	if (left == -1 && top == -1) {
		var left = (screen.width/2) - width/2;
    	var top = (screen.height/2) - height/2;
	}

  popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrolling+',resizable='+resize+',copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// Pop up a new window - extended function (transitional)
function popUpWindowExt(URLStr, name, left, top, width, height, resize, scrolling) {
	
	if (left == -1 && top == -1) {
		var left = (screen.width/2) - width/2;
    	var top = (screen.height/2) - height/2;
	}
	
	if (name == "") {
		name = "popUpWin";
	}

  popUpWin = window.open(URLStr, name, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrolling+',resizable='+resize+',copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// Display a message in a new, variable size size window (using the main websites stylesheet)
function messageWindow(title, msg, width, height, resize, scrolling, alignment) {
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  if (!alignment) { alignment = "center"; }
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar='+scrolling+',resizable='+resize+',copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var msgHead = '<html><head><title>'+title+'</title><link href="../CSS/StyleMain.css" rel="stylesheet" type="text/css"></head>';
  var msgBody = '<body style="padding: 8px;"><p align="'+alignment+'">'+msg+'</p><p align="'+alignment+'"><form><input class="formSubmit" type="button" value="   Close this window   " onClick="self.close()"></form></p></body></html>';
  msgWindow.document.write(msgHead + msgBody);
}

// Display a message in a new, variable size size window (using the admin stylesheet)
function messageWindowAdmin(title, msg, width, height, resize, scrolling, alignment) {
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  if (!alignment) { alignment = "center"; }
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar='+scrolling+',resizable='+resize+',copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var msgHead = '<html><head><title>'+title+'</title><link href="../CSS/StyleAdmin.css" rel="stylesheet" type="text/css"></head>';
  var msgBody = '<body style="padding: 8px;"><p align="'+alignment+'">'+msg+'</p><p align="'+alignment+'"><form><input class="formSubmit" type="button" value="   Close this window   " onClick="self.close()"></form></p></body></html>';
  msgWindow.document.write(msgHead + msgBody);
}

// Change an image at any time...this is called using the image's name attribute.
function changeImage(imageName,fileName) {
	document.all(imageName).src = fileName;
}

// Resize a window to fixed width/height
function resizeWindow(width,height) { 
	if (navigator.appVersion.charAt(0) >=4) { 
		window.resizeTo (width,height)
	}
}

// Toggle z-level of a div (targetID) with z-level value
function changeDivLevel( targetID, zLevel ) {
	target = document.all( targetID );
	target.style.zIndex = zLevel;
}

// Go back one step in history
function goBack() { 
	history.back() 
}

// A (supposedly) Spam-proof method of displaying (and linking) an email address.
function showEmail(name, domain) {
document.write('<a href="mailto:' + name + '@' + domain + '">');
document.write(name + '@' + domain + '</a>');
}

// Form Validation
function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// Auto-Jump Menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// The two generic <div> functions for hiding & showing various layers
// The non-generic one (commented here) needs to be copied and pasted into the page itself and configured with the <div> id's.
// Also, don't forget to put the InitPageLayout(); function in the onload param of the <body> tag.

//<!--
//function InitPageLayout() {	
//	readDivHeightCookie("divName");
//	readDivHeightCookie("divName2");
//}
//-->

function readDivHeightCookie(cookieName) {
	
	thisCookie = document.cookie.split("; ");

	for (i=0;i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			changeDivHeight(cookieName, thisCookie[i].split("=")[1]);
			//alert ("Cookie Name: " + cookieName + "=" + thisCookie[i].split("=")[1]);
		}
	}
		
}

function changeDivHeight(target,height) {
	
	expireDate = new Date;
	expireDate.setMonth(expireDate.getMonth()+12);
	
	document.getElementById(target).style.height = height;
	document.cookie = target + "=" + height + ";expires=" + expireDate.toGMTString();

}