/*
	JavaScripts - Main :: RichVille Properties
	Developed by Rich Art - www.RichArtCreative.com
*/

// Render flash
function renderFlash(containerObj, movieName, width, height, wmode) {
	var flashContainerInnerHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '">';
	flashContainerInnerHtml += '<param name="movie" value="' + movieName + '" />';
	flashContainerInnerHtml += '<param name="quality" value="high" />';
	flashContainerInnerHtml += '<param name="wmode" value="' + wmode + '" />';
	flashContainerInnerHtml += '<param name="menu" value="false" />';
	flashContainerInnerHtml += '<embed src="' + movieName + '" wmode="' + wmode + '" menu="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
	flashContainerInnerHtml += '</object>';
	document.getElementById(containerObj).innerHTML = flashContainerInnerHtml;
}

// Menus - In
function menuIn(imgObj) {
	imgObj.src = imgObj.src.replace(/2/, "1");
}

// Menus - Out
function menuOut(imgObj) {
	imgObj.src = imgObj.src.replace(/1/, "2");
}

// Show thanks
function showThanks() {
	document.getElementById("form").style.display = "none";
	document.getElementById("thanks").style.display = "block";
}

// Tirm space
function LTrim(stringValue){
	var w_space = String.fromCharCode(32);
	if(v_length < 1) return"";
	var v_length = stringValue.length;
	var strTemp = "";
	var iTemp = 0;
	while(iTemp < v_length){
		if(stringValue.charAt(iTemp) == w_space){}
		else{
			strTemp = stringValue.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

// Validate contact form
function validateContactForm(formObj){
	var isError = false;
	
	var requiredFields = Array('name', 'email', 'message');
	var errorMessages = Array('Required', 'Required', 'Required');
	
	var alertMsg = "Please complete the required fields\n\n";
	
	for (var i = 0; i < requiredFields.length; i++){
		var fieldObj = formObj.elements[requiredFields[i]];
		if (fieldObj){
			switch(fieldObj.type){
				case "select-one":
					if (fieldObj.selectedIndex == -1 || fieldObj.options[fieldObj.selectedIndex].value == "") {
						document.getElementById(requiredFields[i] + "-err").innerHTML = errorMessages[i];
						isError = true;
					}
					else document.getElementById(requiredFields[i] + "-err").innerHTML = "";
				break;
				
				case "text": case "textarea": case "password":
					var txtFldValue = fieldObj.value;
					txtFldValue = LTrim(txtFldValue);
					if (txtFldValue.length==0 || txtFldValue==null) {
						document.getElementById(requiredFields[i] + "-err").innerHTML = errorMessages[i];
						isError = true;
					}
					else document.getElementById(requiredFields[i] + "-err").innerHTML = "";
				break;
			}
		}
	}
	
	if (isError) return false;
	else return true;
}

// Add email to holder
function addEmail(email, domain, tld) {
	var email = email + '@' + domain + '.' + tld;
	document.getElementById('email-holder').innerHTML = '<a href="mailto:' + email + '" title="Click to send an e-mail">' + email + '</a>';
}

// Zoom media
function zoomMedia(largeImage) {
	document.getElementById('hover-window-media').style.display = "block";
	document.getElementById('image-media').src='data/images/media/large/' + largeImage;
	document.getElementById('panel-right').style.display = "none";
	return false;
}

// Zoom map
function zoomMap() {
	document.getElementById('hover-window-contact').style.display = "block";
	document.getElementById('image-location').src='App_Themes/Default/images/main/location-map.gif';
    document.getElementById('panel-right').style.display = "none";
	return false;
}

// hide window
function hideWindow(windowId) {
    document.getElementById('panel-right').style.display = "block";
	document.getElementById(windowId).style.display = "none";
	return false;
}

// Srives panel
function togglePanel(panelId) {
    for (var i=1; i<= 7; i++) {
        if (panelId != i)
            $("#services-panel-" + i).hide();
    }
    
    panelId = "#services-panel-" + panelId;
    $(panelId).slideDown("fast");
}

function showPanel(panelId) {
    document.getElementById(panelId).style.display = "block";

}

function hidePanel(panelId) {
    document.getElementById(panelId).style.display = "none";
}

// Togle hover window - Properties
function hoverWindowP(imageName) {
	document.getElementById('hover-window-properties').style.display = "block";
	document.getElementById('image').src='data/properties-files/' + imageName;
	return false;
}

// hide window properties
function hideWindowP(windowId) {
    document.getElementById('hover-window-properties').style.display = "none";
	return false;
}