function ShowVideo()
{
 document.getElementById("welcomeVideo").innerHTML=' <object width="238" height="200"><param name="movie" value="http://www.youtube.com/v/-Dyj6HFKuVw&hl"></param><embed src="http://www.youtube.com/v/-Dyj6HFKuVw&hl&autoplay=1" type="application/x-shockwave-flash" width="238" height="200"></embed></object>';

}

function ShowDetailedMap(title, zone)
{
 window.location="mapSearchResults.php?title="+title+"&zone="+zone;
}

function ChangeMap(zone)
{

 if (zone=="")
     document.getElementById("map").src="images/OttawaArea.png";
 //else
     //document.getElementById("map").src="images/OttawaArea"+zone+".png";
}

function DoSearch()
{
 var searchText = document.getElementById("searchText").value;

 window.location = "condoSearchResults.php?searchText="+searchText;
}

function ChangeTab(action)
{
	var strLoc = window.location+"";
	
	if (strLoc.indexOf("?")>0)
		window.location = strLoc+"&tab="+action;
	else
		window.location = strLoc+"?tab="+action;
}

function SetStars(id, num)
{
	document.getElementById(id).value=num;

	for (var i=1;i<=5;i++)
	{
		if (i<=num)
			document.getElementById(id+i).style.background="url(images/starSB.png)";
		else
			document.getElementById(id+i).style.background="url(images/starUB.png)";
	}
}

function CalcLetters()
{

	var desc = document.getElementById("description").value;

	var len = desc.length;
	if (desc.length>0)
		len++;

	document.getElementById("typed").innerHTML=len;		
	
	if (len>1000)
	{
		document.getElementById("description").value = desc.substring(0,len-2);
		return false;
	}
	else
	{
		return true;
	}
	
}

function ValidateReview()
{
	if (document.getElementsByName("cost")[0].value!="" && document.getElementsByName("cost")[0].value.indexOf("$")==-1)
		document.getElementsByName("cost")[0].value="$"+document.getElementsByName("cost")[0].value;
							   
	if (document.getElementById("agree").checked == false)
		alert("You must agree the terms and conditions before submitting.");
	else if (document.getElementsByName("name")[0].value=="")
		alert("You must enter a title for this review!");
	else if (document.getElementsByName("description")[0].value=="")
		alert("You must enter text for this review!");			
	else
		document.forms[0].submit();
}

function ValidateContactForm()
{
	document.forms[0].submit();
}

function SendPageEmail()
{
	document.forms[0].submit();		
}

function Search()
{
	var province = document.getElementById("province").value;
	var city = document.getElementById("city").value;
	var type = document.getElementById("type").value;
					
	window.location="searchResults.php?province="+province+"&city="+city+"&type="+type;
}

function CatSearch(type)
{
	var province = document.getElementById("province").value;
	var city = document.getElementById("city").value;
					
	window.location="searchResults.php?province="+province+"&city="+city+"&type="+type+"&cat=1";
}

function AddRenovator()
{
	if (document.getElementsByName("name")[0].value=="")
		alert("You must enter a name!");
	//else if (document.getElementsByName("address")[0].value=="")
		//alert("You must enter an address!");
	else if (document.getElementsByName("province")[0].value=="")
		alert("You must enter a province!");		
	else if (document.getElementsByName("city")[0].value=="")
		alert("You must enter a city!");		
	else if (document.getElementsByName("name")[0].value=="")
		alert("You must enter a name!");		
	else if (document.getElementsByName("telephone")[0].value=="")
		alert("You must enter a telephone number!");				
	else	
		document.forms[0].submit();		
}

function register()
{
	if (document.getElementsByName("firstName")[0].value=="")
		alert("You must enter a first name!");
	else if (document.getElementsByName("lastName")[0].value=="")
		alert("You must enter an last name!");
	else if (document.getElementsByName("userName")[0].value=="")
		alert("You must enter a user name!");		
	else if (document.getElementsByName("password")[0].value=="")
		alert("You must enter a password!");		
	else if (document.getElementsByName("password")[0].value!=document.getElementsByName("password2")[0].value)
		alert("Your passwords don't match!");			
	else if (document.getElementsByName("email")[0].value=="")
		alert("You must enter an email!");				
	else if (!document.getElementsByName("agree")[0].checked)
		alert("You must agree to our terms of use!");				
	else	
		document.forms[0].submit();	
}

function ShoBigPic(id, url)
{
	document.getElementById(id).src=url;
}

// change these paths for your images
var myImages = ['images/slideshow/s2.jpg','images/slideshow/s4.jpg','images/slideshow/s5.jpg','images/slideshow/s6.jpg'];

// how many times should the photo change per page load
var maxChanges = myImages.length * 20;

// shuffle images so each time page loads, the photos show in different order
var do_shuffle = true;

// use simple randomness instead of shuffling (tends to repeat images too often)
var do_randomly = false;

// number of seconds between photo changes
var seconds_between_photos = 5;

// name of DIV to load photos into
var div_name = "loader";

var changes = 0;
var timer;
var thisImg = myImages.length - 1;

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};




// shuffling is better than random because of less potential repetition
if (do_shuffle) {
	myImages = shuffle(myImages);	
}


function nextImage () {
	
	var low = 0;
	var high = myImages.length - 1;
	var rand_no = Math.floor((high-(low - 1))*Math.random()) + low;
	
	thisImg++;
	changes++;
	if (thisImg==myImages.length) {
		thisImg = 0;
	}
	if (changes==maxChanges) {
		clearInterval(timer);
	}
	if (do_randomly) {
		thisImg = rand_no;
		return myImages[rand_no];
	} else {
		return myImages[thisImg];
	}
}

function changeImage () {
	
	var t = myImages[thisImg];
	var n = nextImage();
	
	if (t != n) {
		$("#"+div_name).addClass("loading");
		showImage(n);
	} else { 
		changeImage();
	}
}

function showImage(src)
{
	$("#"+div_name+" img").fadeOut("normal").remove();
	var largeImage = new Image();
	$(largeImage).load(function()
                        {
							$(this).hide();
                        	$("#"+div_name).append(this).removeClass("loading");
                                             
                       		$(this).fadeIn("slow");              
                        });    
	$(largeImage).attr("src", src);                                                                               
}

function checkForLoaded () {
	if (document.getElementById(div_name) != null) {
		//alert("loaded");
		clearInterval(timer);
		changeImage();
		timer = setInterval(changeImage, (seconds_between_photos * 1000));
	}
}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	else return true;
	
	if (keycode == 13)
	{
	   Search();
	   return false;
	}
	else
	   return true;
}

