var debug = false;

$(document).ready(function() {
	debugLog("common.document.ready()");
	initDocument();
});

function initDocument() {
	if ($("#customer").length>0) {
		$.ajax({
			url: "/ajax_customer.cfm",
			success: function(data){
				if (data!='') {
					$("#customer").html(data);
				}
			}
		});
        
        
	}
    setupGoogleTracking();
}

function loadRegion(parent_id, region_type, selected_id, div_name, callback) {
	$("#"+div_name).attr('disabled','disabled');
	if (typeof(selected_id)=="undefined") selected_id = 0;
	if (parent_id == -1) {
		$("#"+div_name).html("<option value='0' selected><"+"/option>");
	} else {
		$("#"+div_name).html("<option value='0' selected>Loading...<"+"/option>");
		$.ajax({
			url: "/ajax_getregions.cfm",
			type: "POST",
			data: {region_type: region_type, parent_id: parent_id, selected_id: selected_id},
			cache: false,
			dataType: "html",
			success: function(data, textStatus, XMLHttpRequest){
				$("#"+div_name).html(data);
				$("#"+div_name).attr('disabled','');
				if (typeof(callback)=="function") {
					callback();
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert('error\n XMLHttpRequest['+XMLHttpRequest+']\n textStatus['+textStatus+']\n errorThrown['+errorThrown+']');
			}
		});
	}
}

function showSecure(role){

    var userRole = role;
	
	$.ajax({
		url: "/add_securemenu.cfm",
		data: 'role='+userRole,
		dataType: 'text',
		type: 'post',
		success: function(data, textStatus, XMLHttpRequest){
			$('.id_main_menu').append(data);	
            setupSecureBox();
            
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			
		}
	});

}

function showSubSecure(role){

    var userRole = role;
	
	$.ajax({
		url: "/add_securesubmenu.cfm",
		data: 'role='+userRole,
		dataType: 'text',
		type: 'post',
		success: function(data, textStatus, XMLHttpRequest){
			$('#submenu .inner').append(data);	
            
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			
		}
	});

}

function setupGoogleTracking(){
//alert('hi');
    $('#products_list .product_thumb a').each(function(){
    
    $(this).attr('onclick', "google_Track_Event('External Website', 'Product Catalog', '"+$(this).attr('href')+"');");
    
    });

}
function google_Track_Event(category, action, label){

    _gaq.push(['_trackEvent', category, action, label]);

}


