//Constructor
function QueryString(sQuery){ 

   //Privalege function
   this.getQuery = function (url){
      return url.substr(1);
   }
   
   this.parseQuery = function (){
      var sQuery = this.sQueryString;
      var aQueryArray = new Array();
      lQueryItem = sQuery.split("&");

      for (qi in lQueryItem) {

         atmp = lQueryItem[qi].split("=");
	 var amat = new Array(2);
	 aQueryArray[qi]=amat;
	 aQueryArray[qi][0]=atmp[0]
	 aQueryArray[qi][1]=atmp[1]
	 //document.write(aQueryArray[qi]);
	 //document.write("Name="+atmp[0]+" Value="+atmp[1]);
	 
      }
      return aQueryArray;
   }

   this.sQueryString = this.getQuery(sQuery)
};
//Make and discard dummy object so prototype is created
new QueryString("");

//Declare methods
function QueryString_createFields(type,fields){
   if(!fields){
      fields = new Array();
   }
   var sArr = new Array();
   var newArr = new Array();
   afields = this.parseQuery();
   for (f in fields) {
      for(ifp in afields){
         if(afields[ifp][0]==fields[f]){
	    //Found it save it...
	    newArr.push(afields[ifp]);
         }
      }   
   }
   afields = newArr;
   //ifp 0 is name and 1 is value
   if(type!="querystring"){
      for (ifp in afields){
         sArr[ifp] = "<input type=\""+type+"\" value=\""+afields[ifp][1]+"\" name=\""+afields[ifp][0]+"\">";

      }
      return sArr.join("\n");
   }else {
      for (ifp in afields){
         sArr[ifp]= ""+afields[ifp][0]+"="+afields[ifp][1];
      }
      return sArr.join("&");
   }
}

//Add methods to the prototype...
QueryString.prototype.createFields=QueryString_createFields;

