// This script validate the fields and shows the balloon
var g_lastBalloon;

function ShowMyBallon(oElement, erText)
        {			
        	if (g_lastBalloon != null)
        	  {                     	  	
        	    g_lastBalloon.hide();
        	  } 			 
            bl=new XBalloon();			
            bl.imagesDir="./balloon/images";			
            bl.posX=getX(oElement)+50;
	        bl.posY=getY(oElement);
            bl.title="<img src=\'./images/WebResource.gif\'/> Error";			
            //bl.title="";
            //bl.contentHtml= "<img src=\'../images/WebResource.gif\'/>&nbsp;&nbsp;&nbsp;&nbsp;" + erText; 
            bl.contentHtml=  erText;           
            bl.width=250;
            bl.transShow=true;            
            //bl.autoHide=true;			
            bl.show();			
            g_lastBalloon=bl;  	   
        }  
        
function pick_air_port_click(_checked)
{
	xajax_pick_air_port_click(_checked, xajax.getFormValues('form_data'));
}

function validateFormOnSubmit(theForm) 
  { 
     var reason = "";
	 //alert("0");
     if (theForm.form_status.value == "check_phone")
		  {
			   
               reason += validateEmpty(theForm.phone_number, "Please enter phone number.");			   
               if (reason != "")                   
			      {				   
                    return false;
                  }
				  
			   if (theForm.password != null)
			   {
				  reason += validateEmpty(theForm.password, "Please enter the password.");			   
                  if (reason != "")                   
			      {				   
                    return false;
                  }  
			   }
			   
			   if (theForm.Terms != null)
			   {
				  reason += validateCheckBox(theForm.Terms, "Please check box.");			   
                  if (reason != "")                   
			      {				   
                    return false;
                  }  
			   }
             //alert('1-1');	
			 if (theForm.phone_password !=null)
			 {
		     xajax_checkphone('formstatus=check_phone&phone_number=' + theForm.phone_number.value +'&phone_password=' +  theForm.phone_password.value);
			 }
			 else
			 {
				xajax_checkphone('formstatus=check_phone&phone_number=' + theForm.phone_number.value +'&phone_password=123'); 
			 }
			 //xajax_process_form_data(xajax.getFormValues('form_data'));
			 //alert('1');
			 return false;
		  }
		else
		//alert("4");
		 reason += validateEmpty(theForm.phone_number, "Please enter phone number.");			   
         if (reason != "")                   
		  {				   
             return false;
          }
		reason += validateEmpty(theForm.date, "Please enter date.");			   
         if (reason != "")                   
		  {				   
             return false;
          }  
		reason += validateEmpty(theForm.o_name, "Please enter Name.");			   
         if (reason != "")                   
		  {				   
             return false;
          }   
		reason += validateEmpty(theForm.e_mail, "Please enter E-mail.");			   
         if (reason != "")                   
		  {				   
             return false;
          } 
		reason += validateEmpty(theForm.zip_code, "Please enter Zip_Code.");			   
         if (reason != "")                   
		  {				   
             return false;
          }   
		  
		reason += validateEmpty(theForm.CarType, "Please enter car type.");			   
         if (reason != "")                   
		  {				   
             return false;
          }   
		//reason += validateEmpty(theForm.pass_name, "Please enter Passenger Name.");			   
         if (reason != "")                   
		  {				   
             return false;
          }   
		//alert("2");  
		xajax_process_form_data(xajax.getFormValues('form_data'));  
		//xajax_sendform('categoryID="2"');
		//alert('2');
		return false;
  
   
    reason += validateEmpty(theForm.username, "You didn't enter a user name.");
    if (reason != "") 
      {       
        return false;
      }
    reason += validateEmpty(theForm.password, "You didn't enter a user password.");
    if (reason != "") 
     {       
        return false;
     }  
     return false;
  }
  function validateCheckBox(fld, errText)
  {
	 var error = "";   
	 if (fld.checked == false)
	 {
		error = "You didn't enter a password.\n";  
        ShowMyBallon(fld, errText);  
	 }
	 return error;  
  }
  function validateEmpty(fld, errText) 
   {  
      //alert(fld.value); 
      if (fld == null) return "";
      var error = "";	 
      if (fld.value.length == 0) 
      {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a password.\n";  
        ShowMyBallon(fld, errText);        
      } 
        else 
       {
        fld.style.background = 'White';
       }
    return error;   
}

function getY( oElement )
          {
             var iReturnValue = 0;
              while( oElement != null ) 
           {
              iReturnValue += oElement.offsetTop;
              oElement = oElement.offsetParent;
           }
          return iReturnValue;
         }        
        function getX( oElement )
          {
             var iReturnValue = 0;
              while( oElement != null ) 
           {
              iReturnValue += oElement.offsetLeft;
              oElement = oElement.offsetParent;
           }
          return iReturnValue;
         }  
		 
function getPos(e) 
        {
            var posx = 0;
            var posy = 0;

            if (!e) var e = window.event;
            if (e.pageX || e.pageY) 	
            {
                posx = e.pageX;
                posy = e.pageY;
            }
            else if (e.clientX || e.clientY) 	
            {
                posx = e.clientX + document.body.scrollLeft
	                + document.documentElement.scrollLeft;
                posy = e.clientY + document.body.scrollTop
	                + document.documentElement.scrollTop;
	        }
        	
	        TRACE("getPos " + posx + ", " + posy);


            var pos=new Array();
            pos[0]=posx;
            pos[1]=posy;
            return pos;
        }
	        
	        
        function onBalloonClose(balloon)
        {
            alert("onBalloonClose balloon.title=" + balloon.title);
        }
    
    
        function onGetPopupHtml()
        {   
            g_lastBalloon.traceInnerHtml();
        }


        function TRACE(sText)
        {
            var txtTrace=document.getElementById("txtTrace");
            
            if (txtTrace!=null)
	            txtTrace.value = txtTrace.value + sText + "\n";
        }

        function getY( oElement )
          {
             var iReturnValue = 0;
              while( oElement != null ) 
           {
              iReturnValue += oElement.offsetTop;
              oElement = oElement.offsetParent;
           }
          return iReturnValue;
         }        
        function getX( oElement )
          {
             var iReturnValue = 0;
              while( oElement != null ) 
           {
              iReturnValue += oElement.offsetLeft;
              oElement = oElement.offsetParent;
           }
          return iReturnValue;
         }  
		 