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 getReminderDoc(bool,id){
		location.href="post.php?action=reminderdoc&isreminder="+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 getEditDepartment(bool,id){
	if(bool){
		location.href="admin.php?action=editdepartment&did="+id
	}
}

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

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

function getDeleteCourse(id){
        delconfirm = confirm("Are you sure you want to delete this course?")
        if(delconfirm){location.href="admin.php?action=deletecourse&cid="+id}
}

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

function getDeleteSemester(id){
		delconfirm = confirm("Are you sure you want to delete this semester?")
		if(delconfirm){location.href="admin.php?action=deletesemester&sid="+id}
}

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

function getDupePage(id){
		location.href="admin.php?action=dupepage&pid="+id
}

function getDeletePage(id){
		delconfirm = confirm("Are you sure you want to delete this page?")
		if(delconfirm){location.href="admin.php?action=deletepage&pid="+id}
}

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

function getDupeCoupon(id){
		location.href="admin.php?action=dupecoupon&cid="+id
}

function getDeleteCoupon(id){
		delconfirm = confirm("Are you sure you want to delete this coupon?")
		if(delconfirm){location.href="admin.php?action=deletecoupon&cid="+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("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("departmentID").options.length;v++){
	if(document.getElementById("departmentID").options[v].value == num){
		document.getElementById("departmentID").options[v].selected=1
	}
}
}

function changeCourse(num){

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


function getDepartmentOptions(el){

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

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

	for(v=0;v<departmentAr.length;v++){
		department = departmentAr[v].split("|")
		deptstr = "("+department[0]+")"
		if(calendar == deptstr){
			document.getElementById("departmentID").disabled=0
		if(document.getElementById("departmentID").options.length==0){
		document.getElementById("departmentID").options[document.getElementById("departmentID").options.length] = new Option("Choose a department","")
	}

			document.getElementById("departmentID").options[document.getElementById("departmentID").options.length] = new Option(department[2],department[1])
		}
	}
		if(document.getElementById("departmentID").options.length == 0){
			document.getElementById("departmentID").options[document.getElementById("departmentID").options.length] = new Option("This college has no departments","")
			document.getElementById("departmentID").disabled=1
		}
myArray=null
}

function getCourseOptions(el){

etID = el.value

document.getElementById("courseID").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("courseID").disabled=0
				if(document.getElementById("courseID").options.length==0){
					document.getElementById("courseID").options[document.getElementById("courseID").options.length] = new Option("Choose a course","")
				}
				document.getElementById("courseID").options[document.getElementById("courseID").options.length] = new Option(eventTypeA[2],eventTypeA[1])
			}
		}
	}

		if(document.getElementById("courseID").options.length == 0){
			document.getElementById("courseID").options[document.getElementById("courseID").options.length] = new Option("This college has no courses associated with it","")
			document.getElementById("courseID").disabled=1
		}
}
function setStateOptions(countryid,stateid){

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==countryid){
				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","")
				}
				selected = (stateid == statecode)?true:false;
				document.getElementById("state").options[document.getElementById("state").options.length] = new Option(statename+" - ("+statecode+")",statecode,selected)
				//
			}

	}

		if(document.getElementById("state").options.length == 0){
			document.getElementById("state").options[document.getElementById("state").options.length] = new Option("There are no states available","")
			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("collegeID").value=="")?1:0;
		err +=(document.getElementById("departmentID").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 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,courseid){
        delconfirm = confirm("Do you really want to unenroll this user?")
        if(delconfirm){location.href="attending.php?action=deleteuser&delid="+id+"&courseid="+courseid}
}

function setEndtime(el){

	if(el.selectedIndex+4 >=document.getElementById("endtime").length){
		endtime = el.selectedIndex - document.getElementById("endtime").length +5
	}else{
		endtime  = el.selectedIndex+4
	}
	document.getElementById("endtime").selectedIndex = endtime
}

function addExtraFields(){
	//jquery lib function
	$("#exfields").append('Name: <input type=text name="coursematerialname[]" > File: <input type=file name="coursematerialfile[]" ><br clear=all>');
}

function addArchiveFiles(){
	//jquery lib function
	$("#arexfields").append('URL: <input type=text name="coursearchiveurl[]" > Full Access? <input type=checkbox name=archivefull[] value="1"><br clear=all>');
}

function jquery_showmore(arrowlink,id){
	$("#"+id).slideDown("slow");
	$("#"+arrowlink).replaceWith("<a href='javascript:void(0)' id='"+arrowlink+"' onclick='jquery_showless(\""+arrowlink+"\",\""+id+"\")'><img src='images/arrow_profile_down.png' border=0 align=texttop style='padding-right:3px;'></a>")
}
function jquery_showless(arrowlink,id){
	$("#"+id).slideUp("slow");
	$("#"+arrowlink).replaceWith("<a href='javascript:void(0)' id='"+arrowlink+"' onclick='jquery_showmore(\""+arrowlink+"\",\""+id+"\")'><img src='images/arrow_profile_right.png' border=0 align=texttop style='padding-right:3px;'></a>")
}