<!--
// Global JavaScript Library
// Copyright 2005 CSI Manchester Ltd - All Rights Reserved

// Browser sniffer
var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

function CTSwitchPhoto(PlaceHolderName,ImagePath) {
	if (document.all) {
		document.getElementById(PlaceHolderName).style.filter="blendTrans(duration=1)";
		document.getElementById(PlaceHolderName).filters.blendTrans.Apply();
	}
	//is document.getElementById supported?
	if (document.getElementById) {
		document.getElementById(PlaceHolderName).src = ImagePath;
	}else{
		document.HotelImage.src = PhotoUrl;
	}
	// if fade transition is supported play it
	if (document.all){
		document.getElementById(PlaceHolderName).filters.blendTrans.Play();
	}
}

// Attaches objects dependent on browser
function object_attach(id)
{
	var obj;
	if(ns4) obj = document.layers[id];
	else if(ie4) obj = document.all[id];
	else if(ie5 || ns6) obj = document.getElementById(id);
	return obj;
}

// Shows/hides div objects
function div_switch(id, bShow, bBlock)
{
	
	temp_Obj = object_attach(id);
	if(ns4)
	{
		if(bShow==true)
		{
			if(bBlock==true) { temp_Obj.display = "block"; }
			else { temp_Obj.visibility = "show"; }
		}
		else
		{
			if(bBlock==true) { temp_Obj.display = "none"; }
			else { temp_Obj.visibility = "hide"; }
		}
	}
	else
	{
		if(bShow==true)
		{
			if(bBlock==true) { temp_Obj.style.display = "block"; }
			else { temp_Obj.style.visibility = "visible"; }
		}
		else
		{
			if(bBlock==true) { temp_Obj.style.display = "none"; }
			else { temp_Obj.style.visibility = "hidden"; }
		}
	}
}
function div_switch_auto(id)
{
	temp_Obj = object_attach(id);
	if(!temp_Obj) return;
	temp_Obj.style.display=(temp_Obj.style.display=="none"?"block":"none");
}
function showHideResultItems(id,sHideText,sShowText,bFlash)
{
	var oObjLayer = object_attach("_divHideShow" + id);
	var oObjImg = object_attach("_imgHideShow" + id);
	var oObjHref = object_attach("_hrefHideShow" + id);
	if(!oObjLayer) return;
	if(oObjLayer.style.display == "none")
	{
		if(bFlash==null) { oObjImg.src = "/images/ico_minus.gif"; } else { oObjImg.src = "/images/ico_minusFlash.gif"; }
		oObjHref.innerText = sHideText;
	}
	else
	{
		if(bFlash==null) { oObjImg.src = "/images/ico_plus.gif"; } else { oObjImg.src = "/images/ico_plusFlash.gif"; }
		oObjHref.innerText = sShowText;
	}
	oObjLayer.style.display = (oObjLayer.style.display == "none"?"block":"none");
}

function tabMouseOver(id,className)
{
	temp_Obj = object_attach(id);
	temp_Obj.className = className;
	temp_Obj = object_attach(id+'a');
	if(Right(className, 2)=='00')
		temp_Obj.className = 'white00';
	else
		temp_Obj.className = 'white';
}
// Clears a text field only if the value matches what is passed in
function clearField(fId, sMatch, sChange)
{
	if(sChange == null) sChange = '';
	if(fId.value == sMatch)
	{ fId.value = sChange; }
}
// Similar functionality to ASP Left command
function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
// Similar functionality to ASP Right command
function Right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// Cross-browser function to change the contents inside a DIV tag
function writeInDiv(text, id)
{
	if (document.getElementById)
	{ x = document.getElementById(id); x.innerHTML = ''; x.innerHTML = text; }
	else if (document.all)
	{ x = document.all[id]; x.innerHTML = text; }
	else if (document.layers)
	{ x = document.layers[id]; text2 = '<p>' + text + '</p>'; x.document.open(); x.document.write(text2); x.document.close(); }
}

// Shows popup calendar
function showCalendar3(calTitle,calTarget,calInit,calShowDOW)
{
	paramDOW = '';
	if(calShowDOW!=null)
	{ paramDOW = '&updateDOW='+calShowDOW; }
	if(calInit!=null)
	{ calendarWin=window.open("/includes/calendar.asp?initDate=" + eval("document." + calInit + "_d.value") + "/" + eval("document." + calInit + "_m.value") + "/" + eval("document." + calInit + "_y.value") + "&title=" + escape(calTitle) + "&field=" + escape(calTarget) + paramDOW,"calendarWin","width=220,height=200,left=" + ((screen.width-220)/2) + ",top=" + ((screen.height-200)/2) + ",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"); }
	else
	{ calendarWin=window.open("/includes/calendar.asp?initDate=" + eval("document." + calTarget + "_d.value") + "/" + eval("document." + calTarget + "_m.value") + "/" + eval("document." + calTarget + "_y.value") + "&title=" + escape(calTitle) + "&field=" + escape(calTarget) + paramDOW,"calendarWin","width=220,height=200,left=" + ((screen.width-220)/2) + ",top=" + ((screen.height-200)/2) + ",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"); }
	if(!calendarWin.opener) calendarWin.opener=self;
}

// Opens a popup window
function openPopupWin(popUrl, popWid, popHgt, popScroll, popResize)
{
	popupWin=window.open(popUrl,"popupWin","width=" + popWid + ",height=" + popHgt + ",left=" + ((screen.width-popWid)/2) + ",top=" + ((screen.height-popHgt)/2) + ",status=yes,toolbar=no,menubar=no,scrollbars=" + popScroll + ",resizable=" + popResize);
	if(!popupWin.opener) popupWin.opener=self;
}

// Print page function
function printPage()
{
	if(window.print)
	{ window.print(); }
	else
	{ alert("Your browser does not support this feature!\nPlease try pressing CTRL + P to print this page."); }
}

// Bookmark page function
function bookmarkPage(url, title)
{
	if (document.all) { window.external.AddFavorite(url, title); } else if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }
}

// Enquiry form validation
function checkEnquiryForm(fId)
{
	if(fId.enqEmail.value == '' || isValidField(fId.enqEmail.value,2) == false)
	{ alert("Please enter a valid email address before submitting your enquiry!"); fId.enqEmail.focus(); return false; }
	else if(fId.enqTitle.selectedIndex == 0)
	{ alert("Please select a title before submitting your enquiry!"); fId.enqTitle.focus(); return false; }
	else if(fId.enqFirstname.value == '' || fId.enqFirstname.value == '- Firstname -')
	{ alert("Please enter a firstname before submitting your enquiry!"); fId.enqFirstname.focus(); return false; }
	else if(fId.enqSurname.value == '' || fId.enqSurname.value == '- Surname -')
	{ alert("Please enter a surname before submitting your enquiry!"); fId.enqSurname.focus(); return false; }
	else if(fId.enqTelDay.value == '' && fId.enqTelEve.value == '' && fId.enqTelMob.value == '')
	{ alert("Please enter at least one contact telephone number!"); fId.enqTelDay.focus(); return false; }
	else if(fId.enqEnquiry.value == '')
	{ alert("Please enter a valid comment before submitting your enquiry!"); fId.enqEnquiry.focus(); return false; }
	else
	{ return true; }
}

// Checks if field contains valid characters
// 1 - Numeric Integer, 2 - Email, 3 - Numeric Decimals
function isValidField(sText, iType)
{
	if(iType==1)
	{ ValidChars = "0123456789"; }
	else if(iType==2)
	{ ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-@"; }
	else if(iType==3)
	{ ValidChars = "0123456789."; }
	var isValid=true;
	var Char;
	for (i = 0; i < sText.length && isValid == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{ isValid = false; }
	}
	return isValid;
}
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
}
function checkFormPaxTitles(sErrTxt)
{
	oTitleElements = document.getElementsByTagName("select")
	for (i = 0; i < oTitleElements.length; i++)
	{
		if(oTitleElements.item(i).id.indexOf("title") == 0)
		{
			if(oTitleElements.item(i).selectedIndex == 0)
			{ alert(sErrTxt); oTitleElements.item(i).focus(); return false; break; }
		}
	}
	return true;
}
function checkFormFieldSelectedIndex(sFieldName, sErrTxt)
{
	oTitleElements = document.getElementsByTagName("select")
	for (i = 0; i < oTitleElements.length; i++)
	{
		if(oTitleElements.item(i).id.indexOf(sFieldName) == 0)
		{
			if(oTitleElements.item(i).selectedIndex == 0)
			{ alert(sErrTxt); oTitleElements.item(i).focus(); return false; break; }
		}
	}
	return true;
}
function checkFormFieldValue(sFieldName, sDefaultVal, sErrTxt, iMinLen)
{
	if(iMinLen==undefined || iMinLen==null) { iMinLen = 1; }
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).id.indexOf(sFieldName) == 0)
		{
			if(oFormElements.item(i).value == '' || oFormElements.item(i).value == sDefaultVal || oFormElements.item(i).value.length < iMinLen || (sFieldName == 'surname' && oFormElements.item(i).value.indexOf(' ') > -1))
			{ alert(sErrTxt); oFormElements.item(i).focus(); return false; break; }
		}
	}
	oFormElements = document.getElementsByTagName("textarea")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).id.indexOf(sFieldName) == 0)
		{
			if(oFormElements.item(i).value == '' || oFormElements.item(i).value == sDefaultVal)
			{ alert(sErrTxt); oFormElements.item(i).focus(); return false; break; }
		}
	}
	return true;
}
function checkFormFieldAges(sErrTxt)
{
	oFormElements = document.getElementsByTagName("select")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).id.indexOf("dob") == 0 && oFormElements.item(i).id.lastIndexOf("d") == 3)
		{
			temp_Obj1 = object_attach(oFormElements.item(i).id);
			temp_Obj1a = Math.abs(temp_Obj1.idmin);
			temp_Obj1b = Math.abs(temp_Obj1.idmax);
			temp_Obj2 = object_attach('dobm' + temp_Obj1.id.substr(4,temp_Obj1.id.length-4));
			temp_Obj3 = object_attach('doby' + temp_Obj1.id.substr(4,temp_Obj1.id.length-4));
			if(checkAge(temp_Obj1a, temp_Obj1b, temp_Obj1, temp_Obj2, temp_Obj3) == false)
			{ alert(sErrTxt + '\nPassenger ' + temp_Obj1.id.substr(4,temp_Obj1.id.length-4) + ' is out of the acceptable age range (' + temp_Obj1a + '-' + temp_Obj1b + 'yrs).'); temp_Obj1.focus(); return false; break; }
		}
	}
	return true;
}
function checkRadio(sFieldName)
{
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type == "radio" && oFormElements.item(i).name == sFieldName)
		{
			if(oFormElements.item(i).checked)
			{ return oFormElements.item(i).value; break; }
		}
	}
	return '';
}

function addDurationBYO5(sform)
{
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
//		oSelect = document.getElementById('startdate_d'+sform);
//		iDay = oSelect.options[oSelect.selectedIndex].value;
//		oSelect = document.getElementById('startdate_m'+sform);
//		iMonth = oSelect.options[oSelect.selectedIndex].value;
//		oSelect = document.getElementById('startdate_y'+sform);
//		iYear = oSelect.options[oSelect.selectedIndex].value;
//		
//		DepDaysDiv = document.getElementById('divDepDate'+sform);
//		DepDays = document.getElementById('depdays'+sform);
//		
//		arSplit = document.getElementById("depdays"+sform).options[document.getElementById("depdays"+sform).selectedIndex].value.split("/");
//
//		//clearList5(DepDays);
//		//DepDays.options[0] = new Option('- Choose -','-');
//		
//		if (DepDaysDiv.style.display=='none'){
//			cindate = new Date(iYear, iMonth-1, iDay, 0, 0, 0);
//			//div_switch("divDepDate" + sform,false,true);
//			div_switch("depdays"+sform,true,true);
//			cindate = new Date(arSplit[2], arSplit[1]-1, arSplit[0], 0, 0, 0);
//			document.getElementById("usedepdays"+sFormType).value = 1;
//		}else{
//			
//			//div_switch("divDepDate" + sform,true,true);
//			div_switch("depdays"+sform,false,true);
//			document.getElementById('duration'+sform).disabled = '';
//			cindate = new Date(iYear, iMonth-1, iDay, 0, 0, 0)
//			document.getElementById("usedepdays"+sFormType).value = 0;
//			
//		}
		
	oSelect = document.getElementById('duration'+sform);
	//alert('duration'+sform);
	if (oSelect.options[oSelect.selectedIndex].value == 'other')
	{
		tmpDuration = prompt("Please enter the number of nights","")
		if ( (tmpDuration==' ') || (tmpDuration==null) || (tmpDuration == ''))
		{
			iDuration = 7
			//oSelect.options[0].selected = 'selected';
		}
		else
		{
			var stemp = tmpDuration
			if (stemp < 10)
			{
				stemp = "0" + stemp
			}
			for (loop=0; loop < oSelect.options.length; loop++)
			{
				if (oSelect.options[loop].value == stemp)
				{
					oSelect.options[loop].selected = 'selected';
					iDuration = stemp
				}
			}

			if (isNumeric(tmpDuration) == true)
			{	
				var opt = new Option(tmpDuration + ' days', tmpDuration);
				insertOptionAt (oSelect, opt, oSelect.options.length);
				iDuration = oSelect.options[oSelect.options.length-1].value;
				oSelect.selectIndex = oSelect.options.length;
				oSelect.options[oSelect.options.length-1].selected = 'selected';
			}
			else
			{
				iDuration = 7
				//oSelect.options[0].selected = 'selected';
			}
		}
	}
//	else
//	{
//		iDuration = oSelect.options[oSelect.selectedIndex].value;
//	}
//
//	// Amend the end date
//	days = 1000 * 60 * 60 * 24 * iDuration;
//	//alert(cindate);
//	newdate = new Date(cindate.valueOf() + days);
//	if ((newdate.getHours() != 0) || (newdate.getMinutes() != 0) || (newdate.getSeconds() != 0)) {
//		// Workaround to JavaScript bug: sometimes when adding days represented as milliseconds it would onhly add 23 hrs
//		// Work out time in milliseconds
//		time = newdate.getHours() * 60 * 60 * 1000;
//		time += newdate.getMinutes() * 60 * 1000;
//		time += newdate.getSeconds() * 1000;
//		newdate = new Date(newdate.getTime() + time);
//	}
//	
//	if(newdate.getDate()+'' != "NaN") {
//		sArrDate = newdate.getDate() + ' ' + months[newdate.getMonth()] + ' ' + newdate.getFullYear();
//	} else {
//		 sArrDate = 'Please select a departure date.';
//		 if (document.getElementById("arrdate"+sform).innerHTML == 'Please select a departure date.'){ 
//			 //addDurationBYO5(sform);
//		 }
//		//document.getElementById("duration"+sform).disabled = "";
//	 }
	//
	//alert(sArrDate);
	//document.getElementById("arrdate"+sform).innerHTML = '<b>' + sArrDate + '</b>'
	
	//DepDays.options[0] = null;
	//DepDays.disabled = "";
//	iDay = newdate.getDate();
//	iMonth = newdate.getMonth() + 1;
//	iYear = newdate.getFullYear();

//	oTxt = document.getElementById('enddate_d');	
//	if (iDay < 10) { iDay = '0' + iDay; }
//	oTxt.value = iDay;
//	
//	oTxt = document.getElementById('enddate_m');
//	if (iMonth < 10) { iMonth = '0' + iMonth; }
//	oTxt.value = iMonth;
//	
//	oTxt = document.getElementById('enddate_y');
//	oTxt.value = iYear;	
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function insertOptionAt (select, option, index) {
    for (var i = select.options.length; i > index; i--)
      select.options[i] = select.options[i - 1];
    select.options[index] = option;
  }


function checkNewsletter(form)
{
	if (form.name.value == ''){
		alert("Please enter you name");
		return false;
	}
	
	if (!echeck(form.email.value)){
		alert("Please enter a valid email address");
		return false;
	}
}
	
function echeck(str) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
return (true)
}
return (false)
}

function updateCalendars(form,bDoDuration,mode, Control) {
if(Control == null){
  Control = '';
 }

 twodays = 1000 * 60 * 60 * 24;   // Three days represented in milliseconds
 if(bDoDuration==null) { bDoDuration = true; }
 if(mode == null) { mode = 0; }
 
 
   //Basic error checking if past day selected
  if (mode == 0){
	    tmpcurrentdate = addDays(new Date(),3);
		tmpcurrentselecteddate = new Date(document.getElementById(Control+'start_dt_mnyr').value.split(" ")[1],parseInt(document.getElementById(Control+'start_dt_mnyr').value.split(" ")[0])-1,document.getElementById('startdate_d').value)	  
	  if (tmpcurrentdate > tmpcurrentselecteddate)
	    {
		  document.getElementById('startdate_d')[parseInt(tmpcurrentdate.getDate())-1].selected = true;
		  document.getElementById(Control+'start_dt_mnyr')[0].selected = true;
		}
  }
  else
  {
	    tmpcurrentdate = addDays(new Date(),4);
		tmpcurrentselecteddate = new Date(document.getElementById(Control+'end_dt_mnyr').value.split(" ")[1],parseInt(document.getElementById(Control+'end_dt_mnyr').value.split(" ")[0])-1,document.getElementById('enddate_d').value)	  
	  if (tmpcurrentdate > tmpcurrentselecteddate)
	    {
		  document.getElementById('enddate_d')[parseInt(tmpcurrentdate.getDate())-1].selected = true;
		  document.getElementById(Control+'end_dt_mnyr')[0].selected = true;
		}
  }

 if (mode == 0) {
 
  var month=new Array(12)
  month[0]="Jan"
  month[1]="Feb"
  month[2]="Mar"
  month[3]="Apr"
  month[4]="May"
  month[5]="Jun"
  month[6]="Jul"
  month[7]="Aug"
  month[8]="Sep"
  month[9]="Oct"
  month[10]="Nov"
  month[11]="Dec"
    
  // The user altered the checkin date
  // Check that the new date is not earlier that the current date
  currentdate = new Date();
  // Now trim off the time
  currentdate = new Date(currentdate.getFullYear(), currentdate.getMonth(), currentdate.getDate(), 0, 0, 0); 
  //alert(document.getElementById('startdate_y').value+'/'+addZero(parseInt(document.getElementById('startdate_m').value - 1))+'/'+document.getElementById('startdate_d').value)
  cindate = new Date(parseInt(document.getElementById('startdate_y').value), addZero(parseInt(document.getElementById('startdate_m').value - 1)), document.getElementById('startdate_d').value, 0, 0, 0);
  //alert("cindate:" + cindate)
  dSelectedDate = new String(document.getElementById(Control+'start_dt_mnyr').value.split(" ")[0] + '/' + document.getElementById('startdate_d').value + '/' + document.getElementById(Control+'start_dt_mnyr').value.split(" ")[1]);
  
  iMonth = new Number(cindate.getMonth())
  iMonth = iMonth + 1
  
  // If user selected an invalid date
  //alert(document.getElementById('startdate_d').value +'-'+ addZero(parseInt(cindate.getDate())))
  if(document.getElementById('startdate_d').value != addZero(parseInt(cindate.getDate()))){
   alert('You have entered an invalid date which has now been changed to ' + cindate.getDate() + '/' + iMonth + '/' + cindate.getFullYear());
   document.getElementById('startdate_d')[0].selected = true;
   for (i=0;i<document.getElementById(Control+'end_dt_mnyr').options.length;i++) {
    if (document.getElementById(Control+'start_dt_mnyr').options[i].value ==parseInt(cindate.getMonth())+1+' '+cindate.getFullYear()) {
     document.getElementById(Control+'start_dt_mnyr')[i].selected = true;
    }
   }
  }
  if (bDoDuration) {
   // Amend the end date
   if(document.getElementById('duration')){
    days = 1000 * 60 * 60 * 24 * document.getElementById('duration').value;
    
    //alert("DAYS: "+days);
    newdate = new Date(cindate.valueOf() + days);
       if ((newdate.getHours() != 0) || (newdate.getMinutes() != 0) || (newdate.getSeconds() != 0)) {
    // Workaround to JavaScript bug: sometimes when adding days represented as milliseconds it would onhly add 23 hrs
    // Work out time in milliseconds
    time = newdate.getHours() * 60 * 60 * 1000;
    time += newdate.getMinutes() * 60 * 1000;
    time += newdate.getSeconds() * 1000;
    newdate = new Date(newdate.getTime() + time);
   }
   

    document.getElementById('enddate_d')[newdate.getDate() - 1].selected = true;
    for (i=0;i<document.getElementById(Control+'end_dt_mnyr').options.length;i++) {
     if (document.getElementById(Control+'end_dt_mnyr').options[i].value ==parseInt(newdate.getMonth())+1+' '+newdate.getFullYear()) {
      document.getElementById(Control+'end_dt_mnyr')[i].selected = true;
     }
    }
    
   }
  }
 
 } else if (mode == 1) {
  if (bDoDuration) {
   // User altered the end date
   // Check that the end date and the number of nights is not less than the current date; if not, then amend start date accordingly
   startdate = new Date();
   //startdate = new Date(Date.parse(startdate) + (24  * 60 * 60 * 1000));   // Start date is current date + 2 days
   coutdate = new Date(parseInt(document.getElementById('enddate_y').value), parseInt(document.getElementById('enddate_m').value - 1), parseInt(document.getElementById('enddate_d').value));
   enddate = new Date(Date.parse(coutdate) - (document.getElementById('duration').value * 24 * 60 * 60 * 1000))
   if (enddate > startdate) {
	// Amend the start date, the run this again to check the start date is not earlier than the current date + 2
    checkindate = new Date(parseInt(document.getElementById('startdate_y').value), addZero(parseInt(document.getElementById('startdate_m').value - 1)), document.getElementById('startdate_d').value);
    coutdate = new Date(parseInt(document.getElementById('enddate_y').value), addZero(parseInt(document.getElementById('enddate_m').value - 1)), document.getElementById('enddate_d').value);
    days = 1000 * 60 * 60 * 24 * document.getElementById('duration').value;

	one_day=1000*60*60*24
	NewDuration = Math.ceil((coutdate.getTime()-checkindate.getTime())/(one_day))
	//alert(NewDuration)
	if(parseInt(NewDuration) > 0 && parseInt(NewDuration) <= 60)
	{
		document.getElementById('duration')[parseInt(NewDuration)-1].selected = true;
	}
	else
	{
		newdate = new Date(Date.parse(coutdate) - days);
		document.getElementById('startdate_d').selectedIndex = newdate.getDate() - 1;
	}
	//alert("1:"+newdate)
    document.getElementById('startdate_m').selectedIndex = newdate.getMonth();
    for (i=0;i<document.getElementById(Control+'start_dt_mnyr').options.length;i++) {
     if (document.getElementById(Control+'start_dt_mnyr').options[i].value ==parseInt(newdate.getMonth())+1+' '+newdate.getFullYear()) {
      document.getElementById(Control+'start_dt_mnyr')[i].selected = true;
     }
    }
   } else {
    // Amend the start date, the run this again to check the start date is not earlier than the current date + 2
    checkindate = new Date(document.getElementById('startdate_y').value, addZero(parseInt(document.getElementById('startdate_m').value) - 1), document.getElementById('startdate_d').value);
   	coutdate = new Date(document.getElementById('enddate_y').value, addZero(parseInt(document.getElementById('enddate_m').value - 1)), document.getElementById('enddate_d').value);
	days = 1000 * 60 * 60 * 24 * document.getElementById('duration').value;

	one_day=1000*60*60*24
	NewDuration = Math.ceil((coutdate.getTime()-checkindate.getTime())/(one_day))
	if(parseInt(NewDuration) > 0 && parseInt(NewDuration) <= 60)
	{document.getElementById('duration')[parseInt(NewDuration)-1].selected = true;}
	else{
		newdate = new Date(Date.parse(coutdate) - days);
		document.getElementById('startdate_d').selectedIndex = newdate.getDate() - 1;
		}
	//alert("2:"+newdate)
    for (i=0;i<document.getElementById(Control+'start_dt_mnyr').options.length;i++) {
     if (document.getElementById(Control+'start_dt_mnyr').options[i].value ==parseInt(newdate.getMonth())+1+' '+newdate.getFullYear()) {
      document.getElementById(Control+'start_dt_mnyr')[i].selected = true;
     }
    }


   }
  }
 }
 
}


function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

 function getValue(){
   document.getElementById('startdate_m').value = addZero(document.getElementById('start_dt_mnyr').value.substr(0,2));
   document.getElementById('startdate_y').value = document.getElementById('start_dt_mnyr').value.substr(2,7);
   document.getElementById('enddate_m').value = addZero(document.getElementById('end_dt_mnyr').value.substr(0,2));
   document.getElementById('enddate_y').value = document.getElementById('end_dt_mnyr').value.substr(2,7);
  }
  
  function addZero(ID){
   if(ID < 10){
    return "0"+ID;
   }else{
    return ID;
   }
  }

function showCalendar(calTitle,calTarget,calInit,bDoDuration) {
	if(bDoDuration==null) { bDoDuration = true; }
	if(calInit!=null)
	{ calendarWin=window.open("includes/calendar.asp?startdateMarker=" + eval("document.getElementById('startdate_d').value") + "/" + RTrim(eval("document.getElementById('startdate_m').value")) + "/" + eval("document.getElementById('startdate_y').value") + "&initDate=" + eval("document.getElementById('" + calInit + "_d').value") + "/" + eval("document.getElementById('" + calInit + "_m').value") + "/" + eval("document.getElementById('" + calInit + "_y').value") + "&title=" + escape(calTitle) + "&field=" + escape(calTarget)+"&doduration="+bDoDuration,"calendarWin","width=250,height=240,left=" + ((screen.width-210)/2) + ",top=" + ((screen.height-240)/2) + ",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"); }
	else
	{ calendarWin=window.open("includes/calendar.asp?startdateMarker=" + eval("document.getElementById('startdate_d').value") + "/" + RTrim(eval("document.getElementById('startdate_m').value")) + "/" + eval("document.getElementById('startdate_y').value") + "&initDate=" + eval("document.getElementById('" + calTarget + "_d').value") + "/" + eval("document.getElementById('" + calTarget + "_m').value") + "/" + eval("document.getElementById('" + calTarget + "_y').value") + "&title=" + escape(calTitle) + "&field=" + escape(calTarget)+"&doduration="+bDoDuration,"calendarWin","width=250,height=240,left=" + ((screen.width-210)/2) + ",top=" + ((screen.height-240)/2) + ",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"); }
	if(!calendarWin.opener) calendarWin.opener=self;
}


function loadimg(){
	
	//document.getElementById("loadingimg").innerHTML = '';
	if (document.getElementById("loadingimg")){ document.getElementById("loadingimg").innerHTML = '';}
	//alert('mmm');
	loadimg2();
}
function loadimg2(){
	//document.getElementById("loadingimg").innerHTML = '<img src="/images/searching-animation.gif" style="margin-top:30px;" loop="-1" start="fileopen"/>';
	if (document.getElementById("loadingimg")){ document.getElementById("loadingimg").innerHTML = '<img src="/images/pleasewait/searching_bar.gif" width="178" height="15" loop="-1" start="fileopen" />';}
}

function SubmitForm(sForm){
	document.sForm.submit();
	}
	
	function popupDIV(bool,title,text,verth){
	var left = object_attach('paneLeft');
	var left2 = object_attach('paneLeft2');
	var right = object_attach('paneRight');
	var right2 = object_attach('paneRight2');
	left.style.height = verth
	left2.style.height = verth
	right.style.height = verth
	right2.style.height = verth
	writeInDiv(title,'title');
	writeInDiv(text,'notice');
	div_switch('paneBG',bool,true);
	div_switch('paneFore',bool,true);
	if (bool == true){
		hideSelects();
		}
		else if (bool == false)
		{
		showSelects();
		}
}

function hideSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
   elements[i].style.visibility='hidden';
   }
}
function showSelects(){
   var elements = document.getElementsByTagName("select");
   for (i=0;i< elements.length;i++){
      elements[i].style.visibility='visible';
   }
}

function RTrim(value) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// -->