//startFlash
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
//clip name should match the 'IDhere'_DoFSCommand
function ipBtn_DoFSCommand(command, args) {
	if (command == "ipLink") {
		window.open(args);
	}
}
// Hook for Internet Explorer for intLinkClip 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub ipBtn_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call ipBtn_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}
//
//endofFlash
function RowOver(TID, ID, ImgSrc, Bull){
	if(Bull != ""){
		document.getElementById(TID+'_Bull_'+ID).style.color='#FFFFFF';
	}
	document.getElementById(TID+'_'+ID).style.color='#FFFFFF';
	document.getElementById('Arr_'+ID).src=ImgSrc;
}

function RowOut(TID, ID, ImgSrc, Bull){
	if(Bull != ""){
		document.getElementById(TID+'_Bull_'+ID).style.color='';
	}
	document.getElementById(TID+'_'+ID).style.color='';
	document.getElementById('Arr_'+ID).src=ImgSrc;
}
//
function ShowImg(ShowThis){
	var ImgList = document.getElementsByTagName('img');
	var i = ImgList.length; while( i-- ) {
		if( ImgList[i].id.indexOf('LrgImg_') === 0 ) {
			ImgList[i].style.display = 'none';
		}
	}
	document.getElementById(ShowThis).style.display = 'block';
}
//
// Search Box Stuff
function DisableSearch() {
	document.getElementById('sAccommType').disabled=true;
	document.getElementById('sLocation').disabled=true;
	document.getElementById('sBedNum').disabled=true;
	document.getElementById('sStarRating').disabled=true;
}
//
function SubmitValues() {
	document.getElementById('AccommType').value 	= document.getElementById('sAccommType').value;
	document.getElementById('Location').value 	= document.getElementById('sLocation').value;
	document.getElementById('BedNum').value		= document.getElementById('sBedNum').value;
	document.getElementById('StarRating').value		= document.getElementById('sStarRating').value;
	//
	document.getElementById('sInfo').submit();
}
//
function ResetSearch() {
	document.getElementById('sInfo').action = 'searchBox.asp';
	document.getElementById('sInfo').target = '_self';
	//
	document.getElementById('sAccommType').disabled=false;
	document.getElementById('sLocation').disabled=false;
	document.getElementById('sBedNum').disabled=false;
	document.getElementById('sStarRating').disabled=false;
	//
	document.getElementById('sAccommType').value = '';
	document.getElementById('sLocation').value = '';
	document.getElementById('sBedNum').value = '';
	document.getElementById('sStarRating').value = '';
	//
	document.getElementById('Reset').value = 'Yes';
	document.getElementById('AccommType').value = '';
	document.getElementById('Location').value = '';
	document.getElementById('BedNum').value = '';
	document.getElementById('StarRating').value = '';
	//
	document.getElementById('sInfo').submit();
}
//
function ChkHotel(v) {
	if (v == "Hotel") {
		document.getElementById('StarRatingDD').style.display = 'block';
		document.getElementById('BedNumDD').style.display = 'none';
	} else {
		document.getElementById('StarRatingDD').style.display = 'none';
		document.getElementById('BedNumDD').style.display = 'block';		
	}
}
//
//
//Date Stuff
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
//
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // <b style="color:black;background-color:#ff9999">Check</b> 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(10)
	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 : dd/mm/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 of date stuff
//
function ShowAccommOpts(Val){
	//hides and shows the available options
	var Val = Val;
	//
	document.getElementById('k12').style.display = 'none';
	document.getElementById('k16').style.display = 'none';
	//
	if(Val == 'Private'){
		document.getElementById('k16').style.display = 'block';
	} else {
		document.getElementById('k12').style.display = 'block';
	}
}
//
function isEmail(eml){
	var i = 1;
	var emlLength = eml.length;
	while ((i < emlLength) && (eml.charAt(i) != "@")){
		i++;
	}
	if ((i >= emlLength) || (eml.charAt(i) != "@")) {
		return false;
	}
	else {
		i += 2;
	}
	while ((i < emlLength) && (eml.charAt(i) != ".")){
		i++;
	}
	if ((i >= emlLength - 1) || (eml.charAt(i) != ".")){
		return false;
	}
	else {
		return true;
	}
}
//
function ValEnq() {
	var isAnError = false;
	var errMsg = "Please supply the following;\n\n";
	//
	var fType = document.EnqInfo.fType.value;
	//
	if(fType == "accGen" || fType == "glfGen"){
		if(document.EnqInfo.Region.value == "") {
			errMsg += "Which Region you would like to visit.\n";
			isAnError = true;
		}
		if(document.EnqInfo.Location.value == "") {
			errMsg += "Which Resort you would like to visit.\n";
			isAnError = true;
		}
		if(document.EnqInfo.AccommType.value == "") {
			errMsg += "The type of accommodation you require.\n";
			isAnError = true;
		}
	}
	//
	if(fType != "ofrEnq"){
		if(document.EnqInfo.DateBox_ArrivalDate.value == "") {
			errMsg += "An arrival Date.\n";
			isAnError = true;
		}
	}
	//
	if(fType != "glfPck" && fType != "pckEnq" && fType != "ofrEnq"){
		if(document.EnqInfo.Duration.value == "") {
			errMsg += "How long you wish to stay for.\n";
			isAnError = true;
		}
	}
	//
	if(fType != "glfPck" && fType != "pckGen" && fType != "pckEnq" && fType != "ofrEnq"){
		if(fType != "accGen" && fType != "accH" && fType != "accP" && fType != "accR"){	
			if(document.EnqInfo.PackageType.value == "") {
				errMsg += "The type of Holiday you would like.\n";
				isAnError = true;
			}
		}
		//
		if(document.EnqInfo.Duration.value == "") {
			errMsg += "How long you wish to stay for.\n";
			isAnError = true;
		}
	}
	//
	if(fType == "glfGen"){
		if(document.EnqInfo.RoundsRequired.value == "") {
			errMsg += "How many rounds do wish to play.\n";
			isAnError = true;
		}
	}
	//
	if(fType == "accH"){
		if(document.EnqInfo.RoomType.value == "") {
			errMsg += "Which Region you would like to visit.\n";
			isAnError = true;
		}
		if(document.EnqInfo.BoardType.value == "") {
			errMsg += "Which Resort you would like to visit.\n";
			isAnError = true;
		}
	}
	//
	if(document.EnqInfo.Adults.value == "") {
		errMsg += "The number of Guests.\n";
		isAnError = true;
	}
	//
	if(document.EnqInfo.FullName.value == "") {
		errMsg += "Your name.\n";
		isAnError = true;
	}
	//
	if(document.EnqInfo.Email.value == "") {
		errMsg += "Your email address.\n";
		isAnError = true;
	}
	//
	if(document.EnqInfo.Email.value != "") {
		if (!isEmail(document.EnqInfo.Email.value)){
			errMsg += "A valid email address.\n";
			isAnError = true;
		}
	}
	//
	if(isAnError){
		alert(errMsg);
	}
	//
	if(!isAnError){
		document.getElementById('EnqInfo').submit();
	}
}
//
function PopEnq(enqType, ID){
	wStr = 600;
	hStr = 580;
	lStr = 0;
	tStr = 0;
	//
	if (screen){
		lStr = (screen.width/2) - (wStr/2);
		tStr = (screen.height/2) - (hStr/2);
	}
	//
	EnqWin = window.open('accomm_enquiry.asp?enqType='+enqType+'&ID='+ID,'EnqWin','width='+wStr+', height='+hStr+', top='+tStr+', left='+lStr+', scrollbars=yes, status=no');
	//
	if (window.focus) {
		EnqWin.focus();
	}
}
//
function PopInfo(AssocTable, AssocID){
	wStr = 640;
	hStr = 620;
	lStr = 0;
	tStr = 0;
	//
	if (screen){
		lStr = (screen.width/2) - (wStr/2);
		tStr = (screen.height/2) - (hStr/2);
	}
	//
	InfoWin = window.open('infoPage.asp?AssocTable='+AssocTable+'&AssocID='+AssocID, 'InfoWin', 'width='+wStr+', height='+hStr+', top='+tStr+', left='+lStr+', scrollbars=yes, status=no');
	//
	if (window.focus) {
		InfoWin.focus();
	}
}