function initControls(){
	$('span.tooltip, a.tooltip').tooltip();
	$(".MainMenuLink").MainMenu("MainMenuLink", ".MainMenuContent", { width: "900px", position: 'absolute', marginLeft: 50 });
	$(".toplinkMenu").MainMenu("toplinkMenu", ".toplinkContent", {justify: "right", linkID: "toplinkMenu", marginRight: 10, createNewDiv : false });
}

function multimediaClick(mm_id, page_id, type)
{
	var url = '/system/control/jump.php';
	var params = 'mm=' + mm_id + '&pid=' + page_id + '&type='+ type + '&action=click';
	$.ajax
		({
		 	url: url,
			data: params,
			type: 'GET',
			async: false
			
		 });
	return true;
}

function getMultimedia(path, title, imagelink, target, divName, mm_id, updateImpressions, backgroundStyle, width, height, pageid, type)
{
	var url = '/system/control/getMultimedia.php';
	var params = 'mmid=' + mm_id + '&title=' + title + '&url=' + escape(imagelink) + '&target=' + target + '&path=' + path + '&updateimpressions=' + updateImpressions + '&background=' + backgroundStyle + '&width=' + width + "&height=" + height + "&pid=" + pageid + "&type=" + type;
	// notice the use of a proxy to circumvent the Same Origin Policy.
	$.ajax({
		type: "POST",
		url: url,
		data: params,
		success: function(msg){
					$("#" + divName).css("display", 'block');
					if ( backgroundStyle == true)
					{
						$("#" + divName).css("background", msg);
					}
					else
					{
					$("#" + divName).html(msg);
					}
				}
	});
}

function updateCities(websiteid, languageid, productType, selectedRegionID,selectedCityID, updateField, UpdateLandmark)
{
	var siteurl = document.domain;
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = "http://" +  siteurl + "/system/control/city-update.php?websiteid=" + websiteid + "&langid=" + languageid + "&regionID=" + selectedRegionID + "&cityID=" + selectedCityID + "&updatefield=" + updateField + "&producttype=" + productType + "&updatelandmark=" + UpdateLandmark;
	document.body.appendChild(jsel);
}

function checkField(destinationField, cityField, regionField, noDatesField, fromDateField, toDateField, sectionID){
	var oREGEXPR = /^([0-9]|[0,1,2][0-9]|3[0,1])\/([\d]|[0,1][1-9]|10)\/\d{4}$/
	
	if( !destinationField.val() && cityField.val() <= 0 && regionField.val() <= 0){
		alert("Please type a name of a Region or City which you would like to search for.");
		destinationField.focus();
		return false;
	}
	else if ( ( !oREGEXPR.test(fromDateField.val()) || !oREGEXPR.test(toDateField.val()) ) && noDatesField.attr('checked') == false )
	{
		alert("Please enter the search dates.");
		fromDateField.focus();
		return false;
	}
	else{
		makeMeDissapear();
		updateLabel(sectionID, 'SP');
		return true;
	}	
}

function checkAdvancedField(formName, regionField, cityField){
	if(($("#" + regionField).val() == "All") && ($("#" + cityField).val() == "All")){
		alert("Please specify the Region or City in which you would like to search.");
		$(regionField).focus();
		return false;
	}
	else{
		makeMeDissapear();
		return true;
	}	
}

function popUp(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=780,height=750,left = 200,top = 100');");
}
function popUpImage(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=654,left = 200,top = 100');");
}	
function popUpWithScroll(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=780,height=750,left = 200,top = 100');");
}
function popUpRates(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=600,left = 200,top = 200');");
}
function makeMeDissapear(formId) {
	var formId = ( formId == null )?'contentdisplay':formId;
	var oDiv = $('#' + formId);
	if(oDiv){
		oDiv.css("display", "none");
		oPleaseWait = $("#pleasewait");
		if(oPleaseWait){
			oPleaseWait.css("display", "block");
		}
	}
}

function doAmex() {
   cctype = document.checkout.cctype.options[document.checkout.cctype.selectedIndex].value;
   if (cctype == "American Express"){
	   $('#amexinfo').attr("class", "requiredmessage show");
	}
	else{
	   $('#amexinfo').attr("class", "requiredmessage");
	}
}

function showRequiredBabyAge(value)
{
	var disp;
	if (value == 'Yes')
	{
		disp = 'inline';
	}
	else
	{
		disp = 'none';
	}
	$('#babyagerequired').css("display",disp);
}

function DHTMLSound(surl) {
$("#dummyspan").html("<embed src='"+surl+"' hidden=true autostart=true loop=false>");
}	
function showSearchFilter()
{
	var oSearchFilter = $("#searchfilter");
	var oCurrentSearchText = $("#currentsearchtext");
	if(oSearchFilter.css("display") == "none"){
		oSearchFilter.css("display", "block");
		oCurrentSearchText.html("Hide Search");
	}
	else{
		oSearchFilter.css("display", "none");
		oCurrentSearchText.html("Change Search");
	}
}
function swapPic(divName)
{
	var ran = Math.floor(Math.random() * 9) + 1;
	var picPath='/en/images/webcams/harbour.jpg?'+new Date().getTime();
	$("#" + divName).attr("src", picPath);
	return true;
}

function callProfiler(actionrootpath, divName, websiteid, pageid, languageid, productid, type, languagefolder, sectionfolder, limit)
{
	url = actionrootpath + "getProfilerData.php";
	params = "WebsiteID=" + websiteid + "&PageID=" + pageid + "&LanguageID=" + languageid + "&ProductID=" + productid +"&Type=" + type + "&LanguageFolder=" + languagefolder + "&SectionFolder=" + sectionfolder + "&Limit=" + limit;

	$.ajax({
			type: "POST",
			url: url,
			data: params,
			success: function(msg){
						$("#" + divName).html(msg);
					}
		});
}

function doAjaxCall(path, params, values, divName)
{
	var paramstring = "?";
	for(var i = 0; i<params.length; i++){
		paramstring += "&" + params[i] + "=";
		paramstring += values[i];
	}	
	$.ajax({
		type: "POST",
		url: path,
		data: paramstring,
		success: function(msg){
					$("#" + divName).html(msg);
				}
	});
}

function updateLabel (pid, pod)
{
	var url = '/system/control/ajaxCalls.php';
	var params = 'type=labelling&pid=' + pid + '&pod=' + pod;
	$.ajax({
		type: "POST",
		url: url,
		data: params,
		success: function(msg){
					 return true;
				}
	});
	return true;
}
function setSearchPod ( text, li )
{
	var location = (li)?(li.id).split('-'):text.split('-');
	$('#region').val(location[0]);
	$('#city').val((location[1])?location[1]:'All') ;
}

function panoramioChangeImage(imagePath, imageTitle, imageURL, ownerName, ownerURL)
{
	$('#panoramioimagelink').attr("href", imageURL);
	$('#panoramioimage').attr("src", imagePath);
	$('#panoramioimage').attr("title", imageTitle);
	$('#panoramioimage').attr("alt", imageTitle);
	$('#panoramioimagetitle').html(imageTitle);
	$('#panoramioownerlink').attr("href", ownerURL);
	$('#panoramioownerlink').html(ownerName);
	
}

function removeProduct(actionrootpath, divName, websiteid, pageid, languageid, productid, sectionfolder)
{
	url = actionrootpath + "getProfilerData.php";
	type = "removeProduct";
	params = "WebsiteID=" + websiteid + "&PageID=" + pageid + "&LanguageID=" + languageid + "&ProductID=" + productid +"&Type=" + type + "&SectionFolder=" + sectionfolder;
	$.ajax({
		type: "POST",
		url: url,
		data: params,
		success: function(msg){
			$("#" + divName + '_' + productid).css('display', 'none');
			if($("." + divName + '_div:visible').length == 0){
				$("#" + divName).html('No Recent Hotels Viewed');
			}
			return true;
		}
	});
	return true;
}

var aOpenPopups = Array();
var aSeletedTabs = Array();
var aToggleSigns = Array();
function toggleBottomPopup(oLink, sPopup){
	oLink = $(oLink);
	var oPopup = $("#" + sPopup);
	var oToggleSign = $("#" + sPopup + "_togglesign");
	if(oLink.attr("class") == "barlink selected"){
		oLink.removeClass("selected");
		oToggleSign.html("+");
		oPopup.hide(); 
	}
	else{
		closeAllBottomPopups();
		oLink.addClass("selected");
		oToggleSign.html("-");
		oPopup.show(); 
		
		aOpenPopups.push(oPopup);
		aSeletedTabs.push(oLink);
		aToggleSigns.push(oToggleSign);
	}
	return false;
}

function closeAllBottomPopups(){
	for(var i = 0; i <aOpenPopups.length; i++){
		aOpenPopups[i].hide();
		aSeletedTabs[i].attr("class", "barlink");
		aToggleSigns[i].html("+");
	}
}

function initAutoComplete(filePath)
{
	$("input#destination").autocomplete(
		filePath,
		{
			cityField: '#city',
			regionField: '#region',
			maxSuggestions: 10
		});
}

function selectOther()
{
	$('#city').attr('checked','checked');
	$("#region").val(0);
	$("#city").val(0);
	$("#destination").focus();
}

function showPrices()
{
	$('#hotelsearch #hotelFromDate').focus();
}
function preloadImages(mediabase){
	if (document.images) {
	   imgSearchS = new Image();
	   imgSearchL = new Image();
	   imgBookNow = new Image();
	   imgClose   = new Image();
	   imgFeedbackBg   = new Image();
	   imgClose.src     = mediabase + "images/commonweb/infowindow_close.gif";
	   imgSearchS.src   = mediabase + "images/commonweb/search.gif";
	   imgBookNow.src   = mediabase + "images/commonweb/booknow_small.gif";
	   imgSearchL.src   = mediabase + "images/commonweb/searchbutton.gif";	   
	   imgFeedbackBg.src   = mediabase + "images/commonweb/feedbackbar.gif";	   
	}
}

function productChangeImage(imagePath, imageTitle)
{
	$('#productimage').attr("src", imagePath);
	$('#productimage').attr("title", imageTitle);
	$('#productimage').attr("alt", imageTitle);
	$('#productimagetitle').html(imageTitle);	
}
