function recordStoreVisit(merchantId, segId, name, url) {
	$.ajax({
		type: "POST",
		url: "controller.php",
		data: "Action=recordmerchantclick&segmentId="+segId+"&merchantId="+merchantId+"&pName="+name+"&pUrl="+url+"",
		success: function(msg){
			//alert(msg);	
		}
	});
}

function saveProduct(name,img,price,url,offer) {
	$.ajax({
		type: "POST",
		url: "controller.php",
		data: "Action=savesessionproduct&name="+name+"&img="+img+"&price="+price+"&url="+url+"&offerid="+offer+"",
		success: function(msg){
			$('#savedads').load('savedproducts.php');
			$('#savedadsright').load('savedproductsright.php');
		}
	});

        $('#savedadsright').show('slow');
        $('#aux_savedads').addClass('auxoptions-a-drop');
}

function deleteProduct(offer) {
	$.ajax({
		type: "POST",
		url: "controller.php",
		data: "Action=deletesessionproduct&offerid="+offer+"",
		success: function(msg){
			$('#savedads').load('savedproducts.php');
			$('#savedadsright').load('savedproductsright.php');
		}
	});
}

function clearHistory() {
	$.ajax({
		type: "POST",
		url: "controller.php",
		data: "Action=clearhistory",
		success: function(msg){
			$('#savedads').load('savedproducts.php');
			$('#savedadsright').load('savedproductsright.php');
			$('#recentads').load('recentproductsright.php');
			$('#resentsearches').load('recentsearchesright.php');
			
		}
	});
}

function showMenu(type, regionId, seg_cats) {
	//$('#__menu_popup_div').fadeIn('slow');
	
}

function close() {
	$('#__menu_popup_div').fadeOut('slow');
}

function showDiv(div) {
	$('#'+div).show();
}

function showAll() {
	document.forms.popluarproducts.submit();
}

function lTrim(str) {
	var space = 0;
	if (str.length != 0) {
		for (i = 0; i <= str.length - 1; i++) {
			if (escape(str.charAt(i)) == escape(" ")) {
				space++;
			} else {
				break;
			}
		}
		if (space > 0) {
			str = str.substring(space, str.length);
		}
	}
	return str;
}
function searchKeywordSubmit(message) {
		document.searchFormName.keywords.value=lTrim(document.searchFormName.keywords.value);
		if (document.searchFormName.keywords.value=="") {
			alert(message);
			document.searchFormName.keywords.focus();
		} else
			document.searchFormName.submit();
}

var phone = "+()- 0123456789";
var date = "-/0123456789";
var price = ".0123456789";
var number = "0123456789";
var nonzero = "123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
var alphanumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -0123456789.',\"";

function res(field,validationType){
	var w = "";
	for (i=0; i < field.value.length; i++) {
		x = field.value.charAt(i);
		if (validationType.indexOf(x,0) != -1)
			w += x;
	}
	field.value = w;
}

function toggleSavedAds(){

    $('#savedadsright').toggle('slow');
    $('#aux_savedads').toggleClass('auxoptions-a-drop');
}

function toggleRecentAds(){
    $('#recentads').toggle('slow');
    $('#aux_recentads').toggleClass('auxoptions-a-drop');
}
function toggleRecentSearches(){
    $('#resentsearches').toggle('slow');
    $('#aux_recentsearches').toggleClass('auxoptions-a-drop');
}
function showAllBox(){
    $('#savedadsright').show('slow');
    $('#recentads').show('slow');
    $('#resentsearches').show('slow');
    
    $('#aux_savedads').addClass('auxoptions-a-drop');
    $('#aux_recentads').addClass('auxoptions-a-drop');
    $('#aux_recentsearches').addClass('auxoptions-a-drop');
}
function hideAll(){
    $('#savedadsright').hide('slow');
    $('#recentads').hide('slow');
    $('#resentsearches').hide('slow');

    $('#aux_savedads').removeClass('auxoptions-a-drop');
    $('#aux_recentads').removeClass('auxoptions-a-drop');
    $('#aux_recentsearches').removeClass('auxoptions-a-drop');
}



function setHomePage(tUrl)
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
                document.body.setHomePage(tUrl);
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         }
         catch(e)
         {
                alert("this action is not supported by your browser. If you want to enable, please enter about:config in your address line, and change the value of signed.applets.codebase_principal_support to true");
         }
    }
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage',tUrl);
 }
}