// JavaScript Document

//for admin category change

    function makeRequest(url, fontid) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;a
        }
        http_request.onreadystatechange = function() { updatePage(http_request, fontid); };
        http_request.open('GET', url, true);
        http_request.send(null);

    }


function displaypopup(whichpic) {

				var fontid = whichpic.getAttribute("id");
                //alert(whichpic.getAttribute("id"));
                //alert(whichpic.selectedIndex);

				var catname =  whichpic[whichpic.selectedIndex].getAttribute("value");
				//alert(catname);

                //var confirm = document.getElementById("confirm");
                //confirm.firstChild.nodeValue = catname;

				var url = "../inc/ajax/getcarmodels.php?carsID="+catname;
//alert(url);
				makeRequest(url, fontid);

}

function updatePage(http_request, fontid) {

	if(http_request.readyState == 4)
		{
			var newinformation = http_request.responseText;
			                                                                 //  alert(http_request.responseText);


                 firstarray = newinformation.split("&&");
               // alert(firstarray);
               firstpoint = firstarray[0];
               secondpoint = firstarray[1];

                array1 = firstpoint.split("%");
                array2 = secondpoint.split("%");

 //alert(array1);
// alert(array2);

removeAllOptions(document.getElementById("carmodel"));

addOption(document.getElementById("carmodel"), "Any Model", "none");

for (var i=0; i < array1.length-1;++i){

addOption(document.getElementById("carmodel"), array1[i], array2[i]);
}

		}
	else
		{
			var newinformation = "Loading..";
removeAllOptions(document.getElementById("carmodel"));
addOption(document.getElementById("carmodel"), newinformation, "");

		}

}

function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}

function submitform()
{
  document.mysort.submit();
}

function checkPostcode(postcode)
{

myString = document.getElementById("postcode").value;



if(myString.match(/^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$/))
    { /*Success!*/

   }
else
  {
       alert('Sorry, but you must enter a full UK postcode. eg BS11 8DE');
return false;
  }

}
