/*******************************************************************************************************/
function eComInit(){
	$('form[name=srch]').submit(function(){
		//var c = $.query.get('c');
		//c = (c=='')?'-8':c;
		var lm = $.query.remove('l').set('s', $('#s').val()).set('c', -8).set('pg', 1).toString();
		location.href = lm;
		return false;
	});
	return false;
}

/*******************************************************************************************************/
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.href = newLocation;
				return false;
			}
		}
	});
	selectedCat = false;
	return false;
}
/*******************************************************************************************************/
function switchToListMode(toMode){
	var lm = $.query.set('lm', toMode).toString();
	location.href = lm;
	return false;
}
/*******************************************************************************************************/
function updateSort(srt){
	var s = $.query.set('srt', srt).set('pg', 1).toString();
	location.href = s;
	return false;
}
/*******************************************************************************************************/
function selectCat(CatID){
	var s = $.query.set('c', CatID).set('pg', 1).toString();
	location.href = s;
	return false;
}
/*******************************************************************************************************/
function rppChanged(rpp){
	var s = $.query.set('np', rpp).set('pg', 1).toString();
	location.href = s;
	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){
		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]; }
}
/*******************************************************************************************************/
