var ie=document.all;
var dom=document.getElementById;
var ns4=document.layers;

//Pops up a window of specified size and URL
function popup(URL,winName,winWidth,winHeight) {
	popupscroll(URL,winName,winWidth,winHeight,0)
}

function ask(question){
	var sure = confirm(question);
	if (sure==true){
		return true;
	}
	return false;
}

//Pops up a window of specified size and URL
function popupscroll(URL,winName,winWidth,winHeight,scrollbars) {
	var widthParent = 800, heightParent = 600; // defaults
	var widthChild = winWidth, heightChild = winHeight; // defaults
	var xPos = 300, yPos = 200; // defaults
	if (document.layers) {
	    widthParent = window.innerWidth;
	    heightParent = window.innerHeight;
	}
	else if (document.all) {
	    widthParent = document.body.clientWidth;
	    heightParent = document.body.clientHeight;
	}
	var xPos = (widthParent/2)-(widthChild/2);
	var yPos = (heightParent/2)-(heightChild/2);
    window.open(URL,winName,'personalbar=0,toolbar=0,menubar=0,scrollbars='+scrollbars+',status=0,resizable=1,width=' + widthChild + ',height=' + heightChild + ',left=' + xPos + ',top=' + yPos + ',screenX=' + xPos + ',screenY=' + yPos);
}

//Pops up a window of specified size and writes a message to it
function popupmsg(strMSG,winWidth,winHeight,scrollbars) {
	var widthParent = 800, heightParent = 600; // defaults
	var widthChild = winWidth, heightChild = winHeight; // defaults
	var xPos = 300, yPos = 200; // defaults
	if (document.layers) {
	    widthParent = window.innerWidth;
	    heightParent = window.innerHeight;
	}
	else if (document.all) {
	    widthParent = document.body.clientWidth;
	    heightParent = document.body.clientHeight;
	}
	var xPos = (widthParent/2)-(widthChild/2);
	var yPos = (heightParent/2)-(heightChild/2);
    msgWindow = window.open('about:blank','TWUMessage','personalbar=0,toolbar=0,menubar=0,scrollbars=' + scrollbars + ',status=0,resizable=1,width=' + widthChild + ',height=' + heightChild + ',left=' + xPos + ',top=' + yPos + ',screenX=' + xPos + ',screenY=' + yPos);
	msgWindow.document.open();
    msgWindow.document.close();
	msgWindow.document.write(strMSG);
}

//Pops up a window, writes a message to it, and opens the print dialog
function printerfriendly(pageName){
	var objContent;
	if (ie){
		objContent = pagecontent;
	}
	else if (ns4){
		objContent = document.layers['pagecontent'];
	}
	else if (dom){
		objContent = document.getElementById('pagecontent');
	}
	var content
	content = "<html>\n<head>\n<title>" + pageName + "</title>\n<link href=/includes/plain.css type='text/css' rel='stylesheet'>\n";
	content += "<body>\n" + objContent.innerHTML + "\n</body>\n</html>";
	msgWindow = window.open('about:blank','printer','personalbar=0,toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,width=500,height=500,left=200,top=200,screenX=200,screenY=200');
	msgWindow.document.open();
	msgWindow.document.write(content);
	msgWindow.document.close();
	msgWindow.print();
	msgWindow.close();
}
function hidecontent(pageName){
	var objContent;
	if (ie){
		objContent = pagecontent;
	}
	else if (ns4){
		objContent = document.layers['pagecontent'];
	}
	else if (dom){
		objContent = document.getElementById('pagecontent');
	}
	objContent.style.display = 'none';
}
function showcontent(pageName){
	var objContent;
	if (ie){
		objContent = pagecontent;
	}
	else if (ns4){
		objContent = document.layers['pagecontent'];
	}
	else if (dom){
		objContent = document.getElementById('pagecontent');
	}
	objContent.style.display = '';
}

function getobject(objname){
	if (ie){
		objContent = pagecontent;
	}
	else if (ns4){
		objContent = document.layers['pagecontent'];
	}
	else if (dom){
		objContent = document.getElementById('pagecontent');
	}
}


function setfocus(myObject) {
    myObject.focus();
}

//Checks or Unchecks all checkboxes on a page
function checkall(){
	myStr = document.form1.elements.length ;
	myStatus = document.form1.checkall.checked                 
	for (i=0; i < myStr; i++){
		document.form1.elements[i].checked=myStatus;
	}
}

//Specific popup for slow-loading links
function PleaseWait() {
	setpointer('wait');


	cen=(ie)? document.body.clientWidth/2-155 : (dom)?window.innerWidth/2-155  : window.innerWidth/2-155
	crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
	scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
	crossobj.top=scroll_top+200
	crossobj.width=300
	crossobj.left=cen
	crossobj.visibility=(dom||ie)? "visible" : "show"
	HTML = '<center><h1>Processing...</h1><img src=/images/progbar2.gif width=260 height=24></center>'
	if (ie) {
		document.all.dropin.innerHTML = HTML;
		document.all.dropin.left='200';
	}	
	else if (ns4) {
		document.layers['dropin'].document.open();
		document.layers['dropin'].document.write(HTML);
		document.layers['dropin'].document.close();
	}
	else if (dom) {
		document.getElementById('dropin').innerHTML= HTML;
	}
	hidecontent();
}

//Sets mouse pointer
function setpointer(pointerType) {
    document.body.style.cursor = pointerType;
}



//************* Slider Window Scripts *************
var bounceinc=5;
var bouncelimit=4*bounceinc;
var direction='left';
var timetodrop=30;

function slider(message,width) {
	HTML = '<table cellpadding=0 cellspacing=0 border=0 width='+width+' height=160 bgcolor=#ECE9D8>';
	HTML += '<tr><td width='+width+' height=2 bgcolor=#3C8BED colspan=5></td></tr>';
	HTML += '<tr><td width=2 height=13 bgcolor=#3C8BED></td>';
	HTML += '<td width='+(width-5)+' bgcolor=#0260E9 align=right colspan=2>';
	HTML += '<a href=javascript:closebox()><img src=/images/close.gif border=0></a></td>';
	HTML += '<td width=1 bgcolor=#0260E9></td>';
	HTML += '<td width=2 bgcolor=#0238CD></td></tr>';
	HTML += '<tr><td width=2 height=2 bgcolor=#3C8BED></td>';
	HTML += '<td width='+(width-2)+' bgcolor=#0238CD colspan=4></td></tr>';
	HTML += '<tr><td width=2 height=140 bgcolor=#3C8BED></td>';
	HTML += '<td width=1 bgcolor=#0238CD></td>';
	HTML += '<td width='+(width-6)+' style=padding:5px>' + message + '</td>';
	HTML += '<td width=1 bgcolor=#0260E9></td>';
	HTML += '<td width=2 bgcolor=#0238CD></td></tr>';
	HTML += '<tr><td width=2 height=1 bgcolor=#3C8BED></td>';
	HTML += '<td width=1 bgcolor=#0238CD></td>';
	HTML += '<td width='+(width-5)+' bgcolor=#3C8BED colspan=2></td>';
	HTML += '<td width=2 bgcolor=#0238CD></td></tr>';
	HTML += '<tr><td width=2 height=2 bgcolor=#3C8BED></td>';
	HTML += '<td width='+(width-2)+' bgcolor=#0238CD colspan=4></td></tr></table>';
	if (ie) {
		document.all.dropin.innerHTML = HTML;
		document.all.dropin.left='200';
	  }	
	else if (ns4) {
		document.layers['dropin'].document.open();
		document.layers['dropin'].document.write(HTML);
		document.layers['dropin'].document.close();
	}
	else if (dom) {
		document.getElementById('dropin').innerHTML= HTML;
	}
	initbox();
}

function initbox(){
	if (!dom&&!ie&&!ns4)
	return
	cen=(ie)? document.body.clientWidth/2-155 : (dom)?window.innerWidth/2-155  : window.innerWidth/2-155
	crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
	scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
	crossobj.top=scroll_top-250
	crossobj.width=250
	crossobj.left=cen
	crossobj.visibility=(dom||ie)? "visible" : "show"
	dropstart=setInterval("dropin()",timetodrop)
}

function dropin(){
	scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
	if (parseInt(crossobj.top)<125+scroll_top){
		crossobj.top=parseInt(crossobj.top)+40;
	}
	else{
		clearInterval(dropstart);
		bouncestart=setInterval("bouncein()",timetodrop);
	}
}

function bouncein(){
	crossobj.top=parseInt(crossobj.top)-bouncelimit
	if (bouncelimit<0)
		bouncelimit+=bounceinc
		bouncelimit=bouncelimit*-1
	if (bouncelimit==0){
		clearInterval(bouncestart)
	}
}

function closebox(){
	if (window.bouncestart) clearInterval(bouncestart)
	crossobj.visibility="hidden"
}
//*********** End Slider Window Scripts ************


function readcookie (name) {
	var namearg = name + "=";
	var nlen = namearg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	  var j = i + nlen;
	  if (document.cookie.substring(i, j) == namearg) {
	     var endpos = document.cookie.indexOf (";", j);
	     if (endpos == -1) endpos = document.cookie.length;
	     return unescape(document.cookie.substring(j, endpos));
	}
	  i = document.cookie.indexOf(" ", i) + 1;
	  if (i == 0) break;
	}
	return null;
}

function writecookie (name, value) {
	var expdate=new Date();
	// expire cookie in 10 years by default
	expdate.setTime(expdate.getTime()+10*365*24*60*60*1000);
	document.cookie = name + "=" + escape (value) + "; expires=" + expdate.toGMTString();
}

function deletecookie (name) {
	var expdate = new Date();
	expdate.setTime (expdate.getTime() - 1);  // Already gone!
	var cval = ReadCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + expdate.toGMTString();
}

//****************  REGULAR EXPRESSIONS  *******************************************************************************
function validssn(ssn) {
	var rx_ssn = /^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$/;
	if (rx_ssn.test(ssn)){
		return true;
	}
	return false;
}
function validemail(email) {
	var rx_email = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
	if (rx_email.test(email)){
		return true;
	}
	return false;
}
function validphone(phone) {
	var rx_phone = /^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$/;
	if (rx_phone.test(phone)){
		return true;
	}
	return false;
}
