/*Universal parameter validation http://javascript.about.com/library/blvalid02.htm*/

var numb='0123456789';
var lwr='abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var emlchars='@.-';
var phonechars='.-()';
var emailPat=/^(.+)@(.+)$/;
var space=' ';
var apostrophe="'";
var quote='"';
var searchchar='-+';

function isValid(param,val){
	if(param==""){
		//alert('no params');
		return true;
		}else{
			for(i=0;i<param.length;i++){
			
				if(val.indexOf(param.charAt(i),0) == -1) return false;
			
			}
		return true;
			}
}

function isNum(param) {return isValid(param,numb);}
function isLower(param) {return isValid(param,lwr);}
function isUpper(param) {return isValid(param,upr);}
function isAlpha(param) {return isValid(param,lwr+upr);}
function isAlphaSpace(param) {return isValid(param,lwr+upr+space+apostrophe);}
function isAlphanum(param) {return isValid(param,lwr+upr+numb);}
function isSpecial(param) {return isValid(param,lwr+upr+numb+emlchars);}
function isPhone(param) {return isValid(param,numb+phonechars+space);}
function isSearch(param) {return isValid(param,lwr+upr+space+apostrophe+phonechars+quote+searchchar);}

/*pop ups*/

function new_window(url){
	link = 
	window.open(url,"Link",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,width=550,height=490,screenX=600,screenY=300,top=300,left=600');
	}
function new_windowLongTall(url){
	link = 
	window.open(url,"Link",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,scrollbars=1,width=300,height=600,screenX=600,screenY=300,top=300,left=600');
	}
function popCap(img,caption,width,height){
	if(caption=="undefined"){
		caption=" ";
		}
	var capdivwidth=width-50;//40 is the width assigned in the content formatting function for new window size...
	//var height=height+10;
	newWindow=window.open("","Image",'toolbar=0,location=0,directories=0,menubar=0,resizable=1,width='+width+',height='+height+',screenX=600,screenY=300,top=300,left=600');
	newWindow.document.writeln('<html>');
	newWindow.document.writeln('<head>');
	newWindow.document.writeln('<title>'+img+'</title>');
	newWindow.document.writeln('<style>');//.caption{margin:15px 0 0 0;padding:10px 0 0 0;width:'+capdivwidth+'font-family:verdana;font-size:13px;line-height:14px;}');
	newWindow.document.writeln('.captionbox{margin:15px 8px 8px 8px;padding:10px 5px 5px 5px;background-color: #FFFFFF;');
	newWindow.document.writeln('width:'+capdivwidth+';font-family:verdana;font-size:13px;}</style>');
	newWindow.document.writeln('</head><body>');

	newWindow.document.writeln('<img src="'+ img +'"><br>');
	newWindow.document.writeln('<div class="captionbox">'+ unescape(caption) +'</div>');
	//newWindow.document.writeln('</div>');
	
	//newWindow.document.writeln('<div class="caption">'+ unescape(caption) +'</span><br>');
	//newWindow.document.writeln('</div>');
	
	newWindow.document.writeln('</body></html>');
	}
	
/*===============
#	function openpopup
#	note: Make sure you enclose the popurl string 
#	in single quotes. Escape them with a backslash if you need to
#	...like "openpopup(\'theurl.php\',500,400,true);
================*/
	
function openpopup(popurl, w, h, sizable) {
	str = 'width='+w+',height='+h;
	if ( sizable != true ) {
		str = str + ',scrollbars=no,resizable=no,status=no';
	} else {
		str = str + ',scrollbars=yes,resizable=yes,status=yes';
	}
	window.open(popurl,'',str);
}
/*====================
#	browser detection function
#	http://www.quirksmode.org/js/detect.html
#
#=====================*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();



/*=================================
#	navHover
#
#==================================*/
navHover = function() {


	var lis = document.getElementById("navmenu-h").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", navHover);


/*=================================
#	navHover
#
#==================================*/
navHoverV = function() {
	var lis = document.getElementById("navmenu-v").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", navHoverV);



/*===================JumpPage=======================*/
	

function switchpage(select) {
// JavaScript function for switching to web page when user
// selects option from the given list box.
// Copyright Kelly Yancey, 1997, 1998.
  var index;

  for(index=0; index<select.options.length; index++)
    if(select.options[index].selected)
      {
        if(select.options[index].value!="")
          window.location.href=select.options[index].value;
        break;
      }
}

/*=========================
#	function searchValid()
#	makes sure that search terms are valid before submiting them...
#	======================*/

function searchValid(term){

	if(term=="search"){
	alert(errors[26]);//no first name
	return false;
	
	}else
	
	if((term=="")||(term==null)){
	alert(errors[27]);//no first name
	return false;
	
	}else
	
	if(!isSearch(term)){
	alert(errors[28]+term);//non-alpha
	return false;
	
	}else{
	document.search.submit();
	return true;
	}
	

}

/*Clears content of the search box on click so that 'search' or whatever dummy term is inserted into the search box
is cleared before the user hits 'go';
*/

function clearSearch(box){
	//alert(box);
	box.value="";

}



/*=========================
#	radioOn()
#	enclose a radio button with a label and this clicks it on or off based on the area.
#	Usage: <label for="format" onclick="radioOn(getElementById('rad1'));">
#	<input type="radio" id="rad1" name="format" value="T" <?php echo $type_text;?>>&nbsp;Text</label>
#
=========================*/

function radioOn(el){
	el.checked=el.cheked ? false:true;
	return true;

}

function killAndLoad(){
	deletecookie('CEPf');
	
	window.location.reload();

}

function deletecookie(name) {
//alert ('cookie is '+name);
		var expdate = new Date();
		expdate.setTime(expdate.getTime() - 1);
		document.cookie = name += "=; expires=" + expdate.toGMTString();
		
		document.cookie =
                'CEPf=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
                
            //    setTimeout('doReload()',1000);
}



//closes a pop-up and refreshes the parent

function closeNfresh(){
	window.opener.location.reload();
	window.close();

}
//highlights a div...call with onMouseover
function highlight(div_in){	
	var thearea=document.getElementById(div_in);
	thearea.style.backgroundColor='#FFFFCC';
}
function clearHighlight(div_in){
	var thearea=document.getElementById(div_in);
	thearea.style.backgroundColor='';
}

/*Use this for checkboxes--lets you check all (or none) of the fields in a form. 
Usage:
<input type="checkbox" name="list" value="4">HTML<br>
<input type="checkbox" name="list" value="5">SQL<br>
<input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> */

function checkAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function updateTime(itemid){

		
		var theitem;
		var mselect;
		var dselect;
		var yselect;
		
		var hselect;
		var minselect;
		var apselect;
		
		if(!itemid){
			theitem=document.Form1;
			mselect=theitem.month;
			dselect=theitem.day;
			yselect=theitem.year;
			hselect=theitem.hour;
			minselect=theitem.minute;
			apselect=theitem.ampm;
			
			mselect=theitem.month;
			dselect=theitem.day;
			yselect=theitem.year;
		
			hselect=theitem.hour;
			minselect=theitem.minute;
			apselect=theitem.ampm;
			
			}else{
			
			var amonth='month'+itemid;
			var aday='day'+itemid;
			var ayear='year'+itemid;
			var ahour='hour'+itemid;
			var aminute='minute'+itemid;
			var aampm='ampm'+itemid;
			
			var ahselect= 'hour'+itemid;
			var aminselect= 'minute'+itemid;
			var aapselect= 'ampm'+itemid;
			
			
			

			mselect=$(amonth);
			dselect=$(aday);
			yselect=$(ayear);
			hselect=$(ahour);
			minselect=$(aminute);
			apselect=$(aampm);
			
			
			}
		
		var now = new Date();
		var thehour = now.getHours();
		var theminute= now.getMinutes();
		var theyear = now.getFullYear();
		var themonth = now.getMonth();
			themonth=themonth+1;
		var theday= now.getDate();
		

		for (var i = 0; i < mselect.length; i++){
		
				if(mselect.options[i].value==themonth){
					
					mselect.options[i].selected=true;
					}else{
					mselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < dselect.length; i++){
		
				if(dselect.options[i].value==theday){
					dselect.options[i].selected=true;
					}else{
					dselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < yselect.length; i++){
		
				if(yselect.options[i].value==theyear){
					yselect.options[i].selected=true;
					}else{
					yselect.options[i].selected=false;
					}

		}
		
		
		
/* time select stuff */


var ap = "AM";
if (thehour   > 11) { ap = "PM";        }
if (thehour   > 12) { thehour = thehour - 12; }
if (thehour   == 0) { thehour = 12;        }
		
		
		
		for (i = 0; i < hselect.length; i++){
		
				if(hselect.options[i].value==thehour){
					hselect.options[i].selected=true;
					}else{
					hselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < minselect.length; i++){
		
				if(minselect.options[i].value==theminute){
					minselect.options[i].selected=true;
					}else{
					minselect.options[i].selected=false;
					}

		}
		
		for (i = 0; i < apselect.length; i++){
		
				if(apselect.options[i].value==ap){
					apselect.options[i].selected=true;
					}else{
					apselect.options[i].selected=false;
					}

		}
		
		
}


//function writeEmail(theText,thePrefix,theSuffix){
	function writeEmail(thePrefix){
		var theSuffix='economicprogress.org';
	var address = thePrefix + "@" + theSuffix;
	document.write('<a href="mai');
	document.write('lto:' + address + '">');//+thePrefix);//+'</a>');

}

