// DETERMINE BROWSER AND PLATFORM

// set the browser type
// all boolean
// 	isNS
//	isIE
//	isMac
//	isIE5
// 	isIE4
//  isIE6
//	isNS4
// 	isNS6
//  isDOM : whether you can use W3C DOM (ie5/6 and NS 6)
var appName = navigator.appName;
var appVersion = navigator.appVersion;
var appCodeName = navigator.appCodeName;
var userAgent = navigator.userAgent;
var isMac = appVersion.indexOf('Macintosh');
isMac = (isMac > -1) ? true : false;
var isIE5 = appVersion.indexOf('MSIE 5');
isIE5 = (isIE5 > -1) ? true : false;
var isIE6 = appVersion.indexOf('MSIE 6');
isIE6 = (isIE6 > -1) ? true : false;
var isIE4 = appVersion.indexOf('MSIE 4');
isIE4 = (isIE4 > -1) ? true : false;
var isIE = appVersion.indexOf('MSIE');
var isIE = (isIE > -1) ? true : false;
var nsIndex = appName.indexOf('Netscape');
var isNS = (nsIndex > -1) ? true : false;
var isNS4 = appVersion.indexOf('4');
isNS4 = ((isNS4 > -1) && isNS) ? true : false;
var isNS6 = appVersion.indexOf('5');
isNS6 = ((isNS6 > -1) && isNS) ? true : false;
var isDOM = ((isNS6 || isIE5)|| isIE6) ? true : false;





// SELECTBOX LIST OPTION MANIPULATION FUNCTIONS

// removes all options in a list
//
// listoptions:  the object reference to the list to be cleared
function clearList(listoptions){
	if (listoptions.length >0){
	 for (x=listoptions.length; x >= 0; x--){
	 	if(isIE){
		 	listoptions.options.remove(x);
		}
		else{
			listoptions.options[x] = null;
		}
	 }
	}
}


function addoption(olist,txt,val,def,sel){
	olist.options[olist.length] = new Option(txt,val,def,sel)
}

function createListDays(lst,month, year, defdate){
	var numDays = getDays(year, month);
	clearList(lst);
	for (x=1; x <= numDays; x++){
	 if (typeof defdate != "undefined"){
	 	if(x == defdate){
			addoption(lst,x,x,true,true);
		}
		else{
			addoption(lst,x,x,false,false);
		}
	 }
	 else{
		if(x == 1){
			addoption(lst,x,x,true,true);
		}
		else{
			addoption(lst,x,x,false,false);
		}
	 }
	}
	if(isNS){
		lst.selectedIndex = 0;
	}
}



//	MISC. FUNCTIONS (DATE,TIME,STATES)

// returns true if the year is a leap year
// returns false otherwise
function isLeapYear(year){
	if(year % 4 == 0){
		return true;
	}
	else{
		return false;
	}
}

var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

// returns the number of days in a given month and year
function getDays(year, month){
	var days;
	if (isLeapYear(year)){
		days = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	}
	else{
	    days = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	}
	return (days[month-1]);
}


	
var statesLong = new Array("Alabama","Alaska","Arizona","Arkansas","California",
"Colorado","Connecticut","Delaware","Florida","Georgia"," Hawaii","Idaho","Illinois",
"Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland"," Massachusetts",
"Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire",
"New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon",
"Pennsylvania","Rhode Island","South Carolina"," South Dakota","Tennessee","Texas","Utah","Vermont",
"Virginia","Washington","West Virginia","Wisconsin","Wyoming");

var statesShort = new Array("AL","AK","AZ","AR","CA","CO","CN","DE","FL","GA","HI","ID","IL","IN","IO",
"KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH",
"OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY");

// print out an options list of all of the states
// Len is required, accepted values are l for long, s for short, and m for mixed which will
// print  the long name for what is shown but the short name for the value passed
// if state is defined (must be defined by the states abbreviation IN CAPS) that state will be set as the default selected state
function stateOptions(len,state){
	var disp;
	var val;
	var def = -1;
	switch(len){
		case "l":
			disp=statesLong;
			val=statesLong;
			break;
		case "s":
			disp = statesShort;
			val = statesShort;
			break;
		case "m":
			disp = statesLong;
			val = statesShort;
			break;
		default:
			alert("invalid argument in stateOptions()");
			return;
	}
	if(typeof state != "undefined"){
		for (x=0; x<50; x++){
			if(state == statesShort[x]){
				def = x;
			}
		}
	}			
	for (x=0; x<50; x++){
		if (def == x){
			document.write('<option value=\"'+val[x]+'\" defaultselected selected>'+disp[x]+'</option>\n');
		}
		else{
			document.write('<option value=\"'+val[x]+'\">'+disp[x]+'</option>\n');
		}
	}
}



	
// returns the string value of a specific cookie name
function getCookie(cookieName){
	var c = document.cookie;
	var ic = c.split(';');
	for (var x=0; x<ic.length; x++){
		if(ic[x].indexOf(cookieName+'=') > -1){
			return unescape(ic[x].substr(ic[x].indexOf(cookieName+'=')+cookieName.length+1));
		}
	}
	return false;
}

 function isNumeric(str){
	var numeric = "0123456789";
	for(x=0;x<str.length;x++){
		if(numeric.indexOf(str.charAt(x)) == -1){
			return false;
		}
	}
	return true;
 }
 
 function isAlphaNumeric(str){
 	var lowAlpha = "abcdefghijklmnopqrstuvwxyz";
	var upAlpha = lowAlpha.toUpperCase();
	var numeric = "0123456789";
	for(x=0;x<str.length;x++){
		if(lowAlpha.indexOf(str.charAt(x)) == -1){
			if(upAlpha.indexOf(str.charAt(x)) == -1){
				if(numeric.indexOf(str.charAt(x)) == -1){
					return false;
				}
			}
		}
	}
	return true;
}

function popPhotos(){
		var w=window.open('/photos/','photos','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes, resizable=yes');
		return false;
}

function popPhotosAdmin(){
		var w=window.open('/photos/admin/','photos','location=no,menubar=no,toolbar=no,status=yes,scrollbars=yes, resizable=yes');
		return false;
	}
