

//30-Apr-2010 Tsachi Twig
//ver: 01.05.00
//
//function to allow copy of field content of quick link to schedule url to clipboard
//
//
// ******************* AS THE BELOW CODE WORK ONLT ON IE BROWSER 
// ******************* THE USE OF IT HAS BEEN DROPPED. 
// ******************* USER WILL COPY THE REQUIRED INFO TO CLIPBOARD MANUALY.
//
//function ClipBoard()
//{
//
//	Copied = URLdirectLinkText.createTextRange();
//	Copied.execCommand("Copy");
//
//	window.alert(URLdirectLinkText.value + "\n\n COPIED");
//
//	return true;
//}



// 8-May-2009 Tsachi Twig
// fix problems in the function, 
// 1. change name from checkForm to checkRegistrationFor,
// 2. remove validation for institution, 
// 3. add valudation for username
// 4. get min num of pass char from config file (in check and in message) 
//
function checkRegistrationForm(f) {

	//var msg = "Please fix these errors:\n";
	var msg = f.you_have_the_following_errors_msg.value+"\n";

	var errors = false;
	
	//var f=document.register;



	if (f.logon_name.value == "") {
		//msg+="-First name is required\n";
		msg+=f.logon_name_required_msg.value+"\n";
		errors = true;
	}
	if (f.fname.value == "") {
		//msg+="-First name is required\n";
		msg+=f.first_name_required_msg.value+"\n";
		errors = true;
	}
	if (f.lname.value == "") {
		//msg+="-Last name is required\n";
		msg+=f.last_name_required_msg.value+"\n";
		errors = true;
	}
	if (f.phone.value == "") {
		//msg+="-Phone number is required\n";
		msg+=f.phone_number_required_msg.value+"\n";
		errors = true;
	}

//	if (f.institution.value == "") {
// 		msg+="-Institution is required\n";
//		errors = true;
//	}


	if ( (f.emailaddress.value == "") || ( f.emailaddress.value.indexOf('@') == -1) ) {
		//msg+="-Valid email is required\n";
		msg+=f.valid_email_required_msg.value+"\n";
		errors = true;
	}


	if (f.password.value == "" || 
	   ( (f.password.value != "") && 
	     (f.password.value.length < parseInt(f.min_number_char_in_pass.value)) )
	   ) 
	{
		//msg+="-Min 6 character password is required\n";
		msg+=f.min_char_pass_required_msg.value+"\n";
		errors = true;
	}
	if ( (f.password.value != "") && (f.password.value != f.password2.value) ) {
		//msg+=("-Passwords to not match\n");
		msg+=f.pass_do_not_match_msg.value+"\n";
		errors = true;
	}


	if (errors) {
		window.alert(msg);
		return false;
	}

		
	return true;
}

// 8-May-2009 Tsachi Twig
// this function is almost same as checkRegistrationForm
// with only diff that we don'y verify password field. 
// (as on edit we do not show pass and user don't have to change pass...)
//
function checkRegistrationFormEdit(f) {

	//var msg = "Please fix these errors:\n";
	var msg = f.you_have_the_following_errors_msg.value+"\n";

	var errors = false;
	
	//var f=document.register;



	if (f.logon_name.value == "") {
		//msg+="-First name is required\n";
		msg+=f.logon_name_required_msg.value+"\n";
		errors = true;
	}
	if (f.fname.value == "") {
		//msg+="-First name is required\n";
		msg+=f.first_name_required_msg.value+"\n";
		errors = true;
	}
	if (f.lname.value == "") {
		//msg+="-Last name is required\n";
		msg+=f.last_name_required_msg.value+"\n";
		errors = true;
	}
	if (f.phone.value == "") {
		//msg+="-Phone number is required\n";
		msg+=f.phone_number_required_msg.value+"\n";
		errors = true;
	}

//	if (f.institution.value == "") {
// 		msg+="-Institution is required\n";
//		errors = true;
//	}


	if ( (f.emailaddress.value == "") || ( f.emailaddress.value.indexOf('@') == -1) ) {
		//msg+="-Valid email is required\n";
		msg+=f.valid_email_required_msg.value+"\n";
		errors = true;
	}

	// 8-May-2009 Tsachi Twig
	// on edit - we don't show pass and it is not requried by the user. 
	//
	//if (f.password.value == "" || 
	//   ( (f.password.value != "") && 
	//     (f.password.value.length < parseInt(f.min_number_char_in_pass.value)) )
	//   ) 
	//{
	//	//msg+="-Min 6 character password is required\n";
	//	msg+=f.min_char_pass_required_msg.value+"\n";
	//	errors = true;
	//}

	if ( (f.password.value != "") && (f.password.value != f.password2.value) ) {
		//msg+=("-Passwords to not match\n");
		msg+=f.pass_do_not_match_msg.value+"\n";
		errors = true;
	}


	if (errors) {
		window.alert(msg);
		return false;
	}

		
	return true;
}



// Tsachi comment: It seems like this function is not in use. 
//
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 help(file) {    
		window.open("help.php#" + file ,"","width=500,height=500,scrollbars");    
		void(0);    
}      


// 9-Apr-2009 Tsachi Twig
//

function termsofservice(file) {    
		window.open("TermsOfService.php#" + file ,"","width=500,height=500,scrollbars");    
		void(0);    
}      


function reserve(type, machid, start_date, resid, scheduleid, is_blackout, read_only, pending, starttime, endtime ) {  
		
		//debug
		//window.alert("in (functions.js/reserve)");

		if (is_blackout == null) { is_blackout = 0; }
		
		if (is_blackout != 1) {
			w = (type == 'r' || type == 'm') ? 600 : 520;
			h = (type == 'm') ? 830 : 830;
		}
		else {
			w = (type == 'r') ? 600 : 425;
			h = (type == 'm') ? 460 : 420;
		}
		
		if (machid == null) { machid = ''; }
		if (start_date == null) { start_date = ''; }
		if (resid == null) { resid = ''; }
		if (scheduleid == null) { scheduleid = ''; }

		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 + '&scheduleid=' + scheduleid + "&is_blackout=" + is_blackout + "&read_only=" + read_only + "&pending=" + pending + "&starttime=" + starttime + "&endtime=" + endtime;    

		//debug
		//window.alert("(functions.js/reserve) nurl="+nurl);

		var resWindow = window.open(nurl,"reserve","width=" + w + ",height=" + h + 				",scrollbars,resizable=no,status=no");     

		resWindow.focus();
	
		void(0);   
}

function checkDate() {
	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 ( 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, "");
}

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;
	}
}

// 15-May-2009 Tsachi Twig
// support lang translation for messages. 
//
function checkAdminForm() {
	var f = document.forms[0];

	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?');
			return confirm(f.this_will_delete_all_res_msg.value + "\n" + f.continue_question_msg.value);
	}
	//alert("No boxes have been checked!");	
	alert(f.no_box_checked_msg.value);	

	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=400,height=400,scrollbars,resizable=no,status=no");     
		void(0);    
}


// 27-Mar-2009 Tsachi Twig
// New function - to call checkAddScheudle & checkAddResource in one transaction
//
function checkAddScheudleAndResource(f) {

	return checkAddScheudle(f);
	return checkAddResource(f);
}


// 
// 6-May-2009 Tsachi Twig
// Support messages lang translation. 
//
function checkAddResource() {
	var msg = "";
	var f = document.addResource;

//	minres = (parseInt(f.minH.value) * 60) + parseInt(f.minM.value);
//	maxRes = (parseInt(f.maxH.value) * 60) + parseInt(f.maxM.value);
	
//	if (f.name.value=="")
//		//msg+="-Resource name is required.\n";
//		msg+=f.resource_name_required_msg.value+"\n";
		

//	if (parseInt(minres) > parseInt(maxRes))
//		//msg+="-Minimum reservaion time must be less than or equal to maximum";
//		msg+=f.Min_must_be_less_or_eq_max_msg.value;

//	if (msg!="") {
		alert(f.R_you_have_the_following_errors_msg.value+"\n\n"+msg);
		return false;
//	}
	
	return true;
}

/*
// This function is called from dynamic form created by admin.temolate.php (print_schedule_edit function)
// to perform client validation on fields in the form. 
//
*/
// 6-May-2009 Tsachi Twig
// Support lang translated messages. 
// the approuch is to allow the php to translate all messages and keep it as hidden input.
// the javascript will go to the relevant message in the relevant input field to get \
// the translated message. 
//
//
function checkAddSchedule() {
	var f = document.addSchedule;
	var msg = "";
	

	// 11-Mar-09 change:
	// Tsachi Twig: validate Category 
	// 
	// 6-May-2009 Tsachi Twig - Cancel validation - as we are providing list of values. 
	//
	//if (f.categoryid.value=="")
	//	msg+="-Schedule Category is required.\n";


 	// 11-Mar-09 change:
	// Tsachi Twig: validate Sub Category 
	// 
	// 6-May-2009 Tsachi Twig - Cancel validation - as we are providing list of values. 
	//
	//if (f.subcategoryid.value=="")
	//	msg+="-Schedule Sub Category is required.\n";		

	if (f.scheduletitle.value=="")
		//msg+="-Schedule title is required.\n";
		msg+= f.schedule_title_required_msg.value+"\n";

	if (parseInt(f.daystart.value) > parseInt(f.dayend.value))
		//msg+="-Invalid start/end times.\n";
		msg+= f.invalid_start_end_times_msg.value+"\n";	

	if (f.viewdays.value == "" || parseInt(f.viewdays.value) <= 0)
		//msg+="Invalid view days.\n";
		msg+= f.Invalid_view_days_msg.value+"\n";

	if (f.adminemail.value == "")
		//msg+="Admin email is required.\n";
		msg+= f.Admin_email_is_required_msg.value+"\n";

	if (msg!="") {
		//alert("You have the following errors:\n\n"+msg);

		alert(f.S_you_have_the_following_errors_msg.value+"\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 (msg != "")
		alert(msg);
		
	return (msg == "");
}

function check_for_delete(f) {
	if (f.del && f.del.checked == true)
		return confirm('Delete this reservation?');
}

// 14-Apr-2009 Tsachi Twig
// New function for empty SPquicklinkCode field when gets focus. 
// (in order to allow user to type the SPquicklinkCode). 
// **************** currently doesn'y work ************** so puting it in commnet....
function Empty_quickSPcode_field(f) {

    //alert("in Empty_quickSPcode_field 1");

    //var f = document.forms[0];

	//f.SPquicklinkCode.value = "";
	f.value = "";

	//document.SPQuicklink.SPQuicklinkcode.value = ""

	// debug
	//alert("in Empty_quickSPcode_field 2");

	void(0);
}

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,scheduleid) {
	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];
	var schedid = ""
	
	if (scheduleid == "") {
		for (var i=0;i<pairs.length;i++)
		{
			var pos = pairs[i].indexOf('=');
			if (pos >= 0)
			{
				var argname = pairs[i].substring(0,pos);
				var value = pairs[i].substring(pos+1);
				keys[keys.length] = argname;
				vals[vals.length] = value;		
			}
		}
		
		for (i = 0; i < keys.length; i++) {
			if (keys[i] == "scheduleid") {
				schedid = vals[i];
			}
		}
	}
	else {
		schedid	= scheduleid;
	}
	
	if (isPopup)
		window.opener.location = url + "?date=" + newDate + "&scheduleid=" + schedid;
	else
		document.location.href = url + "?date=" + newDate + "&scheduleid=" + schedid;
}

// BUGFIX by Eric Maclot
function isIE7() {
        return (document.all && (typeof document.body.style.maxHeight != "undefined"));
}
 
// Shorthand functions for schedule display
function ssum(e, text)
{
	showsummary('summary', e, text);
}
function hsum()
{
	hideSummary('summary');
}

function msum(e)
{
	moveSummary('summary', e);
}

function showsummary(object, e, text) {
 
        myLayer = document.getElementById(object);
        myLayer.innerHTML = text;
 
        w = parseInt(myLayer.style.width) ;
        h = parseInt(myLayer.style.height);
 
        if (e != '') {
            if (isIE()) {
                  x = e.clientX;
                  y = e.clientY;
                  browserX = document.body.offsetWidth - 25;
                  if (isIE7()) {
                     // IE 7
                    x += document.documentElement.scrollLeft - document.body.clientLeft ;
                    y += document.documentElement.scrollTop - document.body.clientTop;
                 } else {
                    // IE6, and previous version
                    x += document.body.scrollLeft ;                        // Adjust for scrolling on IE
                    y += document.body.scrollTop ;
                }
 
            }
            if (!isIE()) {
            x = e.pageX;
            y = e.pageY;
            browserX = window.innerWidth - 35;
            }
    }
 
        x1 = x + 20;                // Move out of mouse pointer
        y1 = y + 20;
 
        // Keep box from going off screen
        if (x1 + w > browserX){
                x1 = browserX - w;
        }
    myLayer.style.left = parseInt(x1)+ "px";
    myLayer.style.top = parseInt(y1) + "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 moveSummary(object, e) {
 
        myLayer = document.getElementById(object);
        w = parseInt(myLayer.style.width);
        h = parseInt(myLayer.style.height);
 
    if (e != '') {
        if (isIE()) {
            x = e.clientX;
            y = e.clientY;
            browserX = document.body.offsetWidth -25;
             if (isIE7()) {
   // IE 7
                    x += document.documentElement.scrollLeft - document.body.clientLeft ;
                    y += document.documentElement.scrollTop - document.body.clientTop;
   } else {
   // IE6, and previous version
                    x += document.body.scrollLeft ;                        // Adjust for scrolling on IE
                    y += document.body.scrollTop ;
   }
        }
        if (!isIE()) {
            x = e.pageX;
            y = e.pageY;
                        browserX = window.innerWidth - 30;
        }
    }
 
        x1 = x + 20;        // Move out of mouse pointer
        y1 = y + 20;
 
        // Keep box from going off screen
        if (x1 + w > browserX)
                x1 = browserX - w;
 
    myLayer.style.left = parseInt(x1) + "px";
    myLayer.style.top = parseInt(y1) + "px";
}

function hideSummary(object) {
	myLayer = document.getElementById(object);
	myLayer.style.visibility = 'hidden';
}

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() ? "inline" : "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();
}


// This function is called after choosing service provider indication
// in drop-down of registration (user profile) form, in order to change form display
// based on user choise 
//
//
// 22-Jan-2010 Change
// Tsachi Twig: add support IsServiceProvider indication on registration form
// 
// The only diff between 
// changeIsServiceProviderOnReg and changeIsServiceProviderOnEdit 
// is that on edit we are adding the "&edit=true" to the URL. 
//
// 
// 8-Apr-2010 Tsachi Twig
// Registration form now "Remember" the input parameters used by the user
// in case the user visited the READ-ONLY scheduels screen before registration. 
// when changing the ServiceProvider indication we want to keep this input.  
//
//
function changeIsServiceProviderOnReg() {


	//alert('in changeIsServiceProvider() isServicePorvider=');

	selIsServiceProvider= document.getElementById("isserviceprovider");

	//debug
	//alert('in changeIsServiceProvider() selIsServiceProvider=' + selIsServiceProvider.value);
	
	// 8-Apr-2010 Tsachi Twig
	// Registration form now "Remember" the input parameters used by the user
	// in case the user visited the READ-ONLY scheduels screen before registration. 
	// when changing the ServiceProvider indication we want to keep this input.  
	// the input is stored on the template screen on hidden fields. 
	// the hidden fields value was pupulated based on the first call to registration
	// screen - by transferring it in the URL (get).
	//
	var scheduleid = document.getElementById("scheduleid");
	var categoryid = document.getElementById("categoryid");
	var subcategoryid = document.getElementById("subcategoryid");
	var SPquicklinkCode = document.getElementById("SPquicklinkCode");

    var url = document.URL.split('?')[0];


	// 8-Apr-2010 Tsachi Twig
	// Add additional parameters kept from READ-ONLY schedules screen. 
	//
	//OLD
	//document.location.href = 	url + 	"?isserviceprovider=" + selIsServiceProvider.options[selIsServiceProvider.selectedIndex].value ;
	
	//NEW

	url = url + "?isserviceprovider=" + selIsServiceProvider.options[selIsServiceProvider.selectedIndex].value; 

	// 9-Apr-2010 Tsachi Twig
	// set get parameters in URL only if value is not empty
	//
	//
	// 14-Aug-2010 Tsachi Twig
	// fix problem of object doesn't exist error (which cause to refresh to fail) by checking if VAR != null. 
	//
	//if (typeof scheduleid != "undefined")
	if (scheduleid != null)
	{
		if ((scheduleid.value != null) && (scheduleid.value.length!=0))
			{url = url + "&scheduleid=" + scheduleid.value;}
	}
	if (categoryid != null)
	{
		if ((categoryid.value != null) && (categoryid.value.length!=0))
			{url = url + "&categoryid=" + categoryid.value;}
	}
	if (subcategoryid != null)
	{
		if ((subcategoryid.value != null) && (subcategoryid.value.length!=0))
			{url = url + "&subcategoryid=" + subcategoryid.value;}
	}

	//debug
	//alert('in changeIsServiceProvider() SPquicklinkCode=' + SPquicklinkCode.value);
	//alert('in changeIsServiceProvider() 111');
	
	if (SPquicklinkCode != null)
	{
	
		if ((SPquicklinkCode.value != null) && (SPquicklinkCode.value.length!=0))
			{url = url + "&SPquicklinkCode=" + SPquicklinkCode.value;}
	}
	document.location.href = url;

	//document.location.href = 	url 	+  "?isserviceprovider=" + selIsServiceProvider.options[selIsServiceProvider.selectedIndex].value	+ "&scheduleid=" + scheduleid.value	+ "&categoryid=" + categoryid.value	+ "&subcategoryid=" + subcategoryid.value	+ "&SPquicklinkCode=" + SPquicklinkCode.value;

}


// This function is called after choosing service provider indication
// in drop-down of registration (user profile) form, in order to change form display
// based on user choise 
//
// 22-Jan-2010 Change
// Tsachi Twig: add support IsServiceProvider indication on registration form
// 
// The only diff between 
// changeIsServiceProviderOnReg and changeIsServiceProviderOnEdit 
// is that on edit we are adding the "&edit=true" to the URL. 
//
function changeIsServiceProviderOnEdit() {


	//alert('in changeIsServiceProvider() isServicePorvider=');

	selIsServiceProvider= document.getElementById("isserviceprovider");

      var url = document.URL.split('?')[0];

	document.location.href = 
	url + 
	"?isserviceprovider=" + selIsServiceProvider.options[selIsServiceProvider.selectedIndex].value + 
	"&edit=true";

}




// This function is called after choosing schedule in drop-down, in order to present
// Relevant resources.
//
// xx-Mar-2009 Change
// Tsachi Twig: add support of category & sub category
//
//
// 20-Dec-2010 Tsachi Twig
// add parmeter to "changeSchedule javascript function. 
// the parmeter will inficate if we are changing choosen scheudle or not (not=changing category or sub category)
// this is in order to initiate choosen schedule in URL set by the java script. 
//
 
function changeSchedule(scheduleIdChangeIND) {


	//alert('in changeSchedule() scheudleType=');

	selCategory= document.getElementById("choose_category");
	selSubCategory= document.getElementById("choose_subcategory");
	
	sel= document.getElementById("choose_schedule");
	
	
      var url = document.URL.split('?')[0];

	//alert(scheduleIdChangeIND);
	  
	url = "?categoryid=" + selCategory.options[selCategory.selectedIndex].value+
	"&subcategoryid=" + selSubCategory.options[selSubCategory.selectedIndex].value;

	// 20-Dec-2010 Tsachi
	// in order to ovoid schedule display when chaging category/subcategory, initiate last choosen schedule
	//
	if (scheduleIdChangeIND == "Y") {
		url= url + "&scheduleid=" + sel.options[sel.selectedIndex].value;
	}
	
	document.location.href = url;
}

// 23-May-2009 Tsachi Twig
// New function to support change of schedule in blackouts. 
// in blackouts we don't have category and subcategory, so we are handling 
// only schedule id. 
//
function changeScheduleBlackouts() {


	//alert('in changeScheduleBlackouts()');

	sel = document.getElementById("choose_schedule");

      var url = document.URL.split('?')[0];

	document.location.href = 
	url + 
	"?scheduleid=" + 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) {
	document.getElementById(tabid.getAttribute("id")).className = "tab-selected";
	rows = document.getElementById("tab-container").getElementsByTagName("td");
	for (i = 0; i < rows.length; i++) {
		if (rows[i].className == "tab-selected" && rows[i] != tabid) {
			rows[i].className = "tab-not-selected";
		}
	}

	div_to_display = document.getElementById(panel_to_show);
	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 table = document.getElementById("repeat_table");
	if (table == null) return;
	
	// If the start/end date are not equal, hide the whole repeat section
	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 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);
	
	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 {
				to_select.options.add(from_select.options[i]);
			}
			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 updateEnd(startDrop)
{
	var endDrop = document.getElementById("endtime");
	var index = startDrop.selectedIndex;
	endDrop.selectedIndex = (endDrop.options.length-1 > index) ? index + 1 : index;	
}
