//************************START MAIN MULTI PURPOSE FUNCTIONS******************************************
//*****************PRELOAD IMAGES*****************************

//var root_url = location.href.substring(0,location.href.lastIndexOf('/')+1);
var root_url = 'http://pcsnewfoundland.com/';

<!--
if (document.images)
{
  pic1= new Image(63,53); 
  pic1.src=root_url + "O/inc/modules/calendar/theme/cal_purple_vertical/images/calendarbig_black.jpg"; 

  pic2= new Image(63,53); 
  pic2.src=root_url + "O/inc/modules/calendar/theme/cal_purple_vertical/images/calendarbig_purple.jpg"; 

  pic3= new Image(63,53); 
  pic3.src=root_url + "O/inc/modules/calendar/theme/cal_purple_vertical/images/calendarbig_green.jpg"; 
}
//-->
//*****************MAIN GET OBJECT FUNCTION*****************************
function getXMLHttpObject() {
	var xmlHttp = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {xmlHttp = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {xmlHttp = new XMLHttpRequest();}
		catch (e) {xmlHttp = false;}
	}
	return xmlHttp;
}


//*****************MAIN LOADING FUNCTION*****************************
function loading()  {
	document.getElementById('loading_content').style.display='block';
	document.getElementById('fade').style.display='block';
}  




//******************************START CALENDAR FUNCTIONS******************************************

//*****************CHANGE MONTH FUNCTION - GET DATA *****************************
function cal_change_month()
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_change_month_act(xmlHttp.responseText);

    }
  } 

  	var sel_month = document.getElementById("cal_change_month_id");
	var sel_year = document.getElementById("cal_change_year_id");
	var cat_sort = document.getElementById("cat_sort_id");
	var dis_limit = document.getElementById("dis_limit_id");

	//********CHANGE HEADER MONTH AND YEAR********
	document.getElementById('monthheader').innerHTML = sel_month.options[sel_month.selectedIndex].text;
	document.getElementById('yearheader').innerHTML = sel_year.options[sel_year.selectedIndex].value;

	var url = root_url + "O/inc/modules/calendar/cal_blocks.php?month=" + sel_month.options[sel_month.selectedIndex].value + "&year=" + sel_year.options[sel_year.selectedIndex].value + "&cat=" + cat_sort.options[cat_sort.selectedIndex].value + "&limit=" + dis_limit.options[dis_limit.selectedIndex].value + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);

  xmlHttp.send(null);
}


//*****************CHANGE MONTH FUNCTION - SHOW DATA IN UL TAG CALLED month_data*****************************
function cal_change_month_act(response)  {
	document.getElementById('month_data').innerHTML = response;
	//********TURN OFF LOADING AND LIGHT BOX WHEN CHANGE MONTH COMPLETE********
	document.getElementById('loading_content').style.display='none';
	document.getElementById('fade').style.display='none';
}







//*****************CHANGE MONTH BACK FUNCTION - GET DATA *****************************
function cal_change_month_back()
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_change_month_act(xmlHttp.responseText);

    }
  } 

  	var sel_month = document.getElementById("cal_change_month_id");
	var sel_year = document.getElementById("cal_change_year_id");
	var back_year = sel_year.options[sel_year.selectedIndex].value;
	var cat_sort = document.getElementById("cat_sort_id");
	var dis_limit = document.getElementById("dis_limit_id");

if (sel_month.options[sel_month.selectedIndex].value > 1)  {
var back_month = sel_month.options[sel_month.selectedIndex].value - 1;
} else {
var back_month = 12;
back_year = sel_year.options[sel_year.selectedIndex].value - 1;
sel_year.value = back_year;
}

sel_month.value = back_month;

	//********CHANGE HEADER MONTH AND YEAR********
	document.getElementById('monthheader').innerHTML = sel_month.options[sel_month.selectedIndex].text;
	document.getElementById('yearheader').innerHTML = back_year;

	var url = root_url + "O/inc/modules/calendar/cal_blocks.php?month=" + back_month + "&year=" + back_year + "&cat=" + cat_sort.options[cat_sort.selectedIndex].value + "&limit=" + dis_limit.options[dis_limit.selectedIndex].value + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);

  xmlHttp.send(null);
}







//*****************CHANGE YEAR BACK FUNCTION - GET DATA *****************************
function cal_change_year_back()
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_change_month_act(xmlHttp.responseText);

    }
  } 

  	var sel_month = document.getElementById("cal_change_month_id");
	var sel_year = document.getElementById("cal_change_year_id");
	var back_year = sel_year.options[sel_year.selectedIndex].value;
	var back_month = sel_month.options[sel_month.selectedIndex].value;
	var cat_sort = document.getElementById("cat_sort_id");
	var dis_limit = document.getElementById("dis_limit_id");

back_year = sel_year.options[sel_year.selectedIndex].value - 1;
sel_year.value = back_year;


	//********CHANGE HEADER MONTH AND YEAR********
	document.getElementById('yearheader').innerHTML = back_year;


	var url = root_url + "O/inc/modules/calendar/cal_blocks.php?month=" + back_month + "&year=" + back_year + "&cat=" + cat_sort.options[cat_sort.selectedIndex].value + "&limit=" + dis_limit.options[dis_limit.selectedIndex].value + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);

  xmlHttp.send(null);
}








//*****************CHANGE MONTH NEXT FUNCTION - GET DATA *****************************
function cal_change_month_next()
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_change_month_act(xmlHttp.responseText);

    }
  } 

  	var sel_month = document.getElementById("cal_change_month_id");
	var sel_year = document.getElementById("cal_change_year_id");
	var next_year = sel_year.options[sel_year.selectedIndex].value;
	var cat_sort = document.getElementById("cat_sort_id");
	var dis_limit = document.getElementById("dis_limit_id");

if (sel_month.options[sel_month.selectedIndex].value < 12)  {
var next_month = parseInt(sel_month.options[sel_month.selectedIndex].value) + 1;
} else {
var next_month = 1;
next_year = parseInt(next_year) + 1;
sel_year.value = next_year;
}

sel_month.value = next_month;


	//********CHANGE HEADER MONTH AND YEAR********
	document.getElementById('monthheader').innerHTML = sel_month.options[sel_month.selectedIndex].text;
	document.getElementById('yearheader').innerHTML = next_year;

	var url = root_url + "O/inc/modules/calendar/cal_blocks.php?month=" + next_month + "&year=" + next_year + "&cat=" + cat_sort.options[cat_sort.selectedIndex].value + "&limit=" + dis_limit.options[dis_limit.selectedIndex].value + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);

  xmlHttp.send(null);
}







//*****************CHANGE YEAR NEXT FUNCTION - GET DATA *****************************
function cal_change_year_next()
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_change_month_act(xmlHttp.responseText);

    }
  } 

  	var sel_month = document.getElementById("cal_change_month_id");
	var sel_year = document.getElementById("cal_change_year_id");
	var next_year = sel_year.options[sel_year.selectedIndex].value;
	var next_month = sel_month.options[sel_month.selectedIndex].value;
	var cat_sort = document.getElementById("cat_sort_id");
	var dis_limit = document.getElementById("dis_limit_id");

next_year = parseInt(next_year) + 1;
sel_year.value = next_year;

	//********CHANGE HEADER MONTH AND YEAR********
	document.getElementById('monthheader').innerHTML = sel_month.options[sel_month.selectedIndex].text;
	document.getElementById('yearheader').innerHTML = next_year;


	var url = root_url + "O/inc/modules/calendar/cal_blocks.php?month=" + next_month + "&year=" + next_year + "&cat=" + cat_sort.options[cat_sort.selectedIndex].value + "&limit=" + dis_limit.options[dis_limit.selectedIndex].value + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);

  xmlHttp.send(null);
}







//*********************************BEGIN ADMIN WIZARD FUNCTIONS************************************
//*****************START ADMIN WIZARD FUNCTION - GET FORM DATA FOR OVERLAY EVENT EDITOR*****************************
function cal_wizard(day, event_id)
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_update_form_load(xmlHttp.responseText);

    }
  } 

var sel_year = document.getElementById("cal_change_year_id");
var sel_month = document.getElementById("cal_change_month_id");

var url = root_url + "O/inc/modules/calendar/cal_wizard.php?id=" + event_id + "&day=" + day + "&month=" + sel_month.options[sel_month.selectedIndex].value + "&year=" + sel_year.options[sel_year.selectedIndex].value + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}


//*****************START ADMIN WIZARD FUNCTION - SHOW FORM DATA OVERLAY EVENT EDITOR*****************************
function cal_update_form_load(response)  {
	document.getElementById('light').style.display='block';
	document.getElementById('light').innerHTML = response;
	//********TURN OFF LOADING WHEN SHOW FORM COMPLETE********
	document.getElementById('loading_content').style.display='none';
}



//*****************EDIT DAY FUNCTION - SHOW FORM DATA OVERLAY EVENT EDITOR*****************************
function cal_step_1()  {
if (document.getElementById('cal_wiz_step_1').style.display=='none')  {
	document.getElementById('cal_wiz_step_1').style.display='inline';
	document.getElementById('cal_wiz_step_2').style.display='none';
} else {
	document.getElementById('cal_wiz_step_1').style.display='none';
	document.getElementById('cal_wiz_step_2').style.display='inline';
}
}







function cal_step_2(day, event_id)  {
if (document.getElementById('cal_wiz_step_2').style.display=='inline')  {
	document.getElementById('cal_wiz_step_2').style.display='none';


if (document.getElementById('cal_admin_mode_a').checked)  {
	document.getElementById('cal_wiz_step_3').style.display='inline';
} 

if (document.getElementById('cal_admin_mode_b').checked)  {
	document.getElementById('cal_wiz_step_4').style.display='inline';
cal_edit_list(day, event_id);
}


} else {
	document.getElementById('cal_wiz_step_2').style.display='inline';
	document.getElementById('cal_wiz_step_3').style.display='none';
	document.getElementById('cal_wiz_step_4').style.display='none';
	document.getElementById('cal_wiz_step_5').style.display='none';
}

if (document.getElementById('cal_main_event').checked ? "true" : "false" == "true")  {
document.getElementById('add_mnevt_title').style.display='inline';
document.getElementById('add_subevt_title').style.display='none';
} else {
document.getElementById('add_mnevt_title').style.display='none';
document.getElementById('add_subevt_title').style.display='inline';
}

}










function cal_step_3()  {
if (document.getElementById('cal_wiz_step_3').style.display=='inline')  {
	document.getElementById('cal_wiz_step_3').style.display='none';
	document.getElementById('cal_wiz_step_4').style.display='inline';
} else {
	document.getElementById('cal_wiz_step_3').style.display='inline';
	document.getElementById('cal_wiz_step_4').style.display='none';
}
}






//*****************EDIT LIST FUNCTION - GET ENTRIES*****************************
function cal_edit_list(day, event_id)
{
  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_update_edit_list(xmlHttp.responseText);

    }
  } 

var sel_year = document.getElementById("cal_change_year_id");
var sel_month = document.getElementById("cal_change_month_id");
var sel_main_event = document.getElementById('cal_main_event').checked ? "true" : "false";

var url = root_url + "O/inc/modules/calendar/wiz_editlist.php?id=" + event_id + "&day=" + day + "&month=" + sel_month.options[sel_month.selectedIndex].value + "&year=" + sel_year.options[sel_year.selectedIndex].value + "&type=" + sel_main_event + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}


//*****************EDIT LIST FUNCTION - SHOW FORM DATA OVERLAY EVENT EDITOR*****************************
function cal_update_edit_list(response)  {
	document.getElementById('wiz_edit_list').style.display='block';
	document.getElementById('wiz_edit_list').innerHTML = response;
	//********TURN OFF LOADING WHEN SHOW FORM COMPLETE********
	document.getElementById('loading_content').style.display='none';
}



//******************SHOW EDIT FORM************************
function cal_edit_form(day, event_id)  {

  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_show_edit_form(xmlHttp.responseText);

    }
  } 

var sel_year = document.getElementById("cal_change_year_id");
var sel_month = document.getElementById("cal_change_month_id");
var sel_main_event = document.getElementById('cal_main_event').checked ? "true" : "false";

var url = root_url + "O/inc/modules/calendar/wiz_edit.php?id=" + event_id + "&day=" + day + "&month=" + sel_month.options[sel_month.selectedIndex].value + "&year=" + sel_year.options[sel_year.selectedIndex].value + "&type=" + sel_main_event + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);

}





//*****************EDIT LIST FUNCTION - SHOW FORM DATA OVERLAY EVENT EDITOR*****************************
function cal_show_edit_form(response)  {
	document.getElementById('cal_wiz_step_4').style.display='none';
	document.getElementById('cal_wiz_step_5').style.display='block';
	document.getElementById('wiz_edit_form_area').innerHTML = response;
	//********TURN OFF LOADING WHEN SHOW FORM COMPLETE********
	document.getElementById('loading_content').style.display='none';
}










//*****************UPDATE DAY FUNCTION - GET POST FORM DATA FOR SQL*****************************
   function get(obj) {
      var poststr = "cal_body=" + escape(encodeURI( document.getElementById("cal_body").value )) +
                    "&cal_category_new=" + escape(encodeURI( document.getElementById("edit_category").value )) +
                    "&cal_category_select=" + escape(encodeURI( document.getElementById("cat_select_id").value )) +
                    "&cal_title=" + escape(encodeURI( document.getElementById("cal_title").value )) +
                    "&start_h=" + escape(encodeURI( document.getElementById("start_h").value )) +
                    "&start_min=" + escape(encodeURI( document.getElementById("start_min").value )) +
                    "&start_d=" + escape(encodeURI( document.getElementById("start_d").value )) +
                    "&start_m=" + escape(encodeURI( document.getElementById("start_m").value )) +
                    "&start_y=" + escape(encodeURI( document.getElementById("start_y").value )) +
                    "&end_h=" + escape(encodeURI( document.getElementById("end_h").value )) +
                    "&end_min=" + escape(encodeURI( document.getElementById("end_min").value )) +
                    "&end_d=" + escape(encodeURI( document.getElementById("end_d").value )) +
                    "&end_m=" + escape(encodeURI( document.getElementById("end_m").value )) +
                    "&end_y=" + escape(encodeURI( document.getElementById("end_y").value )) +
                    "&cal_multi_day=" + escape(encodeURI( document.getElementById("cal_multi_day").checked ? "true" : "false" )) +
                    "&cal_all_day=" + escape(encodeURI( document.getElementById("cal_all_day").checked ? "true" : "false" )) +
                    "&cal_published=" + escape(encodeURI( document.getElementById("cal_published").checked ? "true" : "false" )) +
                    "&cal_main_event=" + escape(encodeURI( document.getElementById("cal_main_event").checked ? "true" : "false" )) +
					"&update_id=" + escape(encodeURI( document.getElementById("update_id").value ));
      cal_update_day(root_url + 'O/inc/modules/calendar/cal_update_act.php', poststr);
   }




//*****************UPDATE DAY FUNCTION - GET POST FORM DATA FOR SQL*****************************
   function get_edit(obj) {
      var poststr = "cal_body=" + escape(encodeURI( document.getElementById("edit_body").value )) +
                    "&cal_category_new=" + escape(encodeURI( document.getElementById("edit_category").value )) +
                    "&cal_category_select=" + escape(encodeURI( document.getElementById("edit_select_id").value )) +
                    "&cal_title=" + escape(encodeURI( document.getElementById("edit_title").value )) +
                    "&start_h=" + escape(encodeURI( document.getElementById("edit_start_h").value )) +
                    "&start_min=" + escape(encodeURI( document.getElementById("edit_start_min").value )) +
                    "&start_d=" + escape(encodeURI( document.getElementById("edit_start_d").value )) +
                    "&start_m=" + escape(encodeURI( document.getElementById("edit_start_m").value )) +
                    "&start_y=" + escape(encodeURI( document.getElementById("edit_start_y").value )) +
                    "&end_h=" + escape(encodeURI( document.getElementById("edit_end_h").value )) +
                    "&end_min=" + escape(encodeURI( document.getElementById("edit_end_min").value )) +
                    "&end_d=" + escape(encodeURI( document.getElementById("edit_end_d").value )) +
                    "&end_m=" + escape(encodeURI( document.getElementById("edit_end_m").value )) +
                    "&end_y=" + escape(encodeURI( document.getElementById("edit_end_y").value )) +
                    "&cal_multi_day=" + escape(encodeURI( document.getElementById("edit_multi_day").checked ? "true" : "false" )) +
                    "&cal_all_day=" + escape(encodeURI( document.getElementById("edit_all_day").checked ? "true" : "false" )) +
                    "&cal_published=" + escape(encodeURI( document.getElementById("edit_published").checked ? "true" : "false" )) +
                    "&cal_main_event=" + escape(encodeURI( document.getElementById("edit_main_event").checked ? "true" : "false" )) +
					"&update_id=" + escape(encodeURI( document.getElementById("edit_update_id").value ));
      cal_update_day(root_url + 'O/inc/modules/calendar/cal_update_act.php', poststr);
   }


//*****************UPDATE DAY FUNCTION - SEND POST FORM DATA FOR SQL*****************************
function cal_update_day(url, parameters)  {

  var xmlHttp = getXMLHttpObject();

  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_update_sql(xmlHttp.responseText);

    }
  } 
      
      xmlHttp.open('POST', url, true);
      xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", parameters.length);
      xmlHttp.setRequestHeader("Connection", "close");
      xmlHttp.send(parameters);
   
}


//*****************UPDATE DAY FUNCTION - SHOW RESULTS FROM SQL*****************************
function cal_update_sql(response)  {
	document.getElementById('fade2').style.display='block';
	document.getElementById('light_update').style.display='block';
	document.getElementById('light_update').innerHTML = response;
	//********TURN OFF LOADING WHEN SHOW RESULTS COMPLETE********
	document.getElementById('loading_content').style.display='none';
}




































//******************DELETE ENTRY************************
function cal_del(event_id)  {

  var xmlHttp = getXMLHttpObject();
  
  xmlHttp.onreadystatechange = function()
  {

    if(xmlHttp.readyState < 4 && xmlHttp.readyState > 0)  {
      loading();
    }
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      cal_update_sql(xmlHttp.responseText);

    }
  } 


var url = root_url + "O/inc/modules/calendar/cal_delete.php?id=" + event_id + "&rnd=" + Math.random(); 

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);

}





















//*****************SHOW HIDE ADD CATEGORY - EDIT PAGE*****************************
function more_text(more_id,obj)  {
more_id = "more_text" + more_id;
if (document.getElementById(more_id).className == "dateblock_text1_hidden")  {
	obj.innerHTML="hide";
	document.getElementById(more_id).className="dateblock_text1";
} else {
	obj.innerHTML="more details";
	document.getElementById(more_id).className="dateblock_text1_hidden";
}
}

//*****************SHOW HIDE ADD CATEGORY - EDIT PAGE*****************************
function more_text_next(more_id,obj)  {
more_id = "more_text_next" + more_id;
if (document.getElementById(more_id).className == "dateblock_text1_hidden")  {
	obj.innerHTML="hide";
	document.getElementById(more_id).className="dateblock_text1";
} else {
	obj.innerHTML="more details";
	document.getElementById(more_id).className="dateblock_text1_hidden";
}
}

//*****************UPDATE DAY FUNCTION - CLOSE RESULTS FROM SQL*****************************
function cal_update_sql_close(day, event_id)  {
	document.getElementById('light_update').style.display='none';
	document.getElementById('fade2').style.display='none';
cal_wizard(day, event_id);
}


//*****************SHOW HIDE ADD CATEGORY - EDIT PAGE*****************************
function cat_showhide(obj)  {
if (document.getElementById('edit_category').className == "hidden_content")  {
	obj.innerHTML="choose existing";
	document.getElementById('cat_select_id').className="hidden_content";
	document.getElementById('edit_category').className="display_content";
} else {
	obj.innerHTML="add category";
	document.getElementById('edit_category').className="hidden_content";
	document.getElementById('cat_select_id').className="display_content";
}
}



//*****************SHOW MULTI DAY TIME SELECTOR FOR ALL DAY EVENTS CREATE*****************************
function cal_hide_time()  {

if (document.getElementById("cal_all_day").checked ? "true" : "false" == "true")  {
document.getElementById('start_h').style.display='none';
document.getElementById('start_min').style.display='none';
document.getElementById('end_h').style.display='none';
document.getElementById('end_min').style.display='none';
} else {
document.getElementById('start_h').style.display='inline';
document.getElementById('start_min').style.display='inline';
document.getElementById('end_h').style.display='inline';
document.getElementById('end_min').style.display='inline';

}
}



//*****************SHOW MULTI DAY DATE SELECTOR CREATE*****************************
function cal_show_end_date()  {

if (document.getElementById("cal_multi_day").checked ? "true" : "false" == "true")  {
document.getElementById('end_d').style.display='inline';
document.getElementById('end_m').style.display='inline';
document.getElementById('end_y').style.display='inline';
} else {
document.getElementById('end_d').style.display='none';
document.getElementById('end_m').style.display='none';
document.getElementById('end_y').style.display='none';
}
}




//*****************SHOW MULTI DAY TIME SELECTOR FOR ALL DAY EVENTS EDIT*****************************
function edit_hide_time()  {

if (document.getElementById("edit_all_day").checked ? "true" : "false" == "true")  {
document.getElementById('edit_start_h').style.display='none';
document.getElementById('edit_start_min').style.display='none';
document.getElementById('edit_end_h').style.display='none';
document.getElementById('edit_end_min').style.display='none';
} else {
document.getElementById('edit_start_h').style.display='inline';
document.getElementById('edit_start_min').style.display='inline';
document.getElementById('edit_end_h').style.display='inline';
document.getElementById('edit_end_min').style.display='inline';

}
}



//*****************SHOW MULTI DAY DATE SELECTOR EDIT*****************************
function edit_show_end_date()  {

if (document.getElementById("edit_multi_day").checked ? "true" : "false" == "true")  {
document.getElementById('edit_end_d').style.display='inline';
document.getElementById('edit_end_m').style.display='inline';
document.getElementById('edit_end_y').style.display='inline';
} else {
document.getElementById('edit_end_d').style.display='none';
document.getElementById('edit_end_m').style.display='none';
document.getElementById('edit_end_y').style.display='none';
}
}



//*****************SHOW ADD SUB EVENT FORM*****************************
function cal_show_add_item()  {

if (document.getElementById('cal_show_add_item').style.display=='none')  {
document.getElementById('cal_show_add_item').style.display='inline';
} else {
document.getElementById('cal_show_add_item').style.display='none';
}
if (document.getElementById('cal_show_add_main_event').style.display=='inline')  {
document.getElementById('cal_show_add_main_event').style.display='none';
} 
}



//*****************SHOW ADD MAIN EVENT FORM*****************************
function cal_show_add_main_event()  {

if (document.getElementById('cal_show_add_main_event').style.display=='none')  {
document.getElementById('cal_show_add_main_event').style.display='inline';
} else {
document.getElementById('cal_show_add_main_event').style.display='none';
}
if (document.getElementById('cal_show_add_item').style.display=='inline')  {
document.getElementById('cal_show_add_item').style.display='none';
} 
}





//*****************START DRAG AND DROP FUNCTIONS*****************************
var dragbox;
var deltaX, deltaY;
var client;


function setOpacity(node,val) {
if (node.filters) {
try {
node.filters["alpha"].opacity = val*100;
} catch (e) { }
} else if (node.style.opacity) {
node.style.opacity = val;
}
}

function getX(node) {
return parseInt(node.style.left);
}

function getY(node) {
return parseInt(node.style.top);
}

function getWidth(node) {
return parseInt(node.style.width);
}

function getHeight(node) {
return parseInt(node.style.height);
}

function setX(node,x) {
if ( isNaN(x) ) {    x = 0;}
node.style.left = x + "px";
}

function setY(node,y) {
if ( isNaN(y) ) {    y = 0;}
node.style.top = y + "px";
}

function Evt(evt) {
this.evt = evt ? evt : window.event; 
this.source = evt.target ? evt.target : evt.srcElement;
this.x = evt.pageX ? evt.pageX : evt.clientX;
this.y = evt.pageY ? evt.pageY : evt.clientY;
}

Evt.prototype.toString = function () {
return "Evt [ x = " + this.x + ", y = " + this.y + " ]";
};

Evt.prototype.consume = function () {
if (this.evt.stopPropagation) {
this.evt.stopPropagation();
this.evt.preventDefault();
} else if (this.evt.cancelBubble) {
this.evt.cancelBubble = true;
this.evt.returnValue = false;
}
};

Evt.addEventListener = function (target,type,func,bubbles) {
if (document.addEventListener) {
target.addEventListener(type,func,bubbles);
} else if (document.attachEvent) {
target.attachEvent("on"+type,func,bubbles);
} else {
target["on"+type] = func;
}
};

Evt.removeEventListener = function (target,type,func,bubbles) {
if (document.removeEventListener) {
target.removeEventListener(type,func,bubbles);
} else if (document.detachEvent) {
target.detachEvent("on"+type,func,bubbles);
} else {
target["on"+type] = null;
}
};

//*****************ON CLICK FUNCTION*****************************
function dragPress(evt) {
evt = new Evt(evt);
dragbox = evt.source;
setOpacity(dragbox,.7);
deltaX = evt.x - getX(dragbox);
deltaY = evt.y - getY(dragbox);
Evt.addEventListener(document,"mousemove",dragMove,false);
Evt.addEventListener(document,"mouseup",dragRelease,false);
}

//*****************MOVE FUNCTION*****************************
function dragMove(evt) {
evt = new Evt(evt);
setX(dragbox,evt.x - deltaX);
setY(dragbox,evt.y - deltaY);
evt.consume();
}

//*************RELEASE FUNCTION - (UN)COMMENT IF STATEMENT TO ENABLE/DISABLE DROP FUNCTIONS*******************
function dragRelease(evt) {
evt = new Evt(evt);
setOpacity(dragbox,1);
Evt.removeEventListener(document,"mousemove",dragMove,false);
Evt.removeEventListener(document,"mouseup",dragRelease,false);
//if (droppedOnDropBox(evt)) {
//dragBoxDropped(evt);
//}
}





//*****************START ON DROP PERFORM AJAX FUNCTIONS*****************************
//createClient();


function createClient() {
try {
client = window.XMLHttpRequest ? new XMLHttpRequest() : 
new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { 
alert("Sorry, your browser is not Ajax-enabled!"); 
}
}


function droppedOnDropBox(evt) {
var dropbox = document.getElementById("dropbox");
var x = getX(dropbox);
var y = getY(dropbox);
var width = getWidth(dropbox);
var height = getHeight(dropbox);
return evt.x > x &&
evt.y > y &&
evt.x < x + width &&
evt.y < y + height;
}

function dragBoxDropped(evt) {
client.onreadystatechange = callback;
client.open("get",root_url + "message.php",true);
client.send(null);
}

function callback() {
if (client.readyState == 4) {
if (client.status == 200) {
alert(client.responseText);
createClient();
} else {
alert("Sorry, there seems to be a problem retrieving the response:\n" +
client.statusText);
createClient();
}
}
}
