////////////////////////////////////////
function toUnicode(elmnt,content){
    if (content.length==elmnt.maxLength){
      next=elmnt.tabIndex
      if (next<document.forms[0].elements.length){
        document.forms[0].elements[next].focus()
    }
  }
}

////////////////////////////////////////////////
function fakeKeyScape(input_id)
{
	alert(input_id);
	if (input_id != "undefined")
	{
                document.getElementById(input_id).focus();
        }
}

////////////////////////////////////////////////
function fakeKeyPress(input_id) 
{   
	return; 
   	var input = $(input_id);    
	if(input.fireEvent) 
	{      // ie stuff      
		var evt = document.createEventObject();      
		evt.keyCode = 32;      
		$(input_id).fireEvent("onKeyDown", evt);    
	} else 
	{       // firefox stuff      
		var evt = document.createEvent("KeyboardEvent");      
		evt.initKeyEvent('keydown', true, true, null, false, false, false, false, 32, 0);      
		var canceled = !$(input_id).dispatchEvent(evt);    
	}

}
////////////////////////////////////////
function updateCompleter()
{
        var inputValue = encodeURIComponent($('contractorss_category').value);
        if (inputValue == "")
        {
                inputValue = "a";
                document.getElementById("contractorss_category").value = "a";
        }
}

////////////////////////////////////////
function updateCompleter_category()
{
      	var inputValue = encodeURIComponent($('contractorss_category').value);
	if (inputValue == "")
	{
		inputValue = "a";
	        document.getElementById("contractorss_category").value = "a";
	}
        //fakeKeyPress("contractorss_category");
     	new Ajax.Updater('contractorss_category_choices','services/contractor_sba_contractors_s_category_PTAutocomplete1.php',{parameters:'contractorss_category_choices='+inputValue, onComplete:function(){Element.show('contractorss_category_choices');}});

}
////////////////////////////////////////
function updateCompleter_state()
{
        var inputValue = encodeURIComponent($('contractorss_state').value);
        if (inputValue == "")
        {
                inputValue = "a";
                document.getElementById("contractorss_state").value = "a";
        }
        fakeKeyPress("contractorss_state");
}
////////////////////////////////////////
function updateCompleter_county()
{
        var inputValue = encodeURIComponent($('contractorss_county').value);
        if (inputValue == "")
        {
                inputValue = "a";
                document.getElementById("contractorss_county").value = "a";
        }
        fakeKeyPress("contractorss_county");
}

///////////////////////////////////////////////////////////
function doConfirm(my_msg)
{
        jConfirm(my_msg, "Confirm" , function(r)
        {
                if (r == true)
                {
                        window.location = ("logout.php");
                }
        });
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////
// function that creates the ajax object
////////////////////////////////////////////
        var http_request = false;
        function makePOSTRequest(url, parameters)
        {
                var http_request = false;
                http_request = false;
                if (window.XMLHttpRequest)
                {
                        http_request = new XMLHttpRequest();
                        if (http_request.overrideMimeType)
                        {
                                http_request.overrideMimeType('text/html');
                        }
                        } else if (window.ActiveXObject) { // IE
                                try {
                                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                                } catch (e) {
                                try {
                                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e) {}
                        }
                }
                if (!http_request)
                {
                        alert('Cannot create XMLHTTP instance');
                        return false;
                }

                http_request.onreadystatechange = function()
                {
                        if (http_request.readyState == 4)
                        {
                                if (http_request.status == 200)
                                {
                                        var my_result = http_request.responseText.split("<~>");
                                        evaluate_return( my_result);
                                } else
                                {
                                        alert('There was a problem with the request.');
                                }
                        }

                }
                http_request.open('POST', url, true);
                http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                http_request.setRequestHeader("Content-length", parameters.length);
                http_request.setRequestHeader("Connection", "close");
                http_request.send(parameters);
        }
        //////////////////////////////
        function bring_cat_id()
        {
                var poststr = "my_request=" + encodeURI("Y");
                    poststr += "&fld_0=" + encodeURI("1" );  // indentify the category 
                    poststr += "&fld_1=" + encodeURI( document.getElementById("contractorss_category").value );
                    makePOSTRequest('services/validate_forms.php', poststr);
        }
        //////////////////////////////
        function bring_state_id()
        {
                var poststr = "my_request=" + encodeURI("Y");
                    poststr += "&fld_0=" + encodeURI("2" );  // indentify the state
                    poststr += "&fld_1=" + encodeURI( document.getElementById("contractorss_state").value );
                    makePOSTRequest('services/validate_forms.php', poststr);
        }
        //////////////////////////////
        function bring_county_id()
        {
                var poststr = "my_request=" + encodeURI("Y");
                    poststr += "&fld_0=" + encodeURI("3" );  // indentify the county
                    poststr += "&fld_1=" + encodeURI( document.getElementById("contractorss_county").value );
                    makePOSTRequest('services/validate_forms.php', poststr);
        }
        //////////////////////////////
        function verify_email(f_id)
        {
                if (document.getElementById(f_id).value != "")
                {
                        var poststr = "my_request=" + encodeURI("Y");
                            poststr += "&fld_0=" + encodeURI("6" );  // indentify the requets validate emails
                            poststr += "&fld_1=" + encodeURI( document.getElementById(f_id).value );
                            makePOSTRequest('services/validate_forms.php', poststr);
                }
        }
	//////////////////////////////////
        function verify_username(f_id)
        {
                if (document.getElementById(f_id).value != "")
                {
                        var poststr = "my_request=" + encodeURI("Y");
                            poststr += "&fld_0=" + encodeURI("7" );  // indentify the requets validate username
                            poststr += "&fld_1=" + encodeURI( document.getElementById(f_id).value );
                            makePOSTRequest('services/validate_forms.php', poststr);
                }
        }
        //////////////////////////////////
        function verify_phone(f_id1,f_id2,f_id3)
        {
                if (document.getElementById(f_id1).value != "" && 
			document.getElementById(f_id2).value != "" &&
			document.getElementById(f_id3).value != "")
                {
                        var poststr = "my_request=" + encodeURI("Y");
                            poststr += "&fld_0=" + encodeURI("8" );  // indentify the requets validate phone number
                            poststr += "&fld_1=" + encodeURI( document.getElementById(f_id1).value );
                            poststr += "&fld_2=" + encodeURI( document.getElementById(f_id2).value );
                            poststr += "&fld_3=" + encodeURI( document.getElementById(f_id3).value );
                            makePOSTRequest('services/validate_forms.php', poststr);
                }
        }



        ////////////////////////////////
        function evaluate_return(my_result)
        {
                if (my_result[0] == "0")
                {
                }
                else
                {
                        if (my_result[1] == "1")  // the request was type 1 category
                        {
                                document.getElementById('contractorscontractor_id').value = my_result[2];
                        } 
                        if (my_result[1] == "2")  // the request was type 2 state
                        {
                                document.getElementById('contractorsstate').value = my_result[2];
                        }
                        if (my_result[1] == "3")  // the request was type 3 county
                        {
                                document.getElementById('contractorscounty').value = my_result[2];
                        }
                        else if (my_result[1] == "6")  // validate validation email
                        {
                                document.getElementById('reg_01').innerHTML = my_result[2];
                        }
                        else if (my_result[1] == "7")  // validate validation username
                        {
                                document.getElementById('reg_00').innerHTML = my_result[2];
                        }
                        else if (my_result[1] == "8")  // validate phone number
                        {
                                document.getElementById('reg_02').innerHTML = my_result[2];
                        }



		}
	}
