// fix footer
function fixFooter()
{
	var contentHeight = 255 + $("content").getHeight();
	var sideBarHeight = 405 + $("content-sidebar").getHeight();
	var siteHeight = ( contentHeight > sideBarHeight ) ? contentHeight : sideBarHeight;
	siteHeight += 30;
	$("footerPush").setStyle({ height: siteHeight+'px' });
	$("body").setStyle({ height: siteHeight+'px' });
	$("footer").show();
}
Event.observe( window, 'load', fixFooter );

// mail link
function sendmail()
{
	document.location = 'mai'+'lto:'+'info'+'@'+'cityocity'+'denver.c'+'om?'+'subject=City O\' City inquiry';
}

// contact form validation -------------------------------------------
function validateForm(){
	/*if (document.getElementById("regionType").selectedIndex == 0) {
		alert('Please select');
		document.getElementById("regionType").focus;
		return false;
	}*/
	if (document.getElementById("email").value == "") {
		alert('please enter your email.');
		document.getElementById("email").focus();
		return false;
	}
	if (document.getElementById("message").value == "") {
		alert('please enter a message.');
		document.getElementById("message").focus();
		return false;
	}
	// disable form
	var form = $('contactform');
	// all good. continue
	//return true;
	
	
	new Ajax.Updater( 'formDiv' , 'php/'+'mail/cachemail.'+'p'+'hp', {
	  parameters:$('contactform').serialize(), 
	  method:'post',
	  onComplete: contactThanksYou
	});
	
	
}	

// response for contact form
function contactThanksYou()
{
	Element.Methods.setOpacity( $('formDiv'), 0 );
	Effect.AppearTweaked( $('formDiv'), { duration:.5 } );
}


// newsletter form validate and submit -------------------------------------------
function submitNewsletter()
{
	var newsInputVal = $('newsletterInput').value;
	
	if ( newsInputVal == "" || emailcheck(newsInputVal) == false ) {
		alert('Please enter a valid email.');
		$('newsletterInput').focus();
		return false;
	}
	
	// all good. continue
	var newsletterParams = 'email=' + newsInputVal;
	
	new Ajax.Updater( 'newsletterSubmit' , 'php'+'/news'+'letter.'+'php', {
	  parameters:newsletterParams, 
	  evalScripts:true,
	  method:'post',
	  onComplete: newsletterThanksYou
	});
	
	
}


// response for newsletter form
function newsletterThanksYou()
{
	Element.Methods.setOpacity( $('newsletterSubmit'), 0 );
	Effect.AppearTweaked( $('newsletterSubmit'), { duration:.5 } );
	Effect.Fade( $('newsletterButton'), { duration:.5 } );
}

// email validation
function emailcheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}







// video streaming code -----------------------------------------------

function playVideo(vidFile,height)
{
	var params = 'video='+vidFile+'&width=320&height='+height;
	new Ajax.Updater( 'videoPlayer' , 'php/streamVideo.php', {
	  parameters:params, 
	  method:'post',
	  onComplete: contactThanksYou
	});
}