// JavaScript Document
var firstDot = '';
function mouseOverEffect(imageName, targetImage) {
	document.getElementById(imageName).src = targetImage;
}
function showPic(imageName, targetImage) {
	mouseOverEffect(imageName, targetImage);
}
function showLayer(layerName, displayStatus) {
	document.getElementById(layerName).style.display = displayStatus;
}
function changeDot(roomName) {
	document.getElementById(roomName).src = 'images/dot_green.png';
	if (firstDot != '') {
		document.getElementById(firstDot).src = 'images/dot_purple.png';
		firstDot = roomName;
	} else {
		firstDot = roomName;
	}
}
function validForm() {
	var isFormOk = true;
	if (document.getElementById('first_name').value == '') {
		isFormOk = false;
		alert('Please fill in first name');
	}
	if (document.getElementById('last_name').value == '' && isFormOk) {
		isFormOk = false;
		alert('Please fill in last name');
	}
	if (document.getElementById('company_name').value == '' && isFormOk) {
		isFormOk = false;
		alert('Please fill in company name');
	}
	if (document.getElementById('email').value == '' && isFormOk) {
		isFormOk = false;
		alert('Please fill in email');
	}
	if (Validate_Email_Address(document.getElementById('email').value) == false && isFormOk) {
		isFormOk = false;
		alert('Please fill in a valid email');	
	}	
	if (document.getElementById('mobile').value == '' && isFormOk) {
		isFormOk = false;
		alert('Please fill in mobile');
	}
	if ((document.getElementById('arrival_day').value == 'DD' || document.getElementById('arrival_month').value == 'MM' || document.getElementById('arrival_year').value == 'YYYY') && isFormOk) {
		isFormOk = false;
		alert('Please fill in expected arrival date');
	}
	if (!(isValidNumber(document.getElementById('arrival_day').value) && isValidNumber(document.getElementById('arrival_month').value) && isValidNumber(document.getElementById('arrival_year').value)) && isFormOk) {
		isFormOk = false;
		alert('Please fill in a valid expected arrival date');
	}
	if ((document.getElementById('departure_day').value == 'DD' || document.getElementById('departure_month').value == 'MM' || document.getElementById('departure_year').value == 'YYYY') && isFormOk) {
		isFormOk = false;
		alert('Please fill in expected departure date');
	}
	if (!(isValidNumber(document.getElementById('no_of_adult').value)) && isFormOk) {
		isFormOk = false;
		alert('Please fill in a valid no. of adult');
	}	
	if (!(isValidNumber(document.getElementById('no_of_child').value)) && isFormOk) {
		isFormOk = false;
		alert('Please fill in a valid no. of children');
	}
	if (!(isValidNumber(document.getElementById('departure_day').value)  && isValidNumber(document.getElementById('departure_month').value) && isValidNumber(document.getElementById('departure_year').value)) && isFormOk) {
		isFormOk = false;
		alert('Please fill in a valid expected departure date');
	}	
	if (isFormOk) {
		document.forms[0].submit();
	}
}

function isValidNumber(inpString) {
   return /^[-+]?\d+(\.\d+)?$/.test(inpString);
}


function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }


function Validate_Email_Address(email_address)
{
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	var result = true;
	if(email_address.search(emailRegEx) == -1) {
		result = false;
	}
	return result;
}
		 
// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully
// ------------------------------------------------------------------------- //

// Set slideShowSpeed (milliseconds)
var slideShowStart = false;
var slideShowSpeed = 8000;
// Agent sniffer shamelessly 'stolen' from the excellent X library from cross-browser.com
var xOp7=false,xOp5or6=false,xIE4Up=false,xNN4=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if(document.layers) xNN4=true;
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}

// Duration of crossfade (seconds)
var crossFadeDuration = 4;
var Pic = new Array();
var t;
var j = 0;
var p = Pic.length;
var pos = j;
var preLoad = new Array();

function preLoadPic(index)
{
	if (Pic[index] != ''){
		window.status='Loading : '+Pic[index];
		preLoad[index] = new Image();
		preLoad[index].src = Pic[index];
		Pic[index] = '';
		window.status='';
	}
}

function runSlideShow(){
	if (xIE4Up){
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.style.filter= "blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[j].src;
	if (xIE4Up){
		document.images.SlideShow.filters.blendTrans.Play();
	}	
	pos = j;
	j = j + 1;
	if (j > (p-1)) {
		j = 0;
	}
	t = setTimeout('runSlideShow()', slideShowSpeed);		
	preLoadPic(j);
}

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];}}
}
