function cssPreloadImages() {
	var i, j, img;
	for (i=0; i<document.styleSheets.length; i++) {
	var pos = document.styleSheets[i].href.lastIndexOf("/");
	var cssDir = (pos != -1) ? document.styleSheets[i].href.substring(0, pos + 1) : "";
	var rules = document.styleSheets[i].cssRules ? document.styleSheets[i].cssRules : document.styleSheets[i].rules;
	for (j=0; j<rules.length; j++) {
	var style = rules[j].style;
	if (style.backgroundImage.toLowerCase().substr(0,4) == "url(") {
	var filename = style.backgroundImage.substring(4, style.backgroundImage.length - 1);
	if (filename.indexOf("http://") != 0 && filename.indexOf("/") != 0)
	filename = cssDir + filename;
	var img = new Image();
	img.src = filename;
			}
		}
	}
}

if (window.attachEvent) {
	window.attachEvent("onload", cssPreloadImages);	
} else {
	window.addEventListener("load", cssPreloadImages, false);	
}


function Compute_cost(Mileage)
{
var dist = Mileage.distance.value ;
Mileage.cost.value = 5 ;
var cst = 0;
if  (dist >0) 
    {
     cst = "" + Math.round(((0.00 * dist) + 0.00) *100)/100;
     cst = "" + Math.round(( (.30*Math.floor(5*dist))+ 0.00) *100)/100;
     if(cst.lastIndexOf('.') < 0)
     {
       cst = cst + '.00';
     }
     else if (cst.length - cst.lastIndexOf('.') == 1)
     {
       cst = cst + '0';
     }
    } 
else
   {
    cst  = '0.00' ;
   }
  Mileage.cost.value = cst;
}

function CheckForm() {

			if(document.BookingForm.frm_name.value=="")
			{
				window.alert('Iontrail do thoil Ainm Teagmhala!');
				document.BookingForm.frm_name.focus();
				return false;
			}
			if(document.BookingForm.frm_address.value=="")
			{
				window.alert('Iontrail do thoil Pioc suas Iomha!');
				document.BookingForm.frm_address.focus();
				return false;
			}
			if(document.BookingForm.frm_destination.value=="")
			{
				window.alert('Iontrail do thoil Ceann Scribe!');
				document.BookingForm.frm_destination.focus();
				return false;
			}
			if(document.BookingForm.frm_datetime.value=="")
			{
				window.alert('Iontrail do thoil Data veain glacaire Agus Am!');
				document.BookingForm.frm_datetime.focus();
				return false;
			}
			if(document.BookingForm.frm_phone.value=="")
			{
				window.alert('Iontrail do thoil Uimhir ghuthain Vaild Teagmhail!');
				document.BookingForm.frm_phone.focus();
				return false;
			}
			if(document.BookingForm.frm_mail.value=="")
			{
				window.alert('Iontrail do thoil Seoladh Riomhphoist!');
				document.BookingForm.frm_mail.focus();
				return false;
			}
			if(document.BookingForm.code.value=="")
			{
				window.alert('Iontrail do thoil Cod Deimhniuchain!');
				document.BookingForm.code.focus();
				return false;
			}
                       if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.BookingForm.frm_mail.value))
			{
				return true;
			}
			
			alert("E-mail neamhbhaili Seoladh! Cuir isteach aris.");
			document.BookingForm.frm_mail.focus();
			return false;
}
function CheckQForm() {

			if(document.QuoteForm.frm_name.value=="")
			{
				window.alert('Iontrail do thoil Ainm Teagmhala!');
				document.QuoteForm.frm_name.focus();
				return false;
			}
			if(document.QuoteForm.frm_mail.value=="")
			{
				window.alert('Iontrail do thoil Seoladh Riomhphoist!');
				document.QuoteForm.frm_mail.focus();
				return false;
			}
			if(document.QuoteForm.frm_comments.value=="")
			{
				window.alert('Cuir isteach an meid mionsonrai faoi do thuras lena n-airitear phiocadh suas pointe, chinn scribe, am agus an data!');
				document.QuoteForm.frm_comments.focus();
				return false;
			}
			if(document.QuoteForm.code.value=="")
			{
				window.alert('Iontrail do thoil Cod Deimhniuchain!');
				document.QuoteForm.code.focus();
				return false;
			}
                       if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.QuoteForm.frm_mail.value))
			{
				return true;
			}
			
			alert("E-mail neamhbhaili Seoladh! Cuir isteach aris.");
			document.QuoteForm.frm_mail.focus();
			return false;
}
function CheckCForm() {

			if(document.ContactForm.frm_name.value=="")
			{
				window.alert('Iontrail do thoil Ainm Teagmhala!');
				document.ContactForm.frm_name.focus();
				return false;
			}
			if(document.ContactForm.frm_mail.value=="")
			{
				window.alert('Iontrail do thoil Seoladh Riomhphoist!');
				document.ContactForm.frm_mail.focus();
				return false;
			}
			if(document.ContactForm.frm_comments.value=="")
			{
				window.alert('Iontrail do thoil Do Thuairimi!');
				document.ContactForm.frm_comments.focus();
				return false;
			}
			if(document.ContactForm.code.value=="")
			{
				window.alert('Iontrail do thoil Cod Deimhniuchain!');
				document.ContactForm.code.focus();
				return false;
			}
                       if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.ContactForm.frm_mail.value))
			{
				return true;
			}
			
			alert("E-mail neamhbhaili Seoladh! Cuir isteach aris.");
			document.ContactForm.frm_mail.focus();
			return false;
}
