	var thesite = "http://www.motolimo.com";
	var test = "/test";  //Set to blank for production.
  	test = "";


function doAutoQuote ( form ) {	
//******************************************************************************* 
//  AUTO QUOTE FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "";			// Default receipient 
	var nSubmitFlag = 0;  // Set to 1 if mileage over 50km
	
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n"; 
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n"; 
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"}  	
	
	if (spaceTrim(document.form0.No_of_km.value) == "") errormessage=errormessage + "No. of km.\n";
	var km = spaceTrim(document.form0.No_of_km.value);
	if (isInteger(km) == false)  errormessage=errormessage + "No. of km.\n";

//*-------------------------------------------------------------
//*  Calculate quote
//*
//*-------------------------------------------------------------
	nKm	=  parseFloat(km);
	nPrice1 = 95.00; //* Up to 10 km
	nPrice2 = 2.75;  //* 11-49 km
	nPrice3 = 2.00;  //* => 50 km  NOT USED
	nKm	=  parseFloat(km);
/*----------------------------------------	
	if (nKm > 49) {		
		nKm_diff = nKm - 10;
		nQuote = (nKm_diff * nPrice3) + nPrice1;
	}
	else if ((nKm < 50) & (nKm > 10)) {
		nKm_diff = nKm - 10;
		nQuote = (nKm_diff * nPrice2) + nPrice1;		
	}
	else {
		nQuote = nPrice1;
	}
----------------------------------------------------*/	
	sIsDiscount = "N";  //* set to 1 if discount applied.
	nQuote = 0;
	if (nKm > 10) {
		nKm_diff = nKm - 10;
		nQuote = (nKm_diff * nPrice2) + nPrice1;		
	}
	if (nKm <= 10) {
		nQuote = nPrice1;
	}
	if (nKm > 49) {	
		nQuoteX = nQuote;	
		nQuote = nQuote - (nQuoteX * .15);  //* 15% long distance discount
		sIsDiscount = "Y";
	}	
//*--------------------------------------- 	
//* Dont submit form if mileage over 50km
//*--------------------------------------- 
	if (nKm > 50) {
		errormessage=errormessage+"___________________________________\nFor mileages of over 50km., please call\nfor a more accurate quote since discounts apply.\n"
	}
		
		sDiscountMsg = "";
		if (sIsDiscount == "Y") {
			sDiscountMsg = "\n(15% discount applied)";
		}
		sQuote = "$" + formatDollar(nQuote) + " plus HST";
		
		if (test == "/test") {
			 alert("For testing only: " +  sQuote + "  " + sDiscountMsg);
		} 
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If NAME start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Name.value);		
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 
 

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		sEmailto = "nscn@sympatico.ca"; // Default recipient 	
 	  	document.form0.recipients.value = sEmailto;
 	  	document.form0.recipients.value =  "nscn@sympatico.ca"; // Default recipient 
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
	    document.form0.Quote.value = sQuote;
	    document.form0.IsDiscount.value = sIsDiscount;
		document.form0.bcc.value = "pc@twistedpixel.com"; 
					 	 	
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "QUOTE - Motorcycle Delivery ";
 
//		document.form0.good_url.value = thesite + test + "/Quotes-confirm.html";
		document.form0.good_url.value = "Quotes-confirm.html";
		
// 		document.form0.action = "quotesend.php";    //* Test from LOCALHOST
 		document.form0.action = thesite + test + "/quotesend.php";
// 		document.form0.action = thesite + "/mailer/formmail.php";  
 		
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments

	document.form0.method = "POST";
	document.form0.submit() 
	return(0); 
 }	
}

function doContact ( form ) {	
//******************************************************************************* 
//  CONTACT US FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n"; 
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"}  	
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If Comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 
 

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		sEmailto = "nscn@sympatico.ca"; // Default recipient 	
 	  	document.form0.recipients.value = sEmailto;
 	  	document.form0.recipients.value =  "nscn@sympatico.ca"; // Default recipient 
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
 
		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "Motorcycle Delivery CONTACT US";
 	
		document.form0.good_url.value = thesite + test + "/confirm.html";
 		document.form0.action = thesite + "/mailer/formmail.php";  
 		
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
 	  	document.form0.submit()
  		return(0); 	
   }  
}

function doQuote ( form ) {	
//******************************************************************************* 
//  QUOTE FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"}  	
 	if (spaceTrim(document.form0.Pickup_Address.value) == "") errormessage=errormessage + "PickupAddress\n";
 	if (spaceTrim(document.form0.Destination_Address.value) == "") errormessage=errormessage + "Destination Address\n";
// 	if (spaceTrim(document.form0.Make_and_Model.value) == "") errormessage=errormessage + "Make and Model\n";
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 
	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		sEmailto = "nscn@sympatico.ca"; // Default recipient 	
 	  	document.form0.recipients.value = sEmailto;
 	  	document.form0.recipients.value =  "nscn@sympatico.ca"; // Default recipient 
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
 
		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
 	  	document.form0.email.value = document.form0.Email.value;
	  // document.form0.subject.value = "MOTO - REQUEST QUOTE";   
	  	document.form0.subject.value = "Motorcycle Delivery QUOTE";
 	
		document.form0.good_url.value = thesite + test + "/confirm.html";
 		document.form0.action = thesite + "/mailer/formmail.php";  
 		
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
 	  	document.form0.submit()
  		return(0); 	
   }  
}

function doPickup ( form ) {	
//******************************************************************************* 
//  PICKUP FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "";			// Default receipient 
	
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"}  	
 	if (spaceTrim(document.form0.Pickup_Address.value) == "") errormessage=errormessage + "PickupAddress\n";
 	if (spaceTrim(document.form0.Destination_Address.value) == "") errormessage=errormessage + "Destination Address\n";
 	if (spaceTrim(document.form0.Make_and_Model.value) == "") errormessage=errormessage + "Make and Model\n";
 	if (spaceTrim(document.form0.Pickup_Date_Time.value) == "") errormessage=errormessage + "Pickup Date and Time\n";

 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 
	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		sEmailto = "nscn@sympatico.ca"; // Default recipient 	
 	  	document.form0.recipients.value = sEmailto;
 	  	document.form0.recipients.value =  "nscn@sympatico.ca"; // Default recipient 
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
 
		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	
 	  	document.form0.email.value = document.form0.Email.value;
	  	document.form0.subject.value = "Motorcycle Delivery PICKUP SCHEDULE";
 	
		document.form0.good_url.value = thesite + test + "/pickup-confirm.html";
 		document.form0.action = thesite + "/mailer/formmail.php";  
 		
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
 	  	document.form0.submit()
  		return(0); 	
   }  
}



function showCard() {
//*******************************************************************************
//	Display a window with image   
//*******************************************************************************
 
	var scroll="yes";
	var theDir = "Img/";
	var pic = "express-toy-transit-card.gif";
	var w = 430;
	var h = 480; 
	
	var data = '<html><head><title>Click image to close window</title><body bgcolor="#FFFFFF"  leftmargin=0 topmargin=0 marginheight="0" >';
	data += '<center>';
	data += '<a href="javascript:self.close()" onMouseOver="self.status=\'Click on image to close window.\'; return true" onMouseOut="self.status=\'\'; return true">';
	data += '<img src="' + theDir + pic + '" alt="Click on image to close window." border="0"></a></center>';
	data += '</body></html>';		
	newWindow = window.open('','newWin', "width=" + w + ",height=" + h + ",scrollbars=" + scroll + ",status=yes,menubar=1,toolbar=1;resizable=yes", "alwaysRaised");	
	newWindow.document.write(data);
	newWindow.document.close('newWin'); //* Close the data stream
	newWindow.resizeTo(w,h);			//* Resize the window for latest image 
	newWindow.focus(); 					//* Bring to front	
}

function NewWindow(mypage, myname, w, h, scroll)
{
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1, 
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}

function doClear ( form ) {	
//*******************************************************************************
// Clear Form  -  
//*******************************************************************************	
//alert(pagelang);
    var msg_e = "Are you sure that you want to clear all the data you have entered on this form?";
    var msg_f = "Voulez-vous vraiment effacer toutes les données?";
    var clearmsg = msg_e;
 // if (pagelang == "f") clearmsg = msg_f;
    
	var confirmOK = confirm(clearmsg);
  	if (confirmOK) document.form0.reset();    
} 

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function formatDollar (Val, DollarSign)  {
//*******************************************************************************
// FORMAT DOLLAR
//*******************************************************************************	
	Val=""+Val;
	if (Val.indexOf (".", 0)!=-1) {
		Dollars = Val.substring(0, Val.indexOf (".", 0));
		Cents = Val.substring(Val.indexOf (".", 0)+1, Val.indexOf (".", 0)+3);
		if (Cents.length==0) 
			Cents="00";
		if (Cents.length==1)
			Cents=Cents+"0";
	} else {
		Dollars = Val;
		Cents = "00";
	}
	OutString="";
	len=Dollars.length;
	if (len>=3) {
		while (len>0) {
			TempString=Dollars.substring(len-3, len)
			if (TempString.length==3) {
				OutString=","+TempString+OutString
				len=len-3;
			} else {
				OutString=TempString+OutString
				len=0
			}
		}
		if (OutString.substring(0, 1)==",") 
			Dollars=OutString.substring (1, OutString.length)
		else
			Dollars=OutString
	} 
	if (DollarSign)
		return ("$"+Dollars+"."+Cents);
	else
		return (Dollars+"."+Cents);
}
