function checkForm(f) {
	var msg = "Please fix these errors:\n";
	var errors = false;
	
	if (f.fname.value == "") {
		msg+="-First name is required\n";
		errors = true;
	}
	if (f.lname.value == "") {
		msg+="-Last name is required\n";
		errors = true;
	}
	if (f.phone.value == "") {
		msg+="-Phone number is required\n";
		errors = true;
	}
	if (f.institution.value == "") {
		msg+="-Institution is required\n";
		errors = true;
	}
	if ( (f.email.value == "") || ( f.email.value.indexOf('@') == -1) ) {
		msg+="-Valid email is required\n";
		errors = true;
	}
	if (errors) {
		window.alert(">>>>>>>"+msg);
		return false;
	}
		
	return true;
}

function emailcheck(emailStr) {

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		//alert("Ths username contains invalid characters.");
		return false;
	   }
	}
	
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
		//alert("Ths domain name contains invalid characters.");
		return false;
	   }
}
}
function changeUser(rsIndex){
    
       var data=rsIndex.options[rsIndex.selectedIndex].value;     
	   var mytool_array=data.split(",");
/*    
       var uphone = document.getElementById("uphone");
	   var uemail = document.getElementById("uemail");
	   var memberid = document.getElementById("memberid");
	  
	   memberid.value = mytool_array[0];
	   if(uphone)
	     uphone.value = mytool_array[1];
	   if(uemail)
	      uemail.value = mytool_array[2];
*/
       var uphone = document.getElementById("uphone");
	   var uemail = document.getElementById("uemail");
	   var memberid = document.getElementById("memberid");
	  
	   	memberid.value = mytool_array[0];
		uphone.innerHTML = mytool_array[1];
	    uemail.innerHTML = mytool_array[2];

 	 	  
}
function changeTab(divId){
		
	var div1 = document.getElementById("hp-home");
	var div2 = document.getElementById("hp-admin");
	
	div1.style.background = "#194040";
	div2.style.background = "#194040";
	//alert(div1);
}//end of function changeTab

function verifyEdit() {
	var msg = "Please fix these errors:\n";
	var errors = false;
	
	if ( (document.register.email.value != "") && ( document.register.email.value.indexOf('@') == -1) ) {
		msg+="-Valid email is required\n";
		errors = true;
	}
	if ( (document.register.password.value != "") && (document.register.password.value.length < 6) ) {
		msg+="-Min 6 character password is required\n";
		errors = true;
	}
	if ( (document.register.password.value != "") && (document.register.password.value != document.register.password2.value) ) {
		msg+=("-Passwords to not match\n");
		errors = true;
	}
	if (errors) {
		window.alert(msg);
		return false;
	}
		
	return true;
}

function checkBrowser() {
	if ( (navigator.appName.indexOf("Netscape") != -1) && ( parseFloat(navigator.appVersion) <= 4.79 ) ) {
		newWin = window.open("","message","height=200,width=300");
		newWin.document.writeln("<center><b>This system is optimized for Netscape version 6.0 or higher.<br>" +
					"Please visit <a href='http://channels.netscape.com/ns/browsers/download.jsp' target='_blank'>Netscape.com</a> to obtain an update.");
		newWin.document.close();
	}
}

function help(isAdmin) {
		
		if(isAdmin == 1){		 
			window.open("lang/en.help_admin.php#"  ,"","width=500,height=500,scrollbars");    
		}else{
			window.open("lang/en.help_user.php#" ,"","width=500,height=500,scrollbars");    		
		}	
		void(0);    
}      

function reserve(type, machid, start_date, resid, is_blackout, read_only, pending, starttime, endtime) {  
	w = 613;
	h = ( type == 'v' || type == 'n' || type == 'd' || type == 'a' || type == 'c') ? 470 : 580;

	if (is_blackout == 1) {
		h=426;				
	}else
	    is_blackout = 0; 
		
		if (machid == null) { machid = ''; }
		if (start_date == null) { start_date = ''; }
		if (resid == null) { resid = ''; }
		if (read_only == null) { read_only = ''; }
		if (pending == null) { pending = ''; }
		if (starttime == null) { starttime = ''; }
		if (endtime == null) { endtime = ''; }
		
		nurl = "reserve.php?type=" + type + "&machid=" + machid + "&start_date=" + start_date + "&resid=" + resid +  "&is_blackout=" + is_blackout + "&read_only=" + read_only + "&pending=" + pending + "&starttime=" + starttime + "&endtime=" + endtime;    
		var resWindow = window.open(nurl,"reserve","width=" + w + ",height=" + h + ",scrollbars=no,resizable=yes,status=no");     
		resWindow.focus();
		void(0);   
}

function isValid(parm,val) {
  if (parm == "") return false;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function checkDate() {

	var numb = '0123456789';

	var formStr = document.getElementById("jumpWeek");
	var month = document.getElementById("jumpMonth").value;
	var day = document.getElementById("jumpDay").value;
	var year = document.getElementById("jumpYear").value;
	var dayNum = new Array();
	
	if (isValid(month,numb) && isValid(day,numb) && isValid(year,numb) && (year.length == 4)){
			if ( year%4 == 0 ) {
				dayNum = [31,29,31,30,31,30,31,31,30,31,30,31];
			} 
			else {
				dayNum = [31,28,31,30,31,30,31,31,30,31,30,31];
			}
			
			if ( (month > 12) || (day > dayNum[month-1]) ) {
				alert("Please enter valid date value");
				return false;
			}
			
			for (var i=0; i < formStr.childNodes.length-1; i++) {
				if (formStr.childNodes[i].type == "text" || formStr.childNodes[i].type == "textbox" ) {			
					if ( (formStr.childNodes[i].value <= 0) || (formStr.childNodes[i].value.match(/\D+/) != null) ) {
							alert("Please enter valid date value");
							formStr.childNodes[i].focus();
							return false;
					}
				}
			} 
			
			changeScheduler(month, day, year, 0, "");
	 } 
	 else
	 	alert("Please enter valid date value");
}

function verifyTimes(f) {
	if (f.del && f.del.checked) {
		return confirm("Delete this reservation?");
	}
	if (parseFloat(f.starttime.value) < parseFloat(f.endtime.value)) {
		return true;
	}
	else {
		window.alert("End time must be later than start time\nCurrent start time: " + f.starttime.value + " Current end time: " + f.endtime.value);
		return false;
	}
}

function checkAdminForm(f) {
	for (var i=0; i< f.elements.length; i++) {
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].checked == true) )
			return confirm('This will delete all reservations and permission information for the checked items!\nContinue?');
	}
	alert("No boxes have been checked!");	
	return false;
}

function checkBoxes() {
	var f = document.train;
	for (var i=0; i< f.elements.length; i++) {
		if (f.elements[i].type == "checkbox")
			f.elements[i].checked = true;
	}
	void(0);
}

function viewUser(user) {
	window.open("userInfo.php?user="+user,"UserInfo","width=337,height=270,scrollbars=no,resizable=no,status=no");     
		void(0);    
}

function checkAddResource(f) {

	var msg = "";
	var flag=0;		
	minres = (parseInt(f.minH.value) * 60) + parseInt(f.minM.value);
	maxRes = (parseInt(f.maxH.value) * 60) + parseInt(f.maxM.value);	
	
	
	for (var i=0; i< f.elements.length; i++) {
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].checked == true) )
			{
				flag=1;
				break;
			}

	}
	if(flag==0)
		msg+="-Select atleast one function type!\n";	
	if (f.name.value=="")
		msg+="-Resource name is required.\n";
	/*if (f.location.value=="")
		msg+="-Location is required.\n";
		*/
	if (f.notes.value=="")
		msg+="-Notes is required.\n";		
	if (parseInt(minres) > parseInt(maxRes))
		msg+="-Minimum reservation time must be less than or equal to maximum";
	if (msg!="") {
		alert("You have the following errors:\n\n"+msg);
		return false;
	}
	
}


function checkAddSchedule() {
	var f = document.addSchedule;
	var msg = "";
	
	if (f.scheduletitle.value=="")
		msg+="-Schedule title is required.\n";
	if (parseInt(f.daystart.value) > parseInt(f.dayend.value))
		msg+="-Invalid start/end times.\n";
	if (f.viewdays.value == "" || parseInt(f.viewdays.value) <= 0)
		msg+="Invalid view days.\n";
	if (f.adminemail.value == "")
		msg+="Admin email is required.\n";

	if (msg!="") {
		alert("You have the following errors:\n\n"+msg);
		return false;
	}
	
	return true;
}

function checkAllBoxes(box) {
    var f = document.forms[0];
	
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type == "checkbox" && f.elements[i].name != "notify_user")
			f.elements[i].checked = box.checked;
	}

	void(0);
}

function check_reservation_form(f) {
	
	var recur_ok = false;
	var days_ok = false;
	var is_repeat = false;
	var msg = "";
	
	if ((typeof f.interval != 'undefined') && f.interval.value != "none") {
	is_repeat = true;
	
	if (f.interval.value == "week" || f.interval.value == "month_day") {
		for (var i=0; i < f.elements["repeat_day[]"].length; i++) {
			if (f.elements["repeat_day[]"][i].checked == true)
			days_ok = true;
		}
	}
	else days_ok = true;
		

		if (f.repeat_until.value == "") {
			msg += "- Please choose an ending date-\n";
			recur_ok = false;
		}
  }
	else {
		recur_ok = true;
		days_ok = true;
	}
if (days_ok == false) {
	recur_ok = false;
	msg += "- Please select days to repeat on-";
}

	if(f.rtitle && f.rtitle.value == "")
	 msg += "- Please Enter Title -\n";
	if (f.rsSel)
    {
      var data =f.rsSel.options[f.rsSel.selectedIndex].value;
      if((data == "") || (data =="A"))  
      	msg += "- Please select The Room-\n" ;
      
    }

	if (f.ftype)
    {
      var data =f.ftype.options[f.ftype.selectedIndex].value;
      if((data == "") || (data =="A"))  
      	msg += "- Please select The Function type-\n" ;
     
    }
   	if (f.reason)
    {
      var data =f.reason.value;
      if((data == "") || (data =="A")) { 
      	msg += "- Please provide the Reason for Modification in Basic Screen-\n" ;
          
       } 
    }
	
	
	if (msg != "")
		{
		 alert(msg);
		   return false;
		}		
	return true;
}


function getRadioValue(rgrp)
{
	var i = rgrp.length;
	do
	if (rgrp[--i].checked)
	return rgrp[i].value;
	while (i);
	return '';
}

function check_Concert_form(f) {
	
	var recur_ok = false;
	var days_ok = false;
	var is_repeat = false;
	var msg = "";
	var ptitle = f.p_title;
	var numb = '0123456789./';
	var validpno = false;
	var contentText = document.getElementById("contentText");
		
	var accompanist_detail = f.accompanist_detail;
			
	   if(f.name && f.name.value == '')
			msg += "- Please Enter Performer(s) Name -\n";
	  	
	   if(f.sen_recital && getRadioValue(f.sen_recital) == '')	
	   		msg += "- Is it a  Senior Recital ? -\n";

	   if(f.is_noon && getRadioValue(f.is_noon) == '')	
	   		msg += "- Is it a noon concert ? -\n";
			
	   if(f.ins_voice && f.ins_voice.value == '')
			msg += "- Please Enter Instrument or Voice -\n";
		
		if(f.accompanist && f.accompanist[0].checked){
			if(accompanist_detail.value == '')
				msg += "- Please Enter Other Performer(s) -\n";	
		 } 
		 
		if(f.accompanist && !f.accompanist[0].checked && !f.accompanist[1].checked){
				msg += "- Please Enter Other Performer(s) -\n";	
		 }
				      
	    if(f.p_title && f.p_title.value == '')
			msg += "- Please Enter Program Title -\n";
		
	    if(f.content &&  f.content.value == '')
			msg += "- Please Enter "+document.getElementById("frm_content_label").innerHTML+" -\n";	
			//msg += "- Please Enter "+contentText.innerHTML+"-\n";		
			
	  	if(f.fee){
			 var regex = /([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/;
	  	 if(f.fee.value =='' || ( f.fee.value == "other" && f.feeother.value==''))		
			msg += "- Please Enter Admission Fee -\n";
		  /*else{
			if(f.fee.value == "other" && !isValid(f.feeother.value,numb))
			msg += "- Please Enter Admission Fee (Ex: 15,15/5 or 15.5) -\n";
		  }*/
		else if(f.fee.value == "other" && !regex.exec(f.feeother.value))
			msg += "- Please Enter Admission Fee (Ex: xx,xx or xx.xx) -\n";
		}
		   //var valid_time = /^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
		   var valid_time = /[0-9]{1,2}:[0-5][0-9] ?(AM|PM)/i;
		   if(f.start_time && f.start_time.value == '' || !valid_time.exec(f.start_time.value))
				msg += "- Please Enter a Valid Concert Start Time (Eg: 12:30 PM) -\n";
		   //else{
			//	if(!isValid(f.start_time.value,numb))
			//	msg += "- Please Enter Concert Start Time -\n";
			 // }
		   var valid_runtime = /[0-9]{1,2}:[0-9]{1,2}/i;
		   var valid_runtime2 = /^(\d* ?(Hours|Hour|min|mins|minutes|minute|h|m|hr)?$)/i;
		   if(f.proj_time && f.proj_time.value == '' || (!valid_runtime.exec(f.proj_time.value) && !valid_runtime2.exec(f.proj_time.value)) )
				msg += "- Please Enter a Valid Projected Running Time (Eg: 3:25 or 2 hours) -\n";
		  // else{
			//	if(!isValid(f.proj_time.value,numb))
			//	msg += "- Please Enter Projected Running Time (Eg:3 Hours) -\n";
			//  }

	   if(f.intermission && getRadioValue(f.intermission) == '')	
	   		msg += "- Is there any Intermission ? -\n";
		
	   if(f.is_piano_harps && getRadioValue(f.is_piano_harps) == '')	
			msg += "- Please Enter Either Piano or Harpsichord -\n";	
		
			if(f.is_piano_harps && f.is_piano_harps[0].checked && f.piano_harps.value == ''){
					msg += "- Please Enter Either Piano or Harpsichord -\n";	
			}
										
	   if(f.tech_spec && f.tech_spec.value == '')
				msg += "- Please Enter Technical and Special Arrangements -\n";
	
	   if(f.is_recording && getRadioValue(f.is_recording) == '')	
	   		msg += "- Do you need Recording ? -\n";	
	
	   if(f.is_reception && getRadioValue(f.is_reception) == '')	
	   		msg += "- Do you need Reception ? -\n";				
			
			
			if(f.s_name)
		     if(f.s_name.value == '')
		       msg += "- Please Enter Faculty Sponsor(s) Name -\n";
		      
		     if(f.s_email)
		     if(emailcheck(f.s_email.value) == false )
		       msg += "- Please Enter Sponsor(s)Valid E-mail Address -\n";
			
	
	if (msg != "")
		{
		 alert(msg);
		   return false;
		}		
	return true;
}


function  checkOther(f){

var table = document.getElementById("fee_table");
	if (table == null) return;
	
	if (f.value != 'other') {
		table.style.display = "none";
		table.style.visibility = "hidden";	
	}
	else {
		table.style.display = isIE() ? "inline" : "table";
		table.style.visibility = "visible";
	}

}
function check_for_delete(f) {
	if (f.del && f.del.checked == true)
		return confirm('Delete this reservation?');
}

function toggle_fields(box) {
	document.forms[0].elements["table," + box.value + "[]"].disabled = (box.checked == true) ? false : "disabled";
}

function search_user_lname(letter) {
	var frm = isIE() ? document.name_search : document.forms['name_search'];
	frm.firstName.value = "";
	frm.lastName.value=letter;
	frm.submit();
}

function isIE() {
	return document.all;
}

function changeDate(month, year) {
	var frm = isIE() ? document.changeMonth : document.forms['changeMonth'];
	frm.month.value = month;
	frm.year.value = year;
	frm.submit();
}

// Function to change the Scheduler on selected date click
function changeScheduler(m, d, y, isPopup) {
	newDate = m + '-' + d + '-' + y;
	keys = new Array();
	vals = new Array();

	// Get everything up to the "?" (if it even exists)
	var queryString = (isPopup) ? window.opener.document.location.search.substring(0): document.location.search.substring(0);
	queryString = queryString.replace("?", "");

	var pairs = queryString.split('&');
	var url = (isPopup) ? window.opener.document.URL.split('?')[0] : document.URL.split('?')[0];
	if (isPopup)
		window.opener.location = url + "?date=" + newDate ;
	else
		document.location.href = url + "?date=" + newDate ;
}

///////
function pagesize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
	}
///////

function moveSummary(object, e, height) {
	myLayer = document.getElementById(object);
	w = parseInt(myLayer.style.width);
	h = (parseInt(myLayer.style.height))? parseInt(myLayer.style.height): 0;
	page =new Array();
	page = pagesize();
	
	///////
	BrowserDetect.init();

	var ie=document.all
	var ns6=document.getElementById && !document.all
	var offsetfromcursorX=12 //Customize x offset of tooltip
	var offsetfromcursorY=10 //Customize y offset of tooltip
	
	var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
	var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

	var nondefaultpos=false
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
	var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
	
	var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
	var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
	
	var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<myLayer.offsetWidth){
	//move the horizontal position of the menu to the left by it's width
		myLayer.style.left=curX-myLayer.offsetWidth+"px"
	}
	else if (curX<leftedge)
		myLayer.style.left="5px"
	else{
		//position the horizontal position of the menu where the mouse is positioned
		myLayer.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
	}

	//same concept with the vertical position
	if (bottomedge<myLayer.offsetHeight){
		myLayer.style.top=curY-myLayer.offsetHeight-offsetfromcursorY+"px"
	}
	else{
		myLayer.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
	}


}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showsummary(object, e, text, height) {

if(text!='' && escape(text)!='%A0' && text!='?' && text!=' ') {

	myLayer = document.getElementById(object);
	myLayer.innerHTML = text;
	page =new Array();
	page = pagesize();
	
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

	var ie=document.all
	var ns6=document.getElementById && !document.all
	var offsetfromcursorX=12 //Customize x offset of tooltip
	var offsetfromcursorY=10 //Customize y offset of tooltip
	
	var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
	var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

	var nondefaultpos=false
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
	var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
	
	var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
	var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
	
	var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<myLayer.offsetWidth){
	//move the horizontal position of the menu to the left by it's width
		myLayer.style.left=curX-myLayer.offsetWidth+"px"
	}
	else if (curX<leftedge)
		myLayer.style.left="5px"
	else{
		//position the horizontal position of the menu where the mouse is positioned
		myLayer.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
	}

	//same concept with the vertical position
	if (bottomedge<myLayer.offsetHeight){
		myLayer.style.top=curY-myLayer.offsetHeight-offsetfromcursorY+"px"
	}
	else{
		myLayer.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
	}

	myLayer.style.visibility = "visible";
}

}

function getAbsolutePosition(element) {
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
      var tmp = getAbsolutePosition(element.offsetParent);
      r.x += tmp.x;
      r.y += tmp.y;
    }
    return r;
  };

function hideSummary(object) {
	myLayer = document.getElementById(object);
	if(myLayer)
		myLayer.style.visibility = 'hidden';
}

function resOver(cell, color) {
	//hiliteResource(cell.parentNode, "resourceNameOver");
	cell.style.backgroundColor = color;
	cell.style.cursor='pointer'
}

function resOut(cell, color) {
	//hiliteResource(cell.parentNode, "resourceName");
	cell.style.backgroundColor = color;
}

function blankOver(cell) {	
//	cell.className = "reservationOver";
	cell.style.backgroundColor='#989a9b';	
	cell.style.cursor='pointer';	
}

function blankOut(cell, _class) {
	if(_class == 'cset3' || _class == 'cset3c')
		cell.style.backgroundColor='#f0eedf';	
	else		
		cell.style.backgroundColor='#ffffff';	
//	cell.className = _class;
}

function hiliteResource(parent, _class) {
	var index = isIE() ? 0 : 1;
	parent.childNodes[index].className = _class;
}

function showHideDays(opt) {
	e = document.getElementById("days");
	
	if (opt.options[2].selected == true || opt.options[4].selected == true) {
		e.style.visibility = "visible";
		e.style.display = isIE() ? "block" : "table";
	}
	else {
		e.style.visibility = "hidden";
		e.style.display = "none";
	}
	
	e = document.getElementById("week_num")
	if (opt.options[4].selected == true) {
		e.style.visibility = "visible";
		e.style.display = isIE() ? "inline" : "table";
	}
	else {
		e.style.visibility = "hidden";
		e.style.display = "none";
	}
}

function chooseDate(input_box, m, y) {
	var file = "recurCalendar.php?m=" + m + "&y="+ y;
	if (isIE()) {
		yVal = "top=" + 200;
		xVal = "left=" + 500;
	}
	if (!isIE()) {
		yVal = "screenY=" + 200;
		xVal = "screenX=" + 500
	}
	window.open(file, "calendar",yVal + "," + xVal + ",height=270,width=220,resizable=no,status=no,menubar=no");
	void(0);
}

function selectRecurDate(m, d, y, isPopup) {
	f = window.opener.document.forms[0];
	f._repeat_until.value = m + "/" + d + "/" + y;
	f.repeat_until.value = f._repeat_until.value;
	window.close();
}

function setSchedule(sid) {
	f = document.getElementById("setDefaultSchedule");
	f.scheduleid.value = sid;
	f.submit();
}

function changeSchedule(sel) {
	var url = document.URL.split('?')[0];
	document.location.href = url + "?scheduleid=" + sel.options[sel.selectedIndex].value;
}
/* 
 * onChange for fuctionType
 */
function changeFunctionType(sel){
	
	var url;
	var urlL = document.URL.split('?')[0];
	var urlR = document.URL.split('?')[1];   
   	if(sel.options[sel.selectedIndex].value == "A"){		
		if(urlR[0] == 'f') 	
			document.location.href = urlL;		
		else	
		    document.location.href = document.URL.split('&')[0];	
		    			
		return;
	}
	
    if(urlR == undefined)
      url =urlL +"?";
    else if(document.URL.split('ftype')[1] != undefined  && document.URL.split('date')[1] == undefined)
        url =urlL +"?";
    else
        url = document.URL.split('&ftype')[0] +"&";  
 	document.location.href = url +"ftype=" + sel.options[sel.selectedIndex].value;
		
}
function showHideCpanelTable(element) {
	var expires = new Date();
	var time = expires.getTime() + 2592000000;
	expires.setTime(time);
	var showHide = "";
	if (document.getElementById(element).style.display == "none") {
		document.getElementById(element).style.display='block';
		showHide = "show";
	} else {
		document.getElementById(element).style.display='none';
		showHide = "hide";
	}
	
	document.cookie = element + "=" + showHide + ";expires=" + expires.toGMTString();
}

function changeLanguage(opt) {
	var expires = new Date();
	var time = expires.getTime() + 2592000000;
	expires.setTime(time);
	document.cookie = "lang=" + opt.options[opt.selectedIndex].value + ";expires=" + expires.toGMTString() + ";path=/";
	document.location.href = document.URL;
}

function clickTab(tabid, panel_to_show,index) {
	
	
	div_to_display = document.getElementById(panel_to_show);
    var flag=0;
	if(div_to_display.style.display == "none")
	{
	 rows = document.getElementById("tab-container").getElementsByTagName("a");
	
		for (i = 0; i < rows.length && rows; i++) {
			if ( i==index ) 
					rows[i].className = "popup-nav";				
			else
			    rows[i].className = "popup-nav-link";
			
		}
	}
    
	
	div_to_display.style.display = isIE() ? "block" : "table";
	divs = document.getElementById("main-tab-panel").getElementsByTagName("div");

	for (i = 0; i < divs.length; i++) {
		// only hide panels with prefix "pnl"
		if (divs[i] != div_to_display && divs[i].getAttribute("id").substring(0,3) == "pnl") {
			divs[i].style.display = "none";
		}
	}
}

function checkCalendarDates() {
		var finalDate=checkCalendarDatesValue();
  
    document.getElementById("hdn_end_date").value =  finalDate;	
	document.getElementById("div_end_date").innerHTML =  finalDate;
	
  // If the start/end date are not equal, hide the whole repeat section
	var table = document.getElementById("repeat_table");
	if (table == null) return;
  
	if (document.getElementById("hdn_start_date").value != document.getElementById("hdn_end_date").value) {		
		table.style.display = "none";
		table.style.visibility = "hidden";	
	}
	else {
		table.style.display = isIE() ? "inline" : "table";
		table.style.visibility = "visible";
	}
}

function checkCalendarDatesValue() { 


   var start_date = document.getElementById("hdn_start_date").value;
   var end_date = document.getElementById("hdn_end_date").value;
	
	var startdateResult=	start_date.split("/" ,3);
	var enddateResult =	    end_date.split("/",3);
	var finalDate=new Array();
	var flag =false;
	
	if(startdateResult[2] > enddateResult[2]) {
		return document.getElementById("hdn_start_date").value;
	  }
	 else
		 finalDate[2] = enddateResult[2]; 	
  
 	if( startdateResult[0] > enddateResult[0]) 
	     return document.getElementById("hdn_start_date").value;
	
	 else
		  finalDate[0] = enddateResult[0];
	finalDate = startdateResult.join("/");
	return finalDate;
}
function showHideMinMax(chk) {
	document.getElementById("minH").disabled = document.getElementById("minM").disabled = document.getElementById("maxH").disabled = document.getElementById("maxM").disabled= chk.checked
}

function moveSelectItems(from, to) {
	from_select = document.getElementById(from);
	to_select = document.getElementById(to);
	BrowserDetect.init();
		
	for (i = 0; i < from_select.options.length; i++) {
		if (from_select.options[i].selected) {
			if (isIE()) {
				var option = new Option(from_select.options[i].text, from_select.options[i].value);
				to_select.options.add(option);
				from_select.options.remove(i);
				to_select.options[0].selected = true;
			}
			
			else if(BrowserDetect.browser == 'Safari'){				
					to_select.add(from_select.options[i]);					
					//to_select.remove(i);								
					to_select.options[i].selected = false; 
				}
					
			else {
				to_select.options.add(from_select.options[i]);
				if(to_select.options[i] != undefined)
					to_select.options[i].selected = false;
			}
			i--;	
		}
	}
}

function selectAllOptions(button) {
	var form = button.form;
	var i;
	
	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type == "select-multiple" && form.elements[i].multiple == true) {
			selectbox = form.elements[i];
			for (j = 0; j < selectbox.options.length; j++) {
				selectbox.options[j].selected = true;
			}
		}
	}
}

function changeMyCal(m, d, y, view) {
	var url = document.URL.split('?')[0];
	document.location.href = url + "?date=" + m + "-" + d + "-" + y + "&view=" + view;
}

function changeResCalendar(m, d, y, view, id) {
	var url = document.URL.split('?')[0];
	var type_id = id.split("|");
	var type = type_id[0];
	var p = (type == "s") ? "scheduleid" : "machid";
	var id = type_id[1];
	document.location.href = url + "?date=" + m + "-" + d + "-" + y + "&view=" + view + "&" + p + "=" + id;
}

function selectUserForReservation(memberid, fname, lname, email) {
	var doc = window.opener.document
	doc.forms[0].memberid.value = memberid;
	doc.getElementById('name').innerHTML = fname + " " + lname;
	doc.getElementById('phone').innerHTML = "";
	doc.getElementById('email').innerHTML = email;
	window.close();
}

function adminRowClick(checkbox, row_id, count) {
	var row = document.getElementById(row_id);
	//row.className = (checkbox.checked) ? "adminRowSelected" : "cellColor" + (count%2);
}

function showHide(element) {
	if (document.getElementById(element).style.display == "none") {
		document.getElementById(element).style.display='block';
	}
	else {
		document.getElementById(element).style.display='none';
	}
}

function submitJoinForm(isLoggedIn) {
	var loggedIn = (isLoggedIn != 0);
	var f = document.getElementById("join_form");
	f.h_join_fname.value = (!loggedIn) ? document.getElementById("join_fname").value : "";
	f.h_join_lname.value = (!loggedIn) ? document.getElementById("join_lname").value : "";
	f.h_join_email.value = (!loggedIn) ? document.getElementById("join_email").value : "";
	f.h_join_userid.value= (loggedIn) ? document.getElementById("join_userid").value : "";
	f.h_join_resid.value = document.getElementById("resid").value;
	f.submit();
}

function validateReservationWindow() {
	document.getElementById("check").style.display = "inline";
	var f = document.getElementById("reserve");
	f.target = "check";
	f.submit();
}

function createXMLDoc() {
	var xmlDoc = null;
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 	}
	
	return xmlDoc;
}

function getOption(opt) {
	if (isIE()) {
		return new Option(opt.text, opt.value);
	}
	else {
		return opt;
	}
}

function popGroupEdit(memberid) {
	window.open("group_edit.php?edit=1&memberid=" + memberid, "groups","height=250,width=470,resizable=no,status=no,menubar=no");
	void(0);
}

function popGroupView(memberid) {
	window.open("group_edit.php?edit=0&memberid=" + memberid, "groups","height=250,width=470,resizable=no,status=no,menubar=no");
	void(0);
}

function showHere(parent, id) {
	var element = document.getElementById(id);
	var x;
	var y;
	
	var offset = getOffset(parent);
	x = offset[0];
	y = offset[1];
	element.style.left = parseInt(x) + "px";
    element.style.top = parseInt(y - 34) + "px";
	element.style.display = "inline";
}

function getOffset(obj) {
	var curLeft = 0;
	var curTop = 0;
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curLeft += obj.offsetLeft
			curTop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curLeft += obj.x;
		curTop += obj.y;
	}
	
	return new Array(curLeft, curTop);
}

function switchStyle(obj, style) {
	obj.className = style;
}

function openExport(type, id, start, end) {
	var qs = 'type=' + type;
	
	if (id.length > 0) {
		qs += "&resid=" + id;
	}
	else {
		if (start.length > 0) {
			qs += "&start_date=" + start; 	
		}
		if (end.length >0) {
			qs += "&end_date=" + end;	
		}
	}
	
	window.open("exports/ical.php?" + qs);
}

function exportSearch() {
	var _type = document.getElementById("type");
	var type = _type[_type.selectedIndex].value;
	
	var start = document.getElementById("nostart").checked ? '' : document.getElementById("hdn_start_date").value;
	var end = document.getElementById("noend").checked ? '' : document.getElementById("hdn_end_date").value;
	
	openExport(type, '', start, end);
}

function blurDiv(checkbox, divid) {
	document.getElementById(divid).className = checkbox.checked ? "blur_textbox" : "textbox";
}

function editResourceData(editForm){

	var ftype = new Array();
	var _ftype = '';
	var checked = 0;
	
	var ref_form = document.getElementsByName("addResource");
	ftype = document.getElementsByName("ftype");
	
	for(var i=0; i<ftype.length; i++){
		if(ftype[i].checked){
			checked += 1;
			_ftype += ftype[i].value+' ';			
		}	
	}
	/*change*/
	if(checked == 1){
		alert("Please check atleast one of the Function Type(s)");
		return false;
	}else{		
			
		var dat=document.getElementsByName("new_ftype");
		dat.value = _ftype;
		editForm.action=editForm.action+"?new_ftype="+_ftype;
		ref_form.submit();
	}	
	
	return true;
}

function addResourceData(addForm){

	var ftype = new Array();
	var checked = 0;
	var msg = '';
	var error = false;
	
	var ref_form = document.getElementsByName("addResource");
	ftype = document.getElementsByName("ftype");
	
	var name = document.getElementsByName("name");

	if(name.value == ''){
		msg += "-Please enter the Resource Name \n";
		error = true;
	}	

	for(var i=0; i<ftype.length; i++){
		if(ftype[i].checked){
			checked += 1;					
		}	
	}
	
	if(checked == 0){
		msg += "-Please check atleast one Function Type(s) \n";
		error = true;
	}
	if(error){
		alert(msg);	
		return false;
	}		
	return true;	
}


function showResEdit(url) {

	alert(url);

}

function changeTime(rsIndex ,ref,interval) {    
    
   /* rsIndex = this
   * ref = starttime or endtime
   */
  
   var count = 60/interval;
   var startdate = document.getElementById("div_start_date");
   var enddate = document.getElementById("div_end_date");
   if(startdate.innerHTML == enddate.innerHTML ){
   
    var incordec =0 ;
    var index= rsIndex.selectedIndex;
    
    
    var time = document.getElementById(ref); 
       
   if( (ref== "endtime") && (index + 1 >= rsIndex.options.length))
      {
        alert("--Maximum Allowed Time Crossed--");
        rsIndex.selectedIndex = index -count;
        time.selectedIndex =index ;
        return false;
         
      }
    else if( (ref== "starttime") && index == 0){
     
      alert("--Minimum Allowed Time Crossed--");
      rsIndex.selectedIndex =count;
      time.selectedIndex =0;
      return false;
     }
     if(ref == "endtime" )
     { 
       if(index >= time.selectedIndex){
       	if(index + count < time.options.length)
       	 	time.selectedIndex= index + count; 
       	 else
       	  time.selectedIndex=time.options.length-1;
       	}    	 
     }
     else
         if(index <= time.selectedIndex)
       	 time.selectedIndex= index - count;
	}//end of if

}
function massEmail(f){
	check = document.getElementsByName("emailIDs[]");
	flag = 0;
	msg = '';
	
	if((f.subject.value == '') || (f.subject.value == "No subject"))
		msg = msg + 'Please mention the subject \n';
		
	if((f.message.value == '') || (f.message.value == "No message"))	
		msg = msg + 'Please enter the message \n';
		
	for(i=0;i<check.length;i++)	
	{
		if(check[i].checked)
		   flag = 1;
	}	
	  
	  if(flag == 0)
		   msg = msg + "Please select user";
		   
	  if(msg == '')
	  	return true;
	  else{
	  	alert(msg);
	   return false;
	   }
}
 

function emailAdmin(f){
	check = document.getElementsByName("emailIDs[]");
	select = f.sel.options[f.sel.selectedIndex].value;
	flag = 0;
	msg = '';
	
	if(select == '')
		msg += 'Please select the Room \n'; 
		
	if((f.subject.value == '') || (f.subject.value == "No subject"))
		msg = msg + 'Please mention the subject \n';
		
	if((f.message.value == '') || (f.message.value == "No message"))	
		msg = msg + 'Please enter the message \n';
				
	for(i=0;i<check.length;i++)	
	{
		if(check[i].checked)
		   flag = 1;
	}	
	  
	  if(flag == 0)
		   msg = msg + "Please select user";
		   
	  if(msg == '')
	  	return true;
	  else{
	  	alert(msg);
	   return false;
	   }
}

function ValidateEmailAddr(emailAddress){
  var atSymbol = emailAddress.indexOf("@");                                  // Get the index of the '@'
  var period = emailAddress.lastIndexOf(".");                                // Get the value of the last '.'
  var suffix = emailAddress.substring(period + 1, emailAddress.length);

  // Make sure the '@' symbol and '.' is in a valid location
  if (((atSymbol != 0) && (atSymbol != -1)) && (period != -1) && (atSymbol < period) && (atSymbol != period - 1)) { 
        return true;
  }
  
  /*if (((atSymbol != 0) && (atSymbol != -1)) && (suffix.length >= 2) && (atSymbol < period) && (atSymbol != period - 1)) { 
    if ((suffix == "com") || (suffix == "org") || (suffix == "gov") || (suffix == "net") || (suffix == "edu")) 
      return true;
  }*/
  
  return false;
}

// checks for the format ==> (415)123-4567
function ValidatePhoneNumber(phone){
	
	var numb = '0123456789()-';
	var msg = '';
	var phone_data = new Array()
	
	if(isValid((phone),numb)){
		
		if((phone.charAt(0)== '(') && (phone.charAt(4)== ')') && (phone.charAt(8)== '-'))
		  return true;
		else
		  msg = 'Invalid ';		  
		  
	}
	else{
		msg = 'Invalid ';
		}		  
	
	
	if(msg == '')
		  return true;
	else{
		return false	 
	   }
}



function checkprofile(f){
		
	var phone = f.phone.value;
	var email = f.email.value;
	
	regex = /^[+]?(\d)?[ ]*[\(\.\-]?(\d*)[\)\.\-]?[ ]*(\d*)[\.\- ]?(\d*)[ ]*(x|ext|ex)?\.?[ ]*(\d{1,7})?$/i;
	var isValidphone  = regex.exec(phone);	//ValidatePhoneNumber(phone);	
	var isValidemail = ValidateEmailAddr(email);
	
	if((isValidphone) && (isValidemail))
	    return true;
	else{
		if(!(isValidphone))
		   	alert("Please enter a valid phone number. It must be in the format: (415)555-5555 "); 
		if(!(isValidemail))
		   	alert("Please enter valid Email address"); 
		   	
		return false;
	}
	
}	  

function submitForm(){
		
	document.emailUsers1.submit();
}

function changeHourHeaderLeft(){
	var urlL = document.URL.split('?')[0];
	var urlR = document.URL.split('?')[1];
	var temp = new Array();
	var urlRvar = new Array(); 	
	var start = 1;		
	var j=0;
	var address = '';
	
	if(urlR != undefined){	
	
	   	urlRvar = urlR.split('&');		
		
		for(var i=0;i<urlRvar.length;i++){
			 if((urlRvar[i].substring(0,4)) != 'time') 
			 		{ 
			 		  temp[j] = urlRvar[i]; 
			 		  j++;			 		  
			 		}	
			 else{
			 		start = (urlRvar[i].split('=')[1]);
			 		start = parseInt(start) + 1;
			 	}	 	 
		 }
		 
		for(var i=0;i<j;i++){
			address += temp[i];
			address += '&';
		}
		
		document.location.href = urlL +'?'+ address + 'time=' + start;
	}	
	
	else{
		document.location.href = urlL + '?time=1';
	}	
}


function changeHourHeaderRight(){
	var urlL = document.URL.split('?')[0];
	var urlR = document.URL.split('?')[1];
	var temp = new Array();
	var urlRvar = new Array(); 	
	var start = -1;		
	var j=0;
	var address = '';
	
	if(urlR != undefined){	
	    	
	   	urlRvar = urlR.split('&');		
		
		for(var i=0;i<urlRvar.length;i++){
			 if((urlRvar[i].substring(0,4)) != 'time') 
			 		{ 
			 		  temp[j] = urlRvar[i]; 
			 		  j++;			 		  
			 		}
			 else{
			 		start = (urlRvar[i].split('=')[1]);
			 		start = parseInt(start) - 1;
			 	}	 			
			 					 					 	 
		 }
		 
		for(var i=0;i<j;i++){
			address += temp[i];
			address += '&';
		}
		
		document.location.href = urlL +'?'+ address + 'time=' + start;
	}	
	
	else{
		document.location.href = urlL + '?time=-1';
	}	
}

///testing 

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"
		}
	]

};


