// - JavaScript Document

	var http_request = false;
	// - Main RavontAjax Function to Creat HTTP Request	
	function RavontAjax()
   	{
      http_request = false;
	  // - If Browser is Mozila or FireFox
      if ( window.XMLHttpRequest )
	  {
         http_request = new XMLHttpRequest ( ) ;
         if ( http_request.overrideMimeType )
		 {
         	http_request.overrideMimeType ('text/html') ;
         }
      }
	  else
	  	// - If Browser is Microsoft Explorer
	  	if ( window.ActiveXObject )
		{
			try
			{
				http_request = new ActiveXObject ( "Msxml2.XMLHTTP" ) ;
			}
			catch (e)
			{
				try
				{
					http_request = new ActiveXObject ( "Microsoft.XMLHTTP" ) ;
				}
				catch (e)
				{
					alert ( "Your browser do not support this feature." ) ;
					return ;
				}
			}
      }
   }
   
   // - Makeing Ajax Request 
	function checkCoupon ( )
	{
		RavontAjax ( ) ;
		if ( ! this.http_request )
			return false ;
		if ( document.getElementById ( "txtCouponCode" ).value == "" ) 
		{
			alert ( "Empty Coupon Not allowed" ) ;	
			return false ;
		}
		http_request.onreadystatechange = function ( ) 
										   {
											  if ( http_request.readyState == 4 ) 
											  {
												 if ( http_request.status == 200 ) 
												 {
													var discountPercentage = parseFloat ( http_request.responseText ) ;
													if ( discountPercentage == 0 )
													{
														document.getElementById ( "hidAmount" ).value = 67 ;
														alert ( "Ooops, your Coupon is not accepted, you have to pay US $"+document.getElementById ( "hidAmount" ).value ) ;
													}
													else
													{
														document.getElementById ( "hidAmount" ).value = discountPercentage ;
														alert ( "Coupon Accepted, Now you have to pay US $"+document.getElementById ( "hidAmount" ).value ) ;
													}
												 }
											  }
										   }
		http_request.open ( 'GET' , "coupondiscount.php?id="+document.getElementById ( "txtCouponCode" ).value , true ) ;
		http_request.send ( null ) ;
	}
	
	function saveData ( )
	{
		RavontAjax ( ) ;
		if ( ! this.http_request )
			return false ;
		http_request.onreadystatechange = function ( ) 
										   {
											  if ( http_request.readyState == 4 ) 
											  {
												 if ( http_request.status == 200 ) 
												 {
													if ( http_request.responseText == "1" )
												 		document.frmCheckOut.submit();
													else
														alert ( "Could Not complete your request. This user already exists." ) ;
												 }
											  }
										   }
		var qString = "txtFirstName="+document.getElementById("txtName").value+"&txtLastName="+document.getElementById("txtLastName").value+"&txtEmailAddress="+document.getElementById("txtEmailAddress").value+"&txtPassword="+document.getElementById("txtPassword").value+"&txtLoginName="+document.getElementById("txtLoginName").value+"&txtURL="+document.getElementById("txtURL").value+"&txtCouponCode="+document.getElementById("txtCouponCode").value;
		http_request.open ( 'GET' , "saveUser.php?"+qString , true ) ;
		http_request.send ( null ) ;
	}
