
var OBJ_SELECT = "_sel";
var OBJ_HIGHLIGHT = "_high";

var isIE = (navigator.appName == "Microsoft Internet Explorer");

function addEvent(target, eventType, eventHandler) {
    if (target.addEventListener)
        target.addEventListener(eventType, eventHandler, false);
    else if (target.attachEvent)
        target.attachEvent('on' + eventType, eventHandler);
}

function removeEvent(target, eventType, eventHandler) {
    if (target.removeEventListener)
        target.removeEventListener(eventType, eventHandler, false);
    else if (target.detachEvent)
        target.detachEvent('on' + eventType, eventHandler);
}

function scrollToY(y) {
    window.scrollTo(0,y);    
}


function openWindow(url,height,width,title,scroll,status,resizable,top,left) {
	left = (left)? left :  parseInt((window.screen.width - width)/2);
	top = (top)? top : parseInt((window.screen.height - height)/2);
	title = (title)? title : "popUp";
	scrollBar = (scroll) ? ",scrollbars=yes" : "";
	statusBar = (status) ? ",statusbar=yes" : "";
	resizable = (resizable) ? ",resizable=yes" : "";
	params = "height="+height+",width="+width+",left="+left+",top="+top + scrollBar +statusBar +resizable;
	newWin = window.open(url,title,params);
	newWin.focus();
	return newWin;
}

function openVerisign() {
	if (window.location.protocol.toLowerCase()=="https:"){var mode="https:";} else {var mode="http:";}
	var img = "https://seal.networksolutions.com/images/basicrecgreen.gif";
	var type = "NETSB";
	var host = location.host;
	var baseURL = mode+"//seals.networksolutions.com/siteseal_seek/siteseal?v_shortname="+type+"&v_querytype=W&v_search="+host+"&x=5&y=5";
	window.open(baseURL,type,"width=450,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no");
}

function openWin(page) {
    openWindow(page,400,563,"popup",false,false,true);
}

function getPath() {
	var loc = document.location.toString();
	return loc.substring(0,loc.lastIndexOf("/")) + "/";
}

function showFAQ(question,answer){
	openWindow(getPath() + "faq_pop.php?q=" + question + "&a=" +answer ,500,700,"faq",true,true,true);
}

function showTerms() {
	openWindow(getPath() + "terms_pop.php",500,700,"terms",true,true,true);
}

function showPrivacy() {
	openWindow(getPath() + "privacy_pop.php",500,700,"privacy",true,true,true);
}

function showAptInfo(aptid) {
	openWindow(getPath() + "aptinfo_pop.php?id=" + aptid,500,700,"aptinfo",true,true,true);

}

function showConverter() {
	openWindow("http://www.oanda.com/convert/classic",600,800,"converter",true,true,true);
}

function openApartmentForm(apartmentid) {
	var url = getPath() + "apartment_form.php";
	if (apartmentid != null)
		url += "?apartmentid=" + apartmentid;
    url += "sy=" + getScrollY();
	openWindow(url,600,750,"form",true,true,true);
}

//function openUserForm(userid,isPopulate) {
//	var url = getPath() + "user_form.php";
//	if (userid != null)
//		url += "?userid=" + userid;
//	if (isPopulate != null && isPopulate)
//		url += "?populate=" + true;
//    url += "sy=" + getScrollY();
//	openWindow(url,400,700,"userform",true,true,true);
//}

function openSeasonalRate(aptid,rateid) {
	var url = getPath() + "seasonalrate_form.php";
	url += "?apartmentid=" + aptid;
	if (rateid != null)
		url += "&rateid=" + rateid;
    url += "sy=" + getScrollY();
	openWindow(url,400,600,"seasonal",true,true,true);
}

function openGuestRate(aptid,rateid) {
	var url = getPath() + "guestrate_form.php";
	url += "?apartmentid=" + aptid;
	if (rateid != null)
		url += "&rateid=" + rateid;
    url += "sy=" + getScrollY();
	openWindow(url,400,400,"guest",true,true,true);
}

function openOptionalFee(feeid,isPopulate){
	var url = getPath() + "optionalfee_form.php";
	if (feeid != null)
		url += "?feeid=" + feeid;
	if (isPopulate != null && isPopulate)
		url += "?populate=true"
	openWindow(url,400,600,"optionalfee",true,true,true);
}

function openDiscount(discountid,isPopulate) {
	var url = getPath() + "discount_form.php";
    var qs = "";
	if (discountid != null)
		qs += "?discountid=" + discountid;
	if (isPopulate != null && isPopulate)
		qs += "?populate=true";
    qs += ((qs == ""? "?" : "&") + "sy=" + getScrollY());
	openWindow(url + qs,400,600,"discount",true,true,true);
}

function openApartmentPictures(aptid) {
	var url = getPath() + "photo_form.php?apartmentid=" + aptid;
	openWindow(url,600,750,"photo",true,true,true);
}

function openApartmentPictureDelete(aptid,id) {
	var url = getPath() + "photo_form_delete.php?apartmentid=" + aptid + "&id=" + id;
	openWindow(url,600,650,"photo",true,true,true);
}


function openPictures(apartmentid,pictureid,ref) {

    var params = "aptid=" + apartmentid;
    if (pictureid != null)
        params += "&pictureid=" + pictureid;
     if (ref != null)
        params += "&ref=" + ref;
    openWindow("pictures.php?" + params,700,750,"pic",true,true,true);
}

function closeWindow(refresh) {
	if (window.opener) {
	    if (refresh)
	        window.opener.location.reload();
		window.opener.focus();
    }
	window.close()
}

function getObj(objName) {
	return document.getElementById(objName);
}

function showLayer(obj) {
	if (typeof(obj) == "string")
		obj = getObj(obj);
	obj.style.display = "";
}

function hideLayer(obj) {
	if (typeof(obj) == "string")
		obj = getObj(obj);
	obj.style.display = "none";
}

function toggleLayer(show,hide) {
	showLayer(show);
	hideLayer(hide);
}

function returnPosition(obj) {
	var retVal = new Object();
	retVal.x = 0;
	retVal.y = 0;
	while (obj) {
		retVal.x += obj.offsetLeft;
		retVal.y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return retVal;
}

function trim(str,frontOnly) {
	while (str.substr(0,1) == " ")
		str = str.substring(1,str.length)
	if (!frontOnly) {
		while (str.substr(str.length-1,1) == " ")
			str = str.substring(0,str.length-1)
	}
	return str;
}

function sendMail(email,subject) {
	subject = (subject)? "?subject=" + subject : "";
	window.open("mailto:" + email + subject);
}

function stripImgTag(imgObj,clearSelect) {
	notSelected = (imgObj.src.indexOf(OBJ_SELECT) == -1 || clearSelect);
	if (imgObj.src.indexOf("_") != -1 && notSelected)
		imgObj.src = imgObj.src.substring(0,imgObj.src.indexOf("_")) + ".gif";
}

function addImgTag(imgObj,tag) {
	if (imgObj.src.indexOf(OBJ_SELECT) != -1) return;
	stripImgTag(imgObj)
	imgObj.src = imgObj.src.substring(0,imgObj.src.indexOf(".gif")) + tag + ".gif";
}

function stripClassName(obj,clearSelect) {
	notSelected = (obj.className.indexOf(OBJ_SELECT) == -1 || clearSelect);
	if (obj.className.indexOf("_") != -1 && notSelected)
		obj.className = obj.className.substring(0,obj.className.indexOf("_"));
}

function addClassName(obj,tag) {
	if (obj.className.indexOf(OBJ_SELECT) != -1) return;
	stripClassName(obj);
	obj.className = obj.className + tag;
}

function isEmpty(str,checkWhitespace) {
	if (!str || str.length == 0)
		return true;
	if (checkWhitespace)
		return (trim(str) == "");
	return false;
}

var VALID_DIGITS = "1234567890";
var VALID_ALPHA_LOWER = "abcdefghijklmnopqrstuvwxyz";
var VALID_ALPHA_UPPER = VALID_ALPHA_LOWER.toUpperCase();
var VALID_ALPHA = VALID_ALPHA_LOWER + VALID_ALPHA_UPPER;
var VALID_ALPHANUMERIC = VALID_ALPHA + VALID_DIGITS;


function isValidCharacters(val, validChars) {
    for (var i=0; i<val.length; i++) {
        if (validChars.indexOf(val.charAt(i)) == -1)
            return false;
    }
    return true;
}

function getScrollY() {
    if (typeof(window.pageYOffset) == 'number')
        return window.pageYOffset;
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
        return document.body.scrollTop;
    if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
        return document.documentElement.scrollTop;
    return 0;
}

function showInfo(msg,type) {
	infoObj = getObj("infoLayer");
	if (!infoObj || !msg) return;
	if (type == "error") {
		infoObj.className = "errorText";
		msg = "<img src=\"images/iconError.gif\" valign=\"vertical-align:text-top;\"> <span class=\"errorText\">" + msg + "</span>";
	} else if (type == "info") {
		msg = "<img src=\"img/icon/info.gif\" style=\"vertical-align:text-top;\"> " + msg;
		setTimeout("clearInfo()",4000);
	}
	infoObj.innerHTML = msg;
}

function clearInfo() {
    infoObj = getObj("infoLayer");
    infoObj.innerHTML = "";
}

function setFieldValue(fieldObj,value) {
    if (fieldObj == null) return;
    if (value == null) value = "";

    var fieldType = fieldObj.type.toLowerCase();

    if (fieldType.indexOf("select") != -1)
        setSelect(fieldObj,value);
    else if (fieldType == "radio" || fieldType == "checkbox")
        fieldObj.checked = (fieldObj.value == value);
    else
        fieldObj.value = value;
}

function setSelect(fieldObj,value) {
    if (fieldObj) {
        for (i=0;i<fieldObj.length;i++) {
            if (fieldObj.options[i].value == value)
                fieldObj.options[i].selected = true;
        }
    }
}

function getExpireTime(minutes) {
	expTime = new Date();
	addTime = expTime.getTime() + minutes * (1000*60);
	expTime.setTime(addTime);
	return expTime.toGMTString();
}

function importXML(fileName) {
	if (document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("","",null);
		xmlDoc.onload = parseXML;

	} else if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) parseXML()
		};
 	}
	xmlDoc.load(fileName);
}

imagesArray = new Array();
function preloadImage() {
    imgs = preloadImage.arguments;
	len = imagesArray.length;
    for (j=0;j<imgs.length;j++) {
        imagesArray[len] = new Image;
        imagesArray[len].src = imgs[j];
		len++;
    }
}

function getImage(img,h,w) {
	output = "<img src=\""+img+"\"";
	if (w && w != "") output += " width=\"" + w + "\"";
	if (h && h != "") output += " height=\"" + h + "\"";
	output += " border=\"0\"/>";
	return output;
}


function showMessage(msgKey,cls) {
	if (msgKey != null && msgs != null && msgs[msgKey] != null && getObj("messageLayer") != null) {
		if (cls == null) cls = "messageInfo";
		getObj("messageLayer").innerHTML = "<span class=\""+cls+"\">" + msgs[msgKey] + "</span>";
		showLayer("messageLayer");
	}
}

function clearFromQueryString(qs,param) {

	if (qs != "") {
		if (qs.indexOf("?") == 0)
			qs = qs.substring(1);
		qsArr = qs.split("&");
		qs = "";
		for (var i=0;i<qsArr.length;i++) {
			if (qsArr[i].indexOf(param + "=") != 0 && qsArr[i] != "")
				qs += qsArr[i] + "&";
		}
	}
	return qs;

}

function reloadOpener(msg) {
    
    if (window.opener) {

        window.opener.location = window.opener.location.pathname + document.location.search;
        closeWindow();
/*
        var loc = window.opener.location.toString();
        //var qs = document.location.search;

        if (msg != null && msg != "") {

			var qs = clearFromQueryString(window.opener.location.search,"msg");
            alert(qs);
            if (loc.indexOf("?") != -1)
				loc = loc.substring(0,loc.indexOf("?"));

			loc = loc + "?msg=" + msg + "&" + qs

		}
		window.opener.location = loc;
		closeWindow();
		*/
	}
}

function scrollToAnchor(anchor) {
    var idx = document.location.href.indexOf("#");
    var loc = (idx == -1)
        ? document.location.href
        : document.location.href.substring(0,idx);
    document.location.href = loc + "#" + anchor;
}

function populateOpener(field,val,dis,customFcn) {

	if (window.opener) {

		if (customFcn != null) {
			eval("window.opener." + customFcn + "('" + field + "','"+val+"','"+dis+"')");
		} else {

			inputObj = window.opener.getObj(field);
			var fieldType = inputObj.type.toLowerCase();

			if (fieldType.indexOf("select") != -1) {
				inputObj.options[inputObj.options.length] = new Option(dis,val);
				inputObj.options[inputObj.options.length-1].selected = true;
			} else {
				inputObj.value = val;
			}
		}

		closeWindow();
	}
}

function highlightImg(imgObj) {
	addClassName(imgObj,"_high");
}

function unhighlightImg(imgObj) {
	stripClassName(imgObj);
}

resizeTimer = null;
function resizeContent(isResize) {

    if (isResize) {
        clearTimeout(resizeTimer);
        setTimeout("resizeContent(false)",300);
		return;
    }
	
    if (getObj("scrollableLayer") == null)
        return;

    var staticHeight = getObj("staticContent").offsetHeight + 80;

	var totalHeight = 300;
	if (window.innerHeight)
		totalHeight = window.innerHeight
	else if (document.documentElement && document.documentElement.clientHeight)
		totalHeight = document.documentElement.clientHeight;
	else
		totalHeight = document.body.clientHeight;

    var newContentHeight = totalHeight - staticHeight;
    if (newContentHeight < 100)
        newContentHeight = 100

	if (!isNaN(newContentHeight)) {
    	getObj("scrollableLayer").style.height = newContentHeight + "px";
    	if (getObj("scrollableLayer") != null)
    		getObj("scrollableLayer2").style.height = newContentHeight + "px";
	}
	clearTimeout(resizeTimer);
}

function setHeights() {
	var divs = document.getElementsByTagName("DIV");

	var conts = new Array();
	for (var i=0;i<divs.length;i++) {
		if (divs[i].className != null && divs[i].className.indexOf("containercontent") != -1)
			conts[conts.length] = divs[i];
	}

	if (conts.length == 0) 
		return;
		
	var contheight = 400;
	for (var i=0;i<conts.length;i++) {
		conts[i].style.height = "";
		contheight = (conts[i].offsetHeight > contheight)? conts[i].offsetHeight : contheight;
	}
	for (var i=0;i<conts.length;i++) 
		conts[i].style.height = contheight + "px";

}

function setHeightsHome() {

	var contheight = 650;
	contheight = (getObj("textContainer").offsetHeight > contheight)? getObj("textContainer").offsetHeight : contheight;
	contheight = (getObj("searchContainer").offsetHeight > contheight)? getObj("searchContainer").offsetHeight : contheight;
	contheight = (getObj("dealsContainer").offsetHeight > contheight)? getObj("dealsContainer").offsetHeight :  contheight;
//    contheight = (getObj("dealsContainer").offsetHeight +124 > contheight)? getObj("dealsContainer").offsetHeight +124 :  contheight;


	contheight -= 10;
	
	getObj("textContainer").style.height = contheight + "px";
	getObj("searchContainer").style.height = contheight + "px";
	getObj("dealsContainer").style.height = (contheight) + "px";
//    getObj("dealsContainer").style.height = (contheight -124) + "px";
}

/*
var newHeight = 0;
var adjustment = (isIE)? 14 : 0;
function setHeights(layer1,layer2) {

	if (layer1 == null)
		layer1 = getObj('leftLayer');

	if (layer2 == null)
		layer2 = getObj('rightLayer');

    layer1Height = layer1.clientHeight;
    layer2Height = layer2.clientHeight;

    if (layer1Height > layer2Height) {
		newHeight = layer1Height - adjustment;
        layer2.style.height = (newHeight) + "px";
	} else {
		newHeight = layer2Height - adjustment;
		layer1.style.height = (newHeight) + "px";
	}
}
*/
// determines an expiration time in GMT format for cookies. Returns a GMT date string.
function getExpireTime(minutes) {
	var expTime = new Date();
	var addTime = expTime.getTime() + minutes * (1000*60);
	expTime.setTime(addTime);
	return expTime.toGMTString();
}

function getParentByTag(obj,tag) {
    while(obj && obj.tagName != tag)
        obj = obj.parentNode;
    return obj;
}

function changeLanguage(lang) {
	var loc = location.pathname;//document.location.toString();
	var qs = location.search;
	
	qs = clearFromQueryString(qs,"lang");
	qs = clearFromQueryString(qs,"departure_date");
	qs = clearFromQueryString(qs,"arrival_date");
	qs = clearFromQueryString(qs,"bookFormSubmitted");
	
	qs = "lang=" + lang + "&" + qs;
	/*
	if (loc.indexOf("?lang=") != -1)
		loc = loc.substring(0,loc.indexOf("?lang="));
	if (loc.indexOf("&lang=") != -1)
		loc = loc.substring(0,loc.indexOf("&lang="));
*/
	//loc += (loc.indexOf("?") == -1)? "?lang=" + lang : "&lang=" + lang;
	document.location = loc + "?" + qs;
}

// top nav
navTimer = null;
currentNav = 0;
o_navigator = navigator.userAgent
var isIE5 = (o_navigator.indexOf("MSIE 5") > -1) ? 1 : 0;
var isMac = (o_navigator.indexOf("Mac") > -1) ? 1 : 0;
var isIE50 = (o_navigator.indexOf("MSIE 5.0") > -1) ? 1 : 0;
var isIE52 = (o_navigator.indexOf("MSIE 5.2") > -1) ? 1 : 0;
var isNN6 = (o_navigator.indexOf("Netscape6") > -1) ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;

function mainNavOver(o_div){
	if(isDOM&&!isNN6&&!isIE52&&!isIE50){
		if(currentNav)currentNav.className = "";
		clearTimeout(navTimer);
		o_div.className="navOver";
	}
}
function mainNavOut(o_div){
	if(isDOM&&!isNN6&&!isIE52&&!isIE50){
		currentNav = o_div;
		navTimer = setTimeout('currentNav.className=""',1);
	}
}


// ***** CALENDAR FUNCTIONS ******** //

var CalendarInfo = new Object();
	CalendarInfo.today = new Date();
	CalendarInfo.currentCalendar = null;
	CalendarInfo.timer = null;
	CalendarInfo.yearMax = CalendarInfo.today.getFullYear() + 3;
	CalendarInfo.yearMin = CalendarInfo.today.getFullYear() - 20;
	CalendarInfo.splitCentury = (CalendarInfo.today.getFullYear() - 2000) + 15;
	CalendarInfo.indicatorMonth = "m";
	CalendarInfo.indicatorDay = "d";
	CalendarInfo.indicatorYear = "y";
	CalendarInfo.calendarLayerName = "calendarLayer";
	CalendarInfo.maxDaysInMonthArray = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	CalendarInfo.shortMonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function getArrivalDateObj() {
	if (document.searchForm != null && document.searchForm.arrival_date != null && document.searchForm.arrival_date.value != "")
		return dateStrToDateObj(document.searchForm.arrival_date.value,null,true);
	return null;
}

function getParsableDateStr(dateObj) {
	return (CalendarInfo.shortMonthArray[dateObj.getMonth()] + ", " + dateObj.getDate() + " " + dateObj.getFullYear());
}

function Calendar(inputObj,companionDate,showPreviousDates) {

	this.tableObj = getParentByTag(inputObj,"TABLE");
	this.inputObj = inputObj;
	this.dateFormat = CalendarInfo.dateFormat;
	this.dayDisplayObj = this.tableObj.rows[0].cells[2];
	this.isArrivalDate = false;
	this.isDepartureDate = false;
	this.companionDateObj = null;
	this.currentValue = inputObj.value;
	this.currentDateObj = null;
	this.inputValueDateObj = null;
	this.showPreviousDates = showPreviousDates == null? false : showPreviousDates;
	this.todayIsArrivalDate = false;

	if (companionDate != null) {
		if (companionDate.indexOf("arrival") != -1 || companionDate.indexOf("start") != -1)
			this.isDepartureDate = true;
		else if (companionDate.indexOf("departure") != -1 || companionDate.indexOf("end") != -1)
			this.isArrivalDate = true;
		var companionInputObj = eval(companionDate);
		if (companionInputObj != null)
			this.companionDateObj = dateStrToDateObj(companionInputObj.value,this.dateFormat,true);
	}

	if (this.currentValue != null) {
		this.currentDateObj = dateStrToDateObj(this.currentValue,this.dateFormat,true);
		this.inputValueDateObj = dateStrToDateObj(this.currentValue,this.dateFormat,true);
	}

	if (this.isArrivalDate && !this.showPreviousDates && this.currentDateObj != null && this.currentDateObj.getTime() < CalendarInfo.today.getTime()) {
		this.currentDateObj.setTime(CalendarInfo.today.getTime());
		this.inputObj.value = "";
	}

	if (this.isDepartureDate && this.companionDateObj != null) {


		// if departure date isn't set, set it to the arrival date.
		if (this.currentDateObj == null) {

			this.currentDateObj = new Date();
			this.currentDateObj.setTime(this.companionDateObj.getTime());
			this.inputObj.value = "";

		} else if (this.currentDateObj.getTime() < this.companionDateObj.getTime())  {

			// if departure date is earlier than the arrival date, set it to the arrival date.
			this.currentDateObj.setTime(this.companionDateObj.getTime());
			this.inputObj.value = "";
		}
	}

	if (this.currentDateObj == null) {

		// if the date isn't set, set it to today.
		this.currentDateObj = new Date();
		this.inputObj.value = "";
	}

	/*alert("this.isArrivalDate: " + this.isArrivalDate + "\n" +
			"this.isDepartureDate: " + this.isDepartureDate + "\n" +
			"this.showPreviousDates: " + this.showPreviousDates + "\n" +
			"this.currentValue: " + this.currentValue + "\n" +
			"this.currentDateObj: " + this.currentDateObj + "\n" +
			"this.companionDateObj: " + this.companionDateObj + "\n")*/


	Calendar.prototype.writeCalendar = writeCalendar;
	function writeCalendar() {

		CalendarInfo.currentCalendar = this;
		var calendarLayerObj = getObj(CalendarInfo.calendarLayerName);
		calendarLayerObj.style.display = "";
		calendarPosition = returnPosition(this.inputObj);
		calendarLayerObj.style.top = calendarPosition.y + "px";
		calendarLayerObj.style.left = calendarPosition.x + (this.inputObj.clientWidth + 4) + "px";

		var calendarHTML = "<table cellpadding=\"0\" cellspacing=\"0\"><tr>";
		calendarHTML += "<td valign=\"top\">";
		calendarHTML += this.writeMonth(false);
		calendarHTML += "</td><td><img src=\"img/clear.gif\" width=\"10\" height=\"150\"/></td><td valign=\"top\">";
		calendarHTML += this.writeMonth(true);
		calendarHTML += "</td></tr><tr><td colspan=\"3\"><table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>";

		calendarHTML += "<td width=\"100\" class=\"calendarControl\">";

		var hidePrevious = (this.currentDateObj.getMonth() == CalendarInfo.today.getMonth()) && (this.currentDateObj.getFullYear() == CalendarInfo.today.getFullYear());
		if (!hidePrevious && this.todayIsArrivalDate)
			hidePrevious = true;
		if (hidePrevious && !showPreviousDates)
			calendarHTML += "&nbsp;";
		else
			calendarHTML += "<a href=\"javascript:changeCalendarMonth(-1)\">&lt; previous month</a>";

		calendarHTML += "</td>";
		calendarHTML += "<td align=\"center\" class=\"calendarControl\"><a href=\"javascript:closeCalendar();\">close</a></td>";
		calendarHTML += "<td width=\"100\" class=\"calendarControl\" align=\"right\"><a href=\"javascript:changeCalendarMonth(1)\">next month &gt;</a></td>";
		calendarHTML += "</tr></table></td></tr></table>";

		calendarLayerObj.innerHTML = calendarHTML;
	}

	Calendar.prototype.writeMonth = writeMonth;
	function writeMonth(isSecondMonth) {

		if (isSecondMonth) {
			var calMonth = this.currentDateObj.getMonth() + 1;
			var calYear = this.currentDateObj.getFullYear();
			if (calMonth > 11) {
				calMonth = 0;
				calYear++;
			}
			var dObj = dateValuesToDateObj(1,calMonth,calYear);
		} else {
			var dObj = new Date();
			dObj.setTime(this.currentDateObj.getTime());
		}

		var dayOfWeek = getFirstDayOfMonth(dObj);
		var totalDays = getMaxDaysInMonth(dObj);

		var calendarHTML = "<table cellpadding=\"0\" cellspacing=\"0\" class=\"calendarTable\"><tr>";
		calendarHTML += "<td colspan=\"7\" class=\"calendarTitle\">" + CalendarInfo.monthArray[dObj.getMonth()];
		calendarHTML += " " + dObj.getFullYear() + "</td>";

		calendarHTML += "</td></tr><tr>";
		calendarHTML += "<td class=\"calendarCellHeader\">S</td>";
		calendarHTML += "<td class=\"calendarCellHeader\">M</td>";
		calendarHTML += "<td class=\"calendarCellHeader\">T</td>";
		calendarHTML += "<td class=\"calendarCellHeader\">W</td>";
		calendarHTML += "<td class=\"calendarCellHeader\">T</td>";
		calendarHTML += "<td class=\"calendarCellHeader\">F</td>";
		calendarHTML += "<td class=\"calendarCellHeader\">S</td>";
		calendarHTML += "</tr><tr>";

		if (dayOfWeek != 0)
			calendarHTML += "<td class=\"calendarDayCell\" colspan=\"" + dayOfWeek + "\">&nbsp;</td>";

		for (currentDay = 1; currentDay < totalDays + 1; currentDay++) {
			dayOfWeek++;

			var pastDay = false;

			if (!this.showPreviousDates) {
				if ((	dObj.getMonth() == CalendarInfo.today.getMonth())
						&& (dObj.getFullYear() == CalendarInfo.today.getFullYear())
						&& (CalendarInfo.today.getDate() > currentDay)) {
					pastDay = true;
				}
			}

			if (this.isDepartureDate && this.companionDateObj != null
					&& (dObj.getMonth() == this.companionDateObj.getMonth())
					&& (dObj.getFullYear() == this.companionDateObj.getFullYear())
					&& (currentDay < this.companionDateObj.getDate())) {
				pastDay = true;
			}

			if (pastDay) {

				calendarHTML += "<td class=\"calendarPastDayCell\">" + currentDay + "<br/><img src=\"img/clear.gif\" width=16 height=1></td>";

			} else {

				var todayIsArrival = (this.isDepartureDate)
					? datesEqual(this.companionDateObj,dObj,currentDay)
					: false;

				if (todayIsArrival)
					this.todayIsArrivalDate = true;

				var clsName = (datesEqual(this.inputValueDateObj,dObj,currentDay))? "calendarSelectedDayCell" : "calendarDayCell";

				if (todayIsArrival)
					calendarHTML += "<td class=\"calendarArrivalDayCell\">" + currentDay + "<br/><img src=\"img/clear.gif\" width=16 height=1></td>";
				else
					calendarHTML += "<td class=\""+clsName+"\" onclick=\"setCalendarDate(" + currentDay + "," + dObj.getMonth() + "," + dObj.getFullYear() + ")\" onmouseover=\"highlightCalendarCell(this);\" onmouseout=\"unhighlightCalendarCell(this);\">" + currentDay + "<br/><img src=\"img/clear.gif\" width=16 height=1></td>";
			}
			if (dayOfWeek%7 == 0)
				calendarHTML += "</tr><tr>";
		}

		if (dayOfWeek%7 != 0)
			calendarHTML += "<td class=\"calendarDayCell\" colspan=\"" + (7 -dayOfWeek%7) + "\">&nbsp;</td>";

		calendarHTML += "</tr></table>";
		return calendarHTML;
	}

	Calendar.prototype.calendarDatesEqual = calendarDatesEqual;
	function calendarDatesEqual(dateObj1,dateObj2,calendarDay) {
		if (dateObj1 == null || dateObj2 == null) return false;
		return (dateObj1.getDate() == calendarDay &&
				dateObj1.getMonth() == dateObj2.getMonth() &&
				dateObj1.getFullYear() == dateObj2.getFullYear())
	}
}

function datesEqual(dateObj1,dateObj2,equalDay) {
	if (dateObj1 == null || dateObj2 == null) return false;
	if (equalDay == null) equalDay = dateObj2.getDate();
	return (dateObj1.getDate() == equalDay &&
			dateObj1.getMonth() == dateObj2.getMonth() &&
			dateObj1.getFullYear() == dateObj2.getFullYear())
}

var calendarFormName = "searchForm";
function showCalendar(hrefObj,companionDate,showPreviousDates,formName) {
    calendarFormName = formName == null? "searchForm" : formName;
	tableObj = getParentByTag(hrefObj,"TABLE");
	inputObj = tableObj.rows[0].cells[0].firstChild;
	if (CalendarInfo.currentCalendar == null || CalendarInfo.currentCalendar.inputObj != inputObj) {
		clearTimeout(CalendarInfo.timer);
		var calendar = new Calendar(inputObj,companionDate,showPreviousDates);
		calendar.writeCalendar();
	}
	calendarListener();
}

function calendarListener() {
}

function closeCalendar() {
	if (CalendarInfo.currentCalendar != null)
		getObj(CalendarInfo.calendarLayerName).style.display = "none";
	CalendarInfo.currentCalendar = null;
}

function checkCloseCalendar(inputObj) {
	var dateObj = dateStrToDateObj(inputObj.value,CalendarInfo.dateFormat,true);
	if (CalendarInfo.currentCalendar != null) {
		if (dateObj == null)
			CalendarInfo.currentCalendar.dayDisplayObj.innerHTML = "";
		else
			CalendarInfo.currentCalendar.dayDisplayObj.innerHTML = "&nbsp;" + dayOfWeekFromDateObj(dateObj);
	}
	CalendarInfo.timer = setTimeout("closeCalendar()",200);
}

function setCalendarDate(dayVal,monthVal,yearVal) {

	var selectedDateObj = dateValuesToDateObj(dayVal,monthVal,yearVal);
	CalendarInfo.currentCalendar.inputObj.value = dateObjToDateStr(selectedDateObj);

	/*if (isSecondMonth) {
		CalendarInfo.currentCalendar.secondMonthDateObj.setDate(dayValue);
		dateObjToDateStr(CalendarInfo.currentCalendar.secondMonthDateObj);
	} else {
		CalendarInfo.currentCalendar.currentDateObj.setDate(dayValue);
		dateObjToDateStr(CalendarInfo.currentCalendar.currentDateObj);;
	}*/

	CalendarInfo.currentCalendar.dayDisplayObj.innerHTML = "&nbsp;" + dayOfWeekFromDateObj(selectedDateObj);

    var formObj = document.forms[calendarFormName];
	if (!CalendarInfo.isDepartureDate && formObj != null && formObj.arrival_date != null && formObj.departure_date != null) {

		arDate = null
		depDate = null;
		if (formObj.arrival_date.value != "")
			arDate = dateStrToDateObj(formObj.arrival_date.value)
		if (formObj.departure_date.value != "")
			depDate = dateStrToDateObj(formObj.departure_date.value)

		if (arDate != null && (depDate == null || depDate.getTime() <= arDate.getTime())) {
			//var day = arDate.getDate();
			//arDate.setDate(day + 14);
			//document.searchForm.departure_date.value = dateObjToDateStr(arDate);
			formObj.departure_date.value = "";
		}

		formObj.departure_date.focus();

	} else {
		CalendarInfo.currentCalendar.inputObj.focus();
	}

	closeCalendar();
	//CalendarInfo.timer = setTimeout("closeCalendar()",200);
	/*if (CalendarInfo.currentCalendar.inputObj.name == "arrival_date" && document.searchForm.departure_date.value == "") {
		var departureDate = new Date();
		departureDate.setTime(CalendarInfo.currentCalendar.currentDateObj.getTime());
		departureDate.setDate(departureDate.getDate() + 7);
		document.searchForm.departure_date.value = dateObjToDateStr(departureDate);
	}	*/
    setDateHook();
}

function setDateHook() {
    // over-ride
}

function changeCalendarMonth(monthIndex) {
	clearTimeout(CalendarInfo.timer);
	var month = CalendarInfo.currentCalendar.currentDateObj.getMonth() + monthIndex;
	CalendarInfo.currentCalendar.currentDateObj.setMonth(month);

//	CalendarInfo.currentCalendar.secondMonthDateObj = new Date();
//	CalendarInfo.currentCalendar.secondMonthDateObj.setTime(CalendarInfo.currentCalendar.currentDateObj.getTime());
//	CalendarInfo.currentCalendar.secondMonthDateObj.setMonth(month + 1);

//	if (CalendarInfo.currentCalendar.currentDateObj.getMonth() == 0 && monthIndex == 1)
//		CalendarInfo.currentCalendar.secondMonthDateObj.setYear(CalendarInfo.currentCalendar.currentDateObj.getFullYear());

//	if (CalendarInfo.currentCalendar.currentDateObj.getMonth() == 11 && monthIndex == -1)
//		CalendarInfo.currentCalendar.secondMonthDateObj.setYear(CalendarInfo.currentCalendar.currentDateObj.getFullYear() + 1);

	//alert(CalendarInfo.currentCalendar.currentDateObj.getMonth() + " " + CalendarInfo.currentCalendar.secondMonthDateObj.getMonth())
	//alert(CalendarInfo.currentCalendar.currentDateObj.getFullYear() + " " + CalendarInfo.currentCalendar.secondMonthDateObj.getFullYear())
	CalendarInfo.currentCalendar.writeCalendar();
	CalendarInfo.currentCalendar.inputObj.focus();
}
/*
function changeCalendarYear(yearValue) {
	clearTimeout(CalendarInfo.timer);
	yearValue = parseInt(yearValue);
	CalendarInfo.currentCalendar.currentDateObj.setFullYear(yearValue);
	CalendarInfo.currentCalendar.writeCalendar();
	CalendarInfo.currentCalendar.inputObj.focus();
}*/

function getMaxDaysInMonth(dateObj) {
	return CalendarInfo.maxDaysInMonthArray[parseInt(dateObj.getMonth())]
}

function getFirstDayOfMonth(dateObj) {
	newDate = new Date();
	newDate.setTime(dateObj.getTime());
	newDate.setDate(1);
	return parseInt(newDate.getDay());
}

function dayOfWeekFromDateObj(dateObj) {
	return CalendarInfo.dayOfWeekArray[parseInt(dateObj.getDay())]
}

function highlightCalendarCell(cellObj) {
	if (cellObj.className.indexOf("calendarHigh ") != 0)
		cellObj.className = "calendarHigh " + cellObj.className;
}

function unhighlightCalendarCell(cellObj) {
	if (cellObj.className.indexOf("calendarHigh ") == 0)
		cellObj.className = cellObj.className.substring("calendarHigh ".length);
}

function dateObjToDateStr(dateObj, dateFormat) {
	var dateObj = (dateObj == null)? new Date() : dateObj;
	var dateFormat = (dateFormat == null)? CalendarInfo.dateFormat : dateFormat;
	var delim = dateFormat.charAt(1);
	var dateFormatArray = dateFormat.split(delim);
	var dateStr = "";
	for (ii=0;ii<dateFormatArray.length;ii++) {
		if (dateFormatArray[ii] == CalendarInfo.indicatorDay)
			dateStr += dateObj.getDate();
		else if (dateFormatArray[ii] == CalendarInfo.indicatorMonth)
			dateStr += dateObj.getMonth() + 1;
		else if (dateFormatArray[ii] == CalendarInfo.indicatorYear)
			dateStr += dateObj.getFullYear();
		if (ii < dateFormatArray.length - 1)
			dateStr += delim;
	}
	return dateStr;
}

function dateStrToDateObj(dateStr,dateFormat,returnNull) {

	var defaultVal = (returnNull)? null : CalendarInfo.today;

	if (dateStr instanceof Date)
		return dateStr;

	if (dateStr == null || dateStr.length < 5)
		return defaultVal;

	var dateFormat = (dateFormat == null)? CalendarInfo.dateFormat : dateFormat;
	var delim = dateFormat.charAt(1);

	var dateArray = dateStr.split(delim);
	if (dateArray.length != 3)
		return defaultVal;

 	var dateFormatArray = dateFormat.split(delim);

	var dayVal = null;
	var monthVal = null;
	var yearVal = null;

	for (var ii=0;ii<dateArray.length;ii++) {

        var dateVal = (dateArray[ii].charAt(0) == "0")
                ? parseInt(dateArray[ii].substring(1))
                : parseInt(dateArray[ii]);

//		var dateVal = parseInt(dateArray[ii]);
		if (isNaN(dateVal))
			return defaultVal;

		if (dateFormatArray[ii] == CalendarInfo.indicatorDay) {

			if (dateVal > 31) return defaultVal;
			dayVal = dateVal;

		} else if (dateFormatArray[ii] == CalendarInfo.indicatorMonth) {

			dateVal--;
			if (dateVal > 11) return defaultVal;
			monthVal = dateVal;

		} else if (dateFormatArray[ii] == CalendarInfo.indicatorYear) {

			if (dateVal > 100 && (dateVal > CalendarInfo.yearMax || dateVal < CalendarInfo.yearMin))
				return defaultVal;

			if (dateVal < 100) {
				dateVal = (dateVal < CalendarInfo.splitCentury)? 2000 + dateVal : 1900 + dateVal;
			}
			yearVal = dateVal;

		} else {
			return defaultVal;
		}
	}

	return dateValuesToDateObj(dayVal,monthVal,yearVal);
}

function dateValuesToDateObj(dayVal,monthVal,yearVal) {
	//alert(CalendarInfo.shortMonthArray[parseInt(monthVal)] + " " + dayVal + ", " + yearVal)
	var timestamp = Date.parse(CalendarInfo.shortMonthArray[parseInt(monthVal)] + " " + dayVal + ", " + yearVal);
	var retVal = new Date();
	retVal.setTime(timestamp);
	return retVal;
}

document.write("<div style=\"position:absolute;display:none;z-index:100;\" id=\"calendarLayer\"></div>");



// **** SKYPE FUNCTIONS ***** //


var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function oopsPopup() {
    if((navigator.language && navigator.language.indexOf("ja") != -1) || (navigator.systemLanguage && navigator.systemLanguage.indexOf("ja") != -1) || (navigator.userLanguage && navigator.userLanguage.indexOf("ja") != -1)) {
        var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops_ja.html";
    } else {
        var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops.html";
    }
	var windowName = "oops";
	var popW = 540, popH = 305;
	var scrollB = 'no';
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	oopswindow = window.open(URLtoOpen, windowName,'width=' + popW + ',height=' + popH + ',scrollbars=' + scrollB + ',screenx=' +leftPos +',screeny=' +topPos +',top=' +topPos +',left=' +leftPos);
	return false;
}

if(typeof(detected) == "undefined" && activex) {
    document.write(
        ['<script language="VBscript">',
        'Function isSkypeInstalled()',
        'on error resume next',
        'Set oSkype = CreateObject("Skype.Detection")',
        'isSkypeInstalled = IsObject(oSkype)',
        'Set oSkype = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function skypeCheck() {
    if(CantDetect) {
        return true;
    } else if(!activex) {
        var skypeMime = navigator.mimeTypes["application/x-skype"];
        detected = true;
        if(typeof(skypeMime) == "object") {
            return true;
        } else {
            return oopsPopup();
        }
    } else {
        if(isSkypeInstalled()) {
            detected = true;
            return true;
        }
    }

    detected = true;
    return oopsPopup();
}

function loadDetection() {
    if(document.getElementById && document.getElementsByTagName) {
        if (window.addEventListener) window.addEventListener('load', addDetection, false);
        else if (window.attachEvent) window.attachEvent('onload', addDetection);
    }
}

function addDetection() {
    var pageLinks = document.getElementsByTagName("a");
    for (var i=0; i < pageLinks.length; i++) {
        if(pageLinks[i].childNodes[0] && pageLinks[i].childNodes[0].src) {
            if((pageLinks[i].childNodes[0].src.indexOf('download.skype.com\/share\/skypebuttons') != -1 || pageLinks[i].childNodes[0].src.indexOf('mystatus.skype.com') != -1) && (typeof(pageLinks[i].onclick) == "undefined" || pageLinks[i].onclick == null)) {
                pageLinks[i].onclick = function sChk() { return skypeCheck(); }
            }
        }
    }
}

loadDetection();
