var SlideShowSpeed = 3000;
var CrossFadeDuration = 3;
var Picture = new Array(); // don't change this
var Caption = new Array(); // don't change this

Picture[1]  = 'img/purp2.jpg';
Picture[2]  = 'img/purp3.jpg';
Picture[3]  = 'img/purp4.jpg';
Picture[4]  = 'img/purp5.jpg';
Picture[5]  = 'img/purp6.jpg';
Picture[6]  = 'img/purp7.jpg';
Picture[7]  = 'img/purp8.jpg';
Picture[8]  = 'img/purp9.jpg';
Picture[9]  = 'img/purp10.jpg';
Picture[10]  = 'img/purp11.jpg';
Picture[11]  = 'img/purp12.jpg';
Picture[12]  = 'img/purp13.jpg';

Caption[1]  = " ";
Caption[2]  = " ";
Caption[3]  = " ";
Caption[4]  = " ";
Caption[5]  = " ";
Caption[6]  = " ";
Caption[7]  = " ";
Caption[8]  = " ";
Caption[9]  = " ";
Caption[10]  = " ";
Caption[11]  = " ";
Caption[12]  = " ";

var tss;
var iss;
var jss = 1;
var pss = Picture.length-1;

var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = Picture[iss];}

function runSlideShow(){
if (document.all){
document.images.PictureBox.style.filter="blendTrans(duration=2)";
document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
document.images.PictureBox.filters.blendTrans.Apply();}
document.images.PictureBox.src = preLoad[jss].src;
if (document.getElementById) document.getElementById("CaptionBox").innerHTML= Caption[jss];
if (document.all) document.images.PictureBox.filters.blendTrans.Play();
jss = jss + 1;
if (jss > (pss)) jss=1;
tss = setTimeout('runSlideShow()', SlideShowSpeed);
}

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];}}
}

	function ChangeDestin(pID){
		var arBedRoom 
		var newoption
		var count = 0
		var countArr
		var strBed
		var strBedRoom
		var strIntValue
		var strValue
		for (var i = 0; i < document.Form1.cboBedroom.length; i++) { 
					document.Form1.cboBedroom.options[i]=null;
					i = i - 1;
				}	
			if (pID != ""){
				if (pID == "AX"){
				arBedRoom = new Array();
				strBedRoom = document.Form1.hdnBedBali.value;
				for (var i = 0; i < document.Form1.hdnCountBali.value; i++) { 
					var iLen = String(strBedRoom).length;
					countArr = strBedRoom.indexOf(",");
					strBed = String(strBedRoom).substring(0,countArr);
					if (countArr < 0){
					arBedRoom[i] = strBedRoom;
					}else{
					arBedRoom[i] = strBed;
					}					
					strBedRoom = replaceSubstring(strBedRoom,strBed + ",","");
					}
					
				newoption = new Option("Any # of bedrooms" , "", false , false);
				document.Form1.cboBedroom.options[0] = newoption;
				
				for (var j = 0; j < arBedRoom.length ; j++) { 
					strIntValue = arBedRoom[j].indexOf(" ");
					strValue = String(arBedRoom[j]).substring(0,strIntValue);
					newoption = new Option(arBedRoom[j], strValue, false , false);
					document.Form1.cboBedroom.options[j+1] = newoption;
					}
				}else{
					if (pID == "BX"){
						arBedRoom = new Array();
						strBedRoom = document.Form1.hdnBedPhuket.value;
						for (var i = 0; i < document.Form1.hdnCountPhuket.value; i++) { 
							var iLen = String(strBedRoom).length;
							countArr = strBedRoom.indexOf(",");
							strBed = String(strBedRoom).substring(0,countArr);
							if (countArr < 0){
							arBedRoom[i] = strBedRoom;
							}else{
							arBedRoom[i] = strBed;
							}					
							strBedRoom = replaceSubstring(strBedRoom,strBed + ",","");
							}
							
						newoption = new Option("Any # of bedrooms" , "", false , false);
						document.Form1.cboBedroom.options[0] = newoption;
						
						for (var j = 0; j < arBedRoom.length ; j++) { 
							strIntValue = arBedRoom[j].indexOf(" ");
							strValue = String(arBedRoom[j]).substring(0,strIntValue);
							newoption = new Option(arBedRoom[j], strValue, false , false);
							document.Form1.cboBedroom.options[j+1] = newoption;
							}
					}else{
						arBedRoom = new Array();
						strBedRoom = document.Form1.hdnBedKohSamui.value;
						for (var i = 0; i < document.Form1.hdnCountKohSamui.value; i++) { 
							var iLen = String(strBedRoom).length;
							countArr = strBedRoom.indexOf(",");
							strBed = String(strBedRoom).substring(0,countArr);
							if (countArr < 0){
							arBedRoom[i] = strBedRoom;
							}else{
							arBedRoom[i] = strBed;
							}					
							strBedRoom = replaceSubstring(strBedRoom,strBed + ",","");
							}
							
						newoption = new Option("Any # of bedrooms" , "", false , false);
						document.Form1.cboBedroom.options[0] = newoption;
						
						for (var j = 0; j < arBedRoom.length ; j++) { 
							strIntValue = arBedRoom[j].indexOf(" ");
							strValue = String(arBedRoom[j]).substring(0,strIntValue);
							newoption = new Option(arBedRoom[j], strValue, false , false);
							document.Form1.cboBedroom.options[j+1] = newoption;
							}
					}
				}
			}else{
						arBedRoom = new Array();
						strBedRoom =document.Form1.hdnBedAll.value;
						for (var i = 0; i < document.Form1.hdnCountAll.value; i++) { 
							var iLen = String(strBedRoom).length;
							countArr = strBedRoom.indexOf(",");
							strBed = String(strBedRoom).substring(0,countArr);
							if (countArr < 0){
							arBedRoom[i] = strBedRoom;
							}else{
							arBedRoom[i] = strBed;
							}					
							strBedRoom = replaceSubstring(strBedRoom,strBed + ",","");
							}
							
						newoption = new Option("Any # of bedrooms" , "", false , false);
						document.Form1.cboBedroom.options[0] = newoption;
						
						for (var j = 0; j < arBedRoom.length ; j++) { 
							strIntValue = arBedRoom[j].indexOf(" ");
							strValue = String(arBedRoom[j]).substring(0,strIntValue);						
							newoption = new Option(arBedRoom[j], strValue, false , false);
							document.Form1.cboBedroom.options[j+1] = newoption;
							}
			}
		}
		
	function replaceSubstring(inputString, fromString, toString) {
			// Goes through the inputString and replaces every occurrence of fromString with toString
			var temp = inputString;
			if (fromString == "") {
				return inputString;
			}
			if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
				while (temp.indexOf(fromString) != -1) {
					var toTheLeft = temp.substring(0, temp.indexOf(fromString));
					var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
					temp = toTheLeft + toString + toTheRight;
				}
			} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
				var midStrings = new Array("~", "`", "_", "^", "#");
				var midStringLen = 1;
				var midString = "";
				// Find a string that doesn't exist in the inputString to be used
				// as an "inbetween" string
				while (midString == "") {
					for (var i=0; i < midStrings.length; i++) {
						var tempMidString = "";
						for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
						if (fromString.indexOf(tempMidString) == -1) {
						midString = tempMidString;
						i = midStrings.length + 1;
						}
					}
				} // Keep on going until we build an "inbetween" string that doesn't exist
				// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
				while (temp.indexOf(fromString) != -1) {
					var toTheLeft = temp.substring(0, temp.indexOf(fromString));
					var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
					temp = toTheLeft + midString + toTheRight;
				}
				// Next, replace the "inbetween" string with the "toString"
				while (temp.indexOf(midString) != -1) {
					var toTheLeft = temp.substring(0, temp.indexOf(midString));
					var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
					temp = toTheLeft + toString + toTheRight;
				}
			} // Ends the check to see if the string being replaced is part of the replacement string or not
			return temp; // Send the updated string back to the user
			} // Ends the "replaceSubstring" function
			
			
function ChangeArrival(pCbo,pValue){
			var arDate;
			var arMonth;
			var arYear;
			if (document.Form1.hdnOn.value=1){
				if (pCbo == '1'){
					 
					 arDate=pValue;
					 arMonth= fillMonth(document.Form1.cboArrivalMonth.value);
					 arYear=document.Form1.cboArrivalYear.value;
					 document.Form1.Arrival.value= arDate + '/' +  document.Form1.cboArrivalMonth.value + '/' + arYear;
				}else{
					if (pCbo == '2'){
					
					 arDate=document.Form1.cboArrivalDate.value;
					 arMonth=fillMonth(pValue);
					 arYear=document.Form1.cboArrivalYear.value;
					 document.Form1.Arrival.value= arDate + '/' + pValue + '/' + arYear;
				}else{
					if (pCbo == '3'){
					
					 arDate=document.Form1.cboArrivalDate.value;
					 arMonth=fillMonth(document.Form1.cboArrivalMonth.value);
					 arYear=pValue;
					 document.Form1.Arrival.value= arDate + '/' + document.Form1.cboArrivalMonth.value + '/' + arYear;
					}
					}
				}
			document.Form1.hdnArrival.value= arDate + ' ' + arMonth + ' ' + arYear;
	
			}
		}
		
function ChangeDepart(pCbo,pValue){
			var arDate;
			var arMonth;
			var arYear;
			if (document.Form1.hdnOn.value=1){
				if (pCbo == '1'){
					 arDate=pValue;
					 arMonth= fillMonth(document.Form1.cboDepartureMonth.value);
					 arYear=document.Form1.cboDepartureYear.value;
					 document.Form1.Depart.value= arDate + '/' + document.Form1.cboDepartureMonth.value + '/' + arYear;
				}else{
					if (pCbo == '2'){
					
					 arDate=document.Form1.cboDepartureDate.value;
					 arMonth=fillMonth(pValue);
					 arYear=document.Form1.cboDepartureYear.value;
					  document.Form1.Depart.value= arDate + '/' + pValue + '/' + arYear;
				}else{
					if (pCbo == '3'){
					
					 arDate=document.Form1.cboDepartureDate.value;
					 arMonth=fillMonth(document.Form1.cboDepartureMonth.value);
					 arYear=pValue;
					 document.Form1.Depart.value= arDate + '/' + document.Form1.cboDepartureMonth.value + '/' + arYear;
					}
					}
				}
			document.Form1.hdnDepart.value= arDate + ' ' + arMonth + ' ' + arYear;
		
			}
		}
		
function OpenContact(){
			var Now = new Date();
			
			if (document.Form1.hdnArrival.value == "") 
				{
				document.Form1.hdnArrival.value = '01 Januari 2005'  
				};
			if (document.Form1.hdnDepart.value == "") {
				document.Form1.hdnDepart.value = '01 Januari 2005' };
			if (document.Form1.hdnSubject.value == "Rate Enquiry"){
			window.open('ContactUs.aspx?subject=Rate Enquiry for ' + document.Form1.hdnVillaName.value + '&Arrival=' + document.Form1.hdnArrival.value + '&Depart=' + document.Form1.hdnDepart.value +'&Bed=' + document.Form1.hdnBed.value + '&hdnDepart=' + document.Form1.Depart.value + '&hdnArrival=' + document.Form1.Arrival.value + '','','width=500,height=480,scrollbars=yes');
			}else{
			window.open('ContactUs.aspx?subject=Check Availability for ' + document.Form1.hdnVillaName.value + '&Arrival=' + document.Form1.hdnArrival.value + '&Depart=' + document.Form1.hdnDepart.value +'&Bed=' + document.Form1.hdnBed.value + '&hdnDepart=' + document.Form1.Depart.value + '&hdnArrival=' + document.Form1.Arrival.value + '','','width=500,height=480,scrollbars=yes');
			}
					
		}
		
function fillMonth(pId){
var pMonth;
	switch (pId){
	case '01' : { pMonth = "Jan"; break}
	case '02' : { pMonth = "Feb"; break}
	case '03' : { pMonth = "Mar"; break}
	case '04' : { pMonth = "Apr"; break}
	case '05' : { pMonth = "May"; break}
	case '06' : { pMonth = "Jun"; break}
	case '07' : { pMonth = "Jul"; break}
	case '08' : { pMonth = "Aug"; break}
	case '09' : { pMonth = "Sep"; break}
	case '10' : { pMonth = "Oct"; break}
	case '11' : { pMonth = "Nov"; break}
	case '12' : { pMonth = "Dec"; break}
	}
return pMonth;
}
function GoTo(pID){
	if (pID != "") {
	document.location.href = 'view,villadetail/id,' + pID + '/';
}
}
