// VOID
var MAIN_SESSION_EXPIRED = -1;
function MAIN_Void() { var n = ''; }
// Ajax Updater
function MAIN_AjaxUpdater(mID,mFile,mParam,mOnComplete) {
    var myAjax = new Ajax.Updater(
                     mID,
                     mFile,
                     {
		                method: 'post',
                        parameters: mParam,
			            onComplete: eval(""+mOnComplete+"")
                     }
    );
            
} // ENDS FUNCTION
// Ajax Request
function MAIN_AjaxRequest(mFile,mParams,mOnComplete) {
	

    var myAjax = new Ajax.Request(
    mFile,
        {
            method: 'post',
            parameters: mParams,
            onComplete: eval(""+mOnComplete+"")
        }
   );


} // ENDS FUNCTION


// Numbers Only
function MAIN_NumberOnly(e, currField) {

   
    if( document.all ) {
        var whichCode = event.which ? event.which :
        event.charCode ? event.charCode :
        event.keyCode;
    }
    else {
       var whichCode = e.which ?
       e.which :
       e.charCode ? e.charCode :
       e.keyCode;
    }

	

    var ascii = new Array(256);
    for(var x=0; x<256; x++ ) {
        ascii[x] = 0;
    }
    
    // NUMBERS
    for(x=48; x<58; x++ ) {
        ascii[x] = 1;
    }
    
    // BACK SPACE ALLOW
    ascii[8] = 1;
    // ENTER KEY
    ascii[13] = 1;
    // TAB
    ascii[9] = 1;
    ascii[46] = 1; // DELETE
	
	
    if( ascii[whichCode] == 0 ) {
         currField.focus();
		 return false;
    }
	else
      return true;


} // ENDS FUNCTION



// Numbers Only2
function MAIN_NumberOnly2(e, currField) {

   
    if( document.all ) {
        var whichCode = event.which ? event.which :
        event.charCode ? event.charCode :
        event.keyCode;
    }
    else {
       var whichCode = e.which ?
       e.which :
       e.charCode ? e.charCode :
       e.keyCode;
    }

	//alert(whichCode);
    //alert(currField.id);
    var ascii = new Array(256);
    for(var x=0; x<256; x++ ) {
        ascii[x] = 0;
    }
    
    // NUMBERS
    for(x=48; x<58; x++ ) {
        ascii[x] = 1;
    }
    
    // BACK SPACE ALLOW
    ascii[8] = 1;
    // ENTER KEY
    ascii[13] = 1;
    // TAB
    ascii[9] = 1;
    ascii[46] = 1; // DELETE
	

	
    if( ascii[whichCode] == 0 ) {
		
        var len = $(currField.id).value.length;
        $(currField.id).value = $(currField.id).value.substring(0,(len-1));
	}

   
    


} // ENDS FUNCTION





// Dollar Amount Only
function MAIN_DollarOnly(e, currField) {
  
    if( document.all ) {
        var whichCode = event.which ? event.which :
        event.charCode ? event.charCode :
        event.keyCode;
    }
    else {
       var whichCode = e.which ?
       e.which :
       e.charCode ? e.charCode :
       e.keyCode;
    }
    
    var ascii = new Array(256);
    for(var x=0; x<256; x++ ) {
        ascii[x] = 0;
    }
    
    // NUMBERS
    for(x=48; x<58; x++ ) {
        ascii[x] = 1;
    }
    
    // BACK SPACE ALLOW
    ascii[8] = 1;
    // ENTER KEY
    ascii[13] = 1;
    // TAB
    ascii[9] = 1;
    ascii[46] = 1; // DELETE
    // $
    ascii[36] = 1;
    ascii[44] = 1;
    ascii[46] = 1;
    
    if( ascii[whichCode] == 0 ) {
         currField.focus();
        return false;
   
    }
    

} // ENDS Function


// Format for Dollar
function MAIN_FormatDollar(t,d,r) {

    // Take out all $
    d = d.replace(/\$/g,"");
    
    // Take out all ,
    d = d.replace(/\,/g,"");
    
    var Period = d.split(".");
    for( var i=1; i<Period.length-1; i++ )
         d = d.replace(".","");
	 
    if( r == 1 )
        d = Math.round(parseInt(d));
    
    
    
    if( d > "" ) {
    
        nStr = d+'';    
        x = nStr.split('.');
        x1 = x[0];    
        x2 = x.length > 1 ? '.' + x[1] : '';    
        var rgx = /(\d+)(\d{3})/;    
        while (rgx.test(x1))        
               x1 = x1.replace(rgx, '$1' + ',' + '$2');
    
        t.value =  "$" + x1 + x2;
    }
    else
       t.value = "";
	   
} // ENDS FUNCTION


// Name Only
function MAIN_NameOnly(e, currField) {
  
    if( document.all ) {
        var whichCode = event.which ? event.which :
        event.charCode ? event.charCode :
        event.keyCode;
    }
    else {
       var whichCode = e.which ?
       e.which :
       e.charCode ? e.charCode :
       e.keyCode;
    }
    
        
    
    
    var ascii = new Array(256);
    for(var x=0; x<256; x++ ) {
        ascii[x] = 0;
    }
    
    // UPPER CASE ALLOW
    for(x=65; x<91; x++ ) {
        ascii[x] = 1;
    }
    
    //LOWER CASE ALLOW
    for(x=97;x<123;x++) {
        ascii[x] = 1;
    }
    
    // SINGLE QUOTE ALLOW
    ascii[39] = 1;
    // DASH ALLOW
    ascii[45] = 1;
    // COMMA ALLOW
    ascii[44] =1 ;
    // SPACE ALLOW
    ascii[32] = 1;
    // PERIOD ALLOW
    ascii[46] = 1;
    // BACK SPACE ALLOW
    ascii[8] = 1;
    // ENTER KEY
    ascii[13] = 1;
    // TAB
    ascii[9] = 1;
    ascii[46] = 1; // DELETE
    if( ascii[whichCode] == 0 ) {
         currField.focus();
        return false;
   
    }
     
} // ENDS FUNCTION


// Letters and Number Only
function MAIN_LettersNumbersOnly(e, currField) {
  
    if( document.all ) {
        var whichCode = event.which ? event.which :
        event.charCode ? event.charCode :
        event.keyCode;
    }
    else {
       var whichCode = e.which ?
       e.which :
       e.charCode ? e.charCode :
       e.keyCode;
    }
        
     
    
    var ascii = new Array(256);
    for(var x=0; x<256; x++ ) {
        ascii[x] = 0;
    }
    
    // NUMBERS
    for(x=48; x<58; x++ ) {
        ascii[x] = 1;
    }
    // UPPER CASE ALLOW
    for(x=65; x<91; x++ ) {
        ascii[x] = 1;
    }
    
    //LOWER CASE ALLOW
    for(x=97;x<123;x++) {
        ascii[x] = 1;
    }
    
  
    // BACK SPACE ALLOW
    ascii[8] = 1;
    // ENTER KEY
    ascii[13] = 1;
    // TAB
    ascii[9] = 1;
    ascii[46] = 1; // DELETE
    // SPACE ALLOW
    ascii[32] = 1;
    
    if( ascii[whichCode] == 0 ) {
         currField.focus();
        return false;
   
    }
    

} // ENDS MAIN_NumberOnly()


// Auto Tab
function MAIN_AutoTab(input, len, e) {

    if( input.value.length == len ) {
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }
				
    function getIndex(input) {
        var index = -1,
        i =0, found = false;
        while( i < input.form.length && index == -1 ) {
               if( input.form[i] == input )
                   index = i;
               else
                  i++;
        }
        return index;
    }
    
    return true;
    
} // ENDS FUNCTION


// Text Field No Enter Key
function MAIN_TextFieldNoEnterKey(e, currField) {

    if( document.all ) {
        var whichCode = event.which ? event.which : event.charCode ? event.charCode : event.keyCode;
    }
    else {
       var whichCode = e.which ? e.which : e.charCode ? e.charCode : e.keyCode;
    }
	   
    if( whichCode == 13 ) {
	currField.focus();
	return false;
    }
				   
} // END Function

// Catch Enter Key
function MAIN_CatchEnterKey(obj,e,js) {
	
    if( document.all ) {
        var whichCode = event.which ? event.which :
        event.charCode ? event.charCode :
        event.keyCode;
    }
    else {
       var whichCode = e.which ?
       e.which :
       e.charCode ? e.charCode :
       e.keyCode;
    }
  		       
    if( whichCode == 13 ) {
        eval(js);
    }
    	
}


function MAIN_GetSelectedValue( lst ) { return $(''+lst+'').options[$(''+lst+'').selectedIndex].value; } 
function MAIN_GetSelectedText ( lst ) { return $(''+lst+'').options[$(''+lst+'').selectedIndex].text;  }
function MAIN_GetSelectedIndexByText ( lst, text) { 
     

	 var index = 0;
	 for( var i=0; i<lst.length; i++ ) {  
		  if( lst.options[i].text == text ) {
			  index = i;
			  i = lst.length+1;
		  }
	 }
	 return index;

}
function MAIN_GetSelectedIndexByValue ( lst, value) { 
     

	 var index = 0;
	 for( var i=0; i<lst.length; i++ ) {  
		  if( lst.options[i].value == value ) {
			  index = i;
			  i = lst.length+1;
		  }
	 }
	 return index;

}
// Show Center Grey Box
function MAIN_GB_showCenter(title,url,h,w,js) { GB_showCenter(title,url,h,w,js); }
function MAIN_GB_showCenterPercent(title,url,perc,js) { 
    var nW = new MAIN_Window();
	nW.GetDimensions();
    
	var h = nW.Height*perc/100;
	var w = nW.Width*perc/100;
	
	GB_showCenter(title,url,h,w,js); 

}
// Default function for a completed Ajax Request
function MAIN_SubmitRequestComplete(response) { eval(response.responseText); }
function MAIN_SubmitAjaxTest(response) { alert(response.responseText); }


// FUNCTION Hide Object
function MAIN_ObjHide(hide) { $(''+hide+'').style.display='none'; }

// FUNCTION Show Object
function MAIN_ObjShow(show) { $(''+show+'').style.display=''; }

// Show Hide Show Object
function MAIN_HideShowID(js_init,
						 hide,
						 show,
						 js_complete ) {
	

    if( js_init > "" )
	    eval(js_init);
		

	MAIN_ObjHide(hide);
	MAIN_ObjShow(show);
	
	if( js_complete > "" )
	    eval(js_complete);
		

} // ENDS FUNCTION



// Focus
function MAIN_Focus(obj) { $(obj).focus(); }


/* Get Select Box */
function MAIN_GetSelectBox( mSelectHolderID,
                            mID,
                            mName,
                            mDefVal,
                            mDefText,
                            mSelVal,
                            mJavaS,
                            mClass,
                            mFunction,
                            mInput,
                            mOnComplete ) {
  

							
							
    mParam = "SEL_ID="+mID+"&SEL_NAME="+mName+"&SEL_DEFAULT_VAL="+mDefVal+"&SEL_DEFAULT_TEXT="+mDefText+"";
    mParam = mParam + "&SEL_VALUE="+mSelVal+"&SEL_JS="+mJavaS+"&SEL_CLASS="+mClass+"";
    mParam = mParam + "&SEL_FUNCTION="+mFunction+"&SEL_INPUT="+mInput+"";


	var myAjax = new Ajax.Updater(
                          mSelectHolderID,	        
                          '/share/ajax/share/select_box.php',
                          {
                               method: 'post',
                               parameters: mParam,
                               onComplete: eval(""+mOnComplete+"")							      
                          }
    );

} // ENDS FUNCTION 

function MAIN_GetCheckBox1or0(chcbox) {

    if( $(chcbox).checked == true )
	    return 1;
	else
	   return 0;

}
function MAIN_GetDataTable(mID,mFile,mParam,mOnComplete) {
    var myAjax = new Ajax.Updater(
                          mID, 
                          mFile,
                          {
                                method: 'post',
                                parameters: mParam,
                                onComplete: eval(""+mOnComplete+"")
                          }
    );
      
} // ENDS FUNCTION 


// Add Record
function MAIN_AddRecord(mParam,mOnComplete) {
    
	var myAjax = new Ajax.Request(
                    '/share/ajax/share/add_record.php',
                    {
                         method: 'post',
                         parameters: mParam,
                         onComplete: eval(""+mOnComplete+"")
                    }
    );
	
} // ENDS FUNCTION 



// Update Record
function MAIN_UpdateRecord(mParam,mOnComplete) {
	var myAjax = new Ajax.Request(
                    '/share/ajax/share/update_record.php',
                    {
                         method: 'post',
                         parameters: mParam,
                         onComplete: eval(""+mOnComplete+"")
                    }
    );

} // ENDS FUNCTION 

// Confirm Delete
function MAIN_ConfirmDeleteRecord(mInfo,mParam,mOnComplete) {
    
    if( confirm("Are you sure you want to delete this record?"+mInfo+"") )
	    MAIN_DeleteRecord(mParam,mOnComplete);
}
// Delete Record
function MAIN_DeleteRecord(mParam,mOnComplete) {
    //alert(mParam);
    var myAjax = new Ajax.Request(
                     '/share/ajax/share/delete_record.php',
                     {
                         method: 'post',
                         parameters: mParam,
                         onComplete: eval(""+mOnComplete+"")
                     }
    );

} // ENDS FUNCTION


// UPDATE SYS_CODES
function MAIN_UpdateObjectCode(object_id,code_id,boolean,js) {
	
	var param = "AJAX=1&object_id="+object_id+
	            "&code_id="+code_id+"&add=";
	if( boolean == true )
	    param = param + "1";
		
 
	var myAjax = new Ajax.Request(
                    '/share/ajax/share/update_object_code.php',
                    {
                         method: 'post',
                         parameters: param,
                         onComplete: eval(""+js+"")
                    }
    );
   
	
} // ENDS FUNCTION 


// UPDATE SYS_CODES
function MAIN_UpdateObjectCategoryCode(object_id,code_id,boolean,category_id,js) {
	
	var param = "AJAX=1&object_id="+object_id+
	            "&category_id="+category_id+"&code_id="+code_id+"&add=";
				
	if( boolean == true )
	    param = param + "1";
		
	
	var myAjax = new Ajax.Request(
                    '/share/ajax/share/update_object_category_code.php',
                    {
                         method: 'post',
                         parameters: param,
                         onComplete: eval(""+js+"")
                    }
    );
	
    
} // ENDS FUNCTION 


// Increase Web Content Time To Live
function MAIN_IncreaseContentTTL(c,e,u,js) {
    
	var param = 'content_id='+c+'&intr_expr='+e+'&intr_unit='+u+'';
	

    MAIN_AjaxRequest('/share/ajax/share/increase_content_ttl.php',
					 param,
					 js);

	
} // ENDS FUNCTION 


// Date Time Fields Clear
function MAIN_DateTimeClear(mName,mType,show_hour,show_min,show_sec) {
	
	if( mType == "select" ) {
	
	    $('lstMon'+mName+'').selectedIndex = 0;
		$('lstDay'+mName+'').selectedIndex = 0;
		$('lstYear'+mName+'').selectedIndex = 0;
		if( show_hour == 1 )
		    $('lstHour'+mName+'').selectedIndex = 0;
		if( show_min == 1 )
		    $('lstMin'+mName+'').selectedIndex = 0;
		if( show_sec == 1 )
		    $('lstSec'+mName+'').selectedIndex = 0;
			
        $('txt'+mName+'Date').value = "0000-00-00 00:00:00";
		
		
	}
	
} // ENDS FUNCTION

// Date Time Set Now
function MAIN_DateTimeSetNow(mName,mType,mNow,mMon,mDay,mYear,mHour,mMin,mSec,show_hour,show_min,show_sec) {
	
	if( mType == "select" ) {

	    $('lstMon'+mName+'').selectedIndex = parseInt(MAIN_GetSelectedIndexByValue($('lstMon'+mName+''), mMon));
		$('lstDay'+mName+'').selectedIndex = parseInt(MAIN_GetSelectedIndexByValue($('lstDay'+mName+''), mDay));
		$('lstYear'+mName+'').selectedIndex = parseInt(MAIN_GetSelectedIndexByValue($('lstYear'+mName+''), mYear));
		if( show_hour == 1 )
		    $('lstHour'+mName+'').selectedIndex = parseInt(MAIN_GetSelectedIndexByValue($('lstHour'+mName+''), mHour));
		if( show_min == 1 )
		    $('lstMin'+mName+'').selectedIndex = parseInt(MAIN_GetSelectedIndexByValue($('lstMin'+mName+''), mMin));
		if( show_sec == 1 )
		    $('lstSec'+mName+'').selectedIndex = parseInt(MAIN_GetSelectedIndexByValue($('lstSec'+mName+''), mSec));
			
        $('txt'+mName+'Date').value = mNow;

	}
	
} // ENDS FUNCTION
function MAIN_DateTimeSetHidden(mName,mValue,mPos,mChar) {
     var bvalue = $('txt'+mName+'Date').value;
	 
	 
	 
	 var nvalue = "";
	 var index = 0;
     for( var i=0; i<mPos; i++ )
	      nvalue = nvalue + bvalue.substr(i,1);
		 

	 
	 nvalue = nvalue + mValue;
	 
	 var equal = parseInt(mPos)+parseInt(mChar);
	 
	 for( i=equal; i<bvalue.length; i++ )
	      nvalue = nvalue + bvalue.substr(i,1);

     $('txt'+mName+'Date').value = nvalue;
 
} // ENDS FUNCTION


// Function Intialize a div before processing 
function MAIN_InitDivProcessing(div,message,js_complete) {
    MAIN_AjaxUpdater(div,'/share/ajax/processing.php','message='+message+'',js_complete);
} // ENDS FUNCTION


// Function Execute a Function in a class
function MAIN_ExecClassFunction(mClass,mFunction,mInput,js_complete) {
    var mParams = "class="+mClass+"&function="+mFunction+"&input="+mInput;
    MAIN_AjaxRequest('/share/ajax/share/class_function.php',mParams,js_complete);
} // ENDS FUNCTION



// Function Update a Field in a Table
function MAIN_UpdateTable(table,key_id,key_value,field,value,object_id,sys_user,js_complete) {
   
   var mParams =  "table="+table+
	              "&key_id="+key_id+
				  "&key_value="+key_value+
				  "&field="+field+
				  "&value="+value+
				  "&object_id="+object_id+
				  "&sys_user="+sys_user;

    MAIN_AjaxRequest('/share/ajax/share/update_field.php',mParams,js_complete);
} // ENDS FUNCTION

var MAIN_Window = 
    function () {
      this.Height = 0;
      this.Width = 0;
      this.ScrollTop = 0;
      this.ScrollLeft = 0;
      
      this.Print = function() {
          
	  alert("Width: "+this.Width+"\nHeight: "+this.Height+
	        "\nScroll Left: "+this.ScrollLeft+"\nScroll Top: "+this.ScrollTop+"");
      };
      
      this.GetDimensions = function() {
  
          if( self.innerHeight ) { // all except Explorer 
              this.Width = self.innerWidth;
              this.Height = self.innerHeight;
          }
          else if( document.documentElement && document.documentElement.clientHeight ) { // Explorer 6 Strict Mode
	           this.Width = document.documentElement.clientWidth;
	           this.Height = document.documentElement.clientHeight;
	  }
	  else if( document.body ) { // other Explorers
	           this.Width = document.body.clientWidth;
	           this.Height = document.body.clientHeight;
	  }
      };
      
      this.GetScrollValues = function () {
      
          if( self.pageYOffset ) { // all except Explorer
      
              this.ScrollLeft = self.pageXOffset;
       	      this.ScrollTop  = self.pageYOffset;
	  }
	  else if( document.documentElement && document.documentElement.scrollTop ) { // Explorer 6 Strict
	           this.ScrollLeft = document.documentElement.scrollLeft;
	       	   this.ScrollTop  = document.documentElement.scrollTop;
	  }
	  else if( document.body ) { // all other Explorers
		   this.ScrollLeft = document.body.scrollLeft;
		   this.ScrollTop  = document.body.scrollTop;
	 }
      };
};
function MAIN_OpenWindow(url) {
    window.open(url);	
}
function MAIN_HsClose(id) {
   hs.close(id);	
}
function MAIN_FormError(id,error) {
    $('lbl'+id+'').className = "lblRequired";
	$('Arrow'+id+'').className = "formArrowError";
	$('Error'+id+'').innerHTML = error;
}
function MAIN_GetLoggedInStatus(js) {
    MAIN_AjaxRequest('/share/ajax/get_logged_in_status.php',
					 'AJAX=1&js='+js+'',
					 'MAIN_SubmitRequestComplete'
					 );			 
}
function MAIN_AnnuityDisclaimer(title,url) {
    alert("We make every effort to provide current and accurate interest rates.  However, final rates will be determined by the insurance company.");
		GB_showFullScreen(title,url);
		//GB_showCenter(title,file,540,900,'');
}
function MAIN_TaxGuideDisclaimer(title,url) {
    alert("The information in this tax guide is not to be used as legal or tax advice. Please consult your own personal legal or tax advisor for guidance.");
		GB_showFullScreen(title,url);
		//GB_showCenter(title,file,540,900,'');
}
var thisWindow = new MAIN_Window();
thisWindow.GetDimensions();
function MAIN_InputNormal(inp, text) {    
    $(inp).className = "inputNormal";
    if( $(inp).value == text )
	$(inp).value = "";
} // END FUCNTION

	
function MAIN_InputWaiting(inp, text) {
    if( $(inp).value == "" || $(inp).value == text ) {
	$(inp).className="inputWaiting";
	$(inp).value = text;
    }
} // END FUNCTION
