var curentSection = null;
var currentPage = null;

function openFloorPlan(building,floorNo) {
	//var wnd = window.open('plan.htm?building=' + building + '&floor=' + image + '&name=' + name,'floorplan','width=640,height=512,menubar=no,scrollbars=no,resizable=no');
	//wnd.focus();
	var url = '';
	
	if ((building == 'duplex') && (floorNo == '4th')) {
		url = 'floor/duplex-4th.htm';
	} else if ((building == 'duplex') && (floorNo == 'roof')) {
		url = 'floor/duplex-roof.htm';
	} else if ((building == 'triplex') && (floorNo == 'roof')) {
		url = 'floor/triplex-roof.htm';
	} else if ((building == 'triplex') && (floorNo == '4th')) {
		url = 'floor/triplex-4th.htm';
	} else if ((building == 'triplex') && (floorNo == '1st')) {
		url = 'floor/triplex.htm';
	} else if ((building == 'satelite') && (floorNo == '2nd')) {
		url = 'floor/satelite.htm';
	} else if ((building == 'cabana') && (floorNo == '3th')) {
		url = 'floor/cabana.htm';
	} else if ((building == 'water') && (floorNo == '2nd')) {
		url = 'floor/water-2nd.htm';
	} else if ((building == 'water') && (floorNo == '1st')) {
		url = 'floor/water.htm';
	} else if ((building == 'marina') && (floorNo == '3th')) {
		url = 'floor/marina.htm';
	}
	
	if (url != '')
		var wnd = popWindow('Aquaminium Floor Plan',url,640,515,true);
}

function openVirtual() {
	//var wnd = new popup('virtualplan','Aquaminium - Royal Phuket Marina',512,520,10,(document.body.clientWidth - 512)/2,'virtual.htm');
	var wnd = popWindow('Aquaminium - Royal Phuket Marina','virtual.htm',512,520,true);
}

function openPhuketMap() {
	var wnd = popWindow('Phuket Map','phuket_map.htm',600,619,true);
}

function openTVC() {
	//var wnd = new popup('tvc','TV Commercial - Aquaminium - Royal Phuket Marina',512,530,10,(document.body.clientWidth - 512)/2,'tvc.htm');
	//hideDownloadForm();
	var wnd = popWindow('TV Commercial - Aquaminium - Royal Phuket Marina','tvc.htm',512,510,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 == 'virtual') {
		openVirtual();
	}else 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 == 'unit') {
		url += 'blank.htm';
	}else if (section == 'common') {
		url += 'blank.htm';
	}else if (section == 'gallery') {
		url += 'blank.htm';
	}else if (section == 'about-rpm') {
		url += 'about_rpm.htm';
	}else if (section == 'about-phuket') {
		url += 'about_phuket.htm';
	}else if (section == 'project') {
		url += 'project_update.htm';
	}else if (section == 'virtual') {
		url += 'blank.htm';
	}else if (section == 'contact') {
		url += 'contact.htm';
	}else if (section == 'photo-bathroom') {
		url += 'photo_bathroom.htm';
	}else if (section == 'photo-cabana') {
		url += 'photo_cabana_satellite.htm';
	}else if (section == 'photo-kitchen') {
		url += 'photo_kitchen.htm';
	}else if (section == 'living-room-2floor') {
		url += 'photo_living_room_waterfront.htm';
	}else if (section == 'living-room-3floor') {
		url += 'photo_living_room_marina.htm';
	}else if (section == 'living-room-penthouse') {
		url += 'photo_living_room.htm';
	}else if (section == 'lobby') {
		url += 'photo_lobby.htm';
	}else if (section == 'master-bedroom') {
		url += 'photo_master_bedroom.htm';
	}else if (section == 'pool-deck') {
		url += 'photo_pool_deck_patio_jacuzzi.htm';
	}else if (section == 'roof-top') {
		url += 'photo_rooftop_garden.htm';
	}else if (section == 'rooftop-pool') {
		url += 'photo_rooftop_pool.htm';
	}else if (section == 'yacht-lougne') {
		url += 'photo_yacht_lounge.htm';
	}else if (section == 'download') {
		url += 'download.htm';
	}else if (section == 'faq') {
		url += 'faq.htm';
	}else if (section == 'factsheet') {
		url += 'factsheet.htm';
	}else if (section == 'legal') {
		url += 'legal.htm';
	}else if (section == 'the_architecture') {
		url += 'the_architecture.htm';
	}else if (section == 'the_interior') {
		url += 'the_interior.htm';
	}else if (section == 'the_specification') {
		url += 'the_specification.htm';
	}else if (section == 'press_release') {
		url += 'press_release.htm';
	}else if (section == 'in_the_news') {
		url += 'in_the_news.htm';
	}else if (section == 'aerial-view') {
		url += 'blank.htm';
	}else if (section == 'evening-view') {
		url += 'blank.htm';
	}else if (section == 'yatch') {
		url += 'blank.htm';
	}else if (section == 'outdoor-plaza') {
		url += 'blank.htm';
	}else if (section == 'main-entrance') {
		url += 'blank.htm';
	}else if (section == 'glittering-event') {
		url += 'blank.htm';
	}else if (section == 'buyer_information') {
		url += 'buyer_information.htm';
	}else if (section == 'pr_2') {
		url += 'pr_2.htm';
	}else if (section == 'pr_3') {
		url += 'pr_3.htm';
	}else if (section == 'pr_4') {
		url += 'pr_4.htm';
	}else if (section == 'pr_5') {
		url += 'pr_5.htm';
	}else if (section == 'pr_7') {
		url += 'pr_7.htm';
	}else if (section == 'pr_10') {
		url += 'pr_10.htm';
	}else if (section == 'pr_11') {
		url += 'pr_11.htm';
	}else if (section == 'pr_12') {
		url += 'pr_12.htm';
	}else if (section == 'location') {
		url += 'location.htm';
	}else if (section == 'photo_yacht_lounge') {
		url += 'photo_yacht_lounge.html';
	}else if (section == 'photo_boat_garage') {
		url += 'photo_boat_garage.htm';
	}else if (section == 'photo_home_theatre') {
		url += 'photo_home_theatre.html';
	}else if (section == 'photo_living_room') {
		url += 'photo_living_room.html';
	}else if (section == 'photo_roof_top_cabana') {
		url += 'photo_roof_top_cabana.html';
	}else if (section == 'master_bath_room') {
		url += 'master_bath_room.html';
	}else if (section == 'master_bath_room2') {
		url += 'master_bath_room2.html';
	}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/Aquaminium Brochures.pdf');
		}
		
		resultAreaSide.innerHTML = strResponse + "<iframe id=\"PdfFile\" src=\"download_file.php?file=downloads/Aquaminium Brochures.pdf\" />";
        resultAreaSide.style.display = "block";
    }
}

function flashMovie(name)
{
 if(navigator.appName.indexOf("Microsoft") != -1)
 {
  return window[name];
 }
 else
 {
  return document[name];
 }
}

function gotoMain() {
	flashMovie('mymovie').TCallLabel("/", "replay");
	
	return false;
}