var curentSection = null;
var currentPage = null;

function openPhuketMap() {
	var wnd = popWindow('Phuket Map','phuket_map.htm',600,619,true);
}
function openFloorPlan(building,image,name) {
	//var wnd = window.open('plan.htm?building=' + building + '&floor=' + image + '&name=' + name,'floorplan','width=640,height=512,menubar=no,scrollbars=no,resizable=no');
	var url = '';
	
	if ((building == '1_floor')) {
		url = 'floor/1_floor.htm';
	} else if ((building == '2_floor')) {
		url = 'floor/2_floor.htm';
	} else if ((building == '3_floor')) {
		url = 'floor/3_floor.htm';
	} else if ((building == 'extra')) {
		url = 'floor/extra.htm';
	}
	
	if (url != '')
		var wnd = popWindow('The Royal Villas Floor Plan',url,640,515,true);
}
function processResponse(strResponse) {
    var content = document.getElementById("content");
	
	if (content) {
		content.innerHTML = strResponse;
		
		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"#content h1", sFlashSrc:"SerifGothic.swf", sColor:"#999999", sLinkColor:"#999999", sBgColor:"#3B8795", sHoverColor:"#DBE4E9", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"", sWmode: "transparent"}));
			sIFR.replaceElement(named({sSelector:"#content h2", sFlashSrc:"SerifGothic.swf", sColor:"#999999", sLinkColor:"#999999", sBgColor:"#3B8795", sHoverColor:"#DBE4E9", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"", sWmode: "transparent"}));
			sIFR.replaceElement(named({sSelector:"#content h3", sFlashSrc:"SerifGothic.swf", sColor:"#999999", sLinkColor:"#999999", sBgColor:"#3B8795", sHoverColor:"#DBE4E9", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"", sWmode: "transparent"}));
			//sIFR.replaceElement(named({sSelector:"#content p", sFlashSrc:"SerifGothic.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#3B8795", sHoverColor:"#DBE4E9", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"textsize=12", sWmode: "transparent"}));
		}
	}
}
function displayContent(section) {
	
	if (section == 'phuket_map') {
		openPhuketMap();
	}
	
	var requestedPage = getSectionURL(section);
	
	if (currentPage != requestedPage) {
		var content = document.getElementById("content");
		if (content) {
			//content.innerHTML = '<div class="wait"><p>Loading, please wait...</p><img src="images/wait_anim.gif" /></div>';;
		}
		
		var AJAXConfig = new AJAX.Config();
		
		AJAXConfig.url = requestedPage;
		AJAXConfig.mode = AJAX.GET;
		AJAXConfig.processResponse = processResponse;
		
		var contentRequest = new AJAX(AJAXConfig);
		contentRequest.request();
	}
}

function getSectionURL(section) {
	var url = 'content/';
	
	if (section == 'developer') {
		url += 'developer.htm';
	}else if (section == 'concept') {
		url += 'concept.htm';
	}else if (section == 'floorplan') {
		url += 'floor_plan.htm';
	}else if (section == 'gallery') {
		url += 'blank.htm';
		
	}else if (section == 'photo_waterfront') {
		url += 'photo_waterfront.htm';
	}else if (section == 'photo_vacht_berth') {
		url += 'photo_vacht_berth.htm';
	}else if (section == 'photo_the_entry') {
		url += 'photo_the_entry.htm';
	}else if (section == 'photo_the_entrance') {
		url += 'photo_the_entrance.htm';
	}else if (section == 'photo_living_room') {
		url += 'photo_living_room.htm';	
	}else if (section == 'photo_dining_room') {
		url += 'photo_dining_room.htm';
	}else if (section == 'photo_master_suite_lounge') {
		url += 'photo_master_suite_lounge.htm';
	}else if (section == 'photo_media_room') {
		url += 'photo_media_room.htm';
		}else if (section == 'photo_master_study') {
		url += 'photo_master_study.htm';
	}else if (section == 'photo_master_bedroom') {
		url += 'photo_master_bedroom.htm';
	}else if (section == 'photo_master_bathroom2') {
		url += 'photo_master_bathroom2.htm';
	}else if (section == 'photo_four_idyllic') {
		url += 'photo_four_idyllic.htm';
	}else if (section == 'photo_villa_c') {
		url += 'photo_villa_c.htm';
	}else if (section == 'photo_sheer_indulgence') {
		url += 'photo_sheer_indulgence.htm';
		
	}else if (section == 'about-rpm') {
		url += 'about_rpm.htm';
	}else if (section == 'about-phuket') {
		url += 'about_phuket.htm';
	}else if (section == 'yatch') {
		url += 'private_yacht_berth.htm';
	}else if (section == 'project') {
		url += 'blank.htm';
	}else if (section == 'contact') {
		url += 'contact.htm';
	}else if (section == 'photo-bar') {
		url += 'photo_bar_kitchen.htm';
	}else if (section == 'photo-bathroom') {
		url += 'photo_spa_bathroom.htm';
	}else if (section == 'photo-jacuzzi') {
		url += 'photo_spa_bedroom_suite.htm';
	}else if (section == 'photo-bedroom') {
		url += 'photo_bedroom.htm';
	}else if (section == 'photo-cabana') {
		url += 'photo_cabana_bedroom_suite.htm';
	}else if (section == 'photo-family') {
		url += 'photo_master_bedroom_suite.htm';
	}else if (section == 'photo-living') {
		url += 'photo_ground_floor.htm';
	}else if (section == 'photo-master-bathroom') {
		url += 'photo_master_bathroom.htm';
	}else if (section == 'photo-master-bedroom') {
		url += 'photo_master_bedroom_suite.htm';
	}else if (section == 'download') {
		url += 'download.htm';
	}else if (section == 'buyerinformation') {
		url += 'buyer_information.htm';
	}else if (section == 'faq') {
		url += 'faq.htm';
	}else if (section == 'fact') {
		url += 'factsheet.htm';
	}else if (section == 'loc') {
		url += 'location.htm';
	}else if (section == 'leg') {
		url += 'legal.htm';
	}else if (section == 'press') {
		url += 'press_release.htm';
	}else if (section == 'news') {
		url += 'in_the_news.htm';
	}else if (section == 'project_update') {
		url += 'project_update.htm';
	}else {
		url += 'blank.htm';
	}
	return url;
}

function displayDownloadForm() {
	var form = document.getElementById('frmDownload');
    var resultAreaSide = document.getElementById("resultAreaSide");
    var processAreaSide = document.getElementById("processAreaSide");
	var iframPdf = document.getElementById("iframPdf");
	
	if (form) {
		form.style.display = 'block';
	}
	if (resultAreaSide) {
		resultAreaSide.style.display = 'none';
	}
	if (processAreaSide) {
		processAreaSide.style.display = 'none';
	}
	if (iframPdf) {
		iframPdf.style.display = 'none';
	}
	
	return false;
}

function hideDownloadForm(file) {
	var form = document.getElementById('frmDownload');
	var processAreaSide = document.getElementById("processAreaSide");
	
	if (form) {
		form.style.display = 'none';
		
		if (file) {
			pageTracker._trackPageview('/' + file);
			
			window.open(file);
		}
	}
	
	if (processAreaSide) {
		processAreaSide.style.display = 'none';
	}
	
	return false;
}


function isEmpty(val) {
	return (val.search(/[^\s]/gi) == -1)
}
function isValidEmail(val) {
	return (val.search(/^.+@[^\.].*\.[a-z]{2,}$/gi) != -1)
}
function Validate(frm) {
	var intError = 0;
	var focus_field = null;
	
	if (isEmpty(frm.txtFirstName.value)) { 
		document.getElementById("lblFirstName").className = "error";
		frm.txtFirstName.parentNode.parentNode.className = "error";
		document.getElementById("msgFirstName").style.display = "block";
	
		intError = 1;
		if (focus_field == null) focus_field = frm.txtFirstName;
	}else {
		document.getElementById("lblFirstName").className = "";
		frm.txtFirstName.parentNode.parentNode.className = "";
		document.getElementById("msgFirstName").style.display = "none";
	}

	if (isEmpty(frm.txtLastName.value)) { 
		document.getElementById("lblLastName").className = "error";
		frm.txtLastName.parentNode.parentNode.className = "error";
		document.getElementById("msgLastName").style.display = "block";
	
		intError = 1;
		if (focus_field == null) focus_field = frm.txtLastName;
	}else {
		document.getElementById("lblLastName").className = "";
		frm.txtLastName.parentNode.parentNode.className = "";
		document.getElementById("msgLastName").style.display = "none";
	}
		
	if (isEmpty(frm.txtEmail.value)) { 
		document.getElementById("lblEmail").className = "error";
		frm.txtEmail.parentNode.parentNode.className = "error";
		document.getElementById("msgEmailRequired").style.display = "block";
		document.getElementById("msgEmailFormat").style.display = "none";
	
		intError = 1;
		if (focus_field == null) focus_field = frm.txtEmail;
	}else if (!isValidEmail(frm.txtEmail.value)) {
		document.getElementById("lblEmail").className = "error";
		frm.txtEmail.parentNode.parentNode.className = "error";
		document.getElementById("msgEmailRequired").style.display = "none";
		document.getElementById("msgEmailFormat").style.display = "block";
	
		intError = 1;
		if (focus_field == null) focus_field = frm.txtEmail;
	}else {
		document.getElementById("lblEmail").className = "";
		frm.txtEmail.parentNode.parentNode.className = "";
		document.getElementById("msgEmailRequired").style.display = "none";
		document.getElementById("msgEmailFormat").style.display = "none";
	}
	
	if (!frm.cmbCountry.selectedIndex) {
		document.getElementById("lblCountry").className = "error";
		frm.cmbCountry.parentNode.parentNode.className = "error";
		document.getElementById("msgCountryRequired").style.display = "block";
	
		intError = 1;
		if (focus_field == null) focus_field = frm.txtEmail;
	}else {
		document.getElementById("lblCountry").className = "";
		frm.cmbCountry.parentNode.parentNode.className = "";
		document.getElementById("msgCountryRequired").style.display = "none";
	}
	return (intError == 0);
}

function submitBrochure(frm) {
    if (Validate(frm)) {
        // Patchara - hacky way to by-pass AJAX submit, in order to get google conversion code working
//        var AJAXConfig = new AJAX.Config();
//        AJAXConfig.url = 'req_brochure.php';
//        AJAXConfig.mode = AJAX.POST;
//        AJAXConfig.processResponse = processBrochureResponse;
//
//        var formValue = new AJAX(AJAXConfig);
//        formValue.request("firstname=" + frm.txtFirstName.value + "&lastname=" + frm.txtLastName.value + "&email=" + frm.txtEmail.value + "&phone=" + frm.txtPhone.value + "&country=" + frm.cmbCountry.value + "&message=" + frm.txtMessage.value);
//
//        var frmDownload = document.getElementById("frmDownload");
//        var processAreaSide = document.getElementById("processAreaSide");
//
//        if (frmDownload)
//            frmDownload.style.display = "none";
//
//        if (processAreaSide)
//            processAreaSide.style.display = "block";
        return true;
    }
    return false;
}

function processBrochureResponse(strResponse) {
    var resultAreaSide = document.getElementById("resultAreaSide");
    var processAreaSide = document.getElementById("processAreaSide");

    if (processAreaSide)
        processAreaSide.style.display = "none";

    if (resultAreaSide) {
			if (pageTracker) {
				pageTracker._trackPageview('/downloads/Royal Villa Brochures.pdf');
			}
		
			resultAreaSide.innerHTML = strResponse + "<iframe id=\"PdfFile\" src=\"download_file.php?file=downloads/Royal Villa Brochures.pdf\" />";
	    resultAreaSide.style.display = "block";
    }
}