//check this to know if scripts have been loaded
var base_functions = true;

// Defines the Accordion
function AccordionInit(menupos) {
	var accTitle = $$('.menu_title');
	var accmenu_items = $$('.menu_items');
	var pwAccordion = new Accordion(
		accTitle, accmenu_items, {
		
			onActive: function(tog){
				tog.addClass('selected');
				var accTitleOnOff = new Fx.Styles(tog, {wait: false, duration: 0});
				accTitleOnOff.start({
					'padding-left': 25,
					'background-position': '-175px'
				});
			},

			onBackground: function(tog){
				tog.removeClass('selected');
				var accTitleOnOff = new Fx.Styles(tog, {wait: false, duration: 0});
				accTitleOnOff.start({
					'background-position': '0px',
					'padding-left': 25
				});
			},
		
			alwaysHide: false,
			duration: 500,
			show: menupos
		}
	);

	// Mouse effects
	accTitle.each(function(div) {    
		var mouseFxs = new Fx.Styles(div, {duration: 250, wait: false});
		div.addEvents({
			'mouseover': function(){
				if (!div.hasClass('selected')) {
					mouseFxs.start({
						'padding-left': 25
					});
				}
			},
			'mouseout': function(){
				if (!div.hasClass('selected')) {
					mouseFxs.start({
						'padding-left': 25
					});
				}
			}
		});
	});
}

function AccordionInit2(sid) {
	
	if (Cookie.get("pmenupos_" + sid) == false) {
		var pmenupos = 0;
	} else {
		var pmenupos = Cookie.get("pmenupos_" + sid).toInt();
	}

	var accTitle = $$('.product_title');
	var accmenu_items = $$('.product_items');
	var pwAccordion = new Accordion(
		accTitle, accmenu_items, {
			onActive: function(tog){
				tog.addClass('selected');
				var accTitleOnOff = new Fx.Styles(tog, {wait: false, duration: 0});
				accTitleOnOff.start({
					'padding-left': 25,
					'background-position': '-573px'
				});
			},

			onBackground: function(tog){
				tog.removeClass('selected');
				var accTitleOnOff = new Fx.Styles(tog, {wait: false, duration: 0});
				accTitleOnOff.start({
					'background-position': '0px',
					'width': '548px',
					'padding-left': 25
				});
			},
		
			alwaysHide: false,
			duration: 500,
			show: pmenupos
		}
	);

}

function live_chat() {
	window.open('https://www.ajmoss.com/livehelp/connector.php','new','width=650,height=600,screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=no');
}

function fabric_samples(patternID) {
	window.open('https://www.ajmoss.com/request_fabric_sample.php?patternID=' + patternID,'new','width=650,height=500,screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=yes');
}

function zoom(sid,width,height) {
	var wheight = height+30;
	var wwidth = width+25;
	window.open('/zoom.php?sid=' + sid + '&width=' + width + '&height=' + height,'new','width=' + wwidth + ',height=' + wheight + ',screenX=80%,screenY=80%,top=15%,left=15%,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function zoom_x(xid,width,height) {
	var wheight = height+30;
	var wwidth = width+25;
	window.open('/zoom.php?xid=' + xid + '&width=' + width + '&height=' + height ,'new','width=' + wwidth + ',height=' + wheight + ',screenX=80%,screenY=80%,top=15%,left=15%,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
}
function price_beat() {
	window.open('https://www.ajmoss.com/price-beat.php','new','width=600,height=450,screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=yes');	
}
function full_image(path,width,height) {
	window.open('/fullimage.php?src=' + path,'new','width=' + width + ',height=' + height + ',screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=no');
}
function product_review(vid,uid) {
	window.open('/product_review.php?vid=' + vid + '&uid=' + uid,'new','width=635,height=450,screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=yes,resizable=yes');
}
function swatch_image(path,width,height) {
	window.open('/swatchimage.php?src=' + path + '&width=' + width + '&height=' + height,'new','width=' + width + ',height=' + height + ',screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=no');
}
function menupos(menu) {
	Cookie.remove("menupos");
	Cookie.set("menupos", menu, {duration: false, path: "/" });
}
function symMoodal(href,title,width,height) {
	if (typeof( window[ 'SymRealWinOpen' ] ) != "undefined") {
		window.open(href,'new','width=' + width + ',height=' + height + ',screenX=80%,screenY=80%,top=15%,left=15%,scrollbars=no');
	} else {
		MOOdalBox.open(href,title,'moodalbox ' + width + ' ' + height);
	}
}
function symSlide(urlstring) {
	if (typeof( window[ 'SymRealWinOpen' ] ) != "undefined") {
		document.write('<br />');
	} else {
		document.write('<div class="ig_launcher"><a rel="moodalbox 650 500" href="/image_gallery/?' + urlstring + '"><span>View a Photo Slideshow of this Collection</span></a></div>');
	}
}
function countdown() {
	$$('#countdown').each(function(el) {
			new Ajax('/ajax_new.php?countcoupon=true', {
			update: 'countdown',
			evalScripts: false,
			onComplete: function() { 
				setTimeout("countdown()",60000);
			}
		}).request();
	}); 
}

function updateShipdate(id,pid,pv,qt,vint,sint,pint) {
	if (qt != '') {
		$('est_ship_' + id).setHTML('<i>Recalculating . . . </i>');
	
		var postBody = 'mode=recalc&id=' + id + '&pid=' + pid + '&pVendor=' + pv + '&qt=' + qt + '&vint=' + vint + '&sint=' + sint + '&pint=' + pint;
		new Ajax('/ajax_modules/shipdate.php', {
			update: 'est_ship_' + id,
			method: 'post',
			postBody: postBody,
			evalScripts: false
		}).request();	
	}
}

function registry_check() {
	$('emailconfirm').setProperty('value',$('registry_text').getValue());
	return true;
}

function price_match(id) {
	MOOdalBox.open('/price_match.php?id=' + id,'Aj MOSS 105% Price Match Guarantee','moodalbox 725 450');
}

function price_match_instructions() {
	MOOdalBox.open('/price_match_instructions.php','Aj MOSS 105% Price Match Guarantee','moodalbox 725 450');
}

function price_match_submit() {
	$('results').setHTML('<img src="/moodalbox/img/loading.gif" />');
	var cprice = $('price_match_price').getValue(); 
	var theurl = $('url').getValue(); 
	var theid = $('theid').getValue(); 
	if (cprice == '') {
		$('price_match_price').setStyle('border-color','#CC0000');
		$('results').setHTML('<span style="color: #CC0000;">Please enter the competitor\'s price</span>');
	} else if (theurl == '') {
		$('results').setHTML('<span style="color: #CC0000;">You must enter the web page url where we can verify the price match</span>');
		$('url').setStyle('border-color','#CC0000');		
	} else {
		var postBody = 'mode=price_match&theid=' + theid + '&cprice=' + urlencode(cprice) + '&url=' + urlencode(theurl);
		new Ajax('/price_match.php', {
			method: 'post',
			update: 'response',
			postBody: postBody,
			evalScripts: false,
			onComplete: function() { 
				var response = $('response').innerHTML;
				if (response == 'Success') {
					window.location = '/cart.php';
				} else {
					$('results').setHTML('<span style="color: #CC0000;">' + response + '</span>');
				}
			}
		}).request();	
	}
	
}

function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}
