﻿function $$(id) {
	try {
		return document.getElementById(id);
	}
	catch (e){
		return null;
	}
}

function OpenWindow(URL, Name, Width, Height) {
	var PositionX = 0;
	var PositionY = 0;
	var DefaultWidth  = 600;
	var DefaultHeight = 400;
	var WinObject, Params = 'scrollbars=1, resizable=1, left=' + PositionX + ', top=' + PositionY;
	Params += ', width=' + ((isNaN(parseInt(Width))) ? DefaultWidth : Width);
	Params += ', height=' + ((isNaN(parseInt(Height))) ? DefaultHeight : Height);
	WinObject = window.open(URL, Name, Params)
	if (!WinObject) return true;
	if (WinObject.focus) WinObject.focus();
	return false;
}

function InsertFlash(Target, ID, Version, File, Width, Height, Parameters) {
	var ParametersObjectStr = ''
	var ParametersEmbedStr = ''
	var s, v
	for (s in Parameters) {
		v = Parameters[s]
		ParametersObjectStr += '<param name="'+s+'" value="'+v+'" />'
		ParametersEmbedStr += ' '+s+'="'+v+'" '
	}
	var FlashHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
			'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+Version+',0,0,0" ' +
			'width="'+Width+'" height="'+Height+'" id="'+ID+'">' +
			'<param name="movie" value="'+File+'" />' +
			ParametersObjectStr +
			'<embed src="'+File+'" menu="true" ' +
				'pluginspage="http://www.macromedia.com/go/getflashplayer"  ' +
				'type="application/x-shockwave-flash" width="'+Width+'" height="'+Height+'" name="'+ID+'" '+ParametersEmbedStr+' />' +
		'</object>';
	document.getElementById(Target).innerHTML = FlashHTML
}

function VerifyBrowserFlashSupport(FlashVersion) {
	var flashinstalled = 0;
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x) {
			flashinstalled = 2;
			if (x.description) {
				var y = x.description;
				if (y.charAt(y.indexOf('.')-1)+'' == FlashVersion+'') return true;
			}
		}
		if ((FlashVersion == 2) && (navigator.plugins["Shockwave Flash 2.0"])) {
			return true;
		}
	} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
	} else {
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + FlashVersion);
			return true;
		}
		catch(e){
		}
	}
	return false;
}

function InsertFlashOrHTML(Target, ID, Version, File, Width, Height, Parameters, NoFlashHTML) {
	if (VerifyBrowserFlashSupport(Version)) {
		InsertFlash(Target, ID, Version, File, Width, Height, Parameters)
	} else {
		document.getElementById(Target).innerHTML = NoFlashHTML
	}
}

function __doSearch(){
	SearchFieldTrim();
	if (document.frmSearch.txtSearch.value != DummySearchString && document.frmSearch.txtSearch.value != '') {
		document.getElementById('pp'+'search').value = '200';
		document.frmSearch.action = 'search.asp';
		document.frmSearch.submit();
	}
}

function __doMiceSearch(){
	SearchFieldTrim();
	if (document.frmSearch.txtSearch.value != DummySearchString && document.frmSearch.txtSearch.value != '') {
		document.getElementById('pp'+'search').value = '200';
		document.frmSearch.action = 'mice_search.asp';
		document.frmSearch.submit();
	}
}

function SearchFieldTrim() {
	var s = document.frmSearch.txtSearch.value;
	var x, l, TrimLeft, TrimRight;
	l = s.length;
	TrimLeft = -1;
	TrimRight = l;
	for (x=0; x<l; x++) {
		if ((s.charAt(x) != ' ') && (s.charAt(x) != '	')) break;
		TrimLeft = x;
	}
	TrimLeft++;
	if (TrimLeft < TrimRight) {
		for (x=l-1; x>TrimLeft; x--) {
			TrimRight = x+1;
			if ((s.charAt(x) != ' ') && (s.charAt(x) != '	')) break;
		}
		s = s.substring(TrimLeft, TrimRight);
	} else {
		s = '';
	}
	document.frmSearch.txtSearch.value = s;
	return s;
}

function __focusSearch() {
	if (document.frmSearch.txtSearch.value == DummySearchString) {
		document.frmSearch.txtSearch.value = '';
	}
}

function __blurSearch() {
	SearchFieldTrim();
	if (document.frmSearch.txtSearch.value == '') {
		document.frmSearch.txtSearch.value = DummySearchString;
	}
}

function __enterSearch(event) {
	var code = 0;
	code = event.keyCode;
	if (code==13) {
		__doSearch();
	}
}

function __enterMiceSearch(event) {
	var code = 0;
	code = event.keyCode;
	if (code==13) {
		__doMiceSearch();
	}
}

function ChkNum(sn, dn) {
	if (isNaN(sn) || sn == "" || sn == " "){
		return dn;
	} else {
		return sn;
	}
}

function no_enter() {
	return !(window.event && window.event.keyCode == 13);
}

function switchDivs(div_on, div_off){
	if(document.getElementById('o_miniselected')){
		document.getElementById('o_miniselected').id = '';
	}
	document.getElementById(div_on).style.display = 'block';
	document.getElementById(div_on).style.visibility = 'visible';
	document.getElementById(div_off).style.display = 'none';
	document.getElementById(div_off).style.visibility = 'hidden';
}

/* adrotator */
var i = 1;
var ii = 1;
var timerID = 0;
var timerID1 = 0;
var contentdivs = new Array();
var packetdivs = new Array();

function startTime(){
	var time = new Date();
	hours = time.getHours();
	mins = time.getMinutes();
	secs = time.getSeconds();
	closeTime = hours * 3600 + mins * 60 + secs;
	closeTime += 8; // Delay in seconds
	Timer();
}
function startTime1(){
	var time1 = new Date();
	hours1 = time1.getHours();
	mins1 = time1.getMinutes();
	secs1 = time1.getSeconds();
	closeTime1 = hours1 * 3600 + mins1 * 60 + secs1;
	closeTime1 += 8; // Delay in seconds
	Timer1();
}

function Timer(){
	var time = new Date();
	hours = time.getHours();
	mins = time.getMinutes();
	secs = time.getSeconds();
	curTime = hours * 3600 + mins * 60 + secs;
	if (curTime >= closeTime){
		cmd('');
		startTime();
	} else {
		timerID = window.setTimeout("Timer()", 1000);
	}
}
function Timer1(){
	var time1 = new Date();
	hours1 = time1.getHours();
	mins1 = time1.getMinutes();
	secs1 = time1.getSeconds();
	curTime1 = hours1 * 3600 + mins1 * 60 + secs1;
	if (curTime1 >= closeTime1){
		cmd1('');
		startTime1();
	} else {
		timerID1 = window.setTimeout("Timer1()", 1000);
	}
}

function exGetElementsByName(tag, name) {
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(j = 0, jarr = 0; j < elem.length; j++) {
		att = elem[j].getAttribute("name");
		if(att == name) {
			arr[jarr] = elem[j];
			jarr++;
		}
	}
	return arr;
}

function cmd(c) {
	if (c == 'fwd'){
		clearTimeout(timerID);
		if (i < contentdivs.length) i++
		else i = 1;
		startTime();
	}
	else if (c =='rev'){
		clearTimeout(timerID);
		if (i > 1) i--
		else i = contentdivs.length;
		startTime();
	}
	else if (c == 'stop'){
		clearTimeout(timerID);
	}
	else {
		if (i < contentdivs.length) i++
		else i = 1;
	}
	document.getElementById('adrotator').innerHTML = contentdivs[i - 1].innerHTML;
}

function cmd1(c) {
	if (c == 'fwd'){
		clearTimeout(timerID1);
		if (ii < packetdivs.length) ii++
		else ii = 1;
		startTime1();
	}
	else if (c =='rev'){
		clearTimeout(timerID1);
		if (ii > 1) ii--
		else ii = packetdivs.length;
		startTime1();
	}
	else if (c == 'stop'){
		clearTimeout(timerID1);
	}
	else {
		if (ii < packetdivs.length) ii++
		else ii = 1;
	}
	document.getElementById('packetrotator').innerHTML = packetdivs[ii - 1].innerHTML;
}

function css(el, targetclass){
	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
	return needle.test(el.className)
}

function initAds() {
	var alldivs = document.getElementById('adcontainer').getElementsByTagName('div')
	for (var i = 0; i < alldivs.length; i++){
		if (css(alldivs[i], 'ad')){ // check for DIVs with class 'ad'
			contentdivs.push(alldivs[i])
		}
	}
	document.getElementById('adrotator').innerHTML = contentdivs[0].innerHTML;
	startTime();
}

function initPackets() {
	var alldivs = document.getElementById('packetcontainer').getElementsByTagName('div')
	for (var i = 0; i < alldivs.length; i++){
		if (css(alldivs[i], 'pack')){ // check for DIVs with class 'pack'
			packetdivs.push(alldivs[i])
		}
	}
	document.getElementById('packetrotator').innerHTML = packetdivs[0].innerHTML;
	startTime1();
}

/* /adrotator */

/* booking */
function updateAccomodations(oId, selectedCategory, selectedAccomodation){
	$$('ddAccomodations' + oId).options.length = 0;
	if (selectedCategory >= 0) {
		for (i = 0; i < accomodations[selectedCategory].length; i++) {
			$$('ddAccomodations' + oId).options[$$('ddAccomodations' + oId).options.length] = new Option(accomodations[selectedCategory][i], accomodations[selectedCategory][i])
			if (accomodations[selectedCategory][i] == selectedAccomodation) {
				$$('ddAccomodations' + oId).selectedIndex = i
			}
		}
	}
}
function ValueToIndex(SelectObject, Value) {
	for(index = 0; index < SelectObject.options.length; index++) {
		if(SelectObject[index].value == Value) {
			return index;
		}
	}
}
function __doBooking(oId){
	$$('ppBooking' + oId).value = '200';
	$$('frmBooking' + oId).action = 'booking.asp';
	$$('frmBooking' + oId).submit();
}
function __doMiceBooking(oId, inquiry_page){
	$$('ppBooking' + oId).value = '200';
	$$('frmBooking' + oId).action = inquiry_page;
	$$('frmBooking' + oId).submit();
}
/* booking */
/*
function updateAccomodations(frm, selectedCategory, ddAccommodations){
	frm.ddAccomodations.options.length = 0;
	if (selectedCategory >= 0) {
		for (i = 0; i < accomodations[selectedCategory].length; i++) {
			frm.ddAccomodations.options[frm.ddAccomodations.options.length] = new Option(accomodations[selectedCategory][i], accomodations[selectedCategory][i])
			if (accomodations[selectedCategory][i] == ddAccommodations) {
				frm.ddAccomodations.selectedIndex = i
			}
		}
	}
}
function ValueToIndex(SelectObject, Value) {
	for(index = 0; index < SelectObject.options.length; index++) {
		if(SelectObject[index].value == Value) {
			return index;
		}
	}
}
function __doBooking(frm, pp){
	document.getElementById(pp).value = '200';
	frm.action = 'booking.asp';
	frm.submit();
}
*/
