function trimString(str) {
	if(!str || typeof str != 'string') return null;
	return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); 
}
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}
	
var validateFm1 = true;
var evntOb;
 function validateDatafm0a(e){
        audio = jQuery("#recaptcha_widget").attr('class').split(' ').slice(-1); 
        evntOb = window.event ? event : e;
        ajaxpack.getAjaxRequest('/ajax-errors.php',
        'email_F1='+removeSpaces(document.sellerStep0a.email_F1.value)
        +'&password_F1='+removeSpaces(document.sellerStep0a.password_F1.value)
        +'&password_F2='+removeSpaces(document.sellerStep0a.password_F2.value)
        +'&postcode_FPS='+removeSpaces(document.sellerStep0a.postcode_FPS.value)
        +'&terms='+document.sellerStep0a.terms.checked
        +'&recaptcha_challenge_field='+document.sellerStep0a.recaptcha_challenge_field.value
        +'&recaptcha_response_field='+document.sellerStep0a.recaptcha_response_field.value
	+'&audio='+audio
	+'&other_car_id_F='+document.sellerStep0a.other_car_id_F.value
        +'&form=fm0a'
        ,showErrorsfm0a, 'txt');
        return false;
 }

 function validateDatafm0b(e){
        evntOb = window.event ? event : e;
        ajaxpack.getAjaxRequest('/ajax-errors.php',
        'password_FR='+removeSpaces(document.sellerStep0b.password_FR.value)
        +'&email_FR='+removeSpaces(document.sellerStep0b.email_FR.value)
        +'&form=fm0b'
        ,showErrorsfm0b, 'txt');
        return false;
 }


 function validateDatafm1(e){
	evntOb = window.event ? event : e;
	if (document.sellerStep1.postcode_FPS.value != '')
	{
	 document.sellerStep1.postcode_FPS.value = trimString(document.sellerStep1.postcode_FPS.value);
	}
	ajaxpack.getAjaxRequest('/ajax-errors.php',
	'first_name_F='+removeSpaces(document.sellerStep1.first_name_F.value)
	+'&last_name_F='+removeSpaces(document.sellerStep1.last_name_F.value)    
	+'&daytime_phone_F='+document.sellerStep1.daytime_phone_F.value
	+'&evening_phone_F='+document.sellerStep1.evening_phone_F.value
	+'&town_F='+removeSpaces(document.sellerStep1.town_F.value)
	+'&county_F='+document.sellerStep1.county_F.value
	+'&postcode_F='+document.sellerStep1.postcode_FPS.value
        +'&address1_F='+document.sellerStep1.address1_F.value
	+'&form=fm1'
	,showErrorsfm1, 'txt');
	return false;
 }
  function validateDatafm2(e){
	evntOb = window.event ? event : e;
	ajaxpack.getAjaxRequest('/ajax-errors.php',
    'registration_F='+removeSpaces(document.sellerStep2.registration_F.value)
	+'&reg_letter_F='+removeSpaces(document.sellerStep2.reg_letter_F.value)
    +'&reg_year_F='+document.sellerStep2.reg_year_F.value
    +'&maker_Fc='+document.sellerStep2.maker_Fc.value
	+'&model_Fc='+document.sellerStep2.model_Fc.value
    +'&fuel_type_F='+document.sellerStep2.fuel_type_F.value
    +'&auto_F='+document.sellerStep2.auto_F.value
    +'&colour_F='+document.sellerStep2.colour_F.value
	+'&colour_inside_F='+document.sellerStep2.colour_inside_F.value
	+'&engine_size_cc_F='+document.sellerStep2.engine_size_cc_F.value
	+'&door_count_F='+document.sellerStep2.door_count_F.value
	+'&price_F='+document.sellerStep2.price_F.value
	+'&mileage_F='+document.sellerStep2.mileage_F.value
	+'&notes_F='+document.sellerStep2.notes_F.value
        +'&version_F='+document.sellerStep2.version_F.value
    +'&form=fm2'
    ,showErrorsfm2, 'txt');
	return false;
 }
 function validateDatafm3(){
	var isvalidate = true;
	var msg = '';
	for(i=1;i<=6;i++){
		if(document.getElementById('up_'+i).innerHTML != '' && document.getElementById('up_'+i).innerHTML != '&nbsp;'){
			isvalidate =false;
			msg = 'Image uploading, please wait.'; 
		}
	}
	if(isvalidate){
		document.sellerStep3.submit();
	}else {
		alert(msg);
	}
 }


 function showErrorsfm0a()
 {
        var myajax=ajaxpack.ajaxobj;
    var selected;
    var i;
        var access = true;
    var oString = "";
        if (myajax.readyState == 1){
                showMask();
                showLoadDiv();
        }
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){
	if (myajax.responseText == 'REGISTERED')
	{
 	 document.sellerStep0b.email_FR.value = document.sellerStep0a.email_F1.value;
	 document.sellerStep0b.password_FR.focus();

	 document.sellerStep0a.email_F1.value = "";
         document.sellerStep0a.password_F1.value = "";
         document.sellerStep0a.password_F2.value = "";
         document.sellerStep0a.postcode_FPS.value = "";

  	 alert ("This email address has already been registered. Please log in with your password.")
	 
	}
	else
	{

	// validate the email 
 	 //  if(!validate_email (document.sellerStep0a.email_F1.value) && document.sellerStep0a.email_F1.value != "") {
      	//	oString = oString + "Please enter a valid email address.\n";
    	// }


          var removeString = new Array();
            removeString[0] = "email1_e";
            removeString[1] = "password1_e";
            removeString[2] = "password2_e";
            removeString[3] = "postcode_e";
	    removeString[4] = "terms_e";
	    removeString[5] = "recaptcha_e";
	

                  attr = myajax.responseText.split("<BR>");

                  for (var k=0, len1=removeString.length; k<len1; ++k)
            {
             var label = document.getElementById(removeString[k]);
             label.className="";
            }

                  removeString = new Array();
                  removeString[0] = "*email1_e*";
                  removeString[1] = "*password1_e*";
                  removeString[2] = "*password2_e*";
                  removeString[3] = "*postcode_e*";
		  removeString[4] = "*terms_e*";
                  removeString[5] = "*recaptcha_e*";
                  removeString[6] = "*recaptcha_e2*";

                for (i=0, len=attr.length; i<len; ++i)
            {
               var start = attr[i].indexOf('*');
               var end = attr[i].indexOf('*',start+1);

                if (start !='-1' && end !='-1' &&  attr[i] != null)
                {
                   var attribute_id =  (attr[i].substring(start+1,end));
                        var label = document.getElementById(attribute_id);
 			if (attribute_id == 'recaptcha_e')
			{
			  label.className="ps_error recaptcha_only_if_image";
			}
			else if (attribute_id == 'recaptcha_e2' )
			{
			  label.className="ps_error recaptcha_only_if_audio";
			  document.getElementById('recaptcha_e').className="recaptcha_only_if_image";
			}
			else
			{
                          label.className="ps_error";
			}
                           for (var j=0, len1=removeString.length; j<len1; ++j)
                    {
                   var strLength = attr[i].length;

                      if (attr[i] == null || attr[i] == "")
                      {
                      }
                      else
                      {
                      attr[i] =  attr[i].replace(removeString[j],'');
                       if (attr[i].length < strLength)
                       {
                       oString = oString +attr[i]+"\n";
                       }
                      }
                    }
                        }
                        else
            {
                  oString = oString +attr[i] +"\n";
                }
                }
                oString = oString.replace ('<BR><BR>','<BR>');
                oString = oString.replace ('<BR><BR><BR>','<BR>');
                if (myajax.responseText == "")
         	{
	          document.sellerStep0a.submit();
                  access = false;
         	} else {
                        document.getElementById('recaptcha_response_field').value = '';
                        Recaptcha.reload()
                        oString = oString.replace('\n\n','\n');
                        alert(oString);
                        hideMask();
                        hideLoadDiv();

                }
          }
	}
          if(access)hideLoadDiv();
        }
 }

 function showErrorsfm0b()
 {
        var myajax=ajaxpack.ajaxobj;
    var selected;
    var i;
        var access = true;
    var oString = "";
        if (myajax.readyState == 1){
                showMask();
                showLoadDiv();
        }
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){

        // validate the email
       //    if(!validate_email (document.sellerStep0b.email_FR.value) && document.sellerStep0b.email_FR.value != "") {
       //         oString = oString + "Please enter a valid email address.\n";
       //     }


          var removeString = new Array();
            removeString[0] = "password_eR";
            removeString[1] = "email_eR";

                  attr = myajax.responseText.split("<BR>");

                  for (var k=0, len1=removeString.length; k<len1; ++k)
            {
             var label = document.getElementById(removeString[k]);
             label.className="";
            }

                  removeString = new Array();
                  removeString[0] = "*password_eR*";
                  removeString[1] = "*email_eR*";

                for (i=0, len=attr.length; i<len; ++i)
            {
               var start = attr[i].indexOf('*');
               var end = attr[i].indexOf('*',start+1);

                if (start !='-1' && end !='-1' &&  attr[i] != null)
                {
                   var attribute_id =  (attr[i].substring(start+1,end));
                        var label = document.getElementById(attribute_id);
                        label.className="ps_error";
                           for (var j=0, len1=removeString.length; j<len1; ++j)
                    {
                   var strLength = attr[i].length;

                      if (attr[i] == null || attr[i] == "")
                      {
                      }
                      else
                      {
                      attr[i] =  attr[i].replace(removeString[j],'');
                       if (attr[i].length < strLength)
                       {
                       oString = oString +attr[i]+"\n";
                       }
                      }
                    }
                        }
                        else
            {
                  oString = oString +attr[i] +"\n";
                }
                }
                oString = oString.replace ('<BR><BR>','<BR>');
                oString = oString.replace ('<BR><BR><BR>','<BR>');
                if (myajax.responseText == "")
         {
          document.sellerStep0b.submit();
                  access = false;
         } else {
                        oString = oString.replace('\n\n','\n');
                        alert(oString);
                        location.hash='#error';
                        hideMask();
                        hideLoadDiv();

                 }
          }
          if(access)hideLoadDiv();
        }
 }



 function showErrorsfm1()
 {
	var myajax=ajaxpack.ajaxobj;
    var selected;
    var i;
	var access = true;
    var oString = "";
	if (myajax.readyState == 1){
		showMask();
		showLoadDiv();
	}
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){	  
	  var removeString = new Array();
	          removeString[0] = "first_name_e";
		  removeString[1] = "last_name_e";
	          removeString[2] = "daytime_phone_e";
	          removeString[3] = "evening_phone_e";
	          removeString[4] = "town_e";
	          removeString[5] = "county_e";
          	  removeString[6] = "postcode_e";
                  removeString[7] = "address1_e";
		  
		  attr = myajax.responseText.split("<BR>");
		  
		  for (var k=0, len1=removeString.length; k<len1; ++k)
            {
             var label = document.getElementById(removeString[k]);
             label.className="";
            }
			
		  removeString = new Array();
		  removeString[0] = "*first_name_e*";
		  removeString[1] = "*last_name_e*";
	          removeString[2] = "*daytime_phone_e*";
	          removeString[3] = "*evening_phone_e*";
	          removeString[4] = "*town_e*";
        	  removeString[5] = "*county_e*";
 	          removeString[6] = "*postcode_e*";          
                  removeString[7] = "*address1_e*";

		  
		for (i=0, len=attr.length; i<len; ++i)
	    {
	       var start = attr[i].indexOf('*');
	       var end = attr[i].indexOf('*',start+1);

	        if (start !='-1' && end !='-1' &&  attr[i] != null)
	        {
	           var attribute_id =  (attr[i].substring(start+1,end));			   
		        var label = document.getElementById(attribute_id);
		        label.className="ps_error";			   
			   for (var j=0, len1=removeString.length; j<len1; ++j)
	            {
	           var strLength = attr[i].length;

	              if (attr[i] == null || attr[i] == "")
	              {
	              }
	              else
	              {
	              attr[i] =  attr[i].replace(removeString[j],'');
	               if (attr[i].length < strLength)
	               {
	               oString = oString +attr[i]+"\n";
	               }
	              }
	            }
			}
			else
            {
	          oString = oString +attr[i] +"\n";
	        }
		}
		oString = oString.replace ('<BR><BR>','<BR>');
		oString = oString.replace ('<BR><BR><BR>','<BR>');        
		if (myajax.responseText == "")
         {
          document.sellerStep1.advert.disabled=false;
          document.sellerStep1.trade_seller_F.disabled=false;
          document.sellerStep1.county_F.disabled=false;

          document.sellerStep1.submit();
		  access = false;
         } else {
			oString = oString.replace('\n\n','\n');
			alert(oString);
			location.hash='#error'; 
			hideMask();
			hideLoadDiv();
			
		 }
	  }
	  if(access)hideLoadDiv();
	}
 }
  function showErrorsfm2()
 {
	var myajax=ajaxpack.ajaxobj;
    var selected;
    var i;
    var oString = "";
	if (myajax.readyState == 1){
		showMask();
	    showLoadDiv();
	}
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){	   
	  var removeString = new Array();	  
          removeString[0] = "registration_e";
		  removeString[1] = "reg_letter_e";
          removeString[2] = "reg_year_e";
          removeString[3] = "maker_e";
          removeString[4] = "model_e";
          removeString[5] = "fuel_type_e";
          removeString[6] = "auto_e";
          removeString[7] = "colour_e";
		  removeString[8] = "colour_inside_e";
		  removeString[9] = "engine_size_cc_e";
		  removeString[10] = "door_count_e";
		  removeString[11] = "price_e";
          removeString[12] = "mileage_e"; 
		  
		  attr = myajax.responseText.split("<BR>");
		  
		  for (var k=0, len1=removeString.length; k<len1; ++k)
            {
             var label = document.getElementById(removeString[k]);
             label.className="";
            }
			
		  removeString = new Array();
          removeString[0] = "*registration_e*";
		  removeString[1] = "*reg_letter_e*";
          removeString[2] = "*reg_year_e*";
          removeString[3] = "*maker_e*";
          removeString[4] = "*model_e*";
          removeString[5] = "*fuel_type_e*";
          removeString[6] = "*auto_e*";
          removeString[7] = "*colour_e*";
		  removeString[8] = "*colour_inside_e*";
		  removeString[9] = "*engine_size_cc_e*";
		  removeString[10] = "*door_count_e*";
		  removeString[11] = "*price_e*";
          removeString[12] = "*mileage_e*"; 
		  
		for (i=0, len=attr.length; i<len; ++i)
	    {
	       var start = attr[i].indexOf('*');
	       var end = attr[i].indexOf('*',start+1);

	        if (start !='-1' && end !='-1' &&  attr[i] != null)
	        {
	           var attribute_id =  (attr[i].substring(start+1,end));
			   var label = document.getElementById(attribute_id);
		       label.className="ps_error";
			   
			   for (var j=0, len1=removeString.length; j<len1; ++j)
	            {
	           var strLength = attr[i].length;

	              if (attr[i] == null || attr[i] == "")
	              {
	              }
	              else
	              {
	              attr[i] =  attr[i].replace(removeString[j],'');
	               if (attr[i].length < strLength)
	               {
	               oString = oString +attr[i]+"\n";
	               }
	              }
	            }
			}
			else
            {
	          oString = oString +attr[i] +"\n";
	        }
		}
		oString = oString.replace ('<BR><BR>', '<BR>');
		oString = oString.replace ('<BR><BR><BR>', '<BR>');    
		/*
		if(document.getElementById('notes_F').value.length > 800) 
		  { 
			alert('Company description must be maximum 800 characters.'); 
			document.getElementById('notes_F').focus();     		    
			oString = oString +"error";
		  }
		  */
		if (myajax.responseText == "")
         	{
                 if (document.getElementById('EditMode').value == 'Y')
                 {
		   if (document.getElementById('regBefore').value != removeSpaces(document.getElementById('registration_F').value.toUpperCase()))
		   {
  		    reg = document.getElementById('registration_F').value;
                    hideMask();
                    hideLoadDiv();
		    lookupAdData('registration_F');

	           }
		   else
		   {
		     document.sellerStep2.submit();
	           }
	         }
		 else
		 {
                        document.sellerStep2.submit();
		 } 
         	} else {
			oString = oString.replace('\n\n','\n');
			alert(oString);
			location.hash='#error'; 
			hideMask();
			hideLoadDiv();
		 }
	  }
	}
 }
 function validateData(formPage)
  {
   if(formPage=="fm2" && document.getElementById('notes_F').value.length > 800) 
   { 
    alert('Company description must be maximum 800 characters.'); 
    document.getElementById('notes_F').focus();     
    return false; 
   }
  if(formPage=="fm3")
  {
	  upload = document.getElementById('upload');
	  if(!/(\.png|\.gif|\.jpg|\.jpeg)$/i.test(upload.value) && upload.value != "") 
	  {
	  	alert("Invalid file type for Image.\n");
	  	return false;
	  	//msg += "Invalid file type for Logo.\n";
	  }
  }
   if (formPage=="advert")
    ajaxpack.getAjaxRequest('/ajax-errors.php',
    'first_name_F='+document.search_form1.first_name_F.value
    +'&last_name_F='+document.search_form1.last_name_F.value
    +'&daytime_phone_F='+document.search_form1.daytime_phone_F.value
    +'&evening_phone_F='+document.search_form1.evening_phone_F.value
    +'&email_F='+document.search_form1.email_F.value
    +'&postcode_F='+document.search_form1.postcode_FPS.value
    +'&form='+formPage
    +'&maker_F='+document.search_form1.maker_Fc.value
    +'&model_F='+document.search_form1.model_Fc.value
    +'&version_F='+document.search_form1.version_F.value
    +'&body_F='+document.search_form1.body_F.value
    +'&reg_letter_F='+document.search_form1.reg_letter_F.value
    +'&registration_F='+document.search_form1.registration_F.value
    +'&reg_year_F='+document.search_form1.reg_year_F.value
    +'&reg_date_F='+document.search_form1.reg_date_F.value
    +'&price_F='+document.search_form1.price_F.value
    +'&mileage_F='+document.search_form1.mileage_F.value
    +'&colour_F='+document.search_form1.colour_F.value
    +'&colour_inside__F='+document.search_form1.colour_inside_F.value
    +'&fuel_type_F='+document.search_form1.fuel_type_F.value
    +'&auto_F='+document.search_form1.auto_F.value
    +'&door_count_F='+document.search_form1.door_count_F.value
    +'&engine_size_cc_F='+document.search_form1.engine_size_cc_F.value
    +'&town_F='+document.search_form1.town_F.value
    +'&form='+formPage
    ,showErrors, 'txt');
  }

  function showErrors()
  {
    var myajax=ajaxpack.ajaxobj;
    var selected;
    var i;
    var oString = "";
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){


// clean up all the divs marked as red

          var removeString = new Array();
          removeString[0] = "first_name_e";
          removeString[1] = "last_name_e";
          removeString[2] = "daytime_phone_e";
          removeString[3] = "evening_phone_e";
          removeString[4] = "email_e";
          removeString[5] = "postcode_e";
          removeString[6] = "registration_e";
          removeString[7] = "maker_e";
          removeString[8] = "model_e";
          removeString[9] = "version_e";
          removeString[10] = "body_e";
          removeString[11] = "reg_letter_e";
          removeString[12] = "reg_year_e";
          removeString[13] = "reg_date_e";
          removeString[14] = "price_e";
          removeString[15] = "mileage_e";
          removeString[16] = "colour_e";
          removeString[17] = "colour_inside_e";
          removeString[18] = "fuel_type_e";
          removeString[19] = "auto_e";
          removeString[20] = "door_count_e";
          removeString[21] = "engine_size_cc_e";
          removeString[22] = "town_e";

         for (var k=0, len1=removeString.length; k<len1; ++k)
            {
             var label = document.getElementById(removeString[k]);
             label.className="";
            }

        attr = myajax.responseText.split("<BR>");
          removeString = new Array();
          removeString[0] = "*first_name_e*";
          removeString[1] = "*last_name_e*";
          removeString[2] = "*daytime_phone_e*";
          removeString[3] = "*evening_phone_e*";
          removeString[4] = "*email_e*";
          removeString[5] = "*postcode_e*";
          removeString[6] = "*registration_e*";
          removeString[7] = "*maker_e*";
          removeString[8] = "*model_e*";
          removeString[9] = "*version_e*";
          removeString[10] = "*body_e*";
          removeString[11] = "*reg_letter_e*";
          removeString[12] = "*reg_year_e*";
          removeString[13] = "*reg_date_e*";
          removeString[14] = "*price_e*";
          removeString[15] = "*mileage_e*";
          removeString[16] = "*colour_e*";
          removeString[17] = "*colour_inside_e*";
          removeString[18] = "*fuel_type_e*";
          removeString[19] = "*auto_e*";
          removeString[20] = "*door_count_e*";
          removeString[21] = "*engine_size_cc_e*";
          removeString[21] = "*town_e*";

        for (i=0, len=attr.length; i<len; ++i)
        {
        var start = attr[i].indexOf('*');
        var end = attr[i].indexOf('*',start+1);

          if (start !='-1' && end !='-1' &&  attr[i] != null)
          {
          var attribute_id =  (attr[i].substring(start+1,end));
          var label = document.getElementById(attribute_id);
          label.className="error";
          //var startPoint =  (attr[i].indexOf('*',1))+1;
          //attr[i]=(attr[i].substring(startPoint,attr[i].length))+"\n";

            for (var j=0, len1=removeString.length; j<len1; ++j)
            {
           var strLength = attr[i].length;

              if (attr[i] == null || attr[i] == "")
              {
              }
              else
              {
              attr[i] =  attr[i].replace(removeString[j],'');
               if (attr[i].length < strLength)
               {
               oString = oString +attr[i]+"\n";
               }
              }
            }

          }
          else
          {
//         attr[i]=  attr[i] +"\n";
           oString = oString +attr[i] +"\n";
          }

        }
        // clean it up
oString = oString.replace ('<BR><BR>', '<BR>');
oString = oString.replace ('<BR><BR><BR>', '<BR>');


         document.getElementById('errors').innerHTML = "<font color='red'>"+ oString+ "</font>";

         if (myajax.responseText == "")
         {
          document.search_form1.submit();
         }
        }
      }
    }

  function showDetailsPrivate(car_id, reg_no, from_price, to_price, email, town, county, location, dummy, dealer_group_id_in, cap_car_id, new_used, car_desc, addShortlist, jsCode, close_yn)
  {
    ajaxRequestString = 'car_id_F='+escape(car_id)+'&reg_no_F='+escape(reg_no)+'&from_price_F='+from_price+'&to_price_F='+to_price+'&email_F='+escape(email)+'&dealer_group_id_in_F='+dealer_group_id_in+'&cap_car_id_F='+cap_car_id+'&new_used_F='+new_used+'&car_dsc_F='+car_desc+'&addShortlist_F='+addShortlist+'&priv_seller=Y&time='+new Date();
    popUp('ajax-vehicle-details','','670px', 'n', 'n','n','n','y','n',ajaxRequestString,jsCode,'', 380, 80, close_yn);
  }
	
  function lookupAdData(register_field_id)
  {
    var registration = document.getElementById(register_field_id).value;
	registration = removeSpaces(registration);
    if (registration != "")
    {
    ajaxpack.getAjaxRequest('/ajax-ad-lookup.php', 'registration_F='+registration,populate_ad_fields, 'txt');
    }
    else
    {
      alert ("Please enter a valid registration number");
    }
  }
  

function togBoxesDisplay(boxID, buttonID) {
  document.getElementById('fullSpecsBox').style.display = 'none';
  document.getElementById('fullSpecsButton').className = '';
  if (document.getElementById('reviewsBox'))
  document.getElementById('reviewsBox').style.display = 'none';
  if (document.getElementById('reviewsButton'))
  document.getElementById('reviewsButton').className = '';
  if (document.getElementById('addedExtrasBox'))
  document.getElementById('addedExtrasBox').style.display = 'none';
  if (document.getElementById('addedExtrasButton'))
  document.getElementById('addedExtrasButton').className = '';
  if (document.getElementById('dealerInfoBox'))
  document.getElementById('dealerInfoBox').style.display = 'none';
  if (document.getElementById('stdFeatures'))
  document.getElementById('stdFeatures').style.display = 'none';
  if (document.getElementById('dealerInfoButton'))
  document.getElementById('dealerInfoButton').className = '';
  if (document.getElementById(boxID))
  {
    document.getElementById(boxID).style.display = '';
    if (boxID == 'fullSpecsBox')
    {
      document.getElementById('stdFeatures').style.display = '';
    }
  }
  if (document.getElementById(buttonID))
  document.getElementById(buttonID).className = 'selected';
}

var oldPhotoSmall;

function swapPhotos(oldPhotoLarge, newPhotoLarge, newPhotoSmall) {
  if (!oldPhotoSmall) {
    oldPhotoSmall = 'photo_small_<?php echo $used_car->car_id; ?>';
  }
  oldPhotoLarge.style.display = 'block';
  if(document.getElementById('lrg_img'))document.getElementById('lrg_img').style.display = 'none';
  oldPhotoSmall.className = '';
  newPhotoSmall.className = 'selected';
  oldPhotoLarge.src = newPhotoLarge;
  oldPhotoSmall = newPhotoSmall;
}


  function populate_ad_fields()
  {
    var myajax=ajaxpack.ajaxobj;
    var selected;
    var notfound = 0;
	if(myajax.readyState == 1) {
		showMask();
		showLoadDiv();
	}
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){
        attr = myajax.responseText.split("\n");

	if (attr[61] == 'STOLEN')
        {
	 //hideLoadDiv();
         alert ("Error - Please contact edward@dmri.co.uk");
        }
        else if (attr[1] !=  "")
        {
         //removeEntireOptions(document.sellerStep2.maker_Fc);
         //addOption(document.sellerStep2.maker_Fc, attr[1], attr[1],selected);
           selectValue(document.sellerStep2.maker_Fc,attr[1]);
        }
        else
        {
	 //hideLoadDiv();
	 notfound = 1;
 //        alert ("We have been unable to retrieve the information for this registration plate: "+document.sellerStep2.registration_F.value+ ". Please complete the form manually.");
	   alert ("Your vehicle registration number is not recognised by Experian, please ensure that you have entered your registration number correctly.")
          document.getElementById('full_view').style.display = 'none';
          document.getElementById('find_details').style.display = 'block';
          document.getElementById('cont_but').style.display = 'none';

 //         document.getElementById('removeFields2').style.display = 'none';
          //document.getElementById('submitPage').style.display = 'none';
        }

      if (notfound == 0)
      {
        document.getElementById('full_view').style.display = 'block';
        document.getElementById('find_details').style.display = 'none';
        document.getElementById('cont_but').style.display = 'block';

   //     document.getElementById('removeFields2').style.display = 'block';
        //document.getElementById('submitPage').style.display = 'block';
        document.getElementById('regBefore').value = attr[0];
	document.getElementById('registration_F').value = document.getElementById('registration_F_lookup').value;

       if (attr[61] != 'STOLEN')
       {
        if (attr[2] != "")
        {
        removeEntireOptions(document.sellerStep2.model_Fc);
        addOption(document.sellerStep2.model_Fc, attr[2], attr[2],selected);
        update_modelsd('maker_Fc','model_Fc','','Y');
        }
        else
        {
          var label = document.getElementById('model_e');
          label.className="ps_error";
        }
        document.sellerStep2.reg_year_F.value = '';
        if (attr[5] != "")
        {
			document.sellerStep2.reg_year_F.value = attr[5];
        }
        else if (document.sellerStep2.reg_year_F.value == "")
        {
          var label = document.getElementById('reg_year_e');
          label.className="ps_error";
        }

		document.sellerStep2.colour_F.value = '';
        if ((attr[10] != "")&&(attr[10] != "Unknown"))
        {
			document.sellerStep2.colour_F.value = attr[10];
        }
        else if (document.sellerStep2.colour_F.value == "")
        {
          var label = document.getElementById('colour_e');
          label.className="ps_error";
        }

		document.sellerStep2.version_F.value = '';
        if (attr[15] != "")
        {
        document.sellerStep2.version_F.value = attr[15].substring(0,24);
		if(document.sellerStep2.version_F.value.length!=0)document.getElementById('dversion').innerHTML = 'Version ( '+(25-document.sellerStep2.version_F.value.length)+' chr. remaining)';
			else document.getElementById('dversion').innerHTML = 'Version (Max 25 characters)';		
        }
        if (attr[16] != "")
        {
			document.sellerStep2.door_count_F.value = attr[16];
        }
	else if (document.sellerStep2.door_count_F.value == "")
	{
          var label = document.getElementById('door_count_e');
          label.className="ps_error";
	}
		document.sellerStep2.fuel_type_F.value = '';
        if (attr[17] != "")
        {
        document.sellerStep2.fuel_type_F.value = attr[17];
        }
        else if (document.sellerStep2.fuel_type_F.value == "")
        {
          var label = document.getElementById('fuel_type_e');
          label.className="ps_error";
        }
		document.sellerStep2.reg_letter_F.value = '';
        if (attr[18] != "")
        {
        document.sellerStep2.reg_letter_F.value = attr[18];
        }
	else
	{
          var label = document.getElementById('reg_letter_e');
          label.className="ps_error";
	}
		document.sellerStep2.auto_F.value = '';
        if (attr[19] != "")
        {
          if (attr[19] == 'M')
          {
           attr[19] = '0';
          }
          else
          {
           attr[19] = '1';
          }
        document.sellerStep2.auto_F.value = attr[19];
        }
        else if (document.sellerStep2.auto_F.value == "")
        {
          var label = document.getElementById('auto_e');
          label.className="ps_error";
        }
  
		//document.sellerStep2.engine_size_cc_F.value = '';
        if (attr[20] != "")
        {
		/*	if(attr[20]=='12'){
				attr[20] = attr[20]+'50';
			} else {
				attr[20] = attr[20]+'00';
			}
		*/
			document.sellerStep2.engine_size_cc_F.value = attr[20];
        }
	else if (document.sellerStep2.engine_size_cc_F.value == "")
	{
          var label = document.getElementById('engine_size_cc_e');
          label.className="ps_error";
	}

        if (attr[63] != "")
        {
	 document.sellerStep2.body_F.value = attr[63];
	}

         if (document.sellerStep2.mileage_F.value == "")
         {
          var label = document.getElementById('mileage_e');
          label.className="ps_error";
         }

         if (document.sellerStep2.price_F.value == "")
	 {
          var label = document.getElementById('price_e');
          label.className="ps_error";
	 }

         if (document.sellerStep2.colour_inside_F.value == "")
	 {
          var label = document.getElementById('colour_inside_e');
          label.className="ps_error";
	 }

 
	 if (notfound == 0)
	 {
 	 //hideLoadDiv();
	 }
      }
      else if (attr[61] == "STOLEN" )
	{
        document.sellerStep2.registration_F.value="";
	}
      }
	// hide the mask after its sorted it
      }
	  hideMask();
	  hideLoadDiv();
    }
  }
  
  function DeclineMedia(id) {
	var up_v = document.getElementById('upload_1');
	up_v.innerHTML = '<img src="images/loader.gif">';
	ajaxpack.getAjaxRequest('/ajax-decline-media.php', 'car_id='+id+'&t='+Math.random(),populate_decline_media, 'txt');
  }
  
  function populate_decline_media () {
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			var variables =  myajax.responseText.split(':');
			var up_v = document.getElementById('upload_1');
			up_v.innerHTML = '';
			
		}
	}
  }
  
  var accessDeleteImage = true;
  function deleteImage(uploadId,regNumber,imageId)
  {
   if(confirm("Your are about to permanently delete this car photo. Are you sure you want to do this?"))
   {

	if(accessDeleteImage){
		//var img = document.getElementById(uploadId);
		//var id = uploadId.substring(3);
		//var up_img = document.getElementById('img'+id);
		//img.innerHTML = '<img src="images/loader.gif">';
		ajaxpack.getAjaxRequest('/ajax-delete-image.php', 'uploadId='+uploadId+'&registration='+regNumber+'&imageId='+imageId+'&t='+Math.random(),wait_populate_img_list, 'txt');		
	} else {
		alert('Please wait, deleting image');
	}
	accessDeleteImage = false;
   }
  }

  function populate_image_fields() {
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){
				var variables =  myajax.responseText.split(':');
				accessDeleteImage = true;
				var id = 'fm'+variables[0].substring(3);
				var fm = document.getElementById(id);
				fm.reset();
				document.getElementById(variables[0]).innerHTML = '';
				
			}
		}
	}
	
function showLoadDiv()
 {
	//alert (navigator.userAgent);
		var newdiv = document.createElement ("div");
		var html = '';
		if ((navigator.userAgent.indexOf ("Mozilla/4.7") != -1)||(navigator.userAgent.indexOf ("Mozilla/5.0") != -1)|| (navigator.userAgent.indexOf ("Mozilla/4.0") != -1)) {
			html = '<div id="loadingDiv" class="loadingDivT">&nbsp;</div>';
		} else {
			html = '<div id="loadingDiv" style="_position:absolute;*position:fixed;z-index: 500;top: 45%;right: 0;bottom: 0;*right:60%;_right:50%;"><img src="images/test-loader.gif"></div>';
		}
		newdiv.setAttribute('id','loadingDiv:0');
		newdiv.innerHTML = html;
		document.body.appendChild(newdiv);
        document.getElementById("loadingDiv").style.display="block"; //to show it
 }
function hideLoadDiv(){
	if(document.getElementById('loadingDiv')){
		var parentNode =  document.getElementById('loadingDiv').parentNode;
		var d2=document.getElementById('loadingDiv');
		parentNode.removeChild(d2);
		if(!(document.getElementById('loadingDiv')==null || typeof(document.getElementById('loadingDiv'))=="undefined"))hideLoadDiv();
		hideMask();
	}
}

function go_step(currentfm,gofm)
{
  if (currentfm == 3 && gofm == 4)
  {
   document.getElementById('manufacturer_c').value = document.getElementById('maker_Fd').value;
   document.getElementById('model_c').value = document.getElementById('model_Fd').value;
   document.getElementById('distance_c').value = document.getElementById('distance_Fd').value;
  }

	var fm = document.getElementById('sellerStep'+currentfm);
	fm.action = '/private-seller-'+gofm;
	if(currentfm=='1'){
		validateDatafm1();
	}else if(currentfm=='2'){
		validateDatafm2();
	}else {
	fm.submit();
	}
}

function removeAllOptions(select_box_ps)
  {
    var i;
    for(i=select_box_ps.options.length-1;i>0;i--)
    {
      select_box_ps.remove(i);
    }
  }


 function removeEntireOptions(select_box_ps)
  {
    var i;
    for(i=select_box_ps.options.length;i>0;i--)
    {
      select_box_ps.remove(i);
    }
          select_box_ps.remove(0);


  }


function selectValue(select_box_ps, maker)
{
    var i;
    for(i=0; i<select_box_ps.options.length; i++)
    {
      if (select_box_ps.options[i].value == maker)
      {
        select_box_ps.options[i].selected = true;
      }
    }

}

 function addOption(select_box_ps,text,value,selected)
  {
  //  alert (text);
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    select_box_ps.options.add(optn);
    if (selected) {
      optn.selected = true;
    }
  }

  var select_box_ps;
  var current_model;

  function populate_selectc()
  {
    var myajax=ajaxpack.ajaxobj;
    var selected;
	select_box_ps = document.sellerStep2.model_Fc;
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){
        models = myajax.responseText.split("\n");

//        select_box_ps.disabled=false;
//        select_box_ps.options.length=0;
	  select_box_ps.options[0] = new Option( 'Choose Model', '' );
        for (var i=0, len=models.length; i<len; ++i){
          if (models[i] == '')
          {
            continue;
          }

          if (current_model == models[i]) {
            selected = true;
          } else {
            selected = false;
          }
          addOption(select_box_ps, models[i], models[i],selected);
        }
	
	//addOption(select_box_ps, current_model, current_model,true);
      }
    }
  }

  function populate_selectd()
  {
    var myajax=ajaxpack.ajaxobj;
    var selected;
        select_box_ps = document.sellerStep2.model_Fc;
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){
        models = myajax.responseText.split("\n");

//        select_box_ps.disabled=false;
//        select_box_ps.options.length=0;
                select_box_ps.options[0] = new Option( 'Choose Model', '' );
        for (var i=0, len=models.length; i<len; ++i){
          if (models[i] == '')
          {
            continue;
          }

          if (current_model == models[i]) {
            selected = true;
          } else {
            selected = false;
          }
          addOption(select_box_ps, models[i], models[i],selected);
        }
          selectValue(document.sellerStep2.model_Fc,attr[2]);
      }
    }
  }

  function populate_selecte()
  {
    var myajax=ajaxpack.ajaxobj;
    var selected;
    select_box_ps = document.getElementById('model_Fd');
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){
        models = myajax.responseText.split("\n");

//        select_box_ps.disabled=false;
//        select_box_ps.options.length=0;
                select_box_ps.options[0] = new Option( 'Choose Model', '' );
        for (var i=0, len=models.length; i<len; ++i){
          if (models[i] == '')
          {
            continue;
          }

          if (current_model == models[i]) {
            selected = true;
          } else {
            selected = false;
          }
          addOption(select_box_ps, models[i], models[i],selected);
        }
          selectValue(document.sellerStep2.model_Fd,attr[2]);
      }
    }
  }

  function update_modelsc(maker_Fc,model_Fc,c_model,p_remove)
  {
	select_box_ps = document.sellerStep2.model_Fc;	
 //   select_box_ps = document.getElementById(model_Fc);
    if (p_remove)
    {
    removeEntireOptions(select_box_ps);	
    }
    else
    {
    removeAllOptions(select_box_ps);	
    }	
    if (c_model) {
       current_model = c_model;
    } else {
        current_model = 1;
		select_box_ps.options[0] = new Option( 'Loading...', '' );
    }
    ajaxpack.getAjaxRequest('/ajax-models-list.php', 'maker_F='+document.getElementById(maker_Fc).value+'&ps=1', populate_selectc, 'txt');
// alert ("i guess it is!!");
  }


  function update_modelsd(maker_Fc,model_Fc,c_model,p_remove)
  {
        select_box_ps = document.sellerStep2.model_Fc;
 //   select_box_ps = document.getElementById(model_Fc);
    if (p_remove)
    {
    removeEntireOptions(select_box_ps);
    }
    else
    {
    removeAllOptions(select_box_ps);
    }
    if (c_model) {
       current_model = c_model;
    } else {
        current_model = 1;
                select_box_ps.options[0] = new Option( 'Loading...', '' );
    }
    ajaxpack.getAjaxRequest('/ajax-models-list.php', 'maker_F='+document.getElementById(maker_Fc).value+'&ps=1', populate_selectd, 'txt');
// alert ("i guess it is!!");
  }


  function update_modelse(maker_Fc,model_Fc,c_model,p_remove)
  {
 //       select_box_ps = document.sellerStep3.model_Fd;
    select_box_ps = document.getElementById(model_Fc);
    if (p_remove)
    {
    removeEntireOptions(select_box_ps);
    }
    else
    {
    removeAllOptions(select_box_ps);
    }
    if (c_model) {
       current_model = c_model;
    } else {
        current_model = 1;
                select_box_ps.options[0] = new Option( 'Loading...', '' );
    }
    ajaxpack.getAjaxRequest('/ajax-models-list.php', 'maker_F='+document.getElementById(maker_Fc).value+'&ps=1', populate_selecte, 'txt');
  }



function testAmit()
{
showLoadDiv();
hideLoadDiv();
showLoadDiv();
hideLoadDiv();
}

function autoBlock(obName){
	var obj = document.getElementById(obName);
	if(obj.style.display == 'block'){
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
	}
}

function showhide_remnd(obId)
{
	var remdr = document.getElementById(obId);
	if(remdr.style.display == 'block'){
		remdr.style.display = 'none';
	} else {
		remdr.style.display = 'block';
	}

}

function hideLoadingMask()
{
	var parentNode =  document.getElementById('loadingVideoDiv').parentNode;
	var d2=document.getElementById('loadingVideoDiv'); 
	parentNode.removeChild(d2); 

	hideMask();
}


function showLoadingMask()
{
        var newdiv = document.createElement ("div");
        var html = '      <div id="loadingVideoDiv" class="loadingVideoDiv"></div>';
                newdiv.innerHTML = html;
                document.body.appendChild(newdiv);

        showMask();

}

var global_upload_id ;

function ajax_video_progress(upload_id)
{	
	global_upload_id = upload_id;
	if (document.getElementById('loadingVideoDiv') != null)
	{
     		ajaxpack.getAjaxRequest('/ajax-progress-bar.php', 'upload_id='+upload_id+'&t='+Math.random(), showProgressResults, 'txt');
	}
}

function checkUploadStatus(reference)
{
	var msg = '';
	var access = true;
	if(document.movieStep3.MediaFile.value == ''){
		msg += "Please choose video file\n"; 
		access = false;
	}
	if(!/(\.wmv|\.mov|\.3gp|\.avi|\.mpeg|\.flv|\.mp4|\.WMV|\.MOV|\.3GP|\.AVI|\.MPEG|\.FLV|\.MP4)$/i.test(document.movieStep3.MediaFile.value)) {
		msg += "Please enter correct video file type\n";
		access = false;
	}
	if(access){
		showLoadingMask();
		ajaxpack.getAjaxRequest('/ajax-check-upload.php', 'reference='+reference+'&t='+Math.random(), showProgressCheck, 'txt');
	} else {
		alert(msg);
	}
}



        function showProgressCheck() {
                var myajax=ajaxpack.ajaxobj
                var myfiletype=ajaxpack.filetype
                if (myajax.readyState == 4){
                        if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			var variables =  myajax.responseText.split(':');
			document.movieStep3.Username.value = variables[0];
                        document.movieStep3.Password.value = variables[1];
 			micoxUpload_video(document.movieStep3,'http://api.tigerspike.com/services/MediaUpload.aspx?uploadid=','upload_1','Loading...','Error')

                        }
                }
        }



        function showProgressResults() {
                var myajax=ajaxpack.ajaxobj
                var myfiletype=ajaxpack.filetype
                if (myajax.readyState == 4){
                        if (myajax.status==200 || window.location.href.indexOf("http")==-1){
				if (document.getElementById('loadingVideoDiv') != null)
				{
					document.getElementById('loadingVideoDiv').innerHTML = myajax.responseText;
				}
					var tmp = myajax.responseText.indexOf("PBposition(\"width\",");
					if (tmp > 0)
					{
					  tmp = myajax.responseText.substr(tmp);

					 var tmp2 = tmp.indexOf("</script>");
					 eval (tmp.substring(0,tmp2));
					}
				setTimeout('ajax_video_progress(global_upload_id)','5000');
				//ajax_video_progress(global_upload_id);
                        }
                }
        }


function PBposition(item,pixel) {
 pixel = parseInt(pixel);
 if (document.getElementById("pbar") != null)
 {
 switch(item) {
  case "left": document.getElementById("pbar").style.left=(pixel) + 'px'; break;
  case "top": document.getElementById("pbar").style.top=(pixel) + 'px'; break;
  case "width": document.getElementById("pbar").style.width=(pixel) + 'px'; break;
  case "height": document.getElementById("pbar").style.height=(pixel) + 'px'; break;
  }
 }
}

function PBlabelText(name,text) {
 name = "plbl" + name + "";
 if (document.getElementById(name) != null)
 {
 document.getElementById(name).firstChild.nodeValue=text; 
 }
}

function deleteAdvert(fm) {
	if(confirm("Your are about to permanently delete your car advert. Are you sure you want to do this?")){
		fm.delete_access.value = 'yes';
		fm.submit();
	} else {
		document.location.href='/sell-my-car.php';
	}
}

function validate_price_format(e) {  
    var evt = window.event ? event : e;
    var ucode = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;    
    if ((ucode < 48 || ucode > 57) && ucode != 9 && ucode != 8) { 
        return false //disable key press
    } else {
        return true;
    }     

}

function imageUpload(form,url_action,id_element,html_show_loading,html_error_http,registration){
	var isvalidate = true;
	var id = id_element.substring(3);
	upload = document.getElementById('img'+id);
	  
	if(!/(\.png|\.gif|\.jpg|\.jpeg|\.PNG|\.GIF|\.JPG|\.JPEG)$/i.test(upload.value) && upload.value != "") {
		alert("Invalid file type for Image "+id+".\n");
		document.getElementById('img'+id).value = '';
		isvalidate = false;
	}
	if(isvalidate)micoxUpload_image(form,url_action,id_element,html_show_loading,html_error_http,registration);
}

function validate_phone_format(e) {
    var evt = window.event ? event : e;
    var ucode = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
    if (ucode >= 48 && ucode <= 57 || (ucode == 35 || ucode == 36 || ucode == 8 || ucode == 46 || ucode == 37 || ucode == 38 || ucode == 39 || ucode == 40 || ucode == 16 || ucode == 9)) {	
        return true;            
    } else {
        return false;
    }
}

function count_down(id,e){
	var evt = window.event ? event : e;
	var ucode = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
	
	if(id.name=='version_F'){
		if(id.value.length!=0)document.getElementById('dversion').innerHTML = 'Version ( '+(25-id.value.length)+' chr. remaining)';
			else document.getElementById('dversion').innerHTML = 'Version (Max 25 characters)';
			return true;
	}else if(id.name == 'notes_F'){
		if(id.value.length > 800) id.value = id.value.substring(0,799);
		if(id.value.length!=0)document.getElementById('ddescription').innerHTML = 'Description ( '+(800-id.value.length)+' characters remaining)';
			else document.getElementById('ddescription').innerHTML = 'Description (Max 800 characters)';
			if(id.value.length >=800 && ucode != 46 && ucode != 8){
				return false; 
			}else {
				return true;
			}
	}	
}
function set_county(county, disable){
	document.sellerStep1.county_F.value = county;
        if (disable == 'disabled')
        {
          document.sellerStep1.county_F.disabled = true;
	}
}

function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function viewMedia(url) {
	window.open('/utils/player/videoSample.php?url='+url,'sampleVideo','width=400,height=250,top=300,left=300,dependent=yes,titlebar=no,scrollbars=no');
}

function popupImage(url) {    
	window.open(url,'newwindow','top=200,left=300, width=400, height=300');    
}

function redirect() {
        document.postData.submit();
}

function isNumeric(val) {
    	var numeric = true;
    	var chars = "0123456789 ";
    	var len = val.length;
    	var char = "";
    	for (i=0; i<len; i++) { char = val.charAt(i); if (chars.indexOf(char)==-1) { numeric = false; } }
    	return numeric;
}

function getV5Status()
{
	if (document.sellerStep4.v5_F.value.length >= 10 && isNumeric(document.sellerStep4.v5_F.value))
        {
	  showMask();
  	  showLoadDiv();
          ajaxpack.getAjaxRequest('/v5check.php','v5='+document.sellerStep4.v5_F.value,checkV5, 'txt');
	}
	else
	{ 
	  alert ("Please enter a valid V5C document number");
	}
	
}

function checkV5()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
                        var error = document.getElementById('errorv5');
			error.innerHTML = '';
                        if (myajax.responseText == "FAIL" || myajax.responseText == "ERROR")
			{
                         // error.innerHTML = '<p>V5 number is not valid. Please re-enter it again</p>';
			 // alert ("V5 number is not valid. Please re-enter it again");
	                  hideMask();
                          hideLoadDiv();
			  showPopUp('/help.php?request_id=2&status=failed', 'Rating', 400, 300)
			}
			else
			{
			  //error.innerHTML = '<p>Thank you for entering the v5 number</p>';
			  refresh4thpage();
			}
                }
        }
}

function loadCar(car_id)
{
  //showMask();
  ajaxpack.getAjaxRequest('/selectedCar.php','car_id='+car_id,carSelected, 'txt');
}

function loadCar4thPage(car_id)
{
  showMask();
  showLoadDiv();
  ajaxpack.getAjaxRequest('/selectedCar.php','car_id='+car_id+'&page=2&time='+new Date(),carSelected4thpage, 'txt');
}

function loadCarTab(car_id)
{
  showMask();
  showLoadDiv();
  ajaxpack.getAjaxRequest('/selectedCar.php','car_id='+car_id+'&ord='+new Date(),refresh4thpage, 'txt');
}
/*
function loadCarTabv5(car_id)
{
  showMask();
  showLoadDiv();
  ajaxpack.getAjaxRequest('/selectedCar.php','car_id='+car_id,refresh4thpagev5, 'txt');
}

function loadCarTabpay(car_id)
{
  showMask();
  showLoadDiv();
  ajaxpack.getAjaxRequest('/selectedCar.php','car_id='+car_id,refresh4thpagepay, 'txt');
}
*/
function deleteCarTab(car_id)
{
  ajaxpack.getAjaxRequest('/removeSession.php','',dummy, 'txt');
  if(confirm("Your are about to permanently delete your car advert. Are you sure you want to do this?"))
  {
    ajaxpack.getAjaxRequest('/deleteCar.php','car_id='+car_id,setCar, 'txt');
  }
}

function dummy()
{
}


function EditCar(car_id)
{
   if(confirm("Please note when you edit your advert it will need to be reapproved before it will re-appear"))
   {
     ajaxpack.getAjaxRequest('/editCar.php','car_id='+car_id,carSelected4thpage, 'txt');
   }
}


function carSelected()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
  		  document.sellerStep1.submit();
                }
        }
}

function carSelected4thpage()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
		  go_step(4,2);
                }
        }
}

function refresh4thpage()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
                  go_step(4,4);
                }
        }
}

function setCar()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
		 if (myajax.responseText == '0')
		  {
                    go_step(4,4);
		  }
 		  else
		  {
		    loadCarTab(myajax.responseText);
		  }
                }
        }


}

function showPopUp(url, p_title, p_width, p_height){ // Used for generic popup
        window.open(url,p_title,"status = 1, resizable = 0, location = 0, toolbar = 0, menubar = 0, width="+p_width+", height="+p_height);
}

function show_info()
{
   if (document.getElementById('trade_seller_F').checked)
   {
     //document.getElementById('trade_seller_info').firstChild.data="you selected this yourself, wheres the text?";
       document.getElementById('trade_seller_info').innerHTML = "Thanks for letting us know you are a car dealer. You can list the vehicle - and the advert will show you as a trader";
   }
   else
   {
     document.getElementById('trade_seller_info').innerHTML = "";
   }
}

function showDetails(car_id, reg_no, from_price, to_price, email, town, county, location, dummy, dealer_group_id_in, cap_car_id, new_used, car_desc, addShortlist, jsCode)
{
  ajaxRequestString = 'car_id_F='+escape(car_id)+'&reg_no_F='+escape(reg_no)+'&from_price_F='+from_price+'&to_price_F='+to_price+'&email_F='+escape(email)+'&dealer_group_id_in_F='+dealer_group_id_in+'&cap_car_id_F='+cap_car_id+'&new_used_F='+new_used+'&car_dsc_F='+car_desc+'&addShortlist_F='+addShortlist;
  popUp('ajax-vehicle-details','','670px', 'n', 'n','n','n','y','n',ajaxRequestString,jsCode,'', 380, 80);
}

function selectAll()
{
    var inputs = document.getElementsByTagName("input");
    var checkboxes = [];
    for (var i = 0; i < inputs.length; i++) 
    {
        if (inputs[i].type == "checkbox") 
	{
          inputs[i].checked = true;
        }  
    }
}

function releaseForm(car_id)
{
  var inputs = document.getElementsByTagName("input");
  var checkboxes = [];
  var status_flag =false;
    for (var i = 0; i < inputs.length; i++)
    {
        if (inputs[i].type == "checkbox" && inputs[i].checked == true)
        {
	 status_flag = true;
	 break;
        }
    }
   
   if (status_flag == false)
   {
     alert ("Please check atleast one box to release your information to the buyer");
   }

  return status_flag;
}

function selectCheckboxMobile()
{
 // alert ("hello " + document.sellerStep1.evening_phone_F.value);

  if (document.sellerStep1.advert.checked == true)
  {
    document.sellerStep1.evening_phone_F.readOnly = false;
  }
  else
  {
    document.sellerStep1.evening_phone_F.readOnly = true;
    document.sellerStep1.evening_phone_F.value="";
  }
}

function refreshImageList()
{
  ajaxpack.getAjaxRequest('/refreshImages', 'ord='+new Date(),populate_img_list, 'txt');
}

function populate_img_list()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
                        var up_v = document.getElementById('img_list');
                        up_v.innerHTML = myajax.responseText;
			hideLoadDiv();
			hideMask();
                }
        }
}

function wait_populate_img_list()
{
        var myajax=ajaxpack.ajaxobj
        var myfiletype=ajaxpack.filetype
        if (myajax.readyState == 4){
                if (myajax.status==200 || window.location.href.indexOf("http")==-1){
		  refreshImageList();
                }
        }
}

function clearPhotos(reg)
{
  showMask();
  showLoadDiv();
        ajaxpack.getAjaxRequest('/reuploadit', 'registration_F='+reg+'&ord='+new Date(),displayUpload, 'txt');
}

