function getAddUser(bool,id){
	if(bool){
		location.href="admin.php?action=adduser&id="+id
	}
}

function getEditUser(bool,id){
	if(bool){
		location.href="admin.php?action=edituser&id="+id
	}
}

function getDeleteUser(id){
        delconfirm = confirm("Do you really want to delete this user?")
        if(delconfirm){location.href="admin.php?action=deleteuser&delid="+id}
}



function getEditDoc(bool,id){
	if(bool){
		location.href="post.php?action=editdoc&iid="+id
	}
}

function getDupeDoc(id){
		location.href="post.php?action=dupedoc&iid="+id
}

function getConfirmDoc(bool,id){
		location.href="post.php?action=confirmdoc&isconfirmed="+bool+"&cid="+id
}

function getIsOpenDoc(bool,id){
		location.href="post.php?action=isopendoc&isopen="+bool+"&cid="+id
}
function getPublishDoc(bool,id){
		location.href="post.php?action=publishdoc&ispublished="+bool+"&pid="+id
}

function getDeleteDoc(id){
		delconfirm = confirm("Are you sure you want to delete this event?")
		if(delconfirm){location.href="post.php?action=deletedoc&did="+id}
}

function getEditSection(bool,id){
	if(bool){
		location.href="admin.php?action=editsection&id="+id
	}
}

function getDeleteSection(id){
		delconfirm = confirm("Are you sure you want to delete this section?")
		if(delconfirm){location.href="admin.php?action=deletesection&id="+id}
}

function getEditLocation(bool,id){
	if(bool){
		location.href="admin.php?action=editlocation&id="+id
	}
}

function getEditEventType(bool,id){
    if(bool){
        location.href="admin.php?action=editeventtype&id="+id
    }
}

function getDeleteLocation(id){
		delconfirm = confirm("Are you sure you want to delete this venue?")
		if(delconfirm){location.href="admin.php?action=deletelocation&id="+id}
}

function getDeleteEventType(id){
        delconfirm = confirm("Are you sure you want to delete this event type?")
        if(delconfirm){location.href="admin.php?action=deleteeventtype&id="+id}
}

function checkCardType(el){
//	alert(el)
	if(el == 4){
		document.getElementById("userIDno").style.display='inline'
	}
}

function checkform(frm){

	err = 0;
	pw = document.getElementById("pw").value
	pw2 = document.getElementById("pw2").value
	frmaction = document.getElementById("formaction").value

	if(frmaction == "adduser" || frmaction == ""){
		err +=(document.getElementById("fname").value=="")?1:0;
		err +=(document.getElementById("lname").value=="")?1:0;
		err +=(document.getElementById("address").value=="")?1:0;
		err +=(document.getElementById("city").value=="")?1:0;
		err +=(document.getElementById("email").value=="")?1:0;
		//err +=(document.getElementById("country").selectedIndex==0)?1:0;
		err +=(document.getElementById("pw").value=="")?1:0;
		err +=(document.getElementById("pw2").value=="")?1:0;
		err += (!validEmail(document.getElementById("email").value))?1:0;
		err += ((pw=="" && pw2!="") || (pw!="" && pw2==""))?1:0;

		if(pw!="" && pw2!=""){
				if(pw!=pw2){
					document.getElementById("formerror").innerHTML = "<span class=errtext>Your passwords do not match</span>"
					err++;
					}
		}
		else if(!validEmail(document.getElementById("email").value)){
			document.getElementById("formerror").innerHTML = "<span class=errtext>Please enter a valid email address</span>"
			return false
		}
		else if(err>0){
			document.getElementById("formerror").innerHTML = "<span class=errtext>Please fill in all of the fields marked with a star</span>"
			return false
		}
	}
	if(frmaction == "edituser"){
		err = comparePassword(pw,pw2)
	}
	if(err){
		//alert(err)
		return false
	}
//	alert(err)
}

function comparePassword(pw,pw2,req){

if((pw=="" && pw2!="") || (pw!="" && pw2=="") ||(req && (pw=="" && pw2==""))){
	document.getElementById("formerror").innerHTML = "<span class=errtext>Please leave both password fields blank,<br />or fill in both fields with your new password</span>"
	if(req){
	document.getElementById("formerror").innerHTML = "<span class=errtext>You are required to enter a password</span>"
	}
	return 1
}
else if(pw!="" && pw2!=""){
		if(pw!=pw2){
			document.getElementById("formerror").innerHTML = "<span class=errtext>Your passwords do not match</span>"
			return 1
		}else{
			return 0
		}
	}
}

function validEmail(src) {
   var emailReg = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$";
   var regex = new RegExp(emailReg);
   return regex.test(src);
}

function totalBid(bids,currsym,val){
	document.getElementById("totalbid").innerHTML = "Total bid: "+currsym + bids*val
}

function checkNumBids(bidamt){
	if(bidamt<1){
		document.getElementById("errstr").innerHTML = "<span class=errtext>No bid placed</span>"
		return false
	}
}

function changeVenue(num){
for(v=0;v<document.getElementById("venueID").options.length;v++){
	if(document.getElementById("venueID").options[v].value == num){
		document.getElementById("venueID").options[v].selected=1
	}
}
}

function changeEventType(num){

for(v=0;v<document.getElementById("eventtypeID").options.length;v++){
	if(document.getElementById("eventtypeID").options[v].value == num){
		document.getElementById("eventtypeID").options[v].selected=1
	}
}
}


function getVenueOptions(el){

cal = el[el.selectedIndex].text
document.getElementById("venueID").options.length = 0
myArray = [];
calendar = '';
rx = /\((\w+)\)/g;
myArray = cal.match(rx);

if(myArray){
	calendar = myArray[0];
}

	for(v=0;v<venueAr.length;v++){
		venue = venueAr[v].split("|")
		venstr = "("+venue[0]+")"
		if(calendar == venstr){
			document.getElementById("venueID").disabled=0
		if(document.getElementById("venueID").options.length==0){
		document.getElementById("venueID").options[document.getElementById("venueID").options.length] = new Option("Choose a venue","")
	}

			document.getElementById("venueID").options[document.getElementById("venueID").options.length] = new Option(venue[2],venue[1])
		}
	}
		if(document.getElementById("venueID").options.length == 0){
			document.getElementById("venueID").options[document.getElementById("venueID").options.length] = new Option("This calendar has no venues","")
			document.getElementById("venueID").disabled=1
		}
myArray=null
}

function getEventTypeOptions(el){

etID = el.value

document.getElementById("eventtypeID").options.length = 0 // resets options

	for(v=0;v<eventtypeAr.length;v++){ //iterate through the entire event type JS array
		eventTypeA = eventtypeAr[v].split("~"); //this is the array of event type info
		eventTypeCals = eventTypeA[0].split("|"); //these are the calendars

		for(x=0;x<eventTypeCals.length;x++){

			if(eventTypeCals[x]==etID){
				document.getElementById("eventtypeID").disabled=0
				if(document.getElementById("eventtypeID").options.length==0){
					document.getElementById("eventtypeID").options[document.getElementById("eventtypeID").options.length] = new Option("Choose an event type","")
				}
				document.getElementById("eventtypeID").options[document.getElementById("eventtypeID").options.length] = new Option(eventTypeA[2],eventTypeA[1])
			}
		}
	}

		if(document.getElementById("eventtypeID").options.length == 0){
			document.getElementById("eventtypeID").options[document.getElementById("eventtypeID").options.length] = new Option("This calendar has no event types associated with it","")
			document.getElementById("eventtypeID").disabled=1
		}
}
function setStateOptions(stID){

document.getElementById("state").options.length = 0 // resets options

	for(v=0;v<stateAr.length;v++){ //iterate through the entire event type JS array
		stateA = stateAr[v].split("~"); //this is the array of event type info
		statename = stateA[0]
		statecode = stateA[1]
		countrycode = stateA[2]

			if(countrycode==stID){
				document.getElementById("state").disabled=0
				if(document.getElementById("state").options.length==0){
					document.getElementById("state").options[document.getElementById("state").options.length] = new Option("Choose a state/region","")
				}
				document.getElementById("state").options[document.getElementById("state").options.length] = new Option(statename+" - ("+statecode+")",statecode)
				//
			}

	}

		if(document.getElementById("state").options.length == 0){
			document.getElementById("state").options[document.getElementById("state").options.length] = new Option("State/Province not required","")
			document.getElementById("state").disabled=1
		}
}




function checkeventform(frm){

	err = 0;
	frmaction = document.getElementById("formaction").value

	if(frmaction == "newdoc" || frmaction == ""){
		err +=(document.getElementById("userID").value=="")?1:0;
		err +=(document.getElementById("calendarID").value=="")?1:0;
		err +=(document.getElementById("venueID").value=="")?1:0;
		err +=(document.getElementById("eventdate").value=="")?1:0;
		err +=(document.getElementById("starttime").selectedIndex==0)?1:0;
		err +=(document.getElementById("endtime").selectedIndex==0)?1:0;
		err +=(document.getElementById("title").value=="")?1:0;
		err +=(document.getElementById("intro").value=="")?1:0;
		err +=(document.getElementById("description").value=="")?1:0;

		if(err>0){
			document.getElementById("formerror").innerHTML = "<span class=errtext>Please fill in the entire form</span>"
			scrollTo(0,0)
			return false
		}
	}
}

function searchFocus(el){
	if(el.value=='enter search term'){
	el.value=''
	el.style.color='#000000';
	}
}

function toggleChecks(bool,whichID){
	for(e=0;e<document.getElementById("mailerform").elements.length;e++){
		if(whichID ==document.getElementById("mailerform").elements[e].id){
			if(bool){
				document.getElementById("mailerform").elements[e].checked=true;
			}else{
				document.getElementById("mailerform").elements[e].checked=false;
			}
		}
	}
}

function checkEmailToList(whichID){
	count = 0;
	for(e=0;e<document.getElementById("mailerform").elements.length;e++){
		if(whichID ==document.getElementById("mailerform").elements[e].id){
			if(document.getElementById("mailerform").elements[e].checked){
				count++;
			}
		}
	}
	if(count>0){
	document.getElementById("mailerform").submit()
	}else{
		document.getElementById("formerror").innerHTML = "<span class=errtext>Please select at least one attendee</span>"
	}
}

function showPrivateData(bool){

	if(bool){
        if(document.getElementById("starttime").options[document.getElementById("starttime").selectedIndex].value.indexOf(":")!=-1 && document.getElementById("endtime").options[document.getElementById("endtime").selectedIndex].value.indexOf(":")!=-1 && document.getElementById("eventdate").value!=""){

        document.getElementById("regreq").options.selectedIndex=0;
		document.getElementById("apptmenu").style.display='inline';
		}else{
			alert("Please select a start time, and end time, and an event date");
            document.getElementById("isprivate").checked=false;

		}
	}else{
        document.getElementById("apptmenu").style.display='none';
        document.getElementById("regreq").disabled=false;
	}
}

function showTransportationDepartures(bool){

	if(bool){
		document.getElementById("departuremenudiv").style.display='inline';
	}else{
        document.getElementById("departuremenudiv").style.display='none';
	}
}

function showPrivateSchedule(){

		stime=document.getElementById("starttime").options[document.getElementById("starttime").selectedIndex].value
		etime=document.getElementById("endtime").options[document.getElementById("endtime").selectedIndex].value
		pvtappt=document.getElementById("pvtappt").options[document.getElementById("pvtappt").selectedIndex].value
		eventdate = document.getElementById("eventdate").value

		url="timecalc.php?"+"stime="+stime+"&etime="+etime+"&eventdate="+eventdate+"&pvtappt="+pvtappt

window.scrollTo(0,0);
document.getElementById("confirmscreen").style.visibility="visible"
document.getElementById("ieiframe").style.visibility="visible"
document.getElementById("confirmform").style.visibility="visible"

document.getElementById("confirmscreen").style.width=screen.width

halfscreen=(screen.width)/2

formwidth=document.getElementById("confirmform").offsetWidth/2
document.getElementById("confirmform").style.left=halfscreen-formwidth

schedhtml = ajaxpage(url, 'confirmform');
document.getElementById("confirmform").innerHTML = schedhtml;
document.getElementById("confirmform").innerHTML += "<br><br><a href='javascript:unconfirm()'>close schedule</a>";



}

function unconfirm(){
document.getElementById("confirmscreen").style.visibility="hidden"
document.getElementById("ieiframe").style.visibility="hidden"
document.getElementById("confirmform").style.visibility="hidden"
}

function getDeleteRegisteredUser(id,eventid){
        delconfirm = confirm("Do you really want to unregister this user?")
        if(delconfirm){location.href="attending.php?action=deleteuser&delid="+id+"&eventid="+eventid}
}

function setEndtime(el){
document.getElementById("endtime").selectedIndex  = el.selectedIndex+8
}

function addExtraFields(){
	//jquery lib function
	$("#exfields").append('Type: <select name="extype[]" ><option value=text>text<option value=checkbox>checkbox<option value=menu>menu<option value=upload>upload</select>Label: <input name="exname[]" value=""> Default Value: <input name="exval[]" value="">');
}
