/**************************************************************/
var bs = false;
var ACore = {
xmlHttp:null,
waiting:0,
waitwith:new Array(),
 GetXmlHttpObject:function()
	{
		xmlHttp=null;
		try
			{
				// Firefox, Opera 8.0+, Safari
				xmlHttp=new XMLHttpRequest();
			}
		catch (e)
    		{
			// Internet Explorer
			try
				{
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
		return xmlHttp;
	},

    Wait:function(){

      if(ACore.waiting == 1)
        setTimeout("ACore.Wait()",200);
      else{
        if(this.waitwith.length > 0)
            ACore.Re_Call();
        }
    },

    Re_Call:function(){
        if(this.waitwith[0] != "")
            ACore.Ajax_Call(this.waitwith[0]);
        ACore.Crunch_Array(this.waitwith,0);
    },

    Crunch_Array:function(arra,des){
    var tempa = new Array();
    if(arra.length > 0){
        for(al=0;al<arra.length;al++){
           if(al == des){
             //alert(des);
           }
           else
            tempa[tempa.length] = arra[al];
        }
        this.waitwith = tempa;
    }
    else
       this.waitwith[0] = "";
       //if(this.waitwith.length < 1)
          //ACore.waiting = 0;
    },

    Ajax_Call:function (arra){
    if(ACore.waiting == 1){
    this.waitwith[this.waitwith.length] = arra.toString();
    ACore.Wait();
    }
    if(ACore.waiting == 0){
    ACore.waiting = 1;
    arra = ACore.Clean_Call(arra.toString());
    arra = arra.split(",");
    if(arra && arra.length > 0){
        var cash = Math.random();
        xmlHttp = ACore.GetXmlHttpObject();
        var url=arra[0];
        url = url+"?DB="+arra[1];
        url = url+"&fu="+arra[2];
        if(arra.length > 3){
            for(x=3;x<arra.length;x++){
                url = url+"&misc"+x+"="+arra[x];
            }
        }
        url = url+"&cash="+cash;
        //alert(url);
        xmlHttp.onreadystatechange=ACore.shoresult;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
        url = "";
     }
     else
        alert("Sorry, there are not enough items to make this request. Please try again.");
     }
        return true;
    },



     shoresult:function(){
    if(xmlHttp.readyState === 4){
    var sling = xmlHttp.responseText;
    if(sling != ""){
    var direct = sling.slice(0,1);//output to screen 0, or update a variable = 1, both == 2
    var uloc = sling.slice(1,4);//where in the screen to update, or what variable to update
    var rcount = Number(Math.round(sling.slice(4,8)));//number of updates returned
    var response = sling.slice(8,sling.length );//actual info to update or insert
    response = ACore.Fill_Call(response.toString());
    if(direct == "<"){
       if(document.getElementById("error"))
             document.getElementById("error").innerHTML = sling;
    }
    if(direct == 0){
        if(uloc == "con" || uloc == "ale"){
                   if(uloc == "con"){
                      if(rcount == 2){
                          var conf = confirm(response);
                            if(conf == true && FMJ[0].sync)
                                ACore.Ajax_Call('/BDB.php,stocksimo,5,0,'+FMJ[0].sync);
                            else
                                var dull = null;
                      }
                   }
                   if(uloc == "ale"){
                       alert(response);
                   }

                   if(uloc == "Err"){
                       if(document.getElementById("error"))
                        document.getElementById("error").innerHTML = response;
                   }
                }
                else{
                    if(uloc == "ref"){
                       window.location.href=window.location.href;
                    }
                    if(uloc == "uer"){
                        if(document.getElementById("sstat"))
                            document.getElementById("sstat").innerHTML = response;
                    }
                    else{
                      if(document.getElementById(uloc))
                        document.getElementById(uloc).innerHTML = response;
                    }
                 }


    }
    //alert(rcount+"--"+sling.slice(4,8));
    if(direct == 1 && rcount == 1){
    //alert(uloc);
        if(uloc == "iml")
            imglist = response;
        if(uloc == "bas"){
            basket = response;
            basket = basket.split("*|*");
            //alert(basket+"--"+basket.length);
            if(document.getElementById("sstat")){
                var BC = (basket[1] < 1)? "no items":basket[1]+" items";
                BC = (basket[1] == 1 )? "1 item":BC ;
                document.getElementById("sstat").innerHTML = "You have <br />"+BC+"<br /> in your basket.";
            }
            //document.getElementById(uloc).innerHTML = basket;
            }
        if(uloc == "lnk"){
           var win = window.open(("/popup.php?loc="+response), "PostitPage","width=5,status=0,toolbar=0,location=0,height=5,resizable=1,menubar=0");
            if(!win)
             alert('you appear to have a pop up blocker turned on in your browser. Please turn it off to complete your transaction.');
else{
//alert(response);
            window.location = "/";
//response;
//PostitPage.close();
//win.close();
}
        }

        if(uloc == "pro"){
            products = response;
            //alert(products);
        }
        if(uloc == "rad"){
            var ads = response.split("*|*");
           if(FMJ[0].CellMan)
            FMJ[0].CellMan.Load_Ads(ads);
        }

        if(uloc == "lad"){
            var ads = response.split("*|*");
           if(FMJ[0].CellMan)
            FMJ[0].CellMan.Load_Ad_Value(ads);
        }

        if(uloc == "dad"){
            var ad_avail = response.split("*|*");
           if(FMJ[0].CellMan){
            if(ad_avail[0] == "fail"){
                var productname = prompt("That name is in use, please rename your ad, or hit 'cancel' to overwrite ad named '"+ad_avail[1]+"'.","Ad Name");
                if(!productname){
                   document.interface.aname.value = ad_avail[2];
                   FMJ[0].CellMan.Finalize();
                }
                else{
                    document.interface.aname.selectedIndex = ad_avail[2];
                    document.interface.adname.value = productname;
                    ACore.Ajax_Call('/BDB.php,stocksimo,12,0,'+productname+",1");
                }
            }
            if(ad_avail[0] == "pass")
                FMJ[0].CellMan.Finalize();
           }
        }

        if(uloc == "cat"){
        //alert("out ajaxcore");
           //document.getElementById("category").innerHTML = response;
           var cats = response.split("*|*");
           if(FMJ[0].CellMan)
            FMJ[0].CellMan.Load_Cats(cats);
        }
        if(uloc == "pid"){      
            FMJ[0].adid = response;
            FMJ[0].CellMan.Check_Name(null,FMJ[0].adid);

        }
        if(uloc == "rpr"){
           var prods = response.split("*|*");
           if(FMJ[0].CellMan)
            FMJ[0].CellMan.Load_Product(prods);
        }
    }
    if(direct == 2){
          var coms = response.split("*|*");
          for(x=0;x<coms.length;x++){
            var d2 = coms[x].slice(0,1);//output to screen 0, or update a variable = 1, array == 2
            var u2 = coms[x].slice(1,4);//where in the screen to update, or what variable to update
            var up_d = coms[x].slice(8,sling.length );
            if(d2 === 0){
                if(u2 == "con" || u2 == "ale"){
                   if(u2 == "con"){

                   }
                   if(u2 == "ale"){

                   }
                   if(u2 == "bas"){

                   }
                }
                else{
                    if(document.getElementById(uloc))
                        document.getElementById(uloc).innerHTML = up_d;
                }
            }
            if(d2 == 1){
               if(u2 == "bas")
                basket[0] = coms[0];
               if(u2 == "udb"){
               basket[1] = coms[3];
                if(document.getElementById("sstat")){
                    var BC = (basket[1] < 1)? "no items":basket[1]+" items";
                    BC = (basket[1] == 1 )? "1 item":BC ;
                    document.getElementById("sstat").innerHTML = "You have<br /> "+BC+"<br /> in your basket.";

                }
                if(document.getElementById("bas") && basket[1] > 0 && bs == true)
                    document.getElementById("bas").innerHTML = basket[0];    
                bs = false;
    //else
        //document.getElementById("sstat").innerHTML = basket[0];
               }
            }
            if(d2 == 2){
                if(u2 == "tst"){
                    testimonials[testimonials.length] = up_d;
                }
                if(u2 == "art"){
                    articles[articles.length] = up_d;
                }
                //if(u2 == "pro"){
                    //var parray = up_d.split(",");
               //    products = upd;//[products.length] = new Array(parray[0],parray[1]);
               // }
            }
          }
          if(uloc == "tst"){
             initialize2();
          }
    }
    }
    else{
     alert("return content is empty");
    }
    ACore.waiting = 0;
    }

    return true;
    },


    Clean_Call:function(ar){
    var dirt = new Array();
    dirt["#"] = "$hash$";
    dirt["&"] = "$arro$";
    dirt["@"] = "$ampe$";
    dirt["?"] = "$ques$";
    dirt['"'] = "$dqou$";
    dirt["'"] = "$sqou$";
        for (i in dirt){
            while(ar.indexOf(i) > 0){
                ar = ar.replace(i,dirt[i]);
            }
        }
        /*
        while(ar.indexOf("#") > 0){
          ar = ar.replace("#","$hash$");
        }
        while(ar.indexOf("@") > 0){
          ar = ar.replace("@","$ampe$");
        }
        while(ar.indexOf("?") > 0){
          ar = ar.replace("?","$ques$");
        }

        while(ar.indexOf('"') > 0){
          ar = ar.replace('"',"$dqou$");
        }
        while(ar.indexOf("'") > 0){
          ar = ar.replace("'","$sqou$");
        }
        */
        /*
        while(ar.indexOf("") > 0){
          ar = ar.replace("","");
        }
        */
    return ar;
    },

    Fill_Call:function(ar){
        var dirt = new Array();
    dirt["$hash$"] = "#";
    dirt["$arro$"] = "@";
    dirt["$ampe$"] = "&";
    dirt["$ques$"] = "?";
    dirt["$dqou$"] = '"';
    dirt["$sqou$"] = "'";
        for (i in dirt){
            while(ar.indexOf(i) > 0){
                ar = ar.replace(i,dirt[i]);
            }
        }
    /*
        while(ar.indexOf("#") > 0){
          ar = ar.replace("#","$hash$");
        }
        while(ar.indexOf("@") > 0){
          ar = ar.replace("@","$ampe$");
        }
        while(ar.indexOf("?") > 0){
          ar = ar.replace("?","$ques$");
        }

        while(ar.indexOf('"') > 0){
          ar = ar.replace('"',"$dqou$");
        }
        while(ar.indexOf("'") > 0){
          ar = ar.replace("'","$sqou$");
        }
        */
        /*
        while(ar.indexOf("") > 0){
          ar = ar.replace("","");
        }
        */
    return ar;
    }
    }