/* EMRevilla. Do not use this. Just use show_page.php
var SITE_ROOT = 'http://localhost'; 

function showPage(page) {
    alert (SITE_ROOT + '/show_page.php?page=' + page);
    location.href = SITE_ROOT + '/show_page.php?page=' + page;    
}
*/
function delay(millisec)
{
    var date = new Date();
    var curDate = null;

    do { 
        curDate = new Date(); 
    } while(curDate-date < millisec);
} 

function doUpdateValueOnFocus ( elem, initValue ) { 
    if ( elem.getValue().trim() == initValue ) {
        elem.value = "";
        elem.className = "";
    }
}

function doUpdateValueOnBlur ( elem, initValue ) { 
    if ( elem.getValue().trim() == "" ) {
        elem.value = initValue;
        elem.className = "noFieldValue";
    }
}

var arrFields = ['ClientName', 
                 'BriefDescription',
                 'CellPhone',
                 'DaytimePhone' ];
var arrDescriptions = [ 'Optional. You may remain anonymous.',
                      'Type in here a brief description of the facts surrounding your case, or legal question or concern if you wish legal advice, a free case evaluation or a free initial consultation.',
                      'Optional.',
                      'Optional. If you want attorney to call you.' ];        
function home_page_init()
{                       

    $each( arrFields, function( item, index ) {
        $( item ).value = arrDescriptions[ index ];
        $( item ).className = "noFieldValue";
        $( item ).onfocus = function() { doUpdateValueOnFocus($( item ), arrDescriptions[ index ] ); }
        $( item ).onblur = function() { doUpdateValueOnBlur($( item ), arrDescriptions[ index ] ); }
    } );
    
    $( 'txtEmailPre' ).onblur = function() { 
        $( 'EmailAddress' ).value = $( 'txtEmailPre' ).value; 
    }
    $( 'txtZipCodePre' ).onblur = function() { 
        $( 'ZipCode' ).value = $( 'txtZipCodePre' ).value; 
    }
    $( 'txtDaytimePhonePre' ).onblur = function() { 
        setTextBoxValue(  $( 'DaytimePhone' ), $( 'txtDaytimePhonePre' ).value );
    }
    
    
    $( 'txtZipCodePre' ).focus();
    //$( 'txtEmailPre' ).onpress = function() { $( 'Email_Address' ).value = $( 'txtEmailPre' ).value; }
    
    $('divPracticeAreaText').innerHTML = "None. Please Select from above.";
    
    
}

var scroll = new Fx.Scroll(window, {
    wait: false,
    duration: 1000,
    transition: Fx.Transitions.Quad.easeInOut
});

function __validateClientForm (objForm) {
    var bValid = true;
    var sMessage = "Please correct the following:\n\n";
    var iCounter = 1;
    var ERROR_CLASS_NAME = 'errFld';
    var $elems = new Array();
    
    // first remove the classes on the elements
    !$( 'EmailAddress' ).removeClass( ERROR_CLASS_NAME );
    !$( 'DaytimePhone' ).removeClass( ERROR_CLASS_NAME );
    !$( 'ZipCode' ).removeClass( ERROR_CLASS_NAME );
    
    if ( $( 'EmailAddress' ).getValue().trim() == "" && 
         ( $( 'DaytimePhone' ).getValue().trim() == "" || 
           $( 'DaytimePhone' ).getValue().trim() == arrDescriptions[3]) ) {
        
        $elems.push( $( 'EmailAddress' ) );
        $elems.push( $( 'DaytimePhone' ) );        
        bValid = false;
        sMessage += iCounter++ + ". You have not entered an Email Address or Daytime Phone Number.\n    We need at least one method of contacting you.\n";
        
        if ( !$( 'EmailAddress' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'EmailAddress' ).toggleClass( ERROR_CLASS_NAME );
        
        if ( !$( 'DaytimePhone' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'DaytimePhone' ).toggleClass( ERROR_CLASS_NAME );
    }   
    
    if ( $( 'EmailAddress' ).getValue().trim() != "" && 
         !echeck( $( 'EmailAddress' ).getValue().trim() ) ) {
         
        $elems.push( $( 'EmailAddress' ) );
        bValid = false;
        sMessage += iCounter++ + ". Email Address is invalid.\n";
        if ( !$( 'EmailAddress' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'EmailAddress' ).toggleClass( ERROR_CLASS_NAME );
    }
    
    //alliver 06182008: add check for zipcodes, length should be 5.
    if ( $( 'ZipCode' ).getValue().trim() == "" ||
         $( 'ZipCode' ).getValue().length != 5 ) {
        $elems.push( $( 'ZipCode' ) );
        bValid = false;
        sMessage += iCounter++ + ". A 5-digit Zip Code is required.\n"
        if ( !$( 'ZipCode' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'ZipCode' ).toggleClass( ERROR_CLASS_NAME );
    } 
    
    if ( $( 'txtPracticeAreaId' ).getValue().trim() == "" ) {        
        $elems.push( $( 'txtPracticeAreaId' ) );
        bValid = false;
        sMessage += iCounter++ + ". Please select a Practice Area.\n";       
    } 
    
    if ( !bValid )
    {
        alert( sMessage );    
        $elems.reverse();
        $e = $elems.pop();
        if ( $e.id == 'txtPracticeAreaId' ) {
            scroll.toElement( $('aPracticeArea') );
        }
        else    
            $e.focus();
    }
    return bValid;
}

//alliver 06262008: bug id#38 add visual error message for bad lawyer input.
function __validateLawyerForm (objForm) {

    var bValid = true;
    var sMessage = "Please correct the following:\n\n";
    var iCounter = 1;
    var ERROR_CLASS_NAME = 'errFld';
    var $elems = new Array();

    // first remove the classes on the elements
    !$( 'FirmName' ).removeClass( ERROR_CLASS_NAME );
    !$( 'Name' ).removeClass( ERROR_CLASS_NAME );
    !$( 'EmailAddress' ).removeClass( ERROR_CLASS_NAME );
    !$( 'c5' ).removeClass( ERROR_CLASS_NAME );
    //!$( 'c6' ).removeClass( ERROR_CLASS_NAME );
    !$( 'PracticeArea1' ).removeClass( ERROR_CLASS_NAME );

    if ( $( 'FirmName' ).getValue().trim() == "" ) {
        
        $elems.push( $( 'FirmName' ) );        
        bValid = false;
        sMessage += iCounter++ + ". You have not entered your Firm's name.\n";
        
        if ( !$( 'FirmName' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'FirmName' ).toggleClass( ERROR_CLASS_NAME );
    }
    
    if ( $( 'Name' ).getValue().trim() == "" ) {
        
        $elems.push( $( 'Name' ) );        
        bValid = false;
        sMessage += iCounter++ + ". You have not entered your name.\n";
        
        if ( !$( 'Name' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'Name' ).toggleClass( ERROR_CLASS_NAME );
    }
    
    if ( $( 'EmailAddress' ).getValue().trim() == "" ) {
        
        $elems.push( $( 'EmailAddress' ) );        
        bValid = false;
        sMessage += iCounter++ + ". You have not entered an email address.\n";
        
        if ( !$( 'EmailAddress' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'EmailAddress' ).toggleClass( ERROR_CLASS_NAME );
    }   
    
    if ( $( 'EmailAddress' ).getValue().trim() != "" && 
         !echeck( $( 'EmailAddress' ).getValue().trim() ) ) {
         
        $elems.push( $( 'EmailAddress' ) );
        bValid = false;
        sMessage += iCounter++ + ". Email Address is invalid.\n";
        if ( !$( 'EmailAddress' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'EmailAddress' ).toggleClass( ERROR_CLASS_NAME );
    }
   
    if ( $( 'c5' ).getValue().trim() == "" ||
    	 $( 'c5' ).getValue().trim() == "0" ) {
        
        $elems.push( $( 'c5' ) );        
        bValid = false;
        sMessage += iCounter++ + ". Please select a state.\n    Afterwards select a county.\n";
        
        if ( !$( 'c5' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'c5' ).toggleClass( ERROR_CLASS_NAME );
    }
     
    if ( $( 'c5' ).getValue().trim() != "0" ) {
    	
    	if ( $( 'c6' ).getValue().trim() == "" ||
    	 	 $( 'c6' ).getValue().trim() == "0" ) {
        
	        $elems.push( $( 'c6' ) );        
	        bValid = false;
	        sMessage += iCounter++ + ". Please select a county.\n";
	        
	        if ( !$( 'c6' ).hasClass( ERROR_CLASS_NAME ) )
	            $( 'c6' ).toggleClass( ERROR_CLASS_NAME );
        
        }
        
    }
        
    if ( $( 'PracticeArea1' ).getValue().trim() == "" ||
    	 $( 'PracticeArea1' ).getValue().trim() == "0" ) {        
        $elems.push( $( 'PracticeArea1' ) );
        bValid = false;
        sMessage += iCounter++ + ". Please select a practice area.\n";
        
        if ( !$( 'PracticeArea1' ).hasClass( ERROR_CLASS_NAME ) )
            $( 'PracticeArea1' ).toggleClass( ERROR_CLASS_NAME );       
    } 
  
    if ( !bValid )
    {
        alert( sMessage );    
        $elems.reverse();
        $e = $elems.pop();
        $e.focus();
    }
    return bValid;
}

function setPracticeAreaId($id, $txt) {
    $('txtPracticeAreaId').value = $id;
    $('divPracticeAreaText').innerHTML = $txt;
    
}

function purifySellerForm( $theForm ) {
    
    // clean the form of it's 'optional' text before
    // actually submitting the form
    $each( arrFields, function( item, index ) {    
        if ( $( item ).value == arrDescriptions[ index ] )
            $( item ).value = "";        
    } );   
    
}

function setTextBoxValue( $elem, $txt ) {
    $elem.value = $txt;
    $elem.className = "";
}

var currentDiv;
// args: div to display
function openSubMenu(sender, args, colNum)
{
     closeCurrentSubPADiv()
    // keep track of the current div that's displayed
    currentDiv = args;
    // if the third column offset the x to -50
    var offsetX = 0;
    
    if ( colNum && colNum == 3 )
        offsetX = -200;
    
    var x = $(sender).getPosition()["x"];
    var y = $(sender).getPosition()["y"];
    
    $(args).setStyle('display', 'inline');
    $(args).setStyle('position', 'absolute');
    $(args).setStyle('left',x + 10 + offsetX);
    $(args).setStyle('top' ,y + 10);
    return false;
    
}

function closeCurrentSubPADiv() {
    // close the other div if it's open
    if ( currentDiv ) {
        $( currentDiv ).setStyle('display', 'none');
        currentDiv = null;
    }
}


