﻿// JScript File

function newvalpcode(form){
var pcode = (form.delpcode.value).replace(/[\x20\W_]/g,'');
var size = pcode.length;
var rpcode = Right(pcode,3);
var lpcode = Left(pcode,(size-3));
pcode = (lpcode + " " + rpcode).toUpperCase();
var emailRegxp = /[a-zA-Z0-9]{2,4}\s[0-9][a-zA-Z]{2}/;

if (size < 5 || size > 8){ //Code length rule
  alert(pcode + " is not a valid postcode - wrong length");
  return false;
  }
if (emailRegxp.test(pcode) != true)
            {
                alert(pcode + " is not a valid postcode");
                return false;
             }
         else{
                form.delpcode.value = pcode;
                return true;
             }

}

function newvalccpcode(form){
var pcode = (form.pcode.value).replace(/[\x20\W_]/g,'');
var size = pcode.length;
var rpcode = Right(pcode,3);
var lpcode = Left(pcode,(size-3));
pcode = (lpcode + " " + rpcode).toUpperCase();
var emailRegxp = /[a-zA-Z0-9]{2,4}\s[0-9][a-zA-Z]{2}/;

if (size < 5 || size > 8){ //Code length rule
  alert(pcode + " is not a valid postcode - wrong length");
  return false;
  }
if (emailRegxp.test(pcode) != true)
            {
                alert(pcode + " is not a valid postcode");
                return false;
             }
         else{
                form.pcode.value = pcode;
                return true;
             }

}

function validatepcode(form){ //check postcode format is valid
 test =  form.delpcode.value; size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 if (size < 5 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   return false;
  }
//alert("Postcode Format OK");
return true;
}


function Left(str, n){
          if (n <= 0)
              return "";
          else if (n > String(str).length)
              return str;
          else
              return String(str).substring(0,n);
}
        

function Right(str, n){
          if (n <= 0)
             return "";
          else if (n > String(str).length)
             return str;
          else {
             var iLen = String(str).length;
             return String(str).substring(iLen, iLen - n);
              }
}
        
function preloader() {

        var prod = Request.QueryString("prod") + "";
		if (prod == "null"){
		}
		else{
		    if(document.images) {
		        var pic = new Array;
		        var i=0;
		        pic[0] = new Image();
		        pic[0].src = "/images/pictures_md/" + Left(prod,1) + "_jpegs/" +  prod + ".jpg";
                for (i=1;i<10;i++)
                    {
                    pic[i] = new Image();
                    pic[i].src = "/images/pictures_md/" + Left(prod,1) + "_jpegs/" +  prod + "_in" + i + ".jpg";  
                }
            }
	        return(pic)
	    }
}


		 

function changer(imgname,prod_code, altstring) {
    M = "images/pictures_md/" + Left(prod_code, 1) + "_jpegs/" + prod_code + ".jpg"
    L = "images/pictures_lg/" + Left(prod_code, 1) + "_jpegs/" + prod_code + ".jpg" 
    var imgstr = "<a href='" + L + "' target='_blank'><img border='0' style='width:340px;height340px;' src='" + M + "' alt='" + altstring + "'></a>"
    document.getElementById(imgname).innerHTML=imgstr;  
 }
 
 function movie(){
    var moviestr = "";
    moviestr = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='340' height='340' id='G005D' align='middle'>";
	moviestr = moviestr + "<param name='allowScriptAccess' value='sameDomain' />";
	moviestr = moviestr + "<param name='allowFullScreen' value='false' />";
	moviestr = moviestr + "<param name='movie' value='technical/G005D.swf'/>";
	moviestr = moviestr + "<param name='quality' value='high' />";
	moviestr = moviestr + "<param name='bgcolor' value='#ffffff' />";	
	moviestr = moviestr + "<embed src='technical/G005D.swf' quality='high' bgcolor='#ffffff' width='340' height='340' name='G005D' align='middle' allowscriptaccess='sameDomain' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	moviestr = moviestr + "</object>";
 
    document.getElementById("mainimg").innerHTML= moviestr; 
 
 }
		

function validate_qty(field,alerttxt){
        var noRegxp = /^([0-9])/;
        if (noRegxp.test(field) != true)
            {
                alert(alerttxt);
                return false
             }
        else{
                return true
             }
}
        
function validate_form(thisform)
        {
        with (thisform)
            {
                if (validate_qty(thisform.qty.value,"You Must Enter a Valid Quantity")==false)
                    {
                        qty.focus();
                        return false
                    }else{
                        return true
                    }
            }
}

function addqty (form) {
            var qtystr = form.qty.value;
            qty = parseInt(qtystr);
            qty = qty + 1;
            form.qty.value = qty;
}
        
function subqty (form) {
            var qtystr = form.qty.value;
            qty = parseInt(qtystr);
            if (qty > 0){
                qty = qty - 1;
            }
            form.qty.value = qty;   
}

function changeorder(form){
            var w = form.nos.selectedIndex;
            var selected_text = form.nos.options[w].value;
            //alert(selected_text);
            if(selected_text == "Select"){
            
            }else if (selected_text == "New Order"){
                updateorderno("New");
                form.nos.selectedindex = 0;
            }else if ( selected_text == "Delete"){
                updateorderno("Del");
            }else{
                updateorderno(selected_text);
                form.nos.selectedindex = w;
            }
}


function searchchange(form){
	    
	    var srch = form.srch.value;
        var winURL = "homepage.aspx?com=homepage&srch=" + srch;
        if ( srch == "Search Text"){
    
        }else{
           window.location.replace(winURL);
        }
	
}

function createrequest(){
    var req;
    try{
        req = new XMLHttpRequest();
    }
    catch(e)
    {
        try{
			    req = new ActiveXObject("Msxml2.XMLHTTP");
		   } 
		   catch (e) 
		   {
		    try{
				    req = new ActiveXObject("Microsoft.XMLHTTP");
			    } 
			    catch (e)
			    {
				    // Something went wrong
				   //alert("Sorry Your Browser may not support AJAX Content You Need To Have IE5 Or Above");
				    //return false;
				    //return true;
			      }
		    }
    }
    return req;
}




function cleardelivery(form){
var selectstring = form.countrystring.value
document.getElementById('countryhtml').innerHTML=selectstring;

var newObject = document.createElement('input');
var oldObject = document.getElementById('officename');
newObject.type = 'text';
newObject.value ='';
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.name) newObject.name = 'officename';
if(oldObject.id) newObject.id = 'officename';
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);

var newObject = document.createElement('input');
var oldObject = document.getElementById('deladd1');
newObject.type = 'text';
newObject.value ='';
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.name) newObject.name = 'deladd1';
if(oldObject.id) newObject.id = 'deladd1';
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);

var newObject = document.createElement('input');
var oldObject = document.getElementById('deladd2');
newObject.type = 'text';
newObject.value ='';
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.name) newObject.name = 'deladd2';
if(oldObject.id) newObject.id = 'deladd2';
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);

var newObject = document.createElement('input');
var oldObject = document.getElementById('deladd3');
newObject.type = 'text';
newObject.value ='';
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.name) newObject.name = 'deladd3';
if(oldObject.id) newObject.id = 'deladd3';
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);

var newObject = document.createElement('input');
var oldObject = document.getElementById('delpcode');
newObject.type = 'text';
newObject.value ='';
newObject.onchange ='validatepcode(this.form);';
if(oldObject.size) newObject.size = oldObject.size;
if(oldObject.name) newObject.name = 'delpcode';
if(oldObject.id) newObject.id = 'delpcode';
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);

var newObject = document.createElement('input');
var oldObject = document.getElementById('result');
newObject.type = 'hidden';
newObject.value ='false';
if(oldObject.name) newObject.name = 'result';
if(oldObject.id) newObject.id = 'result';
if(oldObject.className) newObject.className = oldObject.className;
oldObject.parentNode.replaceChild(newObject,oldObject);

}
function updatecountry(form){
changedel(form);
updatedel(form);
}



function updatedel(form){

var country = form.delcountry.value;
var pcode = form.delpcode.value;
var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
document.body.style.cursor="wait";

	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~")
                
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "delstring"){
                        document.getElementById('delhtml').innerHTML=intstring;
                    }
                }
			 }
			document.body.style.cursor="default"; 
			return true;
		}
		else
		{
			return false;
		}
		document.body.style.cursor="default";
    }
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=delchg&ctry=" + country + "&pcode=" + pcode + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
}

function officedelivery(form){

var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "delname"){
                        var newObject = document.createElement('input');
                        var oldObject = document.getElementById('officename');
                        newObject.type = 'text';
                        newObject.readonly = 'true';
                        newObject.value =intstring;
                        if(oldObject.size) newObject.size = oldObject.size;
                        if(oldObject.name) newObject.name = 'officename';
                        if(oldObject.id) newObject.id = 'officename';
                        if(oldObject.className) newObject.className = oldObject.className;
                        oldObject.parentNode.replaceChild(newObject,oldObject);
                    }else if (tablestring == "deladd1"){
                        var newObject = document.createElement('input');
                        var oldObject = document.getElementById('deladd1');
                        newObject.type = 'text';
                        newObject.readonly = 'true';
                        newObject.value =intstring;
                        if(oldObject.size) newObject.size = oldObject.size;
                        if(oldObject.name) newObject.name = 'deladd1';
                        if(oldObject.id) newObject.id = 'deladd1';
                        if(oldObject.className) newObject.className = oldObject.className;
                        oldObject.parentNode.replaceChild(newObject,oldObject);
                    }else if (tablestring == "deladd2"){
                        var newObject = document.createElement('input');
                        var oldObject = document.getElementById('deladd2');
                        newObject.type = 'text';
                        newObject.readonly = 'true';
                        newObject.value =intstring;
                        if(oldObject.size) newObject.size = oldObject.size;
                        if(oldObject.name) newObject.name = 'deladd2';
                        if(oldObject.id) newObject.id = 'deladd2';
                        if(oldObject.className) newObject.className = oldObject.className;
                        oldObject.parentNode.replaceChild(newObject,oldObject);
                    }else if (tablestring == "deladd3"){
                        var newObject = document.createElement('input');
                        var oldObject = document.getElementById('deladd3');
                        newObject.type = 'text';
                        newObject.readonly = 'true';
                        newObject.value =intstring;
                        if(oldObject.size) newObject.size = oldObject.size;
                        if(oldObject.name) newObject.name = 'deladd3';
                        if(oldObject.id) newObject.id = 'deladd3';
                        if(oldObject.className) newObject.className = oldObject.className;
                        oldObject.parentNode.replaceChild(newObject,oldObject);
                    }else if (tablestring == "delpcode"){
                        var newObject = document.createElement('input');
                        var oldObject = document.getElementById('delpcode');
                        newObject.type = 'text';
                        newObject.readonly = 'true';
                        newObject.value =intstring;
                        newObject.onchange ='validatepcode(this.form);';
                        if(oldObject.size) newObject.size = oldObject.size;
                        if(oldObject.name) newObject.name = 'delpcode';
                        if(oldObject.id) newObject.id = 'delpcode';
                        if(oldObject.className) newObject.className = oldObject.className;
                        oldObject.parentNode.replaceChild(newObject,oldObject);
                    }else if (tablestring == "country"){
                        var newObject = document.createElement('input');
                        var oldObject = document.getElementById('delcountry');
                        newObject.type = 'text';
                        newObject.readonly = 'true';
                        newObject.value =intstring;
                        if(oldObject.size) newObject.size = '20';
                        if(oldObject.name) newObject.name = 'delcountry';
                        newObject.id = 'delcountry';
                        if(oldObject.className) newObject.className = oldObject.className;
                        oldObject.parentNode.replaceChild(newObject,oldObject);
                    }  
                }
                var newObject = document.createElement('input');
                oldObject = document.getElementById('result');
                newObject.type = 'hidden';
                newObject.value ='false';
                if(oldObject.name) newObject.name = 'result';
                if(oldObject.id) newObject.id = 'result';
                if(oldObject.className) newObject.className = oldObject.className;
                oldObject.parentNode.replaceChild(newObject,oldObject);
            }
            changedel(form);
		    updatedel(form);
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    document.body.style.cursor="default";
    }
    
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=officedel&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);

}

function tableupdateqty(form, code){
    var valid = validate_form(form);
    if (valid == true){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	if (!ajaxRequest) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split("|");
                    var tablestring = table[0];
                    var intstring = table[1];
                   if (tablestring == "item1"){
                    document.getElementById('tablebasket').innerHTML=intstring; 
                    
                    }else if (tablestring == "item2"){
                    document.getElementById('tableproductlist').innerHTML=intstring;
                                          
                    }
                    
                }
            }
		    
			//return true;
			return false;
		}
		else
		{
			return false;
		}
    }
    var qty = form.qty.value;
    var subtablename = form.subtablename.value;
   
    
    var date = new Date();
    var timestamp = date.getTime();
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=tableupdateqty&code=" + code + "&qty=" + qty
    url = url + "&subtablename=" + subtablename
    url = url + "&timenow=" + timestamp + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	//ajaxRequest.open("POST", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	} 
}

function headchangedel(){
var  form = document.getElementById('deliveryform');

    var pcode = form.delpcode.value;
    var country = form.delcountry.value;
    if (country == "GB"){
        var pcoderesult = newvalpcode(form);
    }else{
        var pcoderesult = true;
    }
    if (pcoderesult == true){
        var addressresult = deladdress(form);
        if(addressresult == true) {
                form.result.value = "true";
                return true;
         }else{
                form.result.value = "false";
                return true;
         }
     }else{
         form.result.value = "false";
         form.delpcode.focus();
         return false
    }
document.body.style.cursor="default";
    
}

function changedel(form){
var  form = document.getElementById('deliveryform');

    var pcode = form.delpcode.value;
    var country = form.delcountry.value;
    if (country == "GB"){
        var pcoderesult = newvalpcode(form);
    }else{
        var pcoderesult = true;
    }
    if (pcoderesult == true){
        var addressresult = deladdress(form);
        if(addressresult == true) {
                form.result.value = "true";
                return true;
         }else{
                form.result.value = "false";
                return true;
         }
     }else{
         form.result.value = "false";
         form.delpcode.focus();
         return false
    }
document.body.style.cursor="default";
    
}

function deladdress(form){
    var  form = document.getElementById('deliveryform');
    var name = form.officename.value;
    var add1 = form.deladd1.value;
    var add2 = form.deladd2.value;
    var add3 = form.deladd3.value;
    var pcode = form.delpcode.value;
    var yourorder = form.yourorder.value;
	var country = form.delcountry.value;
	var delchg = form.delchg.value;
	var delnote = form.delnote.value;
    
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~")   
                
                var table = arr[0].split(",");
                var tablestring = table[0];
                var intstring = table[1];
                if (intstring == "ok"){
                    document.body.style.cursor="default";
			        return true;
			    }else{
			        document.body.style.cursor="default";
			        return false;

			    }
			 }
			 document.body.style.cursor="default";
		}
		else
		{
			return false;
		}
	document.body.style.cursor="default";
    }
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=deladdress&name=" + name + "&add1=" + add1 + "&add2=" + add2 +"&add3=" + add3 +  "&pcode=" + pcode + "&country=" + country + "&delchg=" + delchg + "&delnote=" + delnote + "&yourorder=" + yourorder + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
}

function updateorderno(orderno){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    document.body.style.cursor="default";
		    window.location.reload();
			return true;
		}
		
		else
		{
			return false;
		}
    }
    myRand=parseInt(Math.random()*99999999);
    var url = "ajax.aspx?com=orderno&orderno=" + orderno + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null); 
}


function invoicelist(page){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        

                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split("|");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "result"){
                    document.getElementById('invtable').innerHTML=intstring;
                    }
                }
            document.body.style.cursor="default";
			return true;
		}
		
		else
		{
			return false;
		}
    }
    myRand=parseInt(Math.random()*99999999);
    var url = "ajax.aspx?com=invoicelist&page=" + page + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null); 
}

function showinvoice(orderno, page, ordergen){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        

                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split("|");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "result"){
                    document.getElementById('invtable').innerHTML=intstring;
                    }
                }
            document.body.style.cursor="default";
			return true;
		}
		
		else
		{
			return false;
		}
    }
    myRand=parseInt(Math.random()*99999999);
    var url = "ajax.aspx?com=invoice&orderno=" + orderno + "&ordgen=" + ordergen + "&page=" + page + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null); 
}



function shortorder(form){
    var valid = validate_form(form);
    var status = form.status.value;
    if (valid == true && status == "true"){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        

                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "item1"){
                    document.getElementById('tablebasket').innerHTML=intstring;
                    }else if (tablestring == "item2"){
                    document.getElementById('basketprod').innerHTML=intstring;
                    }
                    
                }
                shortform.code.value = "Code"
                shortform.shortdesc.value="";
                shortform.code.value="";
                shortform.shortprice.value="";
                shortform.shortstock.value="";
                shortform.qty.value="";
                shortform.code.focus();
                document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var qty = form.qty.value;
    var prodcode = form.code.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=shortorder&prodcode=" + prodcode + "&qty=" + qty + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	} 
}


function submitpay(form){
    
    
    //debugger;
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "ButtonString"){
                        document.getElementById('buttondata').innerHTML=intstring;
                    }
                    else if (tablestring == "CardString")
                    {
                        document.getElementById('cardtable').innerHTML=intstring;
                        document.getElementById('paybutton').disabled=false;
                    }
                    else if (tablestring == "PayMethodString")
                    {
                        document.getElementById('paymethod').innerHTML=intstring;
                    }
                    else if (tablestring == "Basket")
                    {
                        document.getElementById('tablebasket').innerHTML=intstring;
                     }
                    else if (tablestring == "iframe")
                    {
                    //document.getElementById('threeD').src=intstring;
                    //document.getElementById('threeD').width ="600";
                    //document.getElementById('threeD').height ="600";
                    //document.getElementById('threeD').scrolling ="yes";
                    document.getElementById('iframe1').innerHTML=intstring;
                    }
                    //else
                    //{
                        //document.getElementById('cardtable').innerHTML="Failed";
                    //}
  
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var option = form.payoption.value;
    if (option == "both") {
    var paylen = payform.payaccount.length;
    for (var i=0; i < paylen; i++)
    {
    if (payform.payaccount[i].checked)
      {
      var paytype = payform.payaccount[i].value;
      }
    }
    }else{
     paytype = "ccard"
    }
    if (paytype == "ccard"){
    
    if (form.country.value == "GB") {
        var pcoderesult = newvalccpcode(form);
    }else{
        var pcoderesult = true;
    }
    
    
    if (pcoderesult == true){
    try{
    var cardtype = form.cardtype.value;
    var cardno = form.cardno.value;
    try{
    var issno = form.issno.value;
    }catch(err){
    var issno = "";
    }
    try{
    var startmonth = form.startmonth.value;
    }catch(err){
    var startmonth = "" ;
    }
    try{
    var endmonth = form.endmonth.value;
    }catch(err){
    var endmonth = "";
    }
    try{
    var startyear = form.startyear.value;
    }catch(err){
    var startyear = "";
    }
    try{
    var endyear = form.endyear.value;
    }catch(err){
    var endyear = "";
    }
    try{
    var cvv2 = form.cvv2.value;
    }catch(err){
    var cvv2 = "";
    }
    var name = form.name.value;
    var add1 = form.add1.value;
    var add2 = form.add2.value;
    var add3 = form.add3.value;
    var pcode = form.pcode.value;
    var country = form.country.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=checkccard&cardtype=" + cardtype + "&cardno=" + cardno + "&issno=" + issno + "&startmonth=" + startmonth + "&startyear=" + startyear + "&endmonth=" + endmonth + "&endyear=" + endyear + "&cvv2=" + cvv2 + "&name=" + name + "&add1=" + add1 + "&add2=" + add2 + "&add3=" + add3 + "&pcode=" + pcode + "&country=" + country + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	}catch(err){
	}
	}
	else{
	    document.getElementById('paybutton').disabled=false;
	    document.body.style.cursor="default";
	}
	}else if (paytype=="account"){
	myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=payacc&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	}
}

function updatedesc(){
    var prodcode = shortform.code.value;
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "desc"){
                    shortform.shortdesc.value=intstring;
                    shortform.qty.readonly="false";
                    }else if (tablestring == "stock"){
                    document.getElementById('Quickorderalert').innerHTML="";
                    shortform.qty.readonly="false";
                    shortform.shortstock.value=intstring;
                    shortform.status.value="true"
                    }else if (tablestring == "price"){
                    shortform.qty.readonly="false";
                    shortform.shortprice.value=intstring;
                    shortform.qty.focus();
                    }else if (tablestring == "alt"){
                    document.getElementById('altprod').innerHTML=intstring;
                    shortform.qty.readonly="false";
                    if(!(intstring=="")){
                        shortform.code.focus();
                    }
                    }else if (tablestring == "bulk"){
                    if(intstring!="<br>"){
                    document.getElementById('Quickorderalert').innerHTML=intstring;
                    shortform.qty.readonly="true";
                    //shortform.code.focus();
                    }
                    }else if (tablestring == "fail"){
                    document.getElementById('Quickorderalert').innerHTML="";
                    shortform.shortdesc.value=intstring;
                    shortform.shortprice.value="";
                    shortform.shortstock.value="";
                    shortform.status.value="false";
                    shortform.qty.readonly="true";
                    document.getElementById('altprod').innerHTML="";
                    shortform.code.value=""
                    shortform.code.focus();
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=updatedesc&prodcode=" + prodcode + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	
}
function updateeventdesc(event){
    var browsername = navigator.appName
    if (browsername == "Microsoft Internet Explorer"){
    var ev = event.keyCode
        if (ev == 13){
	    shortform.qty.focus();
	    return false;
	}
	}else{
	var e = event.keyCode;
	//window.alert('outer ' + e)
	if (e == 13){
	 //window.alert('inner ' + e)
	 //shortform.qty.focus();
	 return false;
	}
	}
}

function altdesc(code){
    
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                shortform.code.value=code;
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "desc"){
                    shortform.shortdesc.value=intstring;
                    }else if (tablestring == "stock"){
                    shortform.shortstock.value=intstring;
                    shortform.status.value="true"
                    }else if (tablestring == "price"){
                    shortform.shortprice.value=intstring;
                    shortform.qty.focus();
                    }else if (tablestring == "alt"){
                        if (!(intstring=="")){
                            document.getElementById('altprod').innerHTML=intstring;
                        }
                    }else if (tablestring == "fail"){
                    shortform.shortdesc.value=intstring;
                    shortform.shortprice.value="";
                    shortform.shortstock.value="";
                    shortform.status.value="false";
                    document.getElementById('altprod').innerHTML="";
                    shortform.code.focus();
             
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=updatedesc&prodcode=" + code + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	
}

function updateman(form){
    
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "desc"){
                    form.shortdesc.value=intstring;
                    }else if (tablestring == "fail"){
                    form.shortdesc.value=intstring;
                    form.status.value="false";
                    form.code.focus();
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var prodcode = form.code.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=updateman&prodcode=" + prodcode + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	
}

function imgsearch(form){

    
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "result"){
                    document.getElementById('manresult').innerHTML=intstring;
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var prodcode = form.code.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=imgsearch&prodcode=" + prodcode + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);	
}

function dealer(form){
   

    if (validatepcode(form) == true){
    var postcode = form.delpcode.value;
    
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "result"){
                    document.getElementById('dealerlist').innerHTML=intstring;
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=dealer&pcode=" + postcode + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	}else{
	
	//document.getElementById('dealerlist').innerHTML="Post Code Not known";
	
	}
	
}


function mansearch(form){

	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "result"){
                    document.getElementById('manresult').innerHTML=intstring;
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var prodcode = form.code.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=mansearch&prodcode=" + prodcode + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);

}


function updateCcard(form){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "ButtonString"){
                       //document.submitbutton.onclick=intstring;
                       //document.getElementById('buttondata').innerHTML=intstring;
                    }
                    else if (tablestring == "CardString")
                    {
                        //document.getElementById('cardtable').innerHTML="";
                        document.getElementById('cardtable').innerHTML=intstring;
                    }
                    
                }
            } 
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var cardtype = form.cardtype.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=updateccard&cardtype=" + cardtype + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
}

function paycard(form){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "cardstring"){
                        document.getElementById('cardtable').innerHTML=intstring;
                    }
                    
                }
            }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=paycard&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
}


function payacc(form){
    intstring = ""
    document.getElementById('cardtable').innerHTML=intstring;
    //document.getElementById('buttondata').innerHTML="<tr><td id='buttondata' class='viewbasketcenter'><BUTTON tabindex='3' class='transparentbutton' onclick=''><IMG src='add_basket.jpg' alt='Submit Payment' width='30' height='19'></BUTTON></td></tr>";
                    	
}


function popup(URL){
        
            window.open(URL),"Large Image","width=300,height=300,toolbar=0,scrollbars=auto,location=0,status=0,menubar=0,resizeable=yes"
            
            }

function updateqty(form){
    var valid = validate_form(form);
    if (valid == true){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        

                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "item1"){
                    document.getElementById('tablebasket').innerHTML=intstring;
                    }else if (tablestring == "item2"){
                    document.getElementById('basketprod').innerHTML=intstring;
                    }
                }
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var qty = form.qty.value;
    var prodcode = form.prodcode.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=updateqty&prodcode=" + prodcode + "&qty=" + qty + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	} 
}

function addtoorder(form){
    var valid = validate_form(form);
    if (valid == true){
	var ajaxRequest = createrequest();  // The variable that makes Ajax possible!
	document.body.style.cursor="wait";
	// Create a function that will receive data sent from the server
	
    function handleresponse(){
		if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
		    var response = ajaxRequest.responseText;
		    //alert(response);
		    //window.location.reload();
		    response=response.substring(0,response.indexOf("<!DOCTYPE")-4);
        
            if(response=="")
            {
                window.location.reload();
            }
            else
            {
                var arr=response.split("~");
        
                //document.getElementById('tablebasket').innerHTML="";
                for(var i=0;i<arr.length;i++)
                {
                    var table = arr[i].split(",");
                    var tablestring = table[0];
                    var intstring = table[1];
                    if (tablestring == "basket"){
                        document.getElementById('tablebasket').innerHTML=intstring;
                    }else if (tablestring == "ordqty"){
                        document.getElementById('qtyord' + prodcode).innerHTML=intstring;
                    }
                    
                }

            }
            
		    document.body.style.cursor="default";
			return true;
		}
		else
		{
			return false;
		}
    }
    var qty = form.qty.value;
    var prodcode = form.prodcode.value;
    myRand=parseInt(Math.random()*99999999);    
    var url = "ajax.aspx?com=addqty&prodcode=" + prodcode + "&qty=" + qty + "&rnd=" + myRand;
	ajaxRequest.open("GET", url, true);
	ajaxRequest.onreadystatechange = handleresponse;
	ajaxRequest.send(null);
	
	} 
}


/* Andrew Urquhart : Client-Side Request Object for javascript : http://andrewu.co.uk/tools/request/
COPYRIGHT:You are free to use this script for any use you wish if this comment is left intact. Feel free to enhance the script and send me the updated version. Please don't redistribute. This script is provided as is,with no warranty of any kind. Use it at your own risk. Copyright Andrew Urquhart; VERSION:#1.41 2007-06-28 18:10 UTC*/
function RObj(ea){
    var LS="";
    var QS=new Object();
    var un="undefined";
    var x=null;
    var f="function";
    var n="number";
    var r="string";
    var e1="ERROR:Index out of range in\r\nRequest.QueryString";
    var e2="ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";
    var e3="ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key";
    var dU=window.decodeURIComponent?1:0;

    function Err(arg){
        if(ea){
            alert("Request Object:\r\n"+arg)
            }
    };
    function URID(t){
        var d="";
        if(t){
            for(var i=0;i<t.length;++i){
                var c=t.charAt(i);
                d+=(c=="+"?" ":c)
            }
        }
        return(dU?decodeURIComponent(d):unescape(d))
    };
    function OL(o){
        var l=0;
        for(var i in o){
            if(typeof o[i]!=f){l++}
        };
        return l};
        function AK(key){
            var auk=true;
            for(var u in QS){
                if(typeof QS[u]!=f&&u.toString().toLowerCase()==key.toLowerCase()){
                    auk=false;return u
                }
            }
            if(auk){
            QS[key]=new Object();
            QS[key].toString=function(){
                                return TS(QS[key])
                             };
            QS[key].Count=function(){
                            return OL(QS[key])
                          };
            QS[key].Count.toString=function(){
                                        return OL(QS[key]).toString()
                                   };
            QS[key].Item=function(e){
                            if(typeof e==un){
                                return QS[key]
                            }else {
                                if(typeof e==n){
                                    var a=QS[key][Math.ceil(e)];
                                    if(typeof a==un){
                                        Err(e1+"(\""+key+"\").Item("+e+")")
                                    };
                                    return a
                                    }else {
                                    Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")")
                                    }
                                 }
                             };
             QS[key].Item.toString=function(e){
                                        if(typeof e==un){
                                            return QS[key].toString()
                                        }else {
                                            var a=QS[key][e];
                                            if(typeof a==un){
                                                Err(e1+"(\""+key+"\").Item("+e+")")
                                            };
                                            return a.toString()
                                        }
                                    };
             QS[key].Key=function(e){
                            var t=typeof e;
                            if(t==r){
                                var a=QS[key][e];
                                return(typeof a!=un&&a&&a.toString()?e:"")
                            }else {
                                Err(e3+"("+(e?e:"")+")")
                            }
                          };
             QS[key].Key.toString=function(){
                                    return x
                                   }
        };
        return key};
        function AVTK(key,val){
            if(key!=""){
                var key=AK(key);
                var l=OL(QS[key]);
                QS[key][l+1]=val
            }
         };
         function TS(o){
         var s="";
         for(var i in o){
            var ty=typeof o[i];
            if(ty=="object"){
                s+=TS(o[i])
            }else if(ty!=f){
                s+=o[i]+", "
            }
          };
          var l=s.length;
          if(l>1){
            var t = ""
            t = s.substring(0,l-2) 
            return(t.toLowerCase())
          }
          return(s==""?x:s)
      };
      function KM(k,o){
        var k=k.toLowerCase();
        for(var u in o){
            if(typeof o[u]!=f&&u.toString().toLowerCase()==k){
                return u
            }
         }
       }
       if(window.location&&window.location.search){
        LS=window.location.search;
        var l=LS.length;
        if(l>0){
            LS=LS.substring(1,l);
            var preAmpAt=0;
            var ampAt=-1;
            var eqAt=-1;
            var k=0;
            var skip=false;
            for(var i=0;i<l;++i){
                var c=LS.charAt(i);
                if(LS.charAt(preAmpAt)=="="||(preAmpAt==0&&i==0&&c=="=")){
                    skip=true
                 }
                 if(c=="="&&eqAt==-1&&!skip){
                    eqAt=i
                 }
                 if(c=="&"&&ampAt==-1){
                    if(eqAt!=-1){
                        ampAt=i
                    }
                    if(skip){
                        preAmpAt=i+1
                     };
                     skip=false
                  }
                  if(ampAt>eqAt){
                    AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));
                    preAmpAt=ampAt+1;
                    eqAt=ampAt=-1;
                    ++k
                  }
               }
               if(LS.charAt(preAmpAt)!="="&&(preAmpAt!=0||i!=0||c!="=")){
                if(preAmpAt!=l){
                    if(eqAt!=-1){
                        AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)))
                    }else if(preAmpAt!=l-1){
                        AVTK(URID(LS.substring(preAmpAt,l)),"")
                    }
                 }
                 if(l==1){
                    AVTK(LS.substring(0,1),"")
                 }
                }
               }
         };
         var TC=OL(QS);
         if(!TC){
            TC=0
         };
         QS.toString=function(){
                        return LS.toString()
                     };
         QS.Count=function(){
                       return(TC?TC:0)
                   };
         QS.Count.toString=function(){
                                return(TC?TC.toString():"0")
                            };
         QS.Item=function(e){
            if(typeof e==un){
                return LS
            }else {
                if(typeof e==n){
                    var e=Math.ceil(e);
                    var c=0;
                    for(var i in QS){
                        if(typeof QS[i]!=f&&++c==e){
                            return QS[i]
                        }
                     };
                     Err(e1+"().Item("+e+")")
                 }else {
                    return QS[KM(e,QS)]
                 }
             };
             return x
          };
          QS.Item.toString=function(){
                                return LS.toString()
                           };
          QS.Key=function(e){
                    var t=typeof e;
                    if(t==n){
                        var e=Math.ceil(e);
                        var c=0;
                        for(var i in QS){
                            if(typeof QS[i]!=f&&++c==e){
                                return i
                            }
                         }
                     }else if(t==r){
                        var e=KM(e,QS);
                        var a=QS[e];
                        return(typeof a!=un&&a&&a.toString()?e:"")
                     }else {
                        Err(e2+"().Key("+(e?e:"")+")")
                     };
                     Err(e1+"().Item("+e+")")
                  };
           QS.Key.toString=function(){
                                Err(e2+"().Key")
                           };
                           
           this.QueryString=function(k){
                                if(typeof k==un){
                                    return QS
                                }else {
                                    if(typeof k==n){
                                        return QS.Item(k)
                                    };
                                    var k=KM(k,QS);
                                    if(typeof QS[k]==un){
                                        t=new Object();
                                        t.Count=function(){
                                                    return 0
                                                };
                                        t.Count.toString=function(){
                                                            return "0"
                                                           };
                                        t.toString=function(){
                                                        return x
                                                    };
                                        t.Item=function(e){
                                                    return x
                                               };
                                        t.Item.toString=function(){
                                                            return x
                                                        };
                                        t.Key=function(e){
                                                  Err(e3+"("+(e?e:"")+")")
                                              };
                                        t.Key.toString=function(){
                                                            return x
                                                       };
                                        return t
                                    }else {
                                        return QS[k]
                                    }
                              }
                        };
                 this.QueryString.toString=function(){
                                               return LS.toString()
                                           };
                 this.QueryString.Count=function(){
                                                return(TC?TC:0)
                                        };
                 this.QueryString.Count.toString=function(){
                                                    return(TC?TC.toString():"0")
                                                 };
                 this.QueryString.Item=function(e){
                                            if(typeof e==un){
                                                return LS.toString()
                                            }else {
                                                if(typeof e==n){
                                                    var e=Math.ceil(e);
                                                    var c=0;
                                                    for(var i in QS){
                                                        if(typeof QS[i]!=f&&++c==e){
                                                            return QS[i]
                                                        }
                                                     };
                                                     Err(e1+".Item("+e+")")
                                                 }else {
                                                    return QS[KM(e,QS)]
                                                 }
                                              }
                                              if(typeof e==n){
                                                Err(e1+".Item("+e+")")
                                              };
                                              return x
                                           };
                 this.QueryString.Item.toString=function(){
                                                    return LS.toString()
                                                };
                 this.QueryString.Key=function(e){
                                           var t=typeof e;
                                           if(t==n){
                                            var e=Math.ceil(e);
                                            var c=0;
                                            for(var i in QS){
                                                if(typeof QS[i]=="object"&&(++c==e)){
                                                    return i
                                                }
                                             }
                                           }else if(t==r){
                                             var e=KM(e,QS);
                                             var a=QS[e];
                                             return(typeof a!=un&&a&&a.toString()?e:"")
                                           }else {
                                             Err(e2+".Key("+(e?e:"")+")")
                                           };
                                           Err(e1+".Item("+e+")")
                                       };
                  this.QueryString.Key.toString=function(){
                                                    Err(e2+".Key")
                                                };
                  this.Version=1.4;
                  this.Author="Andrew Urquhart (http://andrewu.co.uk)"};
                  var Request=new RObj(false);