//-----------------       Javascript Liberary       -------------------------
//===========================================================================



//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
//EMAIL FORM ERROR MESSAGES
//
//This set of functions displays error messages into a form in the webpage.
//It is compatible with: IE6, Firefox, Safari, Chrome
//
//-----------------------------------------------------------------------------
formisgood=1;
//-----------------------------------------------------------------------------
function submit_question()
{
	check_email_form();

	if (formisgood==1)
	{
		//alert('The form is good.');
		document.question_form.submit();
	}
	else
	{
		//Missing information in the form message. 
		alert('Sorry we are missing information in the form.');
	}

	//Reset test value
	formisgood=1;
}
//-----------------------------------------------------------------------------
function check_email_form()
{
	//Runs this list of functions which check and update required form fields.
	check_email();
}
//-----------------------------------------------------------------------------
function check_email() 
{
	//Reset Message Box
	document.getElementById('form_message_email_status').innerHTML="";

	//Reset Message Box
	//Required for Safari to display element - part 1
	document.getElementById('form_message_email_status').style.display = "none";
	document.getElementById('form_message_email_status').style.visibility = 'hidden';

	str=document.getElementById('email').value;
	if (!((str.indexOf(".") > 2) && (str.indexOf("@") > 0)))
	{
		formisgood-=1;
		document.getElementById('form_message_email_status').innerHTML="<div class='form_error_text'>Required Field <br> Example: email@provider.com </div>";

		//Required for Safari to display element - part 2
		document.getElementById('form_message_email_status').style.display = "block";
		document.getElementById('form_message_email_status').style.visibility = 'visible';
	}
}
//-----------------------------------------------------------------------------
//HTML Example
//
//<!-- Email Field Message Box -->
//<!-- Note display is none and visibility hidden so Safari will know the size of the message box to display in the form. -->
//<div id="form_message_email_status" style="display:none;visibility:hidden;width:260px;height:30px;" class='form_error_text'></div>
//<div><input type="text" name="email" id="email" value="your email address" class="ojshort" onfocus="email_form_emailaddress_onfocus()" onblur="email_form_emailaddress_onblur()"></div>
//
//-----------------------------------------------------------------------------
//Code for disabling the Enter Key
//
//This is a useful script to prevent forms from 
//skipping over scripts because the enter key was pressed. 
//
//<script language="JavaScript" type="text/javascript">
////Stop form submit on enterkey. 
//function stopRKey(evt) {
//   var evt = (evt) ? evt : ((event) ? event : null);
//   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
//   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
//}
//document.onkeypress = stopRKey; 
//</script>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------





function submit_free_evaluation_form()
{
	tmp=document.location.href;
	document.free_case_evaluation.submit();
	alert("Thank you! We will get to your question right away.");
	document.location.href=tmp; // This fixes firefox not wanting to go back to the referring page using PHP. 
}

function email_form()
{
	//tmp=document.location.href;
	document.mini_email_form.submit();
	//alert('Thank you! We will get to your message right away!');
	//document.location.href=tmp; // This fixes firefox not wanting to go back to the referring page using PHP. 
}

function form_contact()
{
	//tmp=document.location.href;
	document.contact_Us_big_form.submit();
	//alert('Thank you! We will get to you right away!');
	//document.location.href=tmp; 
}

function popup_contactus()
{
	window.open('form_contact.php','contactus','menubar=1,scrollbars=1,resizable=1,width=600,height=600'); 
}


function popup_disclaimer()
{
	window.open('disclaimer.php','disclaimer','menubar=1,scrollbars=1,resizable=1,width=600,height=600'); 
}






function make_phone_call(){
phone_with_special_chars = document.getElementById('call_now_phone').value;
phone_with_special_chars2=phone_with_special_chars.replace('(','');
phone_with_special_chars=phone_with_special_chars2.replace(')','');
phone_with_special_chars3=phone_with_special_chars.replace('-','');
var x = phone_with_special_chars3 ;

//Copy and paste updates for the Thinking Voice code below here. 
    var foo = '<iframe src="http://c2c.thinkingvoice.com/c2t/calls/html/static/topLevel/noPrePhoneReqW140H90.html?identifier=e970c984-5bbb-102c-bd28-001d096a3ed0'+ 
      '&phone=' + x + '" frameborder="0" left="10px" height="90px"' +
      ' width="140px" style="height:90px;' +
      ' width:140px; overflow:hidden;" MARGINHEIGHT="0px"' + 
      ' MARGINWIDTH="0px" frameborder=0 scrolling="no"> <\/iframe>';
    var bar = document.getElementById('call_now_div');
    bar.innerHTML = foo;
}

function call_now_onfocus(){ 
	if (document.getElementById('call_now_phone').value=='phone number'){
		document.getElementById('call_now_phone').value='';
	}
}


function call_now_onblur(){ 
	if (document.getElementById('call_now_phone').value==''){
		call_now_keep_looping=0;
		call_now_reset();
		//setTimeout(email_form_phone_reset(),500);
	}
}

function call_now_reset(){document.getElementById('call_now_phone').value='phone number'}

//Definition of behavior for input box.
var n;
var p;
var p1;
call_now_keep_looping=1;
function call_now_phonecontrol(){
call_now_onfocus();
p1=document.getElementById('call_now_phone');
call_now_keep_looping=1;
Validate_call_now();
}


function Validate_call_now(){
p=p1.value
if (call_now_keep_looping==1){
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.getElementById('call_now_phone').value="";
	document.getElementById('call_now_phone').value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.getElementById('call_now_phone').value="";
		document.getElementById('call_now_phone').value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.getElementById('call_now_phone').value="";
	pp="("+p13+")"+p14+p15;
	document.getElementById('call_now_phone').value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.getElementById('call_now_phone').value="";
	document.getElementById('call_now_phone').value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
}
//}

if (call_now_keep_looping==1){
	setTimeout(Validate_call_now,100)}
}


function call_now_testphone(obj1){
p=obj1.value
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
	}
}

//Definition of behavior for textarea.
function email_form_caseinfo_onfocus(){ 
	if (document.getElementById('question').value=='what is your question?'){
		document.getElementById('question').value='';
	}
}
function email_form_caseinfo_onblur(){ 
	if (document.getElementById('question').value==''){
		document.getElementById('question').value='what is your question?';
	}
}


//Definition of behavior for email input.
function email_form_emailaddress_onfocus(){ 
	if (document.getElementById('email').value=='your email address'){
		document.getElementById('email').value='';
	}
}
function email_form_emailaddress_onblur(){ 
	if (document.getElementById('email').value==''){
		document.getElementById('email').value='your email address';
	}
}

function free_consultation_form_fullname_onfocus(){ 
	if (document.getElementById('free_consultation_fullname').value=='first and last name'){
		document.getElementById('free_consultation_fullname').value='';
	}
}

function free_consultation_form_fullname_onblur(){ 
	if (document.getElementById('free_consultation_fullname').value==''){
		document.getElementById('free_consultation_fullname').value='first and last name';
	}
}

function free_consultation_form_email_onfocus(){ 
	if (document.getElementById('free_consultation_email').value=='email address'){
		document.getElementById('free_consultation_email').value='';
	}
}

function free_consultation_form_email_onblur(){ 
	if (document.getElementById('free_consultation_email').value==''){
		document.getElementById('free_consultation_email').value='email address';
	}
}


function call_now_onblur2(){  
	if (document.getElementById('free_consultation_phone').value==''){
		call_now_keep_looping=0;
		call_now_reset2();
		//setTimeout(email_form_phone_reset(),500);
	}
}


function call_now_reset2(){document.getElementById('free_consultation_phone').value='phone number'}

var n;
var p;
var p1;
call_now_keep_looping=1;
function call_now_phonecontrol2(){
call_now_onfocus2();
p1=document.getElementById('free_consultation_phone');
call_now_keep_looping=1;
Validate_call_now2();
}

function call_now_onfocus2(){ 
	if (document.getElementById('free_consultation_phone').value=='phone number'){
		document.getElementById('free_consultation_phone').value='';
	}
}


function Validate_call_now2(){
p=p1.value
if (call_now_keep_looping==1){
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.getElementById('free_consultation_phone').value="";
	document.getElementById('free_consultation_phone').value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.getElementById('free_consultation_phone').value="";
		document.getElementById('free_consultation_phone').value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.getElementById('free_consultation_phone').value="";
	pp="("+p13+")"+p14+p15;
	document.getElementById('free_consultation_phone').value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.getElementById('free_consultation_phone').value="";
	document.getElementById('free_consultation_phone').value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
}
//}

if (call_now_keep_looping==1){
	setTimeout(Validate_call_now2,100)}
}

function call_now_testphone2(obj1){
p=obj1.value
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
	}
}


//movie controls
// F. Permadi May 2000
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function StopFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.StopPlay();
}

runonce=0;
function PlayFlashMovie()
{

	if (runonce==0)
	{
		object="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0' id='myFlashMovie' width=265 height=177><param name=movie value='17740_MML_OSP_GENERIC_0_090306_1.swf'><param name=quality value=high><param name=play value=false><param name=bgcolor value=#BAD6E2><embed id='embed_movie_settings' play=false swliveconnect='true' name='myFlashMovie' src='17740_MML_OSP_GENERIC_0_090306_1.swf' quality=high bgcolor=#FFFFFF width=265 height=177 type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> </embed ></object ><input type='button' value='Play' name='Play' onClick='PlayFlashMovie();'> <input type='button' value='Stop' name='Stop' onClick='StopFlashMovie();'>";
		document.getElementById('tv_play_image').height='0';
		document.getElementById("playmoviediv").innerHTML=object;
		runonce=1;
	}

	//Settimeout fixes a firefox issue.
	setTimeout ("playFlashMovieNow()", "500");	
}

function playFlashMovieNow()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Play();
	//embed.nativeProperty.anotherNativeMethod();
}

function RewindFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Rewind();
}

function NextFrameFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	// 4 is the index of the property for _currentFrame
	var currentFrame=flashMovie.TGetProperty("/", 4);
	var nextFrame=parseInt(currentFrame);
	if (nextFrame>=10)
		nextFrame=0;
	flashMovie.GotoFrame(nextFrame);		
}


function ZoominFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Zoom(90);
}

function ZoomoutFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.Zoom(110);
}


function SendDataToFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	flashMovie.SetVariable("/:message", document.controller.Data.value);
}

function ReceiveDataFromFlashMovie()
{
	var flashMovie=getFlashMovieObject("myFlashMovie");
	var message=flashMovie.GetVariable("/:message");
	document.controller.Data.value=message;
}


//===========================================================================
