



function Validate ( thecontrol , cid , e , save )
    {
    if ( e )
        {
        if ( e.keyCode == 9 ) return;
        }
    else
        {
        e = 'blur';
        }

    if ( !thecontrol )
        {
        thecontrol = document.getElementById ( cid + '_txtDateMain' );
        }

    var focusedcontrolid = thecontrol.id.toLowerCase();
    
    thecontrol.setAttribute ( 'validationevent' , e );

    if ( ValidateControl ( thecontrol ) == true )
        {

        }

    thecontrol.setAttribute ( 'validationevent' , '' );  
    }

function MaskAlphaNumeric ( e , textbox )
    {
    if ( e )
        {
        if (e.keyCode == 8) //backspace
            {
            return;
            } 
        }

    str = textbox.value;
    str2 = stripCharsInList ( str , '!@#$%^&*()_+=|}{[];:></?~`' );
    if ( str != str2 )
        {
        textbox.value = str2;
        }
    }
    
function select_all ( control )
    {
    control.select();
    }

function ValidateControl ( thecontrol )
    {
    var valid = false;
    
    if ( thecontrol.getAttribute ( 'validationstring' ) == '' ) return ( true );

    var re = new RegExp ( thecontrol.getAttribute ( 'validationstring' ) );
    if ( thecontrol.value.match ( re ) )
        {
        valid = true;
        }

    if ( valid )
        {
        HideValidationError ( thecontrol );
        }
    else
        {
        if ( thecontrol.getAttribute ( 'validationevent' ) == 'blur' )
            {
            ShowValidationError ( thecontrol );
            }
        }
        
    return ( valid );    
    }

function ShowValidationError ( thecontrol )
    {
    var exclamation = document.getElementById ( GetParentID ( thecontrol ) + '_imgAlert' );

    if ( thecontrol.getAttribute ( 'validationevent' ) == 'blur' )
        {
        exclamation.style.display = '';
        thecontrol.style.backgroundColor = thecontrol.getAttribute ( 'backColorInvalid' );
        thecontrol.style.color = thecontrol.getAttribute ( 'foreColor' );
        var helptext = document.getElementById ( GetParentID ( thecontrol ) + '_lblMessage' );
        helptext.innerHTML = thecontrol.getAttribute ( 'helptext' );
        helptext.style.display = '';
        }
    thecontrol.setAttribute ( 'validated' , 'false' );
    }

function HideValidationError ( thecontrol )
    {
    document.getElementById ( GetParentID ( thecontrol ) + '_imgAlert' ).style.display = 'none';
    document.getElementById ( GetParentID ( thecontrol ) + '_lblMessage' ).style.display = 'none';
    thecontrol.style.backgroundColor = thecontrol.getAttribute ( 'backColorValid' );
    thecontrol.style.color = thecontrol.getAttribute ( 'foreColor' );
    thecontrol.setAttribute ( 'validated' , 'true' );
    }
    
function stripCharsInList ( s , charlist )
    {
	var i;
    var returnString = "";

    for ( i = 0 ; i < s.length ; i++ )
        {   
        var c = s.charAt ( i );
        if ( charlist.indexOf ( c ) == -1 ) returnString += c;
        }
        
    return returnString;
    }

function GetParentID ( thecontrol )
    {
    var theparentid = thecontrol.id;
    theparentid = theparentid.replace ( '_cboMain' , '' );
    theparentid = theparentid.replace ( '_txtDateMain' , '' );
    theparentid = theparentid.replace ( '_txtMain' , '' );
    return ( theparentid );
    }

function focusControl ( thecontrol )
    {
    thecontrol.style.backgroundColor = thecontrol.getAttribute ( 'backColorInitial' );
    thecontrol.style.color = '#000000';
    }

function MaskPhone(e,textbox){

    if ( e )
        {
        if (e.keyCode == 8){return} //backspace
        }

     if ( isDefaultMasking ( textbox ) )
        {
        textbox.value = '';
        textbox.style.color = '';
        return;
        }
    
     str = textbox.value;
     str = StripChars ( str );
     str = str.substring ( 0 , 10 );
     
     if ( str.length >= 6 )
        {
        str = '(' + str.substring ( 0 , 3 ) + ')' + str.substring ( 3 , 6 ) + '-' + str.substring ( 6 );
        }
     else if ( str.length >= 3 )
        {
        str = '(' + str.substring ( 0 , 3 ) + ')' + str.substring ( 3 );
        }    
     else if (str)
        {
        str = '(' + str;
        }
     
    textbox.value = str;
    }
    
function MaskEmail ( e , textbox )
    {
    if ( e )
        {
        if (e.keyCode == 8) //backspace
            {
            return;
            } 
        }

    str = textbox.value;
    str2 = stripCharsInList ( str , '\/\'\\ ";:?!()[]\{\}^|%$^*+=#' );
    if ( str != str2 )
        {
        textbox.value = str2;
        }
    }

function isDefaultMasking ( thecontrol )
    {
    if ( thecontrol.value == thecontrol.getAttribute ( 'masktext' ) ) return ( true );
    return ( false );
    }
    
function StripChars(str)
    {
    var c
    var ret = '';
    for( var i = 0; i < str.length; i++ )
        {
        c = str.charAt(i);
        if ( !isNaN(c) )
            {
            ret += c;    
            } 
        }
    return ret
    }
    
    
function MaskZip(e,textbox)
    {

    if ( e )
        {
        if ( e.keyCode == 8 ) //backspace
            {
            return;
            } 
        }

     if ( isDefaultMasking ( textbox ) )
        {
        textbox.value = '';
        textbox.style.color = '';
        return;
        }
     
    str = textbox.value;
    str = StripChars ( str );
    str = str.substring ( 0 , 5 );

    textbox.value = str;
    }
   
function ControlValidated ( thecontrolid )
   {
   var thecontrol = document.getElementById ( thecontrolid );
   
   if ( thecontrol.getAttribute ( 'validated' ) == 'true' ) return ( true );
   
   ShowValidationError ( thecontrol );
   
   alert ( "Please fill out the entire form" );
   
   return ( false );
   } 
    
function FormValidated ( )
    {
    if ( !ControlValidated ( 'CompanyName_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'FirstName_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'LastName_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'Address1_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'City_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'LongState_cboMain' ) ) return ( false );
    if ( !ControlValidated ( 'ZipCode_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'Phone1_txtMain' ) ) return ( false );
    //if ( !ControlValidated ( 'Phone2_txtMain' ) ) return ( false );
    //if ( !ControlValidated ( 'TollFreePhone_txtMain' ) ) return ( false );
    //if ( !ControlValidated ( 'Fax1_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'RealEmail_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'NumPro_cboMain' ) ) return ( false );
    if ( !ControlValidated ( 'Category1_cboMain' ) ) return ( false );
    if ( !ControlValidated ( 'Description_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'Website_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'WebsiteTitle_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'KeywordList_txtMain' ) ) return ( false );
    if ( !ControlValidated ( 'WebsiteDescription_txtMain' ) ) return ( false );
    if ( document.getElementById ( 'TOS' ).checked == false ) return ( false );

    return ( true );
    }

function DropDownChanged ( control , cid )
    {

    }