function openWin(w,h,URL,opt) { 
	var scrollers
	if (opt == "scroll"){
		scrollers = "scrollbars=yes"
	} else {
		scrollers = "scrollbars=no"
	}
	var xCoord = 327; // distance from left
	var yCoord = 275; // distance from top
	if(navigator.appName != "Netscape"){
		w = parseInt(w) + 15
		h = parseInt(h) + 15
    newWin=window.open(URL,"HandBags","left=" + xCoord + ",top=" + yCoord + ",resizable=no," + scrollers + ",width=" + w + ",height=" + h)	
	} else {
		newWin=window.open(URL,"HandBags","screenX=" + xCoord + ",screenY=" + yCoord + ",resizable=no," + scrollers + ",width=" + w + ",height=" + h)
	}
}

function changeValue(form,myText){
	if(myText.indexOf("Alert") != -1){
		myAction01 = "delete_alert"
		myAction02 = "view_redirect"
		myLabel01  = "Delete "		
		myLabel02  = "Save "
	}
	if(myText.indexOf("Account") != -1){
		myAction01 = "delete_user"
		myAction02 = "update_user"		
		myLabel01  = "Delete "		
		myLabel02  = "Update "		
	}
	if(form.myDelete.checked == true) {
		form.AccountSubmit.value = myLabel01 + myText
		form.action.value = myAction01
	} else {
		form.AccountSubmit.value = myLabel02 + myText
		form.action.value = myAction02
	}
}

function checkSnowForm(form){
	var warn = ""
	for( i = 0; i < form.elements.length; i++ ) {
		if (( form.elements[i].type == "text" && form.elements[i].value == "" ) || ( form.elements[i].type == "password" && form.elements[i].value == "" )){
			warn = warn + form.elements[i].name + "\n"
		}
		if (( form.elements[i].type == "select" && form.elements[i].name == "city")){
			myCheck = true
		} else {
			myCheck = false
		}
	}

	illegalWarn = "";
	illegalChars = /[^a-zA-Z0-9_\-\@\.]/;
	for(i=0;i<form.elements.length;i++){
		if((form.elements[i].type == "text")||(form.elements[i].type == "password")){
			if (illegalChars.test(form.elements[i].value)){
				illegalWarn += form.elements[i].name + "\n";
			}
		}
	} 
	if(illegalWarn != ""){
		alert("You appear to have some illegal characters in your \n" + illegalWarn + "\n Illegal characters include: , & space * / \ ^ % # ! ( )")
		return
	}
	
//	alert(myCheck)
	if(myCheck == true){
		if(form.city.options[form.city.selectedIndex].value == "") {
			warn = warn + "City\n"
		}
	}

	if( warn != ""){
		alert("Please enter a value for:\n" + warn)
		return
	} else {
		//alert("form would be submitted from checkSnowForm")
		checkEmail(form,'email')
		//form.submit()
	}
}



function checkForm(form){
	warn = ""
	if (form.city.options[form.city.selectedIndex].value == ""){
		warn = warn + "city\n"
	}
	if (form.condition.options[form.condition.selectedIndex].value == ""){
		warn = warn + "condition\n"
	}
	if (warn != ""){
		alert("Please select a choice for: \n" + warn)
		return
	} else {
//		alert("form would be submitted from checkForm")
		goConfirm(form,'add',null)
	}
}

function checkFormOut(form){
	message = ""
	warn = ""
	if (form.city.options[form.city.selectedIndex].value == ""){
		warn = warn + "city\n"
	}
	if (form.condition.options[form.condition.selectedIndex].value == ""){
		warn = warn + "condition\n"
	}
	if (form.comments.value == ""){
		warn = warn + "comments\n"
	}
	if (warn != ""){
		alert("Please select a choice for: \n" + warn)
		return
	} else {
/*
		alert("form would be submitted from checkFormOut")
		for(i=0;i<form.elements.length;i++){
			message = message + form.elements[i].name + "=" + form.elements[i].value + "\n"
		}
		alert (message)
*/
		form.submit()		
	}
}

function goConfirm(form,action,arg){
	if (action == "remove"){
		//alert("action = " + action + "\n" + "arg = " + arg )
		// arg is either city or condition - is this realy necessary??
		// confirm they want to remove what they have asked to remove
		form.submit()
	}else if (action == "add"){
		alert("action = " + action + "\n" + "arg = " + arg )
		// arg is either city or condition - is this realy necessary??
		// confirm they want to remove what they have asked to remove
		//form.submit()
	}
}



function formSize(form){
// The form needs to be named "form" ie <form name="form" .....
	for( i = 0; i < document.form.elements.length; i++ ) {
		if ( document.form.elements[i].type == "text" || document.form.elements[i].type == "password" ){
			if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) < "6"){
				document.form.elements[i].size = "15"
			} else {
				document.form.elements[i].size = "30"
			}
		}
	}
}

function dateGet(form,myear,mmonth,mday) {
	yrData = eval("document.myDate." + myear + ".options[document.myDate." + myear + ".selectedIndex].value");
	data = eval("document.myDate." + mmonth + ".options[document.myDate." + mmonth + ".selectedIndex].value");
	form.mday = eval("form." + mday)
	if ((data == "04")||(data == "06")||(data == "09")||(data == "11")) {
	form.mday.length=0
		for (i=0;i<30;i++){
			x = i + 1 
			if(x<10){ x = "0" + x }
			form.mday.options[i] = new Option("  " + x + "  ",x)
		}
	}
	
	if ((data != "04")&&(data != "06")&&(data != "09")&&(data != "11")&&(data != "02")) {
	form.mday.length=0
		for (i=0;i<31;i++){
			x = i + 1 
			if(x<10){ x = "0" + x }
			form.mday.options[i] = new Option("  " + x + "  ",x)
		}
	}
	
	if (data == "02"){
		if ((yrData == "2004")||(yrData == "2008")){
			form.mday.length=0
			for (i=0;i<29;i++){
				x = i + 1 
				if(x<10){ x = "0" + x }
				form.mday.options[i] = new Option("  " + x + "  ",x)
			}
		}	else{
			form.mday.length=0
			for (i=0;i<28;i++){
				x = i + 1 
				if(x<10){ x = "0" + x }
				form.mday.options[i] = new Option("  " + x + "  ",x)
			}
		}
	}
	form.checkOut.value = 1
}

function makeDate(form,elem){
	makeYear  = eval("document.myDate.year" + elem + ".options[document.myDate.year" + elem  + ".selectedIndex].value");
	makeMonth = eval("document.myDate.month" + elem + ".options[document.myDate.month" + elem + ".selectedIndex].value");
	makeDay   = eval("document.myDate.day" + elem   + ".options[document.myDate.day" + elem   + ".selectedIndex].value");
	elemLow = elem.toLowerCase()
	tempDate = eval("document.myDate." + elemLow + "Date.value")
	tempDate = makeMonth + makeDay + makeYear
	document.myDate.checkOut.value = 1
}

function checkDate(form){
	warn = ""
	/*if (form.yearExpires.options[form.yearExpires.selectedIndex].value == ""){
		form.checkOut.value = 0
		warn = warn + "Expires Year\n"
	}
	if (form.monthExpires.options[form.monthExpires.selectedIndex].value == ""){
		form.checkOut.value = 0
		warn = warn + "Expires Month\n"
	}
	if (form.dayExpires.options[form.dayExpires.selectedIndex].value == ""){
		form.checkOut.value = 0
		warn = warn + "Expires Day\n"
	}*/
	form.expiresDate.value = form.monthExpires.options[form.monthExpires.selectedIndex].value + form.dayExpires.options[form.dayExpires.selectedIndex].value + form.yearExpires.options[form.yearExpires.selectedIndex].value

	if (form.yearIssue.options[form.yearIssue.selectedIndex].value == ""){
		form.checkOut.value = 0
		warn = warn + "Issue Year\n"
	}
	if (form.monthIssue.options[form.monthIssue.selectedIndex].value == ""){
		form.checkOut.value = 0
		warn = warn + "Issue Month\n"
	}
	if (form.dayIssue.options[form.dayIssue.selectedIndex].value == ""){
		form.checkOut.value = 0
		warn = warn + "Issue Day\n"
	}
	form.issueDate.value = form.monthIssue.options[form.monthIssue.selectedIndex].value + form.dayIssue.options[form.dayIssue.selectedIndex].value + form.yearIssue.options[form.yearIssue.selectedIndex].value
	if (warn != ""){
		alert("Please Select a:\n" + warn)
		return
	} else {
		makeDate(form,'Issue')
		makeDate(form,'Expires')
	}
	checkFormOut(form)
}

function checkEmail(form,temp){
//you must pass both the name of the element you want checked (as a string) AND the form object itself.
	for( i = 0; i < form.elements.length; i++ ) {
		if ( form.elements[i].type == "text" && form.elements[i].name == temp ){
			email = form.elements[i].value
			email = email.toLowerCase()
			if( email == "" ) {
				alert( "Please enter your Email Address" )
				form.elements[i].focus()
				return
			} else
			if( form.elements[i].value.indexOf("@") > -1 ){
				if((email.indexOf(".com") > -1)||(email.indexOf(".org") > -1)
		   		||(email.indexOf(".gov") > -1)||(email.indexOf(".net") > -1)
			    ||(email.indexOf(".mil") > -1)||(email.indexOf(".edu") > -1)
	    		||(email.indexOf(".us") > -1)||(email.indexOf(".int") > -1)
			    ||(email.indexOf(".um") > -1)||(email.indexOf(".cc") > -1)    
			    ||(email.indexOf(".tv") > -1)||(email.indexOf(".ws") > -1)
			    ||(email.indexOf(".biz") > -1)||(email.indexOf(".int") > -1)    
			    ||(email.indexOf(".zz") > -1)||(email.indexOf(".ca") > -1)
			    ||(email.indexOf(".de") > -1)||(email.indexOf(".ca") > -1)
					||(email.indexOf(".jp") > -1)||(email.indexOf(".dk") > -1)
					||(email.indexOf(".name") > -1)||(email.indexOf(".info") > -1)){			
				} else {
					alert("That does not appear to be a valid email address")
					return
				}
			} else {
				alert("That does not appear to be a valid email address")
				return
			}
		}
	}

 	
//alert("form would be submitted")
form.submit()
}

function getTodaysDate() {
	form = document.myDate
	now = new Date()
	year = now.getYear()
	month = now.getMonth()
	day = now.getDate()
	month = month + 1
	//alert(year + "\n" + month + "\n" + day)
	for(i=0; i < form.yearIssue.options.length; i++){
		if (form.yearIssue.options[i].value == year){
			form.yearIssue.options[i].selected = true
		}
	}
	for(i=0; i < form.monthIssue.options.length; i++){
		if (form.monthIssue.options[i].value == month){
			form.monthIssue.options[i].selected = true
		}
	}
dateGet(form,'yearIssue','monthIssue','dayIssue')
	for(i=0; i < form.dayIssue.options.length; i++){
		if (form.dayIssue.options[i].value == day){
			form.dayIssue.options[i].selected = true
		}
	}
	
	
	for(i=0; i < form.yearExpires.options.length; i++){
		if (form.yearExpires.options[i].value == year){
			form.yearExpires.options[i].selected = true
		}
	}
	for(i=0; i < form.monthExpires.options.length; i++){
		if (form.monthExpires.options[i].value == month){
			form.monthExpires.options[i].selected = true
		}
	}
dateGet(form,'yearExpires','monthExpires','dayExpires')
	for(i=0; i < form.dayExpires.options.length; i++){
		if (form.dayExpires.options[i].value == day){
			form.dayExpires.options[i].selected = true
		}
	}	

}
