function HideThickBox(){
document.getElementById("hiddenModalContent").style.display="none";
}

function mImg(ImageMainURL, srcId){
	
	var maxWidth = 330; // Max width for the image
	var maxHeight = 240;    // Max height for the image
	var LargePhoto = document.getElementsByName('largePhoto')[0];
	//var linkLargePhoto = document.getElementsByName('magiczoom1');
	//var linkLargePhoto = document.links['magiczoom1'].href;
	
	
		
	var height = document.getElementById('BikeDetailsThumbs'+srcId).height;  // Current image height
	var width = document.getElementById('BikeDetailsThumbs'+srcId).width;
	LargePhoto.style.width = "0px";
	LargePhoto.style.height = "0px";
	
	if(width / height < 1.3 ){
		LargePhoto.style.height = maxHeight+"px";// Set new height
		LargePhoto.style.width = "";
	}
	else {
		LargePhoto.style.width = maxWidth + "px";// Set new width
		LargePhoto.style.height = "";
	}

	//document.links['magiczoom1'].href = ImageMainURL;
	//document.getElementById('magiczoom1').href = ImageMainURL;
	//LargePhoto.src = ImageMainURL;
	
	//alert(width +'\n'+LargePhoto.style.width +'\n'+ height +'\n'+LargePhoto.style.height +'\n'+ document.getElementById('magiczoom1').href);
}

var story=new Array()
story[0]='Get a low <a href="http://www.motorcyclesupermarket.com/motorcycle-insurance/">Insurance Quote!</a> from one of our partners!'
story[1]='Get a fantastic <a href="http://www.motorcyclesupermarket.com/motorcycle-finance/">Finance Quote!</a> from one of our lenders!'
story[2]='Buy quality <a href="http://www.motorcyclesupermarket.com/buy-bikes/">New and Used Motorcycles</a> from Thousands'
 
 var urlAddress = "http://www.motorcyclesupermarket.com";
 var pageName = "New and used bikes from Motorcyclesupermarket.com - for everything under the helmet!";

 function addToFavorites()
 {
  if (window.external)
  {
   window.external.AddFavorite(urlAddress,pageName)
  }
  else
  { 
   alert("Sorry! Your browser doesn't support this function.");
  }
 }
 
 function rTrim(str,toFind,toReplace) {
	 for(i=str.length-1;i>0;i++){
		if(str[i]== toFind){
			str=str.substr(0,i);
		}else{
			break;
		}
	 }
	return str;
	/*
	 if(toFind == null){
		toFind = '\s';
	 }
	 if(toReplace == null){
		toReplace ='';
	 }
	var regex = ''+ toFind +'+$';
	
 //alert('rTrim\n'+str+'\n'+toFind+'\n'+toReplace+'\n'+regex);
	return str.replace(regex,toReplace);
	*/
}

 function submitForm(){
	
	document.forms["mainsearch"].submit();
	//document.forms[0].submit();
 }
 
 function AddBikeMoreOpts()
 {
	 if(document.getElementById("MoreOptions").style.display=='none')
		 {
			document.getElementById("MoreOptions").style.display='';
		 }
	 else
		 {
			document.getElementById("MoreOptions").style.display='none';
		 }
 }
 
 
 /*
 function submitFinanceEmailFrm(){
	FinanceName = document.getElementById('financeFName').value;
	FinancePostAdd = document.getElementById('financePostAdd').value;
	FinanceEmail = document.getElementById('financeEmail').value;
	FinancePostCode = document.getElementById('financePostCode').value;
	FinanceDateOfBirth = document.getElementById('financeDOB').value;

	error = "";
	if (FinanceName == ""){
		error += "First Name should have a value\n";
	}
	if (FinancePostAdd == ""){
		error += "Postal Address should have a value\n";
	}
	if (FinanceEmail == ""){
		error += "Email should have a value\n";
	}
	if (FinancePostCode == ""){
		error += "Post Code should have a value\n";
	}
	if (FinanceDateOfBirth == ""){
		error += "Date of Birth should have a value\n";
	}
	if (error != ""){
	//document.getElementById('ErrorField').value="";
		alert(error);
		return false;
	}else{
        document.getElementById('FinanceEmailFrm').submit();
    }
	
 }
 
 
 function submitFormSubscription(){
	Name = document.getElementById('SubsName').value;
	Email = document.getElementById('SubsEmail').value;
	error = "";
	if (Name == ""){
		error += "Name should have a value\n";
	}
	if (Email == ""){
		error += "Email should have a value\n";
	}
	if (error != ""){
	document.getElementById('ErrorField').value="";
		alert(error);
		return false;
	}else{
        document.getElementById('frmSubscription').submit();
    }
	
 }*/
 
 function submitFormV(){
	Name = document.getElementById('Name').value;
	Email = document.getElementById('Email').value;
	Phone = document.getElementById('Phone').value;
	Comments = document.getElementById('Comments').value;
	error = "";
	if (Name == ""){
		error += "Name should have a value\n";
	}
	if (Email == ""){
		error += "Email should have a value\n";
	}
	if (Phone == ""){
		error += "Phone should have a value\n";
	}
	if (Comments == ""){
		error += "Comments should have a value\n";
	}
	if (error != ""){
		alert(error);
		return false;
	}else{
        document.getElementById('findRV').submit();
    }
	//return true;
 }
/* 
 function submitFormEmailDealer(){
	var Name = document.getElementById('frmName').value;
	var Email = document.getElementById('frmEmail').value;
	var Phone = document.getElementById('frmPhone').value;
	var Comments = "Comments";
	if(document.getElementById('frmComments')){
		Comments = document.getElementById('frmComments').value;
	}
	error = "";
	if (Name == ""){
		error += "Name should have a value\n";
	}
	if (Email == ""){
		error += "Email should have a value\n";
	}
	if (Phone == ""){
		error += "Phone should have a value\n";
	}
	if (Comments == ""){
		error += "Comments should have a value\n";
	}
	
	if(document.getElementById("frmPartExchange").checked == true){
		var fileUploaded = true;
		var iMultiPowUpload;
		if(document.getElementById("MultiPowUpload")){	
			iMultiPowUpload = document.getElementById("MultiPowUpload");
			var list = [];
			if(iMultiPowUpload.getFiles()){
				list = iMultiPowUpload.getFiles();
			}
			// status: Integer [read-only]		// 0 	STATUS_READY
			// 1	STATUS_INPROGRESS		// 2 	STATUS_COMPLETE
			// 3 	STATUS_CANCELLED		// 4 	STATUS_ERROR

			for(var i=0; i<list.length; i++)
			{	if(list[i].status !=2){
					fileUploaded = false;
				}
			}
		}
		if(fileUploaded ==false){
				error += "Upload Images(s) by clicking on 'Upload' Button.\n";
		}
	}
	if (error != ""){
		alert(error);
		return false;
	}else{
        document.getElementById('frmEmailDealer').submit();
    }
	//return true;
 }
 */
function submitFormEmailSeller(){
	var Name = document.getElementById('Name').value;
	var Email = document.getElementById('Email').value;
	var Phone = document.getElementById('Phone').value;
	var Comments = "";
	if(document.getElementById('Comments')){
		Comments = document.getElementById('Comments').value;
	}
	error = "";
	if (Name == ""){
		error += "Name should have a value\n";
	}
	if (Email == ""){
		error += "Email should have a value\n";
	}
	if (Phone == ""){
		error += "Phone should have a value\n";
	}
	if (Comments == ""){
		error += "Comments should have a value\n";
	}

	if (error != ""){
		alert(error);
		return false;
	}else{
        document.getElementById('findRV').action = "/emailToSellerNew.php";
        
        //alert(document.getElementById('findRV').action);
        document.getElementById('findRV').submit();
        //return false;
    }
	//return true;
 }
 
  function submitFormInv(){
	InvoiceNo = document.getElementById('InvoiceNo').value;
	Qty = document.getElementById('Qty').value;
	PriceValue = document.getElementById('PriceValue').value;
	
	error = "";
	if (InvoiceNo == ""){
		error += "Invoice No should have a value\n";
	}
	if (Qty == "" || Qty=="0" || parseInt(Qty)==0){
		error += "Quantity should have a value\n and Quantity cannot be 0(zero).";
	}
	if (PriceValue == ""||PriceValue == "0"|| parseInt(PriceValue)==0){
		error += "Price should have a value\n and Price cannot be 0(zero).";
	}
	
	if (error != ""){
		alert(error);
		return false;
	}
	//document.forms[0].submit();
	return true;
 }
 
 function submitFormFinance(theForm){


	surname = document.getElementById('surname').value;
	firstname = document.getElementById('firstname').value;
	dob = document.getElementById('dob').value;
	hometel = document.getElementById('hometel').value;
	mobiletel = document.getElementById('mobiletel').value;
	emailaddress = document.getElementById('emailaddress').value;
	
	error = "";
	if (surname == ""){
		error += "Surname should have a value\n";
	}
	if (firstname == ""){
		error += "Firstname should have a value\n";
	}
	if (dob == ""){
		error += "Date of birth should have a value\n";
	}
	if (hometel == ""){
		error += "Home Tel. should have a value\n";
	}
	if (error != ""){
		alert(error);
		return false;
	}
	theForm.submit();
	return true;
 }
 
 function submitFormWarranty(theForm){


	name = document.getElementById('name').value;
	phone = document.getElementById('phone').value;
	
	error = "";
	if (name == ""){
		error += "Name should have a value\n";
	}
	if (phone == ""){
		error += "Phone should have a value\n";
	}
	if (error != ""){
		alert(error);
		return false;
	}
	theForm.submit();
	return true;
 }
 
 function submitForm2(frmID){
	document.getElementById(frmID).submit();
 }
 function windowOpener(URL){
	window.open(URL,"window","status=1,toolbar=0,width=800,height=600,resizable=1,scrollbars=yes"); 

 }
 
 function windowDetailImages(BikeName, BikeID){
 
	URL = "../imageDetail.php?ImageURL="+document.getElementsByName('largePhoto')[0].src+"&BikeName="+BikeName+"&BikeID="+BikeID;
	window.open(URL,"window","status=1,toolbar=0,width=980,height=730,resizable=1,scrollbars=yes"); 

 }
 
 function windowOpenerSmall(URL){
	window.open(URL,"window","status=1,toolbar=0,width=450,height=370,resizable=1"); 

 }
 
 function mImage(ImageMainURL){
 //alert("")
 //alert(document.getElementById('magiczoom1').innerHTML)
	document.getElementById('largePhoto').src= ImageMainURL;
	//document.getElementById('mainBikeLink').onclick = function() {windowOpener(ImageMainURL);}
 }
 
function isInteger(s)
{
      var i;
	s = s.toString();
      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
         if (isNaN(c)) 
	   {
		alert("Given value should be a number");
		return false;
	   }
      }
      return true;
}


 function isFloat(val) {
    if (isNaN(val)) {
		alert("Given value should be a number");
          return false;
     }
     return true
}

// for bulk upload
function setDealerID(dealerID){
	document.getElementById('BikesDealerID').value= dealerID;
 }

// for bikeinvoice
function calculateInvoiceTotal(){
	
	var iQty=document.getElementById('Qty').value;
	var iMem=document.getElementById('MSMMember').value;
	var date=document.getElementById('InvoiceDate').value;
    var discount=0.00;
	if(document.getElementById('Discount')){
		if(document.getElementById('Discount').value !=''){
			discount = document.getElementById('Discount').value;
		}
	}
	
	var	theDiscount = document.getElementById('Discount');
	var theObj = document.getElementById('PriceValue');
	var thePart = document.getElementById('PartExchange');
	var theVatFree = document.getElementById('VatFree');
	var thePartDesc = document.getElementById('ExchangeDescription');

	var iVal = 0.00;

    date = date.split("-");
    
    if(date.length == 3){
        date = date[2];
    }else{
        alert("Invalid Invoice Date");
    }
	if(thePart.checked==true){
		thePartDesc.setAttribute('readOnly',false);
        thePartDesc.removeAttribute('readonly');
	}else{
		thePartDesc.setAttribute('readOnly','readOnly');
	}
	
	if("1"==iMem){
		if(thePart.checked==true){
			//iVal = '150.00';
			if(discount==0){
				discount = '48.00';
			}
			theDiscount.value=discount;
		}else{
			//iVal = '99.00';
			if(discount==0){
				discount = '31.00';
			}
			theDiscount.value=discount;			
		}		
	}else{
		//discount = '0.00';
		//theDiscount.value=discount;
	}
	/*if(thePart.checked==true)
		{	iVal = '198.00';}
		else{
			iVal = '130.00';
		}
		theObj.value = Math.round(iVal,2);
	*/
	iVal = theObj.value;
	var totalVal = iQty * iVal;
	var totalVal1 = totalVal - discount;
	var iVAT = 0;
	if(theVatFree.checked ==false){
		if (date < 2010){
			iVAT = Math.round(totalVal1*0.15*100)/100;
		}else if (date < 2011){
			iVAT = Math.round(totalVal1*0.175*100)/100;
		}else{
			iVAT = Math.round(totalVal1*0.20*100)/100;
		}
	}
	var gTotal = Math.round((totalVal1+iVAT)*100)/100;
	
	// TO Append xx.00 at the end
	iVAT = (iVAT+0.000001).toFixed(2);
	totalVal = (totalVal+0.000001).toFixed(2);
	gTotal = (gTotal+0.000001).toFixed(2);
	
	document.getElementById('Total').value= totalVal;
	document.getElementById('VAT').value= iVAT;
	document.getElementById('AmtDue').value= gTotal;
}


// for Dealer bikeinvoice
function calculateInvoiceTotal2(){

	var iQty=document.getElementById('Qty').value;
	var iMem=document.getElementById('MSMMember').value;
	var date=document.getElementById('InvoiceDate').value;
    var discount=0.00;//
	var objDiscount = document.getElementById('lblDiscount');
	var theObj = document.getElementById('lblPriceValue');
	var theObj2 = document.getElementById('lblExchangePriceValue');
	var thePart = document.getElementById('PartExchange');
	var thePartDesc = document.getElementById('ExchangeDescription');

	var iVal = 0.00;
	
    date = date.split("-");
    
    if(date.length == 3){
        date = date[2];
    }else{
        alert("Invalid Invoice Date");
    }
	if(thePart.checked==true){
		thePartDesc.setAttribute('readonly',false);
		thePartDesc.removeAttribute('readonly');
	}else{
		thePartDesc.setAttribute('readonly','readonly');
	}
	
	if("1"==iMem){
		if(thePart.checked==true)
		{
			iVal = '198.00';
			if(discount==0){
				discount = '48.00';
			}
			objDiscount.innerHTML=discount;
			//theObj.innerHTML ='99.00';
			//theObj2.innerHTML ='99.00';
			}
		else{
			iVal = '130.00';
			if(discount==0){
				discount = '31.00';
			}
			objDiscount.innerHTML=discount;
			//theObj.innerHTML ='130.00';
			//theObj2.innerHTML ='0.00';
		}
		theObj.value = iVal;
	}
	if(thePart.checked==true)
	{	iVal = '198.00';
		theObj.innerHTML ='99.00';
		theObj2.innerHTML ='99.00';

	}
	else{
		iVal = '130.00';
		theObj.innerHTML ='130.00';
		theObj2.innerHTML ='0.00';

	}
	//alert(parseFloat(iVal.toFixed(2)));
	theObj.value = iVal;


	var totalVal = iQty * iVal;
	var totalVal1 = totalVal - discount;
    if (date < 2010){
        var iVAT = Math.round(totalVal1*0.15*100)/100;
    }else if (date < 2011){
        var iVAT = Math.round(totalVal1*0.175*100)/100;
    }else{
        var iVAT = Math.round(totalVal1*0.20*100)/100;
    }
	var gTotal = Math.round((totalVal1+iVAT)*100)/100;
	
	//document.getElementById('Total').value = totalVal;
	// TO Append xx.00 at the end
	iVAT = (iVAT+0.000001).toFixed(2);
	totalVal = (totalVal+0.000001).toFixed(2);
	gTotal = (gTotal+0.000001).toFixed(2);
	
	document.getElementById('lblTotal').innerHTML = totalVal;
	//document.getElementById('VAT').value = iVAT;
	document.getElementById('lblVAT').innerHTML = iVAT;
	//document.getElementById('AmtDue').value = gTotal;
	document.getElementById('lblAmtDue').innerHTML = gTotal;
	
}

// for Dealer EDIT bikeinvoice
function calculateInvoiceTotal3(){

	var iQty=document.getElementById('Qty').value;
	var iMem=document.getElementById('MSMMember').value;
	var date=document.getElementById('InvoiceDate').value;
    var discount=0.00;//
	var objDiscount = document.getElementById('lblDiscount');
	var theObj = document.getElementById('lblPriceValue');
	var theObj2 = document.getElementById('lblExchangePriceValue');
	var thePart = document.getElementById('PartExchange');
	var thePartDesc = document.getElementById('ExchangeDescription');

	var iVal = 0.00;
	
	if(theObj.innerHTML!=""){
		iVal = theObj.innerHTML;
	}
	if(objDiscount.innerHTML!=""){
		discount = objDiscount.innerHTML;
	}
	
    date = date.split("-");
    
    if(date.length == 3){
        date = date[2];
    }else{
        alert("Invalid Invoice Date");
    }
	if(thePart.checked==true){
		thePartDesc.setAttribute('readOnly',false);
	}else{
		thePartDesc.setAttribute('readOnly','readOnly');
	}
	/*
	if("1"==iMem){
		if(thePart.checked==true)
		{
			iVal = '198.00';
			if(discount==0){
				discount = '48.00';
			}
			objDiscount.innerHTML=discount;
			//theObj.innerHTML ='99.00';
			//theObj2.innerHTML ='99.00';
			}
		else{
			iVal = '130.00';
			if(discount==0){
				discount = '31.00';
			}
			objDiscount.innerHTML=discount;
			//theObj.innerHTML ='130.00';
			//theObj2.innerHTML ='0.00';
		}
		theObj.value = iVal;
	}
	if(thePart.checked==true)
	{	iVal = '198.00';
		theObj.innerHTML ='99.00';
		theObj2.innerHTML ='99.00';

	}
	else{
		iVal = '130.00';
		theObj.innerHTML ='130.00';
		theObj2.innerHTML ='0.00';

	}*/
	//alert(parseFloat(iVal.toFixed(2)));
	theObj.value = iVal;

	if(thePart.checked==true)
	{
		iVal = iVal*2;
	}
	
	var totalVal = iQty * iVal;
	var totalVal1 = totalVal - discount;
    if (date < 2010){
        var iVAT = Math.round(totalVal1*0.15*100)/100;
    }else if (date < 2011){
        var iVAT = Math.round(totalVal1*0.175*100)/100;
    }else{
        var iVAT = Math.round(totalVal1*0.20*100)/100;
    }
	var gTotal = Math.round((totalVal1+iVAT)*100)/100;
	
	//document.getElementById('Total').value = totalVal;
	// TO Append xx.00 at the end
	iVAT = (iVAT+0.000001).toFixed(2);
	totalVal = (totalVal+0.000001).toFixed(2);
	gTotal = (gTotal+0.000001).toFixed(2);
	
	document.getElementById('lblTotal').innerHTML = totalVal;
	//document.getElementById('VAT').value = iVAT;
	document.getElementById('lblVAT').innerHTML = iVAT;
	//document.getElementById('AmtDue').value = gTotal;
	document.getElementById('lblAmtDue').innerHTML = gTotal;
	
}
// Dealer Subscription Options Change
function DisplayPaymentFrequency(theOption){

	if(theOption=="Monthly"){
		document.getElementById("tblPaymentDay").style.display = '';
	}else{
		document.getElementById("tblPaymentDay").style.display = 'none';
	}
}

// Bike Details Direct Dealer Email
function DisplayDirectDealerEmail(theOption){

	if(theOption==true){
		document.getElementById("tblDirectDealerEmail").style.display = '';
	}else{
		document.getElementById("tblDirectDealerEmail").style.display = 'none';
	}
}

/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
this.pos=0;
document.write('<div id="'+divId+'" class="'+divClass+'" style=" position: relative; overflow: hidden"><div class="innerDiv" style="text-align:right;position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="text-align:right;position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

function startIndex(content,extras){
	var dataArray = new Array("Alarm / Immobiliser", "Superb Original Condition", "Nationwide Delivery", "Good Condition", "12 Months MOT Included", "Fully Serviced Before Delivery", "Full service history", "Partial service history", "Free Insurance", "Free Helmet and Gloves Included", "FREE CBT Included", "12 Months Road Tax", "Recently Reduced", "Warranty Included", "Extended Warranty Available", "Extended Roadside Rescue and Recovery Available", "Part Exchange Welcome", "Finance Available", "0% Finance", "FREE UK Delivery", "Panniers", "Back Box", "Double Bubble Screen", "Aftermarket exhaust", "One of the Best Examples Available", "Discount on Accessories", "Discount on Clothing", "New Tyres Fitted", "New Rear Tyre Fitted", "New Front Tyre Fitted", "Custom paint", "Luggage","MotoProtect Included", "£99 UK Delivery", "Money Back Guarantee", "Low Rate Finance Available","33bph Legal");
	
    if(extras){
        var spltd = extras.split(",");
        for (i=0; i < spltd.length; i ++){
            dataArray.push(spltd[i]);
        }
    }
    
	for (i=0; i < dataArray.length; i ++){
		if (content.indexOf(dataArray[i]) > -1){
			return content.indexOf(dataArray[i]);
		}
	}	
	return -1;
}

function endIndex(content,extras){
	var dataArray = new Array("Alarm / Immobiliser", "Superb Original Condition", "Nationwide Delivery", "Good Condition", "12 Months MOT Included", "Fully Serviced Before Delivery", "Full service history", "Partial service history", "Free Insurance", "Free Helmet and Gloves Included", "FREE CBT Included", "12 Months Road Tax", "Recently Reduced", "Warranty Included", "Extended Warranty Available", "Extended Roadside Rescue and Recovery Available", "Part Exchange Welcome", "Finance Available", "0% Finance", "FREE UK Delivery", "Panniers", "Back Box", "Double Bubble Screen", "Aftermarket exhaust", "One of the Best Examples Available", "Discount on Accessories", "Discount on Clothing", "New Tyres Fitted", "New Rear Tyre Fitted", "New Front Tyre Fitted", "Custom paint", "Luggage","MotoProtect Included", "£99 UK Delivery", "Money Back Guarantee", "Low Rate Finance Available","33bph Legal");
	if(extras){
        var spltd = extras.split(",");
        for (i=0; i < spltd.length; i ++){
            dataArray.push(spltd[i]);
        } 
    }
    
	for (i=dataArray.length-1; i >= 0 ; i --){
		if (content.indexOf(dataArray[i]) > -1){
			return content.indexOf(dataArray[i]) + dataArray[i].length;
		}
	}	
	return -1;
}

function AddDesc(theValue){

   var content = document.getElementById("Comments");
   
   var theContent = content.innerHTML;
   //var theContent = content.value;

//alert(content +'\n\n\n'+content.innerHTML +'\n\n\n'+content.value);   
	
    var startI = startIndex(theContent,theValue);
	var endI = endIndex(theContent,theValue);
	
	appendStart = "";
	appendEnd = "";
	if (startI > -1){
		appendStart = theContent.substr(0, startI);
	}else{
		appendStart = theContent.substr(0, theContent.length);
	}
	if (endI > -1){
		appendEnd = theContent.substr(endI, theContent.length);
	}
	textToWrite = "";
	for (i=1;i<42;i++){
		if (document.getElementById("chk"+i)){			
			if( document.getElementById("chk"+i).checked){
				textToWrite += document.getElementById("chk"+i).getAttribute('theValue') + ", ";
			}
		}
	}
	end = textToWrite.length -2;
	textToWrite = textToWrite.substr(0, end);
	//content.value = appendStart+textToWrite+appendEnd;
	content.innerHTML = appendStart+textToWrite+appendEnd;
	
}





 
var fadeimages=new Array()
fadeimages[0]=["/images/bikeTypes/rotate-sports.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=19", ""] 
fadeimages[1]=["/images/bikeTypes/rotate-sportstourer.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=18", ""] 
fadeimages[2]=["/images/bikeTypes/rotate-touring.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=23", ""] 
fadeimages[3]=["/images/bikeTypes/rotate-dualpurpose.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=8", ""] 
fadeimages[4]=["/images/bikeTypes/rotate-trialenduro.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=1", ""] 
fadeimages[5]=["/images/bikeTypes/rotate-cruiser.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=6", ""] 
fadeimages[6]=["/images/bikeTypes/rotate-atv.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=3", ""] 
fadeimages[7]=["/images/bikeTypes/rotate-commuter.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=5", ""] 
fadeimages[8]=["/images/bikeTypes/rotate-scooter.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=16", ""] 
fadeimages[9]=["/images/bikeTypes/rotate-motocross.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=12", ""] 
fadeimages[10]=["/images/bikeTypes/rotate-naked.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=13", ""] 
fadeimages[11]=["/images/bikeTypes/rotate-moped.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=11", ""] 
fadeimages[12]=["/images/bikeTypes/rotate-supersports.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=22", ""] 
fadeimages[13]=["/images/bikeTypes/rotate-minibike.jpg", "http://www.motorcyclesupermarket.com/bikeListings/?Type=10", ""] 


var fadeimagesWinWin=new Array()
fadeimagesWinWin[0]=["/images/WinWinSituation/yamahaYZF125_blue3.jpg", "http://www.motorcyclesupermarket.com/terms.php", "_blank"] 
fadeimagesWinWin[1]=["/images/WinWinSituation/yamahaYZF125_redwhite2.jpg", "http://www.motorcyclesupermarket.com/terms.php", "_blank"] 
fadeimagesWinWin[2]=["/images/WinWinSituation/yamahaYZF125_yellow1.jpg", "http://www.motorcyclesupermarket.com/terms.php", "_blank"] 
 
 
var fadebgcolor="white"

////NO need to edit beyond here/////////////
 
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
 
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
 
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}
 
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}
 
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
 
 
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
 
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
 
 
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}


window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" 
 && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" 
 && bVer < 4);
 var blink_speed=100;
 var i=0;
 
if (NS4 || IE4) {
 if (navigator.appName == "Netscape") {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
}

//BLINKING
function Blink(layerName){
 if (NS4 || IE4) { 
 if(i%2==0)
 {
 eval(layerRef+'["'+layerName+'"]'+
 styleSwitch+'.visibility="visible"');
 }
 else
 {
 eval(layerRef+'["'+layerName+'"]'+
 styleSwitch+'.visibility="hidden"');
 }
 } 
 if(i<1)
 {
 i++;
 } 
 else
 {
 i--
 }
 setTimeout("Blink('"+layerName+"')",blink_speed);
}


function ValidateAddEdit(){
	var btnSubmit = document.getElementById("btnSubmit");
	var lblMessage = document.getElementById("lblMessage");
		btnSubmit.disabled = true;
		//lblMessage.style.display = '';
		//alert(lblMessage.style.display);
    try{
        var Make = document.getElementById("Make").value;
        var Model = document.getElementById("Model").value;
        var Mileage = document.getElementById("Mileage").value;
        }
    catch(err){
        var Make = make_sel.getSelectedValue();
        var Model = model_sel.getSelectedValue();
        var Mileage = mileageunit_sel.getSelectedValue();
    }
    
	var Price = document.getElementById("Price").value;
	
	ErrorText = "";
	if(Make == "" || Make == "-1"){/*|| Model == "" || Model == "-1"*/
		ErrorText += "Please select a Make.\n";
	}
    else if(Make == null){
        ErrorText += "Please select a Make from given options.\n";
    }
	/*if(Model == "" || Model == "-1"){
		ErrorText += "Please select a Model.\n";
	}*/
	
	if(Price == ""){
		ErrorText += "Price cannot be empty.\n";
	}
	if(Mileage == ""){
		ErrorText += "Mileage cannot be empty.\n";
	}
	
	var fileUploaded = true;
	var iMultiPowUpload;
	if(document.getElementById("MultiPowUpload")){
	
		iMultiPowUpload = document.getElementById("MultiPowUpload");
		var list = iMultiPowUpload.getFiles();
		// status: Integer [read-only]		// 0 	STATUS_READY
		// 1	STATUS_INPROGRESS		// 2 	STATUS_COMPLETE
		// 3 	STATUS_CANCELLED		// 4 	STATUS_ERROR

		for(var i=0; i<list.length; i++)
		{
			//alert("File " + list[i].name + " in list, status"+list[i].status);
			if(list[i].status !=2){
				//ErrorText += "File '"+list[i].name+"' is not Uploaded.\n";
				fileUploaded = false;
			}
		}
	}
	if(fileUploaded ==false){
			ErrorText += "Upload File(s) by clicking on 'Upload' Button.\n";
	}
	if (ErrorText != ""){
		alert(ErrorText);
		btnSubmit.disabled = false;
		return false;
	}
	lblMessage.style.display = '';
	
	return true;
}

function ValidateOfferBike(){
	
	Make = document.getElementById("Make").value;
	Model = document.getElementById("Model").value;
	Mileage = document.getElementById("Mileage").value;
	Price = document.getElementById("TradePrice").value;
	
	ErrorText = "";
	
	if(Make == "" || Make == "-1"){
		ErrorText += "Please select a Make.\n";
	}
	if(Model == "" || Model == "-1"){
		ErrorText += "Please select a Model.\n";
	}
	
	if(Price == ""){
		ErrorText += "Price cannot be empty.\n";
	}
	if(Mileage == ""){
		ErrorText += "Mileage cannot be empty.\n";
	}
	
	if (ErrorText != ""){
		alert(ErrorText);
		return false;
	}
}

function ValidateRequestBike(){
	
	Make = document.getElementById("Make").value;
	Model = document.getElementById("Model").value;
	MileageFrom = document.getElementById("MileageFrom").value;
	MileageTo = document.getElementById("MileageTo").value;
	EngineSize = document.getElementById("EngineSize").value;
	
	ErrorText = "";
	
	if(Make == "" || Make == "-1"){
		ErrorText += "Please select a Make.\n";
	}
	if(Model == "" || Model == "-1"){
		ErrorText += "Please select a Model.\n";
	}
	
	if(EngineSize == ""){
		ErrorText += "Please enter an EngineSize.\n";
	}
	if(MileageFrom == "" || MileageTo == ""){
		ErrorText += "Please enter MileageFrom and MileageTo.\n";
	}
	
	if (ErrorText != ""){
		alert(ErrorText);
		return false;
	}
}


function YearChanged(selYear){
    var radioNewUsed = document.getElementsByName("BikeCondition");
    if(selYear=="UnRegistered"){
        setCheckedValue(radioNewUsed,'New');
    }else{
        setCheckedValue(radioNewUsed,'Used');
    }
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

/* LOGIN PANEL ---- LOGIN PANEL */
	jQuery(document).ready(function() {
	
	// Expand Panel
	jQuery("#PanelOpen").click(function(){
		jQuery("div#panel").slideDown("slow");
	});	
	jQuery("#PanelOpen").attr("href", "#");
	
	// Collapse Panel
	jQuery("#PanelClose").click(function(){
		jQuery("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	jQuery("#toggle a").click(function () {
		jQuery("#toggle a").toggle();
	});		
		
});

/*DEALER LOGIN ---- DEALER LOGIN */
 jQuery(document).ready(function(){
	jQuery("#submitlogin1").click(function(){
	document.getElementById("username2").value="";
	document.getElementById("password2").value="";
	document.getElementById("rememberMe2").checked=false;
		var valid = '';
		var isr = ' is required.';
		
		var username1 = jQuery("#username1").val();
		var password1 = jQuery("#password1").val();
		//var rememberMe1 = jQuery("#rememberMe1").val();
		if (document.getElementById("rememberMe1").checked==true)
		{
		var rememberMe1 = "1";
		}
		else
		{
		var rememberMe1 = "0";
		}
		
		if (username1.length<1) {
			valid += '<br />Dealer Username'+isr;
		}
		if (password1.length<1) {
			valid += '<br />Dealer Password'+isr;
		}
		
		if (valid!='') {
			jQuery("#DealerLoginResponse").fadeIn("slow");
			jQuery("#DealerLoginResponse").html("Error:"+valid);
		}
		else {
			var datastr ='username1=' + username1 + '&password1=' + password1 + '&rememberMe1=' + rememberMe1;
			jQuery("#DealerLoginResponse").css("display", "block");
			jQuery("#DealerLoginResponse").html("Logging In .... ");
			jQuery("#DealerLoginResponse").fadeIn("slow");
			setTimeout("SendRequestDealer('"+datastr+"')",2000);
		}
		return false;
	});
});
function SendRequestDealer(datastr){
	jQuery.ajax({	
		type: "POST",
		url: "/doLogin.php",
		data: datastr,
		cache: false,
		success: function(html){
		jQuery("#DealerLoginResponse").fadeIn("slow");
		jQuery("#DealerLoginResponse").html(html);

		if(html=="Login Successful")
{
window.location = "/Dealer/"; 
}

	} 
	});
}

/*MEMBER LOGIN ---- MEMBER LOGIN */
 jQuery(document).ready(function(){
	jQuery("#submitlogin2").click(function(){
	document.getElementById("username1").value="";
	document.getElementById("password1").value="";
	document.getElementById("rememberMe1").checked=false;
		var valid = '';
		var isr = ' is required.';
		
		var username2 = jQuery("#username2").val();
		var password2 = jQuery("#password2").val();
		//var rememberMe2 = jQuery("#rememberMe2").val();
		if (document.getElementById("rememberMe2").checked==true)
		{
		var rememberMe2 = "1";
		}
		else
		{
		var rememberMe2 = "0";
		}
		
		if (username2.length<1) {
			valid += '<br />Member Username'+isr;
		}
		if (password2.length<1) {
			valid += '<br />Member Password'+isr;
		}
		
		if (valid!='') {
			jQuery("#MemberLoginResponse").fadeIn("slow");
			jQuery("#MemberLoginResponse").html("Error:"+valid);
		}
		else {
			var datastr ='username2=' + username2 + '&password2=' + password2 + '&rememberMe2=' + rememberMe2;
			jQuery("#MemberLoginResponse").css("display", "block");
			jQuery("#MemberLoginResponse").html("Logging In .... ");
			jQuery("#MemberLoginResponse").fadeIn("slow");
			setTimeout("SendRequestMember('"+datastr+"')",2000);
		}
		return false;
	});
});
function SendRequestMember(datastr){
	jQuery.ajax({	
		type: "POST",
		url: "/doLogin.php",
		data: datastr,
		cache: false,
		success: function(html){
		jQuery("#MemberLoginResponse").fadeIn("slow");
		jQuery("#MemberLoginResponse").html(html);

		if(html=="Login Successful")
{
window.location = "/Seller/"; 
}

	} 
	});
}

