// predefine

attr_id = '0';
attr_disp = '';
product_id = '';
product_view = 1;
tab_query = '';
addtocart_off_msg = 'Please select a size<br />before adding this item<br /> to your cart';
addtocart_on_msg = 'Add this item<br />to your cart.';
whichmsg = 'off';

// for tool tip library

var domTT_styleClass = 'domTTOverlib';
var domTT_oneOnly = true;

function dispatch(myelementid,url,querystring,formid) {
	if (formid == '') {
		new Ajax.Updater(myelementid,url,{method: 'get',onComplete:function(){ new Effect.Appear(myelementid);},parameters: querystring,asynchronous:true, evalScripts:true});
	} else {
		new Ajax.Updater(myelementid,url,{onComplete:function(){ new Effect.Appear(myelementid);},parameters: $(formid).serialize(true) + '&' + querystring,asynchronous:true, evalScripts:true});
	}
}

function custom(this_product_id,prodsrc,toggle,base_id,dec_id,desc_id,desc,zoom_image_new,zoom_image2_new,product_image1_new,thumb1_new,product_image2_new,thumb2_new) {
	domTT_close('[domTT]' + toggle);
	zoom_source1 = zoom_image_new;
	zoom_source2 = zoom_image2_new;
	if (product_view == 1)
	{
		document.getElementById('zoom_box').src = zoom_source1;
		document.getElementById('zoom_preload').src = zoom_source2;
	}
	if (product_view == 2)
	{
		document.getElementById('zoom_box').src = zoom_source2;
		document.getElementById('zoom_preload').src = zoom_source1;
	}
	prod_image1 = product_image1_new;
	prod_image2 = product_image2_new;
	var myelementid = 'ajax_panel';
	var url = '/ajax/update_panel';
	changeStyle(toggle,'swatch');
	if (base_id != '') {
		changeStyleID(base_id,'swatch_on');
	}
	if (dec_id != '') {
		changeStyleID(dec_id,'d_swatch_on');
	}
	document.getElementById(desc_id).innerHTML = desc;
	if (product_view == 1) {
		document.getElementById('large_product_clothing').src=prodsrc;
	}
	if (product_view == 2) {
		document.getElementById('large_product_clothing').src=prod_image2;
	}
	document.getElementById('thumb_1').src=thumb1_new;
	document.getElementById('thumb_2').src=thumb2_new;
	document.getElementById('thumb_1_popup').src=thumb1_new;
	document.getElementById('thumb_2_popup').src=thumb2_new;
	product_id = this_product_id;
	tab_query='custom_product_id=' + product_id + '&ajax=1&attr_id=' + attr_id + '&attr_disp=' + attr_disp;
	dispatch(myelementid,url,tab_query,'');

	
}

function pickAttribute(attribute,toggle,display) {
	attr_id = toggle;
	attr_disp = display;
	changeStyle('attr_on','attr');
	changeStyleID(toggle,'attr_on');
	document.add_cart_form.sku_id.value = attribute;
	offButton();
	tab_query='custom_product_id=' + product_id + '&attr_id=' + attr_id + '&attr_disp=' + attr_disp;
	document.getElementById('selected_size').innerHTML = display;
	Div1 = document.getElementById("no_stock_attr");
        Div1.style.display = "none";
        Div2 = document.getElementById("no_stock_discontinued");
        Div2.style.display = "none";
}

function changeStyle(newclassname,oldclassname){
	var toggles = document.getElementsByClassName(newclassname);
	for (var i = 0, j = toggles.length; i < j; i++){
		toggles[i].className=oldclassname;
	}
}

function changeStyleID(newid,newclassname){
	document.getElementById(newid).className = newclassname;
}

function toggleDiv(divName) {
    thisDiv = document.getElementById(divName);
    if (thisDiv) {
        if (thisDiv.style.display == "none") {
            thisDiv.style.display = "block";
        } else {
            thisDiv.style.display = "none";
        }
    }
}

function offButton() {
	var button = document.getElementById('add_cart_button');
	if (document.forms.add_cart_form.sku_id.value == "") {
		button.className="disabled";
	} else {
		button.className="add";
		domTT_update('add_cart_button',addtocart_on_msg)
	}
}

function switchtab(personalize,other,default_id) {
	document.getElementById('ajax_tab_personalize').className = 'ajax_tab_' + personalize;
	document.getElementById('ajax_tab_other').className = 'ajax_tab_' + other;
	if (product_id == '') {
		product_id = default_id;
	}
 	if (document.getElementById('ajax_tab_other').className == 'ajax_tab_on') {
 		var myelementid = 'ajax_panel';
		var url = '/ajax/update_panel';
		tab_query='custom_product_id=' + product_id + '&ajax=2&attr_id=' + attr_id + '&attr_disp=' + attr_disp;
		dispatch(myelementid,url,tab_query,'');
 	} else {
 		tab_query='custom_product_id=' + product_id + '&ajax=1&attr_id=' + attr_id + '&attr_disp=' + attr_disp;
 		var myelementid = 'ajax_panel';
		var url = '/ajax/update_panel';
		dispatch(myelementid,url,tab_query,'');
 	}
}

function zoom() {
	document.getElementById('ajax_layer').style.visibility="visible";
	if (typeof document.all != "undefined") // for IE only
	{
		document.getElementById('darkenBackground').style.height = document.documentElement.clientHeight;
		document.getElementById('darkenBackground').style.width = document.documentElement.clientWidth;
	}
	document.getElementById('darkenBackground').style.visibility="visible";
	
}

function hidezoom() {
	document.getElementById('ajax_layer').style.visibility="hidden";
	document.getElementById('darkenBackground').style.visibility="hidden";
}

function switchview(source,border,view) {
	document.getElementById('large_product_clothing').src = source;
	if (view == 1)
	{
		document.getElementById('zoom_box').src = zoom_source1;
	}
	else
	{
		document.getElementById('zoom_box').src = zoom_source2;
	}
	if (border == 1) {
		document.getElementById('large_product_clothing').style.borderColor = "black";
	} else {
		document.getElementById('large_product_clothing').style.borderColor = "white";
	}
	product_view = view;
}

function test_submit() {
        if (document.forms.add_cart_form.sku_id.value != "") {
                document.add_cart_form.submit();
	}
}

function showAttrDiv(attribute,toggle,display) {
	document.add_cart_form.no_sku_id.value = attribute;
	document.add_cart_form.sku_id.value = "";
	otherDiv = document.getElementById("no_stock_discontinued");
 	otherDiv.style.display = "none";
	thisDiv = document.getElementById("no_stock_attr");
	thisDiv.style.display = "block";
	document.getElementById('selected_size').innerHTML = "None Selected"
	document.getElementById('no_selected_size').innerHTML = display;
	offButton();
}

function showDisContinued(attribute,toggle,display) {
        document.add_cart_form.no_sku_id.value = attribute;
	document.add_cart_form.sku_id.value = "";
	otherDiv = document.getElementById("no_stock_attr");
        otherDiv.style.display = "none";
	thisDiv = document.getElementById("no_stock_discontinued");
        thisDiv.style.display = "block";
	document.getElementById('selected_size').innerHTML = "None Selected";
	offButton();
}

function SubscribeSize(item_type,alert_type) {
	var querystring = 'sku_id=' + document.add_cart_form.no_sku_id.value + '&item_type=' + item_type + '&alert_type=' + alert_type + '&email_addr=' +  document.add_cart_form.email_addr.value;
	
	myAjax = new Ajax.Updater ('no_stock_attr','/ajax/subscribe_sku',{
                method: 'post',
                asynchronous: true,
                parameters: querystring,
                evalScripts: true
        });
}

function SubscribeClass(class_id,alert_type) {
        var querystring = 'class_id=' + class_id + '&alert_type=' + alert_type + '&email_addr=' +  document.signup_class.email_addr.value;

        myAjax = new Ajax.Updater ('signupclass','/ajax/subscribe_class',{
                method: 'post',
                asynchronous: true,
                parameters: querystring,
                evalScripts: true
        });
}

function seeNoAttr() {
	var querystring = "/SKU-" + document.add_cart_form.no_sku_id.value;
	window.location = querystring;
}
