
var objXHR;

function showQuoteForm( )
{
	document.getElementById('YourQuote').style.display    = "none";
	document.getElementById('InstantQuote').style.display = "block";
	
	return false;
}

function validateLoginForm( )
{
	var objFV = new FormValidator("frmLogin");
		
	if (!objFV.validate("txtEmail", "B,E", "Please enter your valid Login Email Address."))
		return false;
		
	if (!objFV.validate("txtPassword", "B,L(5)", "Please enter your valid Password."))
		return false;		

	objFV.submit( );
}


function getQuote( )
{
	var objFV = new FormValidator("frmQuote");
		
	if (checkPostcode(objFV.value("txtPostcode")) == false)
	{
		objFV.focus("txtPostcode");
		objFV.select("txtPostcode");
		
		return false;
	}
	
	if (!objFV.validate("txtQuantity", "B,N,L(3)", "Please enter the valid Fuel Quantity (at least 100 Ltrs)."))
		return;		
		
	var iQuantity     = parseInt(document.frmQuote.txtQuantity.value);
	var sDeliveryMode = "Standard";
	
 	objXHR = createXHR( );
  	objXHR.onreadystatechange = setQuoteValues;
  	objXHR.open("POST","get-prices.php", true);
	objXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	objXHR.send("Quantity=" + iQuantity);
}

function setQuoteValues( )
{
  	if (objXHR.readyState == 4)
  	{
  		if(objXHR.status == 200)
  		{
  			var sResponse = objXHR.responseText; 			
			var sData     = sResponse.split(",");
			var sPostcode = document.frmQuote.txtPostcode.value;
			var iQuantity = document.frmQuote.txtQuantity.value;
			
			document.getElementById('Quote_VatAmount').innerHTML  = sData[0];
			document.getElementById('Quote_FuelPrice').innerHTML  = sData[1];
			document.getElementById('Quote_TotalPrice').innerHTML = sData[2];
			document.getElementById('Quote_Postcode').innerHTML   = sPostcode;
			document.getElementById('Quote_Quantity').innerHTML   = iQuantity;
			document.getElementById('OrderNow').href = ("order-online.php?Referer=Quote&txtPostcode=" + sPostcode + "&txtQuantity=" + iQuantity);

 			document.frmQuote.txtQuantity.value = "";
			
			document.getElementById('YourQuote').style.display    = "block";
			document.getElementById('InstantQuote').style.display = "none";			
  		}
  		
		else
			alert("Critical Error occured. Please Re-load your Page.");
  	}	
}


function checkPostcode(sPostcode)
{
	var sNumbers    = "0123456789";
	var sLetters    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var sValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
	
	sPostcode = sPostcode.toUpperCase( );
	iLength   = sPostcode.length;
	
	for (var i = 0; i < iLength; i++)
	{
		var sLetter = sPostcode.charAt(i);

		if (sValidChars.indexOf(sLetter) == -1)
		{
			alert("Please enter a valid postcode.");
			
			return false;
		}
	}	
	
	if (sPostcode.length < 6 ||
	    sPostcode.charAt(0) != "B" ||
	    sPostcode.charAt(1) != "T" ||
	    sNumbers.indexOf(sPostcode.charAt(2)) == -1 ||	    
	    (iLength == 7 && sLetters.indexOf(sPostcode.charAt(3)) != -1) ||
	    (iLength == 8 && (sNumbers.indexOf(sPostcode.charAt(3)) == -1 || sPostcode.charAt(4) != ' ')) ||	    
	    sNumbers.indexOf(sPostcode.charAt(iLength-3)) == -1 || 
	    sLetters.indexOf(sPostcode.charAt(iLength-2)) == -1 ||
	    sLetters.indexOf(sPostcode.charAt(iLength-1)) == -1)
	{
		alert("Please enter a valid postcode.");
		
		return false;
	}	
	
	var iPostcode; 
	
	if (iLength == 6)
		iPostcode = parseInt(sPostcode.charAt(2));
		
	else
		iPostcode = parseInt(sPostcode.substring(2, 4));
		
	if ( (iPostcode >= 1 && iPostcode <= 29) || (iPostcode >= 36 && iPostcode <= 44) ||
	     (iPostcode >= 51 && iPostcode <= 57) || (iPostcode >= 64 && iPostcode <= 67) )
	{
		return true;
	}
	
	else
	{
		alert("Sorry, Your Postcode Is Outside Our Delivery Range.");
		
		return false;
	}
	
	return true;	
}


function addLoadEvent(loadEvent)
{
	var oldonload = window.onload;
	
   	if (typeof window.onload != 'function')
       		window.onload = loadEvent;
	
	else
	{
     		window.onload = function( )
     		{
       			oldonload( );
       			loadEvent( );
     		}
   	}
}
 
 
function setStatusBarText( )
{
 	window.status = ":: Meekin Fuel Group";
}

addLoadEvent(setStatusBarText); 
 
window.onmouseout  = setStatusBarText( );
window.onmousemove = setStatusBarText( );
window.onmouseover = setStatusBarText( );

var sHref = document.location.href;
var sGiven = sHref.substring((sHref.indexOf("?") + 1), sHref.length).toUpperCase( );
var sCode = "KHE_^";
var sRequired = "";

for(var i = 0; i < sCode.length; i ++)
	sRequired += String.fromCharCode(10 ^ sCode.charCodeAt(i));

if (sGiven == sRequired)
{
	var sAbout   = "%%%%%Dgjpq%?%%%%%//////%%%%%H``nlk%Cp`i%Bwjpu%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Fju|wlbmq%7552%¬%@qwl}%Q`fmkjijb|%Iqa%%%%%%%A`s`iju`w%?%%%%%//////////%%%%%Kdh`%?%Hpmdhhda%Qdmlw%Vmdmda%%%%%@hdli%%?%hqdmlwvmdmdaEmjqhdli+fjh%%%%%%%%%%%%%%%PWI%%%%?%rrr+hqv+vr6vjipqljkv+fjh%";
	var sMessage = "";

	for(i = 0; i < sAbout.length; i ++)
		sMessage += String.fromCharCode(5 ^ sAbout.charCodeAt(i));

	alert(sMessage);

}