
var urlAddress = "http://www.globaltravellounge.com"; 
var pageName = "Globaltravellounge.com"; 
function addToFavorites() {
	if (window.external) { 
		window.external.AddFavorite(urlAddress,pageName) 
	}else{
		alert("Sorry! Your browser doesn't support this function.");
	}
}

function validateNewsletter(fId) {
	var m = '';
	if(!fId.name.value || fId.name.value=='Enter your name') {m+='- Please enter your name\n'}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false || fId.email.value=='Enter your email address'){m+='- Please enter a valid email address\n'}
	if(m){
		alert(m);
		return false;		
	}else{
		return true;		
	}
}

function validateSendToFriend(fId) {
	var m = '';
	if(!fId.name.value || fId.name.value=='Friend\'s name') {m+='- Please enter your friends name\n'}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.email.value) || isValidField(fId.email.value,2) == false || fId.email.value=='Friend\'s email address'){m+='- Please enter a valid email address\n'}
	if(!fId.comment.value || fId.comment.value=='- Comment -') {m+='- Please enter a comment\n'}
	if(m){
		alert(m);
		return false;		
	}else{
		return true;		
	}
}

function RequestCallback() {
	if(document.getElementById('idRequestCallbackForm')) {
		document.getElementById('idRequestCallbackForm').style.display='';
	}
}

function validateRequestCallback(fId) {
	var m = '';
	if(!fId.name.value || fId.name.value=='Your name') {m+='- Please enter your name\n'}
	if(!fId.phone.value || fId.phone.value=='Your phone number') {m+='- Please enter your phone number\n'}
	if(!fId.besttocall.value || fId.besttocall.value=='When is best to call?') {m+='- When is best to call?\n'}
	if(m){
		alert(m);
		return false;		
	}else{
		return true;		
	}
}

function validateHomeSearch(fId) {
	if(!fId.destination.value) {
		alert('Please select a destination');
		return false;
	}
}

function addtoWishlist(id, referrer) {
	if(confirm('Click OK to add this offer to your wishlist')) {
		location.href='/includes/wishlist.asp?action=add&id='+id+'&referrer='+referrer;
	}
}

function removefromWishlist(id) {
	if(confirm('Click OK to remove this offer from your wishlist')) {
		location.href='/includes/wishlist.asp?action=remove&id='+id;
	}
}
// 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."; }
	else if(iType==4)
	{ ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "; }
	else if(iType==5)
	{ ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-/ "; }
	var isValid=true;
	var Char;
	for (iii = 0; iii < sText.length && isValid == true; iii++) 
	{ 
		Char = sText.charAt(iii); 
		if (ValidChars.indexOf(Char) == -1) 
		{ isValid = false; }
	}
	return isValid;
}

function clearField(fId, sMatch, sChange){
	if(sChange == null) sChange = '';
	if(fId.value == sMatch)
	{ fId.value = sChange; }
}

function enquiryChildren(number) {
	for(x=1;x<10;x++) {
		if(x<=parseFloat(number)) {
			document.getElementById('child'+x).style.display='';	
		}else{
			document.getElementById('child'+x).style.display='none';	
		}
	}
}

function validateEnquiryForm(fId) {
	var e = '';
	if(!fId.enqFirstname.value){e+='- First name\n';}
	if(!fId.enqSurname.value){e+='- Surname\n';}
	if(!/.+@[^.]+(\.[^.]+)+/.test(fId.enqEmail.value) || isValidField(fId.enqEmail.value,2) == false){e+='- Valid email address\n'}
	if(!fId.enqTelephone.value){e+='- Telephone\n';}
	if(!fId.enqEnquiry.value){e+='- Enquiry\n';}
	if(!fId.enqAdults.value){e+='- Number of adults\n';}
	if(!fId.enqDuration.value){e+='- Preferred duration\n';}
	if(!isDate(fId.enqStartdate_d.value+'/'+fId.enqStartdate_m.value+'/'+fId.enqStartdate_y.value)){e+='- Valid date of travel\n';}
	if(!fId.enqDepAirport.value){e+='- Departure airport\n';}
	if(!fId.enqContactMethod.value){e+='- Preferred contact method\n';}
	if(e) {
		alert('The following fields are mandatory\n\n'+e);
		return false;
	}else{
		return true;
	}
}

function gotoPage(iPage) {
	document.paging._pg.value=iPage;
	document.paging.submit();
}

function SwitchPhoto(PlaceHolderName,ThumbImg, ThumbAlt){
	var ImagePath = ThumbImg;
	if (document.all){
		document.getElementById(PlaceHolderName).style.filter="blendTrans(duration=1)";
		document.getElementById(PlaceHolderName).filters.blendTrans.Apply();
	}
	if(document.getElementById) {
		document.getElementById(PlaceHolderName).src = ImagePath;
		document.getElementById(PlaceHolderName).alt = ThumbAlt;
	}else{
		document.HotelImage.src = ImagePath;
		document.HotelImage.alt = ThumbAlt;
	}
	if(document.all){
		document.getElementById(PlaceHolderName).filters.blendTrans.Play();
	}
}


function LoadGoogleAdvanced(sDivID, iCount) {
	if(iCount>0) {
		if(document.getElementById('idMapLink')) {
			document.getElementById('idMapLink').style.display='';
		}
		document.getElementById('googlemapAll').style.display='';
		
		divGoogle = document.getElementById(sDivID);
		divGoogle.style.display='';
		divGoogle.style.width = '540px';
		divGoogle.style.height = '230px';
		
		var hotelIcon = new GIcon();
		hotelIcon.image = "/images/ico_gm_hotel.png"
		hotelIcon.iconSize = new GSize(24, 25);
		hotelIcon.iconAnchor = new GPoint(9, 34);
		hotelIcon.infoWindowAnchor = new GPoint(9, 2);
		
		var airportIcon = new GIcon();
		airportIcon.image = "/images/ico_gm_airport.png"
		airportIcon.iconSize = new GSize(32, 32);
		airportIcon.iconAnchor = new GPoint(9, 34);
		airportIcon.infoWindowAnchor = new GPoint(11, 1);
		
		var interestIcon = new GIcon();
		interestIcon.image = "/images/ico_gm_interest.png"
		interestIcon.iconSize = new GSize(22, 22);
		interestIcon.iconAnchor = new GPoint(9, 34);
		interestIcon.infoWindowAnchor = new GPoint(11, 1);
		
		function createMarker(point, title, distance, type) {
			if(type=='hotel') {
				var marker = new GMarker(point, hotelIcon);
			}else if(type=='interest'){
				var marker = new GMarker(point, interestIcon);
			}else{
				var marker = new GMarker(point, airportIcon);
			}
			marker.image = "/images/ico_gm_"+type+".png";
			
			GEvent.addListener(marker, "click", function() {
				sHTML = title;
				marker.openInfoWindowHtml(sHTML);
			});
			return marker;
		}
		
		var map = new GMap2(divGoogle);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
		for(x=1;x<=iCount;x++) {
			
			sTitle = document.getElementById('googlemap_title'+x).value;
			sLat = document.getElementById('googlemap_lat'+x).value;
			sLng = document.getElementById('googlemap_lng'+x).value;
			sType = document.getElementById('googlemap_type'+x).value;
						
			if(x==1) {
				map.setCenter(new GLatLng(sLat,sLng), 9);	
			}
			if(sType!='resort') {
				//alert(sLat+', '+sLng);
				var point = new GLatLng(sLat,sLng);
				if(sType=='hotel') {
					map.addOverlay(createMarker(point, sTitle, '', sType));
				}
				if(sType=='airport') {
					map.addOverlay(createMarker(point, sTitle, '', sType));
				}
				if(sType=='interest') {
					sDistance = document.getElementById('googlemap_distance'+x);
					sImage = document.getElementById('googlemap_pic'+x);
					sDescription = document.getElementById('googlemap_desc'+x);
					sResortDescID = document.getElementById('googlemap_resortdescid'+x);
					sHTML='';
					sHTML+='<table border="0" cellpadding="0" cellspacing="0"><tr>'
					if(sImage) {
						sHTML+='<td valign="top"><div class="imageContainerGoogle"><img src="'+sImage.value+'" onerror="this.src=\'/images/_noimage.gif\'" /></div><td>';	
					}
					sHTML+='<td valign="top"><strong>'+sTitle+'</strong>'
					if(sDescription) {
						sHTML+='<br>'+sDescription.value;
					}
					if(sDistance) {
						sHTML+='<br>'+sDistance.value + ' from hotel';	
					}
					if(sResortDescID) {
						sHTML+='<br/><a href="/destinations/resortdesc.asp?id='+sResortDescID.value+'">More information</a>';
					}
					sHTML+='</td></tr></table>'
					
					map.addOverlay(createMarker(point, sHTML, '', sType));
				}
			}
		}	
	}
}


/* START DATE VALIDATION */
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function stripCharsInBag(s, bag){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++){   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   } 
	   return this
	}
	
	function isDate(dtStr){
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			//alert("The date format should be : mm/dd/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			//alert("Please enter a valid day")
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			//alert("Please enter a valid date")
			return false
		}
		return true
	}
/* END DATE VALIDATION */


function showGoogleMap(iLat, iLng) {
	grayOut(true);
	document.getElementById('googleMapDiv').innerHTML = '<div align="right" style="padding:2px 15px 4px 0px;"><a href="javascript:hideGoogleMap()">Close map viewer</a></div><div id="popupMap" style="margin:0px 15px 15px 15px;"></div>';
	document.getElementById('googleMapDiv').style.display='block';
	document.getElementById('googleMapDiv').style.marginLeft='-250px';
	LoadGoogleMap('popupMap',iLat,iLng);
}
function hideGoogleMap() {
	grayOut(false);
	document.getElementById('googleMapDiv').innerHTML = '';
	document.getElementById('googleMapDiv').style.display='none';
}

function grayOut(vis, options) {
	// Pass true to gray out screen, false to ungray
	// options are optional.  This is a JSON object with the following (optional) properties
	// opacity:0-100         // Lower number = less grayout higher = more of a blackout 
	// zindex: #             // HTML elements with a higher zindex appear on top of the gray out
	// bgcolor: (#xxxxxx)    // Standard RGB Hex color code
	// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
	// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
	// in any order.  Pass only the properties you need to set.
	var options = options || {}; 
	var zindex = options.zindex || 100;
	var opacity = options.opacity || 70;
	var opaque = (opacity / 100);
	var bgcolor = options.bgcolor || '#000000';
	var dark=document.getElementById('darkenScreenObject');
	if (!dark) {
		// The dark layer doesn't exist, it's never been created.  So we'll
		// create it here and apply some basic styles.
		// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('div');           // Create the layer.
		tnode.style.position='absolute';                 // Position absolutely
		tnode.style.top='0px';                           // In the top
		tnode.style.left='0px';                          // Left corner of the page
		tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
		tnode.style.display='none';                      // Start out Hidden
		tnode.id='darkenScreenObject';                   // Name it so we can find it later
		tbody.appendChild(tnode);                            // Add it to the web page
		tbody.onclick="alert('')"
		dark=document.getElementById('darkenScreenObject');  // Get the object.
	}
	if (vis) {
		sSelectHide = 'none';
		// Calculate the page width and height 
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
			var pageWidth = document.body.scrollWidth+'px';
			var pageHeight = document.body.scrollHeight+'px';
		} else if( document.body.offsetWidth ) {
			var pageWidth = document.body.offsetWidth+'px';
			var pageHeight = document.body.offsetHeight+'px';
		} else {
			var pageWidth='100%';
			var pageHeight='100%';
		}   
		//set the shader to cover the entire page and make it visible.
		dark.style.opacity=opaque;                      
		dark.style.MozOpacity=opaque;                   
		dark.style.filter='alpha(opacity='+opacity+')'; 
		dark.style.zIndex=zindex;        
		dark.style.backgroundColor=bgcolor;  
		dark.style.width= pageWidth;
		dark.style.height= pageHeight;
		dark.style.display='block';				 
	} else {
		dark.style.display='none';
		sSelectHide = '';
	}
	oSelects = document.getElementsByTagName('select');
	for(x=0;x<oSelects.length;x++) {
		//oSelects[x].style.display = sSelectHide;
	}
}

function LoadGoogleMap(sDiv, iLat, iLng, bOverrideSize) {
	if(document.getElementById(sDiv)) {
		sDiv = document.getElementById(sDiv)
		if(!bOverrideSize) {
			sDiv.style.width = '500px';
			sDiv.style.height = '420px';
		}
		if (GBrowserIsCompatible()) {
			var mygmap = new GMap2(sDiv);
			//map.addControl(new YSliderControl());
			mygmap.addControl(new GSmallMapControl());
    		mygmap.addControl(new GMapTypeControl());
			mygmap.setCenter(new GLatLng(iLat, iLng), 13);
			var point = new GLatLng(iLat,iLng);
			mygmap.addOverlay(new GMarker(point));
		}
	}
}