var allowable_tags = new Array("a", "b", 
"br", "cite", "code", "dd", "del", "dfn", 
"div", "dl", "dt", "em", "h1", "h2", "h3", 
"h4", "h5", "h6", "hr", "i", "ins", "kbd", 
"li", "ol", "p", "q", "samp", "span", "strike", 
"strong", "sub", "sup", "tt", "u", "ul", "var", "img",
"table", "thead", "tbody", "tfoot", "tr", "td", "th", "font", "?xml");

// Include the ?xml tag to allow for <?xml /> nodes inside rich HTML

var exec_address_boxes = new Array();
var exec_phones = new Array();

// National addreses
// National addreses
exec_address_boxes['sydney_office'] = "sydney";
exec_address_boxes['melbourne_office'] = "melbourne";
exec_address_boxes['perth_office'] = "perth";
exec_phones['sydney_office_phone'] = "(02) 9662 4855"; exec_phones['sydney_office_fax'] = "(02) 9663 4868";
exec_phones['melbourne_office_phone'] = "(03) 9272 5622"; exec_phones['melbourne_office_fax'] = "(03) 9272 5620";
exec_phones['perth_office_phone'] = ""; exec_phones['perth_office_fax'] = "";

exec_address_boxes['national_pres'] = "liam"; exec_phones['national_pres'] = "0405 814 035";
exec_address_boxes['national_vp'] = "glen"; exec_phones['national_vp'] = "0405 020 105";
exec_address_boxes['national_trs'] = "dan"; exec_phones['national_trs'] = "0466 335 344";
exec_address_boxes['national_ed'] = "rachel"; exec_phones['national_ed'] = "";
exec_address_boxes['political'] = "political"; exec_phones['political'] = "0437 430 882";
exec_address_boxes['national_exec_director'] = "ed"; exec_phones['national_exec_director'] = "";
exec_address_boxes['public_affairs_director'] = "dikla"; exec_phones['public_affairs_director'] = "";

exec_address_boxes['NSW_pres'] = "danny"; exec_phones['NSW_pres'] = "";
exec_address_boxes['NSW_vice_pres'] = "simon"; exec_phones['NSW_vice_pres'] = "";

exec_address_boxes['VIC_pres'] = "tamara"; exec_phones['VIC_pres'] = "";
exec_address_boxes['VIC_vice_pres'] = "oliver"; exec_phones['VIC_vice_pres'] = "0424 875 819";

exec_address_boxes['WA_pres'] = "shayna"; exec_phones['WA_pres'] = "0425 441 390";
exec_address_boxes['WA_vice_pres'] = ""; exec_phones['WA_vice_pres'] = "";

exec_address_boxes['QLD_pres'] = "ronan"; exec_phones['QLD_pres'] = "0423 636 226";
exec_address_boxes['SA_pres'] = "reuben"; exec_phones['SA_pres'] = "";
exec_address_boxes['ACT_pres'] = "lia"; exec_phones['ACT_pres'] = "0416 202 693";
exec_address_boxes['NZ_pres'] = "jonathan"; exec_phones['NZ_pres'] = "+64 275 807 478";

exec_address_boxes['HAW_coordinator'] = ""; exec_phones['HAW_coordinator'] = "";
exec_address_boxes['Winter_Retreat_coordinator'] = ""; exec_phones['Winter_Retreat_coordinator'] = "";
exec_address_boxes['PTS_coordinator'] = ""; exec_phones['PTS_coordinator'] = "";
exec_address_boxes['webmaster'] = "webmaster";
exec_address_boxes['shaliach'] = "shaliach"; exec_phones['shaliach'] = "";
exec_address_boxes['IP_director'] = "ip"; exec_phones['IP_director'] = "(02) 8344 9788";


// VIC Regional addresses
exec_address_boxes['MonJSS_Caulfield_pres'] = "monashcaulfield";
exec_address_boxes['MonJSS_Clayton_pres'] = "monashclayton";
exec_address_boxes['MUJSS_pres'] = "melbourneuni";
exec_address_boxes['Deakin_pres'] = "deakin";
exec_address_boxes['Swinburne_pres'] = "swinburne";
exec_address_boxes['LaTrobe_pres'] = "latrobe";
exec_address_boxes['RMIT_pres'] = "rmit";

var chosen_domain = "";
if (document.location.protocol.toUpperCase() == "HTTPS:")
	chosen_domain = secure_domain;
else
	chosen_domain = public_domain;

var sponsor_listing = new Array();
sponsor_listing[0] = ["http://www.jca.org.au/", "Jewish Communal Appeal (JCA)", new Image()];
sponsor_listing[0][2].src = chosen_domain + "images/global/logo/sponsors/logo_JCA.png";
sponsor_listing[1] = ["http://www.prattfoundation.com.au/", "The Pratt Foundation", new Image()];
sponsor_listing[1][2].src = chosen_domain + "images/global/logo/sponsors/logo_Pratt_Foundation.png";
sponsor_listing[2] = ["http://www.zfa.com.au/", "Zionist Federation of Australia (ZFA)", new Image()];
sponsor_listing[2][2].src = chosen_domain + "images/global/logo/sponsors/logo_ZFA.png";
sponsor_listing[3] = ["http://www.unitedisraelappeal.org.au/", "United Israel Appeal (UIA)", new Image()];
sponsor_listing[3][2].src = chosen_domain + "images/global/logo/sponsors/logo_UIA.png";
sponsor_listing[4] = ["http://www.besenfoundation.org.au/", "The Besen Family Foundation", new Image()];
sponsor_listing[4][2].src = chosen_domain + "images/global/logo/sponsors/logo_BesenFoundation.png";
sponsor_listing[5] = ["javascript:void(0);", "The Gandel Charitable Trust", new Image()];
sponsor_listing[5][2].src = chosen_domain + "images/global/logo/sponsors/logo_Gandel.gif";
//sponsor_listing[6] = ["http://www.claytonutz.com/", "Clayton UTZ", new Image()];
//sponsor_listing[6][2].src = chosen_domain + "images/global/logo/sponsors/logo_Clayton_UTZ.png";
sponsor_listing[6] = ["http://www.abl.com.au/", "Arnold Bloch Leibler", new Image()];
sponsor_listing[6][2].src = chosen_domain + "images/global/logo/sponsors/logo_ABL.png";
sponsor_listing[7] = ["http://www.austfhu.org.au/", "Australian Friends of Hebrew University", new Image()];
sponsor_listing[7][2].src = chosen_domain + "images/global/logo/sponsors/logo_AUSTFHU.png";
sponsor_listing[8] = ["http://www.jnfaustralia.com.au/", "JNF Australia", new Image()];
sponsor_listing[8][2].src = chosen_domain + "images/global/logo/sponsors/logo_JNF.png";
sponsor_listing[9] = ["http://www.zcv.org.au/", "Zionist Council of Victoria", new Image()];
sponsor_listing[9][2].src = chosen_domain + "images/global/logo/sponsors/logo_ZCV.png";
sponsor_listing[10] = ["http://www.standwithus.com/", "StandWithUs", new Image()];
sponsor_listing[10][2].src = chosen_domain + "images/global/logo/sponsors/logo_StandWithUs.png";
sponsor_listing[11] = ["http://www.j-net.com.au/hagshama/index.html", "Hagshama", new Image()];
sponsor_listing[11][2].src = chosen_domain + "images/global/logo/sponsors/logo_Hagshama.png";
sponsor_listing[12] = ["http://www.aijac.org.au/", "Australia/Israel &amp; Jewish Affairs Council (AIJAC)", new Image()];
sponsor_listing[12][2].src = chosen_domain + "images/global/logo/sponsors/logo_AIJAC.png";
sponsor_listing[13] = ["http://www.hillel.com.au/", "Hillel Foundation of NSW", new Image()];
sponsor_listing[13][2].src = chosen_domain + "images/global/logo/sponsors/logo_Hillel_NSW.png";
sponsor_listing[14] = ["http://www.wujs-arad.org/", "WUJS Arad", new Image()];
sponsor_listing[14][2].src = chosen_domain + "images/global/logo/sponsors/logo_WUJS_Arad.png";
sponsor_listing[15] = ["http://www.griffintheatre.com.au/", "Griffin Theatre", new Image()];
sponsor_listing[15][2].src = chosen_domain + "images/global/logo/sponsors/logo_Griffin_Theatre.png";
sponsor_listing[16] = ["http://www.brookespartytours.com.au/", "Brookes Party Tours", new Image()];
sponsor_listing[16][2].src = chosen_domain + "images/global/logo/sponsors/logo_Brookes_Party_Tours.png";


function rotate_sponsor_profile(sponsor_listing_index, timer_obj)
{
	var next_profile_index = sponsor_listing_index;
	if (sponsor_listing[sponsor_listing_index][0] == "javascript:void(0);")
		document.getElementById('sponsor_URL').target = "_self";
	else
		document.getElementById('sponsor_URL').target = "_blank";
	document.getElementById('sponsor_URL').href = sponsor_listing[sponsor_listing_index][0];
	document.getElementById('sponsor_URL').title = sponsor_listing[sponsor_listing_index][1];
	document.getElementById('sponsor_logo').src = sponsor_listing[sponsor_listing_index][2].src;
	document.getElementById('sponsor_logo').title = sponsor_listing[sponsor_listing_index][1];
 	(sponsor_listing_index == sponsor_listing.length - 1) ? next_profile_index = 0 : next_profile_index++;
	timer_obj = setTimeout("rotate_sponsor_profile(" + next_profile_index + ")", 7000);
}


function print_addr(addr_box_ID)
{
  var email_domain_1 = "aujs"; var email_domain_2 = ".com.au";
  var full_addr = exec_address_boxes[addr_box_ID] + "@" + email_domain_1 + email_domain_2;
  document.write("<a href=\"mailto:" + full_addr + "\">" + full_addr + "</a>");
}


function print_phone(phone_ID)
{
	document.write(exec_phones[phone_ID]);
}


function print_addr_textlink(addr_box_ID, hyperlink_text)
{
  var email_domain_1 = "aujs"; var email_domain_2 = ".com.au";
  var full_addr = exec_address_boxes[addr_box_ID] + "@" + email_domain_1 + email_domain_2;
  document.write("<a href=\"mailto:" + full_addr + "\">" + hyperlink_text + "</a>");
}


function format_Date()
{
  if (format_Date.arguments[0] == "TBA" || format_Date.arguments[0] == "late")
    return (format_Date.arguments[0]);

  var dateArray = format_Date.arguments[0].match(/^.+ /).toString().replace(/ $/, "").split(/-/);
  var timeArray = format_Date.arguments[0].match(/ .+$/).toString().replace(/^ /, "").split(/:/);

  var weekday = full_days[new Date(dateArray[0], dateArray[1] - 1, dateArray[2]).getDay()];
  var formattedDateTime = weekday + ", " + dateArray[2].replace(/^0/, "");

  if (dateArray[2].match(/\d$/) == "1")
    formattedDateTime += (dateArray[2] != "11") ? "st" : "th";
  else if (dateArray[2].match(/\d$/) == "2")
    formattedDateTime += (dateArray[2] != "12") ? "nd" : "th";
  else if (dateArray[2].match(/\d$/) == "3")
    formattedDateTime += (dateArray[2] != "13") ? "rd" : "th";
  else
    formattedDateTime += "th";

  switch (dateArray[1].replace(/^0/, ''))
  {
    case '1': formattedDateTime += " January"
      break
    case '2': formattedDateTime += " February"
      break
    case '3': formattedDateTime += " March"
      break
    case '4': formattedDateTime += " April"
      break
    case '5': formattedDateTime += " May"
      break
    case '6': formattedDateTime += " June"
      break
    case '7': formattedDateTime += " July"
      break
    case '8': formattedDateTime += " August"
      break
    case '9': formattedDateTime += " September"
      break
    case '10': formattedDateTime += " October"
      break
    case '11': formattedDateTime += " November"
      break
    case '12': formattedDateTime += " December"
      break
  }
  formattedDateTime += " " + dateArray[0];

  if (timeArray.join(":") != "00:00:00")
  {
    var hours = parseInt(timeArray[0]);
    formattedDateTime += ", ";
    if (hours > 12)
      formattedDateTime += (hours - 12).toString() + ":" + timeArray[1] + " PM";
    else if (hours == 12)
      formattedDateTime += timeArray[0] + ":" + timeArray[1] + " PM";
    else
      formattedDateTime += timeArray[0].replace(/^0/, "") + ":" + timeArray[1] + " AM";
  }

  return(formattedDateTime);
}


function format_short_Date(day_val, month_val, year_val)
{
	var formattedDate = "";
	if (day_val < 10)
		formattedDate += "0";
	formattedDate += day_val + "-";
	switch (month_val)
	{
    case '0': formattedDate += "Jan-"
      break
    case '1': formattedDate += "Feb-"
      break
    case '2': formattedDate += "Mar-"
      break
    case '3': formattedDate += "Apr-"
      break
    case '4': formattedDate += "May-"
      break
    case '5': formattedDate += "Jun-"
      break
    case '6': formattedDate += "Jul-"
      break
    case '7': formattedDate += "Aug-"
      break
    case '8': formattedDate += "Sep-"
      break
    case '9': formattedDate += "Oct-"
      break
    case '10': formattedDate += "Nov-"
      break
    case '11': formattedDate += "Dec-"
      break
	}
	formattedDate += year_val;
	return formattedDate;
}


function format_SQL_Date(day_val, month_val, year_val)
{
	var formattedDate = year_val + "-";
	month_val = parseInt(month_val) + 1;
	if (month_val < 10)
		formattedDate += "0";
	formattedDate += month_val + "-";
	if (day_val < 10)
		formattedDate += "0";
	formattedDate += day_val;
	return formattedDate;
}


function get_Cookie_Value(tag)
{
  var value = null;
  var cookieObj = document.cookie + ";";
  var beginPos = cookieObj.indexOf(tag);

  if (beginPos != -1)
  {
    beginPos = beginPos + tag.length;
    var endPos = cookieObj.indexOf(";", beginPos);
    if (endPos == -1)
      endPos = cookieObj.length;
    value = unescape(cookieObj.substring(beginPos, endPos));
    if (tag == "authorised_unit_name=" || tag == "authorised_unit_abbrev=" || tag == "region_abbrev=")
      value = value.replace(/\+/g, " ");
  }
  return value;
}


function delete_Cookie(tag)
{
  document.cookie = tag + ";expires=" + (new Date(1970, 1, 1)).toGMTString();
  return false;
}


function search_array_elem()
{
  var array_arg = search_array_elem.arguments[0];
  var elem = search_array_elem.arguments[1];

  for (i = 0; i < array_arg.length; i++)
  {
    if (array_arg[i] == elem)
      return true;
  }
  return false;
}


function check_file_extensions(upload_filetype, filepath)
{
  var ext = filepath.match(/[^\.]+$/).toString().toLowerCase();

	if (upload_filetype == "illustration" && ext != "jpeg" && ext != "jpg" && ext != "gif" && ext != "png")
	{
    alert("Selected image file must be one of the following types: .jpeg, .jpg, .gif, .png");
    return false;
	}
	if (upload_filetype == "document" && ext != "doc" && ext != "docx" && ext != "pdf" && ext != "rtf")
  {
    alert("Selected document file must be one of the following types: .doc, .docx, .pdf, .rtf");
    return false;
  }
  if (upload_filetype == "memberXML" && filepath.indexOf("_registered_members.xml") == -1)
  {
    alert("Selected XML file must be named _registered_members.xml");
    return false;
  }
  return true;
}


function trim(field_val)
{
  field_val = field_val.replace(/^ +/, "");
  field_val = field_val.replace(/ +$/, "");
  return field_val;
}


function escape_and_trim(field_val)
{
  field_val = field_val.replace(/\&/g, "#38;");
  field_val = field_val.replace(/>/g, "#62;");
  field_val = field_val.replace(/</g, "#60;");
  field_val = field_val.replace(/\'/g, "#39;");
  field_val = field_val.replace(/\"/g, "#34;");
  field_val = field_val.replace(/\+/g, "#43;");
  field_val = field_val.replace(/\\/g, "#92;");
  field_val = field_val.replace(/\//g, "#47;");
  return trim(field_val);
}


function parse_entities(field_val)
{
  field_val = field_val.replace(/\&gt;/g, ">");
	field_val = field_val.replace(/\&lt;/g, "<");
	field_val = field_val.replace(/\&amp;/g, "&");
	field_val = field_val.replace(/\&quot;/g, "\"");
	return field_val;
}

function toggleHyperlinkAvailability(isDisabled)
{
  var objHyperlinks = document.links;
  if (isDisabled)
  {
    disabledHyperlinkInfo = new Object();
    for(i = 0; i < objHyperlinks.length; i++)
    {
      // Only disable those hyperlinks that are actually visible
      if (objHyperlinks[i].style.display != 'none')
      {
				disabledHyperlinkInfo[objHyperlinks[i].id] = new Object();
				disabledHyperlinkInfo[objHyperlinks[i].id]['href'] = objHyperlinks[i].href;
				objHyperlinks[i].href = "javascript:alert('Update is in progress. Please wait...');";
				if (objHyperlinks[i].onmousedown != null)
					disabledHyperlinkInfo[objHyperlinks[i].id]['onMouseDown'] = objHyperlinks[i].onmousedown.toString().getFunctionBody();
				else
					disabledHyperlinkInfo[objHyperlinks[i].id]['onMouseDown'] = null;
				objHyperlinks[i].onmousedown = function() { return false; }
				objHyperlinks[i].disabled = true;
      }
    }
  }
  else
  {
    for(i = 0; i < objHyperlinks.length; i++)
    {
      // Only enable those hyperlinks that are actually visible
      if (objHyperlinks[i].style.display != 'none')
      {
				if (disabledHyperlinkInfo[objHyperlinks[i].id])
				{
					objHyperlinks[i].href = disabledHyperlinkInfo[objHyperlinks[i].id]['href'];
					if (disabledHyperlinkInfo[objHyperlinks[i].id]['onMouseDown'] != null)
					{
						objHyperlinks[i].onmousedown = new Function(disabledHyperlinkInfo[objHyperlinks[i].id]['onMouseDown']);
					}
					objHyperlinks[i].disabled = false;
				}
			}
		}
		disabledHyperlinkInfo = null;
	}
}


String.prototype.getFunctionBody = function()
{
  var str = this.toString();
  // Flush out everything that precedes the opening { character of the function's body
  str = str.replace(/[^\{]+\{/, "");
  // Flush out everything that follows the closing } character of the function's body
	str = str.replace(/\}[^\}]*$/, "");
  // Flush out all the blank lines
  str = str.replace(/\n/gi, "");
  return str;
}

function show_system_notification(height_offset, notification_msg_code)
{
  // Re-position the "PAGE LOADING" message to the centre of the screen
  var h_offset = getScrollY();
  var w_0 = getWindowWidth();
  var h_0 = getWindowHeight();
  var h = document.getElementById('system_notification').style.height; h = h.replace(/px/, "");
  var w = document.getElementById('system_notification').style.width; w = w.replace(/px/, "");

  var notification_msg_text = "";
  switch (notification_msg_code)
  {
    case "PG_LD" :
    	notification_msg_text = "Page loading...";
      break;
		case "SUBMIT" :
    	notification_msg_text = "Submitting...";
      break;
    case "SEARCH" :
      notification_msg_text = "Searching...";
      break;
    case "VERIFY" :
      notification_msg_text = "Verifying...";
      break;
    case "UPD_ANC" :
      notification_msg_text = "Updating announcement details...";
      break;
    case "REM_ANC" :
			notification_msg_text = "Removing announcement...";
			break;
    case "UPD_EV" :
      notification_msg_text = "Updating event details...";
      break;
    case "ADD_EV" :
      notification_msg_text = "Adding event details...";
      break;
    case "UPL_ILL" :
      notification_msg_text = "Uploading illustration...";
      break;
    case "REM_ILL" :
      notification_msg_text = "Removing illustration...";
      break;
    case "UPL_DOC" :
      notification_msg_text = "Uploading document...";
      break;
    case "REM_DOC" :
      notification_msg_text = "Removing document...";
      break;
    case "GET_DET" :
			notification_msg_text = "Retrieving details...";
			break;
    case "UPD_MB" :
			notification_msg_text = "Updating member details...";
			break;
    case "UPD_MLG" :
			notification_msg_text = "Updating mailgroup details...";
			break;
    case "ADD_MB" :
			notification_msg_text = "Adding member details...";
			break;
    case "REM_MB" :
			notification_msg_text = "Removing member...";
			break;
    case "AUTH" :
			notification_msg_text = "Authorising...";
			break;
    case "INIT" :
			notification_msg_text = "Initialising...";
			break;
    case "UPL_XML" :
			notification_msg_text = "Uploading member XML file...";
			break;
    case "UPD_BNR" :
     	notification_msg_text = "Updating banner details...";
     	break;
    case "ADD_BNR" :
     	notification_msg_text = "Adding banner details...";
     	break;
    case "REM_BNR" :
     	notification_msg_text = "Removing banner...";
     	break;
    case "UPL_BNR_IMG" :
    	notification_msg_text = "Uploading banner image...";
			break;
    case "REM_BNR_IMG" :
			notification_msg_text = "Removing banner image...";
			break;
		case "UPD_NLTR" :
			notification_msg_text = "Updating newsletter details...";
			break;
		case "ADD_NLTR" :
			notification_msg_text = "Adding newsletter details...";
			break;
		case "REM_NLTR" :
			notification_msg_text = "Removing newsletter...";
			break;
    case "UPL_NLTR_IMG" :
    	notification_msg_text = "Uploading newsletter image...";
			break;
    case "REM_NLTR_IMG" :
			notification_msg_text = "Removing newsletter image...";
			break;
		case "REL_NLTR" :
			notification_msg_text = "Releasing newsletter...";
			break;
		case "UNREL_NLTR" :
			notification_msg_text = "Un-releasing newsletter...";
			break;
		case "ADD_NEWS" :
			notification_msg_text = "Adding news article...";
			break;
		case "UPD_NEWS" :
			notification_msg_text = "Updating news article...";
			break;
    case "REM_NEWS" :
      notification_msg_text = "Removing news article...";
      break;
		case "REM_PLN" :
			notification_msg_text = "Removing registration plan...";
			break;
		case "REL_PLN" :
			notification_msg_text = "Releasing registration plan...";
			break;
		case "CLS_PLN" :
			notification_msg_text = "Closing registration plan...";
			break;
		case "LOGOUT" :
			notification_msg_text = "Logging out...";
			break;
  }
  document.getElementById('notification_text').innerHTML = notification_msg_text;

  document.getElementById('system_notification').style.left = ((w_0 - w)/2) + "px";
  document.getElementById('system_notification').style.top = (h_offset + ((h_0 - h)/2) - height_offset) + "px";
  document.getElementById('system_notification').style.display = 'inline';
  if (navigator.appName.indexOf("Internet Explorer") != -1)
  {
    document.getElementById('system_notification_block').style.left = ((w_0 - w)/2) + "px";
    document.getElementById('system_notification_block').style.top = (h_offset + ((h_0 - h)/2) - height_offset) + "px";
    document.getElementById('system_notification_block').style.display = 'inline';
  }
}

function pause_execution(pause_duration)
{
  objDate = new Date(); var curDate = null;
  do
  {
    var curDate = new Date();
  }
  while(curDate - objDate < pause_duration);
  return true;
}

function getScrollY()
{
  var scrOfY = 0;
  if (typeof(window.pageYOffset) == 'number' )
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getWindowWidth()
{
  var myWidth = 0;
  if (typeof(window.innerWidth) == 'number')
  {
    //Non-IE
    myWidth = window.innerWidth;
  }
  else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  }
  else if (document.body && (document.body.clientWidth || document.body.clientHeight))
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getWindowHeight()
{
  var myHeight = 0;
  if (typeof(window.innerHeight) == 'number')
  {
    //Non-IE
    myHeight = window.innerHeight;
  }
  else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if (document.body && (document.body.clientWidth || document.body.clientHeight))
  {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function preload_image(system_name, image_filename, secure_flag)
{
  var x = new Image();
  if (secure_flag)
    x.src = secure_domain + system_name + (system_name == "" ? "" : "/") + "icons/" + image_filename;
  else
    x.src = public_domain + system_name + (system_name == "" ? "" : "/") + "icons/" + image_filename;
}

function titleCase(str)
{
  var strOut = "";
  var str_array = str.split(/\s/);

  for (var i = 0; i < str_array.length; i++)
  {
    str_array[i] = str_array[i].toLowerCase();
    str_array[i] = str_array[i].replace(/^[a-z]/, str_array[i].substring(0, 1).toUpperCase());
  }
  strOut = str_array.join(" ");
  return strOut;
}

function count_number(num_Str)
{
	if (num_Str == "11" || num_Str == "12" || num_Str == "13")
		return "th";
	if (num_Str.match(/1$/))
		return "st";
	if (num_Str.match(/2$/))
		return "nd";
	if (num_Str.match(/3$/))
		return "rd";
	return "th";
}

function change_region(region_id)
{
	// Display the logo label of the selected region and highlight the link programmatically
	if (region_id == "001")
	{
		document.getElementById('region_label').style.display = "none";
		document.getElementById('dynamic_logo').src = public_domain + "images/global/logo/aujs_region_000.png";
	}
	else
	{
		document.getElementById('region_label').style.display = "inline";
		document.getElementById('dynamic_logo').src = public_domain + "images/global/logo/aujs_region_" + region_id + ".png";
	}
	document.getElementById("lnk_UNIT_" + region_id).className = "current_region_link";

	// Display the banner of the selected region
	display_region_banner(region_id);
}

function refilter_campus_list(region_id)
{
  var i = 0;
  // Clear the campus dropdown
  for (i = document.getElementById('filtered_campus_selector').options.length - 1; i >= 0; i--)
	  document.getElementById('filtered_campus_selector').remove(i);

	if (region_id == "001")
	{
		for (i = 0; i < document.getElementById('campus_selector').options.length; i++)
		{
			var opt_val = document.getElementById('campus_selector').options[i].value;
			var opt_txt = document.getElementById('campus_selector').options[i].text;
			document.getElementById('filtered_campus_selector').options[i] = new Option(opt_txt, opt_val);
		}
	}
	else
	{
		var j = 0;
		for (i = 0; i < document.getElementById('campus_selector').options.length; i++)
		{
			var opt_val = document.getElementById('campus_selector').options[i].value;
			var opt_txt = document.getElementById('campus_selector').options[i].text;
			if (opt_val.indexOf("_" + region_id + "_") != -1 || opt_val == "campus_region_separator")
			{
				document.getElementById('filtered_campus_selector').options[j] = new Option(opt_txt, opt_val);
				j++;
			}
		}
		
		// If the last item in the filtered_campus_selector dropdown is the ------------ separator then 
		// it means the region has no campuses and the separator must be removed from the dropdown
		if (document.getElementById('filtered_campus_selector').options[j - 1].value == "campus_region_separator")
		{
			document.getElementById('filtered_campus_selector').remove(j - 1);
		}
	}
	prepare_event_summary_XML();
	prepare_news_summary_XML(region_id, "GENERAL_NEWS");
	document.getElementById('filtered_campus_selector').value = get_Cookie_Value("campus_region_code=");
}


function display_region_banner(region_id)
{
 if (window.XMLHttpRequest)
    var objHttpRequest = new XMLHttpRequest();
  else if(window.ActiveXObject)
    var objHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");

  if (objHttpRequest)
  {
    objHttpRequest.onreadystatechange = function()
    {
      if (objHttpRequest.readyState == 4)
      {
				if (!objHttpRequest.responseXML)
					return;
    		objBannerXML = objHttpRequest.responseXML.getElementsByTagName('banner');

				// Setup the hyperlink for the dynamic banner image
				if (objBannerXML[0].getAttribute('img_link'))
				{
					document.getElementById('img_banner_link').href = parse_entities(objBannerXML[0].getAttribute('img_link'));
					document.getElementById('img_banner_link').target = "_blank";
				}
				else document.getElementById('img_banner_link').href = "javascript:void(0);";

				// Setup the file path for the dynamic banner image
				/*if (region_id == "001")
					document.getElementById('img_banner').src = "frontpage_banners/banner_images/" + objBannerXML[0].getAttribute('img_path');
				else*/
				document.getElementById('img_banner').src = public_domain + "frontpage_banners/banner_images/" + objBannerXML[0].getAttribute('img_path');

				// Setup the tooltip text for the dynamic banner image
				if (objBannerXML[0].getAttribute('img_tooltip'))
					document.getElementById('img_banner').title = objBannerXML[0].getAttribute('img_tooltip');
				else
					document.getElementById('img_banner').title = "";
      }
    }
    objHttpRequest.open("POST", public_domain + "includes/build_region_banner.php", true);
    objHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    objHttpRequest.send("action=build_regional_website_banner" + "&" + "region_id=" + region_id);
  }
}


function display_alumni_banner()
{
 if (window.XMLHttpRequest)
    var objHttpRequest = new XMLHttpRequest();
  else if(window.ActiveXObject)
    var objHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");

  if (objHttpRequest)
  {
    objHttpRequest.onreadystatechange = function()
    {
      if (objHttpRequest.readyState == 4)
      {
				if (!objHttpRequest.responseXML)
					return;
    		objBannerXML = objHttpRequest.responseXML.getElementsByTagName('banner');

				// Setup the hyperlink for the dynamic banner image
				if (objBannerXML[0].getAttribute('img_link'))
				{
					document.getElementById('img_banner_link').href = parse_entities(objBannerXML[0].getAttribute('img_link'));
					document.getElementById('img_banner_link').target = "_blank";
				}
				else document.getElementById('img_banner_link').href = "javascript:void(0);";

				// Setup the file path for the dynamic banner image
				document.getElementById('img_banner').src = "../frontpage_banners/banner_images/" + objBannerXML[0].getAttribute('img_path');

				// Setup the tooltip text for the dynamic banner image
				if (objBannerXML[0].getAttribute('img_tooltip'))
					document.getElementById('img_banner').title = objBannerXML[0].getAttribute('img_tooltip');
				else
					document.getElementById('img_banner').title = "";
      }
    }
    objHttpRequest.open("POST", public_domain + "includes/build_region_banner.php", true);
    objHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    objHttpRequest.send("action=build_alumni_banner");
  }
}



function prepare_news_summary_XML(region_id, news_category)
{
 if (window.XMLHttpRequest)
    var objHttpRequest = new XMLHttpRequest();
  else if(window.ActiveXObject)
    var objHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	var objNewsFeed;
	var strContent;

  if (objHttpRequest)
  {
    objHttpRequest.onreadystatechange = function()
    {
			if (news_category == "ALUMNI_NEWS")
				show_system_notification(0, "PG_LD");
			
      if (objHttpRequest.readyState == 4)
      {
				objNewsFeed = objHttpRequest.responseXML.getElementsByTagName('news_item');
				strContent = "";
				for (i = 0; i < objNewsFeed.length; i++)
				{
					strContent += "<h4><a href=\"" + public_domain + "news_mgmt/news_viewer.php?news_viewer_GUID=" + 
						objNewsFeed[i].getAttribute('GUID') + "\" target=\"_blank\">" + objNewsFeed[i].getAttribute('headline') + 
						"</a></h4><p style=\"text-align:justify\">" + objNewsFeed[i].getAttribute('summary') + "</p>";
				}
				
				if (news_category == "ALUMNI_NEWS")
				{
					document.getElementById('news_section').innerHTML = strContent;
					pause_execution(1500);
					document.getElementById('system_notification').style.display = 'none';
					document.getElementById('system_notification_block').style.display = 'none';
					document.getElementById('wrapper').style.display = 'block';
				}
				else document.getElementById('news_section').innerHTML = strContent;
			}
		}
    objHttpRequest.open("POST", public_domain + "includes/build_news_feed.php", true);
    objHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    objHttpRequest.send("action=build_latest_news_summary" + "&" + "region_id=" + region_id + 
			"&" + "news_category=" + news_category);
	}
}


function convertCarriageReturns(strArgVal)
{
	var strCarriageReturn = "";
	var bypassEscape = (convertCarriageReturns.arguments[1] ? true : false);
	
	strArgVal = escape(strArgVal);
	if (strArgVal.match("\%0D\%0A"))
		strCarriageReturn = "\%0D\%0A";	// Windows platform
	else if (strArgVal.match("\%0D"))
		strCarriageReturn = "\%0D";	// Macintosh platform
	else
		strCarriageReturn = "\%0A";	// other platforms (*nix, VMS, etc.)

	// Convert OS-specific carriage returns to <BR> line breaks (when submitting)
	var rx = new RegExp(strCarriageReturn, "g");
	strArgVal = strArgVal.replace(rx, "<BR>");
	if (bypassEscape)
		strArgVal = unescape(strArgVal);
	else
		strArgVal = escape_and_trim(unescape(strArgVal));
	return strArgVal;
}


function readCarriageReturns(strArgVal)
{
	var strCarriageReturn = "";
	if (navigator.userAgent.toUpperCase().indexOf('WINDOWS'))
		strCarriageReturn = "%0D%0A";	// Windows platform
	else if (navigator.userAgent.toUpperCase().indexOf('MACINTOSH'))
		strCarriageReturn = "%0D";	// Macintosh platform
	else
		strCarriageReturn = "%0A";	// other platforms (*nix, VMS, etc.)

	// Convert <BR> line breaks to OS-specific carriage returns (when switching into edit mode)
	strArgVal = strArgVal.replace(/(\#\d{2};)/g, "&$1").replace(/\&\#60;/g, "<").replace(/\&\#62;/g, ">");
	var rx = new RegExp("<BR\/?>", "gi");
	strArgVal = strArgVal.replace(/\r\n/g, "");
	strArgVal = strArgVal.replace(/\n/g, "");
	strArgVal = strArgVal.replace(rx, strCarriageReturn);
	strArgVal = parse_entities(unescape(strArgVal));
	return strArgVal;
}


function generate_section(section_type, id_num, title_required)
{
	var contentStr = "<hr/><table width=\"632px\" cellspacing=\"15\" align=\"center\">";
	if (title_required)
	{
		contentStr += "<tr><td" + ((section_type != 'graphic_only' && section_type != 'text_only') ? " colspan=\"2\">" : ">") + 
			"<div id='title_display_" + id_num + "' style=\"font-family: 'Verdana'; font-size: 12px; " + 
	  	"font-weight: bold; color: #3300FF; display:none\"></div>" + 
			"<input id='title_edit_" + id_num + "' type=\"text\" class=\"event_title_edited\" style=\"display:inline; " + 
			"width:550px\" value=\"Section title goes here\" />" + 
			"</td></tr>";
	}
	if (section_type == "graphic_only")
	{
		contentStr += "<tr><td valign=\"middle\" align=\"center\" " + 
				"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
				"background-color:#FFFFFF; border:1px solid #000000; height:150px; width:602px\">" +  
				"<span id='img_unavailable_" + id_num + "' style=\"width:100%\">Image goes here</span>" +
			"</td></tr>" +
			"<tr><td>" +
				"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left;\">" +
					"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
						"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'long')\">" +
						"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
						"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
					"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' " + 
						"style=\"display:none\" onMouseDown=\"clear_illustration_image('" + id_num + "', 'long')\">" +
						"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
						"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
					"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
						"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
						"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
						"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
				"</div>" +
				"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
					"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
						"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
						"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
						"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
					"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
						"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
						"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
						"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
					"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
						"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
						"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
						"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
				"</div>" +
			"</td></tr>";
	}
	else if (section_type == "text_only")
	{
		contentStr += "<tr><td>" + 
			"<div id='text_display_long_1_" + id_num + "' style=\"width:602px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_long_1_" + id_num + "_RTE", "602px", "");
		
		/*"<textarea id='text_edit_long_1_" + id_num + "' rows=\"7\" class=\"text_value_edited\" " + 
		"style=\"display:inline; width:602px\">Text goes here</textarea>"*/
		
		contentStr += "</td></tr>" +
			"<tr><td>" +
				"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left;\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
				"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	else if (section_type == "graphic_left_text_around")
	{
		contentStr += "<tr><td valign=\"middle\" align=\"center\" " + 
				"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
				"background-color:#FFFFFF; border:1px solid #000000; height:100px; width:180px\">" +
				"<span id='img_unavailable_" + id_num + "' style=\"width:100%\">Image goes here</span>" +
			"</td><td valign=\"top\">" +
				"<div id='text_display_short_1_" + id_num + "' style=\"width:405px; height:100px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; text-align:left; display:none\"></div>";
		contentStr += construct_RTE("text_edit_short_1_" + id_num + "_RTE", "412px", "");
						
		/*"<textarea id='text_edit_short_1_" + id_num + "' class=\"text_value_edited\" " + 
		"style=\"display:inline; width:405px; height:100px\" rows=\"7\">Text goes here</textarea>"*/
		
		contentStr +=	"</td></tr>" +
			"<tr><td colspan=\"2\" valign=\"top\">" +
				"<div id='text_display_long_2_" + id_num + "' style=\"width:602px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_long_2_" + id_num + "_RTE", "602px", "");
		
		/*"<textarea id='text_edit_long_2_" + id_num + "' class=\"text_value_edited\" " + 
		"style=\"display:inline; width:602px\" rows=\"5\">Text goes here</textarea>"*/
		
		contentStr +=	"</td></tr>" +
			"<tr><td colspan=\"2\">" +
			"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left;\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
					"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
					"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' " + 
					"style=\"display:none\" onMouseDown=\"clear_illustration_image('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
					"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
			"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style='vertical-align:middle; float:right; clear:none'>" +
				"<a href='javascript:void(0)' id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href='javascript:void(0)' id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					" title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	else if (section_type == "graphic_right_text_around")
	{
		contentStr += "<tr><td align=\"left\" valign=\"top\">" +
				"<div id='text_display_short_1_" + id_num + "' style=\"width:405px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; height:100px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_short_1_" + id_num + "_RTE", "412px", "");
		
		/*"<textarea id='text_edit_short_1_" + id_num + "' class=\"text_value_edited\" " + 
		"style=\"display:inline; width:405px; height:100px;\" rows=\"7\">Text goes here</textarea>"*/
		
		contentStr += "</td><td valign=\"middle\" align=\"center\" " + 
			"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
				"background-color:#FFFFFF; border:1px solid #000000; height:100px; width:180px\">" +
				"<span id='img_unavailable_" + id_num + "' style=\"width:100%\">Image goes here</span>" +
			"</td></tr>" +
			"<tr><td colspan=\"2\">" +
				"<div id='text_display_long_2_" + id_num + "' style=\"width:602px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_long_2_" + id_num + "_RTE", "602px", "");
		
		/*"<textarea id='text_edit_long_2_" + id_num + "' class=\"text_value_edited\" " + 
		"style=\"display:inline; width:602px\" rows=\"5\">Text goes here</textarea>"*/
		
		contentStr +=	"</td></tr>" +
			"<tr><td colspan=\"2\">" +
			"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
					"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
					"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' " + 
					"style=\"display:none\" onMouseDown=\"clear_illustration_image('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
					"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
			"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	else if (section_type == "graphic_above_text_below")
	{
		contentStr += "<tr><td valign=\"middle\" align=\"center\" " + 
				"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
				"background-color: #FFFFFF; border:1px solid #000000; height:100px; width:602px\">" +
				"<span id='img_unavailable_" + id_num + "' style=\"width:100%\">Image goes here</span>" +
			"</td></tr>" +
			"<tr><td>" +
				"<div id='text_display_long_1_" + id_num + "' style=\"width:602px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_long_1_" + id_num + "_RTE", "602px", "");
		
		/*"<textarea id='text_edit_long_1_" + id_num + "' rows=\"5\" class=\"text_value_edited\" " + 
		"style=\"display:inline; width:602px\">Text goes here</textarea>"*/
		
		contentStr += "</td></tr>" +
			"<tr><td>" +
			"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
					"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'long')\">" +
					"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
					"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' style=\"display:none\" " + 
					"onMouseDown=\"clear_illustration_image('" + id_num + "', 'long')\">" +
					"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
					"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
			"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	else if (section_type == "graphic_below_text_above")
	{
		contentStr += "<tr><td><div id='text_display_long_1_" + id_num + "' style=\"width:602px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_long_1_" + id_num + "_RTE", "602px", "");

		/*"<textarea id='text_edit_long_1_" + id_num + "' rows=\"5\" class=\"text_value_edited\" " + 
		"style=\"display:inline; width:602px;\">Text goes here</textarea>"*/
		
		contentStr +=	"</td></tr>" +
			"<tr><td valign=\"middle\" align=\"center\" " + 
				"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
				"background-color: #FFFFFF; border:1px solid #000000; height:100px; margin:0px; padding:0px; width:602px\">" +
				"<span id='img_unavailable_" + id_num + "' style=\"width:100%\">Image goes here</span>" +
			"</td></tr>" +
			"<tr><td>" +
			"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left;\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
					"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'long')\">" +
					"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
					"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' style=\"display:none\" " + 
					"onMouseDown=\"clear_illustration_image('" + id_num + "', 'long')\">" +
					"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
					"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
			"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	else if (section_type == "graphic_left_text_right")
	{
		contentStr += "<tr><td valign=\"middle\" align=\"center\" " + 
			"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
			"background-color:#FFFFFF; width:180px; border:1px solid #000000; height:100px\">" + 
				"<span id='img_unavailable_" + id_num + "' style=\"padding:15px 0px 15px 15px; width:100%\">Image goes here</span></td>" +
				"<td valign=\"top\">" +
				"<div id='text_display_short_1_" + id_num + "' style=\"width:405px; float:left; height:100px; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_short_1_" + id_num + "_RTE", "412px", "");
		
		/*"<textarea id='text_edit_short_1_"+ id_num + "' class=\"text_value_edited\" " + 
		"style=\"display:inline; width:405px; height:100px\" rows=\"7\">Text goes here</textarea>"*/
		
		contentStr +=	"</td></tr>" +
			"<tr><td colspan=\"2\">" +
			"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
					"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
					"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' style=\"display:none\" " + 
					"onMouseDown=\"clear_illustration_image('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
					"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
			"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	else if (section_type == "graphic_right_text_left")
	{
		contentStr += "<tr><td valign=\"top\">" +
				"<div id='text_display_short_1_" + id_num + "' style=\"width:405px; float:left; line-height:1.5; " + 
				"font-family:Arial,Helvetica,sans-serif; font-size:11px; height:100px; display:none\"></div>";
		contentStr += construct_RTE("text_edit_short_1_" + id_num + "_RTE", "412px", "");
		
		/*"<textarea id='text_edit_short_1_" + id_num + "' class=\"text_value_edited\" " + 
		"style=\"display:inline; width:405px; height:100px\" rows=\"7\">Text goes here</textarea>"*/
		
		contentStr +=	"</td><td valign=\"middle\" align=\"center\" " + 
				"style=\"font-family:Verdana; font-size:10px; color:#003366; font-weight:bold; " + 
				"border:1px solid #000000; background-color:#FFFFFF; height:100px; width:180px\">" +
				"<span id='img_unavailable_" + id_num + "' style=\"width:100%\">Image goes here</span>" +
			"</td></tr>" +
			"<tr><td colspan=\"2\">" +
			"<div id='section_" + id_num + "_image_icons' style=\"vertical-align:middle; float:left\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_selection' " + 
					"onMouseDown=\"showHide_illustration_upload_box('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_selection' src=\"icons/add_section_image.png\" " + 
					"title=\"Load illustration\" alt=\"Load illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_image_clear' style=\"display:none\" " + 
					"onMouseDown=\"clear_illustration_image('" + id_num + "', 'short')\">" +
					"<img id='img_section_" + id_num + "_image_clear' src=\"icons/clear_section_image.png\" " + 
					"title=\"Clear illustration\" alt=\"Clear illustration\" border=\"0\" /></a>&nbsp;" + 
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_document_selection' " + 
					"onMouseDown=\"showHide_document_upload_box('" + id_num + "', 'document')\">" + 
					"<img id='img_document_selection_" + id_num + "' src=\"icons/add_document.gif\" " + 
					"title=\"Load document\" alt=\"Load document\" border=\"0\" /></a>" +
			"</div>" +
			"<div id='section_" + id_num + "_clear_icon' style=\"vertical-align:middle; float:right; clear:none\">" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_clear' " + 
					"onMouseDown=\"clear_section('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_clear' src=\"icons/clear_section.png\" " + 
					"title=\"Clear section\" alt=\"Clear section\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_up' " + 
					"onMouseDown=\"move_section_up('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_up' src=\"icons/move_section_up.png\" " + 
					"title=\"Move section up\" alt=\"Move section up\" border=\"0\" /></a>&nbsp;&nbsp;" +
				"<a href=\"javascript:void(0)\" id='section_" + id_num + "_move_down' " + 
					"onMouseDown=\"move_section_down('section_" + id_num + "')\">" +
					"<img id='img_section_" + id_num + "_move_down' src=\"icons/move_section_down.png\" " + 
					"title=\"Move section down\" alt=\"Move section down\" border=\"0\" /></a>" +
			"</div>" +
			"</td></tr>";
	}
	contentStr += "</table>";
	
	return contentStr;
}


function move_section_up(section_id)
{
	var current_section = document.getElementById(section_id);
	var prev_section = current_section.previousSibling;
	var content_to_be_moved = current_section.innerHTML;
	
	if (prev_section != null)
	{
		// Get the previous "<div>" node. Loop needed because in Firefox previousSibling may return a text node.
		while (prev_section.nodeType != 1)
		{
			prev_section = prev_section.previousSibling;
		}
		
		if (prev_section.id.match(/section_\d+/))
		{
			// Get section numbers
			var prev_section_num = prev_section.id.replace("section_", "");
			var current_section_num = current_section.id.replace("section_", "");

			// Capture the values of titles (if they exist) for current and previous sections			
			if (document.getElementById('title_edit_' + current_section_num))
				current_title = document.getElementById('title_edit_' + current_section_num).value;
			else
				current_title = null;
			if (document.getElementById('title_edit_' + prev_section_num))
				prev_title = document.getElementById('title_edit_' + prev_section_num).value;
			else
				prev_title = null;
			
			// Capture the values of textareas for current section
			if (document.getElementById('text_edit_short_1_' + current_section_num))
			{
				var current_textarea_short = document.getElementById('text_edit_short_1_' + current_section_num).value;
			}
			if (document.getElementById('text_edit_long_1_' + current_section_num))
			{
				var current_textarea_long_1 = document.getElementById('text_edit_long_1_' + current_section_num).value;
			}
			if (document.getElementById('text_edit_long_2_' + current_section_num))
			{
				var current_textarea_long_2 = document.getElementById('text_edit_long_2_' + current_section_num).value;
			}
			
			// Capture the values of textareas for previous section
			if (document.getElementById('text_edit_short_1_' + prev_section_num))
			{
				var prev_textarea_short = document.getElementById('text_edit_short_1_' + prev_section_num).value;
			}
			if (document.getElementById('text_edit_long_1_' + prev_section_num))
			{
				var prev_textarea_long_1 = document.getElementById('text_edit_long_1_' + prev_section_num).value;
			}
			if (document.getElementById('text_edit_long_2_' + prev_section_num))
			{
				var prev_textarea_long_2 = document.getElementById('text_edit_long_2_' + prev_section_num).value;
			}
			
			// Swap the content of the two sections
			current_section.innerHTML = prev_section.innerHTML;
			prev_section.innerHTML = content_to_be_moved;
					
			// Re-instate the text values in titles after the swap
			if (current_title != null && document.getElementById('title_edit_' + current_section_num))
				document.getElementById('title_edit_' + current_section_num).value = current_title;
			if (prev_title != null && document.getElementById('title_edit_' + prev_section_num))
				document.getElementById('title_edit_' + prev_section_num).value = prev_title;

			// Re-instate the text values in short textareas after the swap
			if (document.getElementById('text_edit_short_1_' + current_section_num))
				document.getElementById('text_edit_short_1_' + current_section_num).value = readCarriageReturns(current_textarea_short);
			if (document.getElementById('text_edit_short_1_' + prev_section_num))
				document.getElementById('text_edit_short_1_' + prev_section_num).value = readCarriageReturns(prev_textarea_short);
			
			// Re-instate the text values in long textareas 1 after the swap
			if (document.getElementById('text_edit_long_1_' + current_section_num))
				document.getElementById('text_edit_long_1_' + current_section_num).value = readCarriageReturns(current_textarea_long_1);
			if (document.getElementById('text_edit_long_1_' + prev_section_num))
				document.getElementById('text_edit_long_1_' + prev_section_num).value = readCarriageReturns(prev_textarea_long_1);

			// Re-instate the text values in long textareas 2 after the swap
			if (document.getElementById('text_edit_long_2_' + current_section_num))
				document.getElementById('text_edit_long_2_' + current_section_num).value = readCarriageReturns(current_textarea_long_2);
			if (document.getElementById('text_edit_long_2_' + prev_section_num))
				document.getElementById('text_edit_long_2_' + prev_section_num).value = readCarriageReturns(prev_textarea_long_2);
			
			// Swap the IDs of the two section DIVs
			var temp_val = prev_section.id;
			prev_section.id = section_id;
			current_section.id = temp_val;
			var prev_section_id = prev_section.id.replace("section_", "");
			var current_section_id = current_section.id.replace("section_", "");
		}
	}
}


function move_section_down(section_id)
{
	var current_section = document.getElementById(section_id);
	var next_section = current_section.nextSibling;
	var content_to_be_moved = current_section.innerHTML;
		
	if (next_section != null)
	{
		// Get the next "<div>" node. Loop needed because in Firefox nextSibling may return a text node.
		while (next_section.nodeType != 1)
		{
			next_section = next_section.nextSibling;
		}
	
		if (next_section.id.match(/section_\d+/))
		{
			// Get section numbers
			var next_section_num = next_section.id.replace("section_", "");
			var current_section_num = current_section.id.replace("section_", "");
			
			// Capture the values of titles for current and next sections
			if (document.getElementById('title_edit_' + current_section_num))
				current_title = document.getElementById('title_edit_' + current_section_num).value;
			else
				current_title = null;
			if (document.getElementById('title_edit_' + next_section_num))
				next_title = document.getElementById('title_edit_' + next_section_num).value;
			else
				next_title = null;
			
			// Capture the values of textareas for current section
			if (document.getElementById('text_edit_short_1_' + current_section_num))
			{
				var current_textarea_short = document.getElementById('text_edit_short_1_' + current_section_num).value;
			}
			if (document.getElementById('text_edit_long_1_' + current_section_num))
			{
				var current_textarea_long_1 = document.getElementById('text_edit_long_1_' + current_section_num).value;
			}
			if (document.getElementById('text_edit_long_2_' + current_section_num))
			{
				var current_textarea_long_2 = document.getElementById('text_edit_long_2_' + current_section_num).value;
			}
			
			// Capture the values of textareas for next section
			if (document.getElementById('text_edit_short_1_' + next_section_num))
			{
				var next_textarea_short = document.getElementById('text_edit_short_1_' + next_section_num).value;
			}
			if (document.getElementById('text_edit_long_1_' + next_section_num))
			{
				var next_textarea_long_1 = document.getElementById('text_edit_long_1_' + next_section_num).value;
			}
			if (document.getElementById('text_edit_long_2_' + next_section_num))
			{
				var next_textarea_long_2 = document.getElementById('text_edit_long_2_' + next_section_num).value;
			}

			// Swap the content of the two sections
			current_section.innerHTML = next_section.innerHTML;
			next_section.innerHTML = content_to_be_moved;
			
			// Re-instate the text values in titles after the swap
			if (current_title != null && document.getElementById('title_edit_' + current_section_num))
				document.getElementById('title_edit_' + current_section_num).value = current_title;
			if (next_title != null && document.getElementById('title_edit_' + next_section_num))
				document.getElementById('title_edit_' + next_section_num).value = next_title;

			// Re-instate the text values in short textareas after the swap
			if (document.getElementById('text_edit_short_1_' + current_section_num))
				document.getElementById('text_edit_short_1_' + current_section_num).value = readCarriageReturns(current_textarea_short);
			if (document.getElementById('text_edit_short_1_' + next_section_num))
				document.getElementById('text_edit_short_1_' + next_section_num).value = readCarriageReturns(next_textarea_short);
			
			// Re-instate the text values in long textareas 1 after the swap
			if (document.getElementById('text_edit_long_1_' + current_section_num))
				document.getElementById('text_edit_long_1_' + current_section_num).value = readCarriageReturns(current_textarea_long_1);
			if (document.getElementById('text_edit_long_1_' + next_section_num))
				document.getElementById('text_edit_long_1_' + next_section_num).value = readCarriageReturns(next_textarea_long_1);

			// Re-instate the text values in long textareas 2 after the swap
			if (document.getElementById('text_edit_long_2_' + current_section_num))
				document.getElementById('text_edit_long_2_' + current_section_num).value = readCarriageReturns(current_textarea_long_2);
			if (document.getElementById('text_edit_long_2_' + next_section_num))
				document.getElementById('text_edit_long_2_' + next_section_num).value = readCarriageReturns(next_textarea_long_2);
			
			// Swap the IDs of the two section DIVs
			var temp_val = next_section.id;
			next_section.id = section_id;
			current_section.id = temp_val;
			var next_section_id = next_section.id.replace("section_", "");
			var current_section_id = current_section.id.replace("section_", "");			
		}
	}
}


function generate_created_on_stamp()
{
  var tempDate = new Date();
  var currentYr = tempDate.getFullYear();
	var currentMonth = tempDate.getMonth() + 1;
	var currentDay = tempDate.getDate();
	var currentHour = tempDate.getHours();
	var currentMinute = tempDate.getMinutes();
	var currentSecond = tempDate.getSeconds();
	currentMonth = (currentMonth.toString().length == 1) ? ("0" + currentMonth.toString()) : currentMonth;
	currentDay = (currentDay.toString().length == 1) ? ("0" + currentDay.toString()) : currentDay;
	currentHour = (currentHour.toString().length == 1) ? ("0" + currentHour.toString()) : currentHour;
	currentMinute = (currentMinute.toString().length == 1) ? ("0" + currentMinute.toString()) : currentMinute;
	currentSecond = (currentSecond.toString().length == 1) ? ("0" + currentSecond.toString()) : currentSecond;
	return (currentYr + "-" + currentMonth + "-" + currentDay + " " + currentHour + ":" + currentMinute + ":" + currentSecond);
}

function validate_HTML_tags(field_val)
{
  var j; var foundTags = field_val.match(/<[^!>]+>/g);
  if (foundTags == null)
    return true;

  for (j = 0; j < foundTags.length; j++)
  {
    var stripped_Tag = foundTags[j]; stripped_Tag = stripped_Tag.replace(/^<\//, "<");
    stripped_Tag = stripped_Tag.replace(/^< */, "");
    if (stripped_Tag.indexOf(' ') != -1)
      stripped_Tag = stripped_Tag.replace(/ [^>]*>$/, "");
    else
      stripped_Tag = stripped_Tag.replace(/(\/)?>$/, "");
    if (!search_array_elem(allowable_tags, stripped_Tag.toLowerCase()))
    {
      alert("HTML tag " + foundTags[j] + " is invalid");
      return false;
    }
  }
  return true;
}

function RGBtoHex(R, G, B)
{
	return toHex(R) + toHex(G) + toHex(B);
}

function toHex(N)
{
 if (N == null) return "00";
 N = parseInt(N); 
 if (N == 0 || isNaN(N)) return "00";
 N = Math.max(0, N);
 N = Math.min(N, 255);
 N = Math.round(N);
 return "0123456789ABCDEF".charAt((N - N%16)/16) + "0123456789ABCDEF".charAt(N % 16);
}


function validate_date_integrity(day_val, month_val, year_val, field_name)
{
  if (day_val == -1 && month_val == -1 && year_val == "") return true; // in case date is not specified

  if (day_val == -1 && (month_val != -1 || year_val != ""))
  {
    alert(field_name + " is incompletely specified");
    return false;
  }
  if (month_val == -1 && (day_val != -1 || year_val != ""))
  {
    alert(field_name + " is incompletely specified");
    return false;
  }
  if (year_val == "" && (day_val != -1 || month_val != -1))
  {
    alert(field_name + " is incompletely specified");
    return false;
  }
  return true;
}


function validate_date_year(year_val, field_name)
{
  if (year_val == "") return true; // in case date is not specified

  if (year_val.match(/[^\d]/) || year_val.match(/^0/))
  {
    alert(field_name + " has invalid format");
    return false;
  }
	
	if (field_name.indexOf("Date of birth") != -1)
	{
		if (!(parseInt(year_val) >= 1900 && parseInt(year_val) <= 1999))
		{
			alert(field_name + " must be between 1900 and 1999");
			return false;
		}
	}
  return true;
}


function validate_date_day_month(day_val, month_val, year_val, field_name)
{
  if (day_val == "-1" && month_val == "-1" && year_val == "") return true; // in case date is not specified

  // Check 31-day months
  if ((month_val == "0" || month_val == "2" || month_val == "4" || month_val == "6" ||
	  month_val == "7" || month_val == "9" || month_val == "11") && !(day_val >= 1 && day_val <= 31))
  {
    alert(field_name + " - incorrect date for the chosen month");
    return false;
  }
  // Check 30-day months
  if ((month_val == "3" || month_val == "5" || month_val == "8" || month_val == "10") &&
	  !(day_val >= 1 && day_val <= 30))
  {
    alert(field_name + " - incorrect date for the chosen month");
    return false;
  }
  // Check February and leap year
  if (month_val == "1")
  {
    if (((parseInt(year_val) % 4) == 0) && !(day_val >= 1 && day_val <= 29))
	{
      alert(field_name + " - incorrect date for the chosen month");
      return false;
    }
	if (((parseInt(year_val) % 4) != 0) && !(day_val >= 1 && day_val <= 28))
	{
      alert(field_name + " - incorrect date for the chosen month");
      return false;
    }
  }
  return true;
}


function auto_expand_collapse(objLink, imgArray)
{
	var expander = objLink.previousSibling.previousSibling.previousSibling;
	if (expander.onmousedown)
	{
		eval(expander.onmousedown.toString().getFunctionBody());
		if (expander.src.indexOf("minus.gif") > 0)
			expander.src = imgArray['tree_minus'].src;
		else if (expander.src.indexOf("minusbottom.gif") > 0)
			expander.src = imgArray['tree_minus_bottom'].src;
		else if (expander.src.indexOf("plus.gif") > 0)
			expander.src = imgArray['tree_plus'].src;
		else if (expander.src.indexOf("plusbottom.gif") > 0)
			expander.src = imgArray['tree_plus_bottom'].src;
	}
}


function reset_region_selection()
{
	var link_array = document.getElementsByTagName("a");
	for (var i = 0; i < link_array.length; i++)
	{
		if (link_array[i].id.indexOf("lnk_UNIT_0") != -1)
			link_array[i].className = "region_link";
	}
}


function construct_RTE(rte_name, rte_width, content_source_container)
{
	var contentHTML =	"<iframe id=\"" + rte_name + "\" name=\"" + rte_name + "\" " + 
		"src=\"" + secure_domain + "includes/rte/template_RTE.php?RTE_name=" + rte_name;
	
	if (content_source_container != "")
		contentHTML += "&amp;RTE_display_container=" + content_source_container;
	
	contentHTML += "\" style=\"margin:0px; margin-bottom: 0px; padding:0px; padding-bottom:0px; " + 
		"width:" + rte_width + "; height:210px; border:1px #3399CC solid;\" frameborder=\"0\" marginwidth=\"0\" " + 
		"marginheight=\"0\" scrolling=\"no\"></iframe>";
	
	return contentHTML;
}