/* scripts for 51 Buckingham Gate */

// print function
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage() {
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  return false;
}
    
  
 function openWindow(theURL,winName,features) 
 { //v2.0
  window.open(theURL,winName,features);
} 
   
// REMOVES THE LINK BORDER IN IE4+, NS6
// Works: IE4+, NS6+
// Notes: In NS6 the select tags are not blurred

	function unblur() {
		this.blur();
	}

	function getLinksToBlur() {
		if ((browserNew) || (browserName == "IE")) {
			if (browserNew) {
				links = document.getElementsByTagName("a");
			}
			else {
				links = document.all.tags("a");
			}
			for(i=0; i<links.length; i++) {
				links[i].onfocus = unblur
			}
		}
		if (browserName == "IE") {
			if (browserNew) {
				drops = document.getElementsByTagName("select");
			}
			else {
				drops = document.all.tags("select");
			}
			for(i=0; i<drops.length; i++) {
				drops[i].onfocus = unblur
			}
		}
	}
   
   function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function showCal(eile){
   if (document.getElementById) {
      with (document.getElementById('date' + eile).style){
      display = 'inline';
       
      }
   }
}

function hideCal(eile){
   if (document.getElementById) {
      document.getElementById('date' + eile).style.display = 'none';
   }
}
function updateDateControl(controlName, dateValue) {
    if (document.getElementById) {
        alert("COntrolName = " + controlName + "") ;
        alert("Date Value = " + dateValue + "") ;
  eval('document.form1.' + controlName + 'day.value = ' + dayValue);
} 
} 
function sendVal(control, dayValue,monthValue,yearValue){
    if (document.getElementById) {
      eval('document.form1.'+ control +'day.value =' + dayValue) ;
      eval('document.form1.'+ control +'month.value =' + monthValue) ;
      eval('document.form1.'+ control +'year.value =' + yearValue) ;

      if (control == "arrive") { 
         hideCal(1);
      }
      else {
         hideCal(2);
      }
        }
   }        
 
function JumpMe(dropdown) {
var tempURL = dropdown.options[dropdown.selectedIndex].value;
	if(tempURL!="") {
		document.location.href = tempURL;
	}
}

function CreateWindow(filename,width,height,scrollbars)
        {
        msgWindow=window.open(filename,"displayWindow","toolbar=no,width="+width+",height="+height+",directories=no,status=no,scrollbars="+scrollbars+",resize=yes,menubar=no")
        }  
        
function openChromeslessWindow(openUrl, winName, wWidth, wHeight, wPosx, wPosy, wTIT,
												windowBORDERCOLOR, windowBORDERCOLORsel, windowTITBGCOLOR, windowTITBGCOLORsel,
													bCenter, sFontFamily, sFontSize, sFontColor){
	
	openchromeless(openUrl,winName, wWidth, wHeight, wPosx, wPosy, wTIT, wTIT ,
							windowBORDERCOLOR, windowBORDERCOLORsel, windowTITBGCOLOR, windowTITBGCOLORsel,
								bCenter, sFontFamily, sFontSize, sFontColor);
}
   
   
   
// Date Checker

   
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate (day,month,year) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}


function StartBeforeEndDate(startDate_dd,startDate_mm,startDate_yyyy,endDate_dd,endDate_mm,endDate_yyyy)
{
	var boolReturnVal=false;	
	
	var startdate = new Date(startDate_yyyy,startDate_mm-1, startDate_dd);
	var enddate = new Date(endDate_yyyy,endDate_mm-1, endDate_dd);
	
	if (startdate >= enddate)
	{
		alert('Invalid departure date - must be after arrival date');
		boolReturnVal=false;
	}
	else
	{
		boolReturnVal=true;
	}

	return boolReturnVal;   
}


// Cookie Funtion Start
function getCookie(NameOfCookie){
    if (document.cookie.length > 0) {              
    begin = document.cookie.indexOf(NameOfCookie+"=");       
    if (begin != -1) {           
      begin += NameOfCookie.length+1;       
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
        return unescape(document.cookie.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(NameOfCookie, value, expiredays) {
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

  document.cookie = NameOfCookie + "=" + escape(value) + 
  ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) {
  if (getCookie(NameOfCookie)) {
    document.cookie = NameOfCookie + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function checkForCookie()
{
 visited=getCookie('visited');
 if (visited==null) 
 {
    setCookie('visited','yes',365)
    MyWindow=window.open('http://www.aro.ie','popup_window','width=555,height=555,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,left=0,top=0,screenX=0,screenY=0');
 }
 else {alert("The cookie has been set.")}
}
// Cookie Funtion End  


function openPopUp()
{
 // function call (onLoad="openPopUp()") 
 window.open('/functions/offer_popup.asp','Offer','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=390')
//alert('test')
}

// externalLinks - for "target=_blank like" action
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}
window.onload = externalLinks;
