/*******************************************************************************************************/
var listingLoaded = false;
function eComInitCatTree(selectedCat){
	var caturl = 'include/cats.php?mtd=cats';
	$('#MyDivTag').tree({
		data : { type : 'html', opts : { url : caturl } },
		selected: selectedCat, ui: { context: false, theme_path : '/js/themes/', theme_name: 'mystore', animation : 500 },
		types : { "default" : { draggable : false } },
		callback: {
			onchange : function (NODE) {
				if(String(location).indexOf('l=') > 0 && listingLoaded==false){ listingLoaded = true; return false; }
				// this line is in here because otherwise IE will keep ‘loading’ the page in a F*cked up way
				if(String(location).indexOf('c='+$(NODE).attr('id')) > 0){ return false; }
				var newLocation = '?c='+$(NODE).attr('id');
				location.replace(newLocation);
				return false;
			}
		}
	});
	selectedCat = false;
	return false;
}
/*******************************************************************************************************/
function switchToListMode(toMode){
	var lm = $.query.set('lm', toMode).toString();
	location.replace(lm);
	return false;
}
/*******************************************************************************************************/
function initCartDialog(){
	$('form.cart_form').submit(function(){
		var url = '/cart_action.php';
		url += ($('input[name=order_code]', this).length > 0)?'?order_code='+$('input[name=order_code]', this).val():'';
		url += ($('input[name=quantity]', this).length > 0)?'&quantity='+$('input[name=quantity]', this).val():'';
		var iframe = '<iframe frameborder="0" hspace="0" src="'+url+'" style="width:100%; height:100%;"></iframe>';
		$('#dialog').empty().append(iframe);
		$('#dialog').dialog({
			modal: true,
			width:780,
			height:500,
			position:'center',
			title:'Shopping Cart',
			resizable:false
		});
		return false;
	});
	return false;
}
/*******************************************************************************************************/
function mmSubscribe(){
	if($('#mmEmail').length <= 0){
		alert('Email Address Textbox is missing, please contact the Website Administrator to let them know');
		return false;
	}
	if($('#mmEmail').val() == ''){
		alert('Please enter an Email Address and Try Again');
		return false;
	}
	$('#SubscribeBtn').attr('disabled', 'disabled');
	var o = Array('mmEmail', 'mmFirstName', 'mmLastName', 'mmCountry', 'mmSource');
	var optional = Array();
	for(var i = 0; i < o.length; i++){
		if($('#'+o[i]).length > 0){
			optional[o[i]] = $('#'+o[i]).val();
		}else{
			optional[o[i]] = '';
		}
	}
	$.post('include/mm.php', { mtd:'SubscribeContact', Email:optional['mmEmail'], FirstName:optional['mmFirstName'], LastName:optional['mmLastName'], CountryCode:optional['mmCountry'], Source:optional['mmSource'] },
	function(data){ //alert(data);
		var dat = data.split(':');
		switch(dat[0]){
			case 'Success':
				if(dat[1] == '807'){
					alert('Your Email Address already exists in our Mailing List');
				}else{
					alert('Thank You for Subscribing to our Mailing List');
				}
				for(i = 0; i < o.length; i++){
					if($('#'+o[i]).length > 0){
						$('#'+o[i]).val('');
					}
				}
			break;
			case 'Failure':
				alert(dat[3]);
			break;
			default:
				alert('Error! ['+data+']');
			break;
		}
		$('#SubscribeBtn').attr('disabled', '');
		return false;
	});
	return false;
}
/*******************************************************************************************************/
function eCom_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.eCom_imgs) d.eCom_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.eCom_imgs[i]=new Image; d.eCom_imgs[i].src=a[i]; }
}
/*******************************************************************************************************/
