$(document).ready(function(){
	fillSelect();
//	redirSelect();
});

function fillSelect(){
	  var oSelect = $("#stor-select");
	  $("#stor-select").selectbox();
//	  oSelect[0].options.add(new Option("Select a Store", ""));
//	  $.ajax({
//		type: "GET",
//	    url: "/ajax/async-getmerchant.php",
//	    dataType: "json",
//	    success: function(msg) {
//		  $.each(msg, function(i, n) {
//			  oSelect[0].options.add(new Option(n.Name, n.NameURL));
//		  });
//		  $("#stor-select").selectbox();
//	    }
//	  });	
}

function redirSelect(){
	$("#stor-select").bind("change", function(){
		urlBase = $(this).val();
		if (urlBase){
			document.location.href = "/" + urlBase + ".html";
		}
	}); 	
}

function chkSearch(){
	if($.trim($("#keywords").val()) == "" || $("#keywords").val() == "Store like Dell"){
		return false;
	}
	else {
		act = $("#search").attr("action");
		keyword = $("#keywords").val();
//		$("#search").attr("action", act + "/" + URLEncode(URLEncode(keyword)) + ".html");
		document.location.href = act + "/" + URLEncode(URLEncode(keyword)) + ".html";
		return false;
	}
}

function URLEncode(clearString) {
	  var output = '';
	  var x = 0;
	  clearString = clearString.toString();
	  var regex = /(^[a-zA-Z0-9-_.]*)/;
	  while (x < clearString.length) {
	    var match = regex.exec(clearString.substr(x));
	    if (match != null && match.length > 1 && match[1] != '') {
	    	output += match[1];
	      x += match[1].length;
	    } else {
	      if (clearString.substr(x, 1) == ' ')
	        output += '+';
	      else {
	        var charCode = clearString.charCodeAt(x);
	        var hexVal = charCode.toString(16);
	        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
	      }
	      x++;
	    }
	  }
	  return output;
}

function storeOver(obj) {
	obj.className='store over';
}

function storeOut(obj) {
	obj.className='store';
}

