// Creating XML HTTP Request Object
var xhr = null;
function createRequestSort() {
	try {
		xhr = new XMLHttpRequest();
	}
	catch (trymicrosoft) {
		try {
			xhr = new ActiveXObject("Msxm12.XMLHTTP");
		}
		catch (othermicrosoft) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				xhr = null;
			}
		}
	}
	if(xhr == null) {
		
	}
}


function sortIt(target,fetchURL)
{
	createRequestSort();
	var tab_body_obj = document.getElementById(target);
	if(!document.getElementById('sortWaitBox'))
	{
	var waitAnimBox = document.createElement("div");
	waitAnimBox.setAttribute("id","sortWaitBox");
	tab_body_obj.appendChild(waitAnimBox);

	var waitBox = document.getElementById("sortWaitBox");
	scrWd = waitBox.parentNode.offsetWidth;
	animX = (scrWd/2)-100;
	waitBox.style.display = "none";
	waitBox.style.position = "absolute";
	waitBox.style.border = "1px solid gray";
	waitBox.style.left = animX+"px";
	waitBox.style.top = "270px";
	waitBox.style.zIndex = "100";
	waitBox.style.width = "200px";
	waitBox.style.height = "100px";
	waitBox.style.background = "#ffffff";
	waitBox.style.textAlign = "center";
	var waitAnimImg = document.createElement("img");
	waitAnimImg.setAttribute("id","sortAnim");
	waitAnimImg.setAttribute("src","/stores/all/images/ajax-loader.gif");
	waitBox.appendChild(waitAnimImg);
	var waitAnim = document.getElementById("sortAnim");
	waitAnim.style.margin = "10px 0 10px 0";
	var waitAnimText = document.createElement("div");
	waitAnimText.innerHTML="<strong>Loading... please wait!</strong>";
	waitBox.appendChild(waitAnimText);
	}
	xhr.onreadystatechange  = function()
    	{
		if(xhr.readyState < 4)
		{
			if(waitBox)
				waitBox.style.display = "block";
		}
		
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) 
                 {
		  tab_body_obj.innerHTML=xhr.responseText;
		   CheckFav();
		 }  
              else 
                 tab_body_obj.innerHTML=xhr.status;
         }
    }; 
	xhr.open('GET',fetchURL,true); 
   	xhr.send(null);
	
}
function CheckFav(){
    $("div.fav-s").click(function(){
		var store_name = $(this).attr('id');
		var store_id = $(this).attr('lang');
		checkAdd($(this) , store_id , store_name);
	});
	$("div.fav-n").click(function(){
		var store_name = $(this).attr('id');
		var store_id = $(this).attr('lang');
		checkAdd($(this) , store_id , store_name);
	});
}

