

function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) 
	elem = document.getElementById( whichLayer );
	else if( document.all ) 
	elem = document.all[whichLayer];
	else if( document.layers ) 
	elem = document.layers[whichLayer];
	vis = elem.style;
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}





function showhide(layer_ref,state) {
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		try
		{
			eval( "document.all." + layer_ref + ".style.display = state");
		}
		catch(err)
		{
			//Handle errors here
		}
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		try
		{
			document.layers[layer_ref].display = state;
		}
		catch(err)
		{
			//Handle errors here
		}
	}
	if (document.getElementById &&!document.all) {
		try
		{
			document.getElementById(layer_ref).style.display = state;
		}
		catch(err)
		{
			//Handle errors here
		}


	}
}

function turn_all_off(){
  showhide("catalog_step","none");
	showhide("catalog_intro","none");
	showhide("catalog_shop_by","none");
	showhide("catalog_stock_form","none");
	showhide("catalog_category_name","none");
	showhide("catalog_category_image","none");
	showhide("catalog_category_description","none");
	showhide("category_product_form","none");
	showhide("catalog_product_price_list","none");
	showhide("catalog_product_options","none");
	showhide("catalog_product_total","none");
	showhide("catalog_shipping_address","none");
	showhide("catalog_shipping_method","none");
	showhide("catalog_uds_form","none");

}


function get_select_stock(category_id,site_id){
  var size_id_select = document.product_price_form.size_id ;
	var size_id= size_id_select.options[size_id_select.selectedIndex].value;
	set_to_loading("category_select_stock","Returning Available Stock...",'');
	var url_string = "ms="+new Date().getTime() + "&site_id="+site_id+"&category_id="+category_id+"&size_id="+size_id+"&action=stock";
	var html_string = "includes/ajax_return_selector.php?" + url_string;
	//alert(url_string);
	return_options(html_string,"category_select_stock","N");
	return false;
}

function get_select_color(category_id,site_id){
  var size_id_select = document.product_price_form.size_id ;
	var size_id= size_id_select.options[size_id_select.selectedIndex].value;
  var stock_id_select = document.product_price_form.stock_id ;
	var stock_id= stock_id_select.options[stock_id_select.selectedIndex].value;
	set_to_loading("category_select_color","Returning Available Colors...",'');
	var url_string = "ms="+new Date().getTime() + "&site_id="+site_id+"&category_id="+category_id+"&size_id="+size_id+"&action=color&stock_id="+stock_id;
	var html_string = "includes/ajax_return_selector.php?" + url_string;
	//alert(url_string);
	return_options(html_string,"category_select_color","N");
	return false;
}


function catalog_return_pricing(stock_id,color_id,size_id,category_id,site_id){

	var category_id= document.product_price_form.category_id.value;
	var site_id= document.product_price_form.site_id.value;

	var stock_id_select = document.product_price_form.stock_id ;
	var stock_id= stock_id_select.options[stock_id_select.selectedIndex].value;

	var color_id_select = document.product_price_form.color_id ;
	var color_id= color_id_select.options[color_id_select.selectedIndex].value;

	var size_id_select = document.product_price_form.size_id ;
	var size_id= size_id_select.options[size_id_select.selectedIndex].value;
	
	if ((stock_id == 0) || (size_id == 0) || (color_id == 0)){
	  alert ("Please select all options");
		return false;
	}

	turn_all_off();
	set_step_image("2");
	showhide("catalog_product_price_list","block");
	set_to_loading("catalog_product_price_list","<div class='catalog_loading'>One moment while we retrieve prices for you.<P><img src='/sites/39/images/loading3.gif'> ",'');


	var url_string = "ms="+new Date().getTime() + "&site_id="+site_id+"&category_id="+category_id+"&stock_id="+stock_id+"&color_id="+color_id+"&size_id="+size_id;
	var html_string = "includes/ajax_return_price_grid.php?" + url_string;

	return_options(html_string,"catalog_product_price_list","N");
	return false;
}

function catalog_return_pricing_url(stock_id,color_id,size_id,category_id,site_id){
	turn_all_off();
	showhide("catalog_product_price_list","block");
	set_to_loading("catalog_product_price_list","<div class='catalog_loading'>One moment while we retrieve prices for you.<P><img src='/sites/39/images/loading3.gif'> ",'');
	var url_string = "ms="+new Date().getTime() + "&site_id="+site_id+"&category_id="+category_id+"&stock_id="+stock_id+"&color_id="+color_id+"&size_id="+size_id;
	var html_string = "includes/ajax_return_price_grid.php?" + url_string;
	return_options(html_string,"catalog_product_price_list","N");
	return false;
}

var return_pricing_info;
var return_options_info;

function return_options(url_string,div,run_update){
	var xmlHttp=null;
	try {
		xmlHttp = new XMLHttpRequest(); 
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4)
		try {
			if (xmlHttp.status == 200) {
				if (div != "no_display_change"){
					document.getElementById(div).innerHTML  = xmlHttp.responseText;
				}
				if (run_update == "Y"){
					catalog_update_product_total();
				}
				return true;
			}
		} catch (e) {
			if (div != "no_display_change"){
				try {
					document.getElementById(div).innerHTML  = "Error retrieving Prices : " + e.description;
				}  catch (e) {

				}
			}
			return false;
		}

	}
	xmlHttp.open("get",url_string); // .open(RequestType, Source);
	xmlHttp.send(null); // Since there is no supplied form, null takes its place
}

function catalog_update_product_total(){
	showhide("catalog_product_types","none");
	showhide("catalog_product_totals","block");
	return_options("includes/ajax_return_product_total.php","catalog_product_totals","N");
}


function catalog_show_product_categories(){
	showhide("catalog_product_types","block");
	showhide("catalog_product_totals","none");
}



function catalog_get_product_options(url_string){
	turn_all_off();
	set_step_image("3");
	showhide("catalog_product_options","block");
	set_to_loading("catalog_product_options","<div class='catalog_loading'>One moment,  while we load our stocks available.<P><img src='/sites/39/images/loading3.gif'> ",'');
	var html_string = "includes/ajax_return_product_options.php?" + url_string;
	return_options(html_string,"catalog_product_options","Y");
	return false;
}


function catalog_product_options_change(option_type_id,option_id){
	var url_string = "ms="+new Date().getTime() + "&change_option=Y&option_id="+option_id+"&option_type_id="+option_type_id;
	var html_string = "includes/ajax_return_product_options.php?" + url_string;
	return_options(html_string, "no_display_change","Y");
}


function catalog_product_options(){
	turn_all_off();
	showhide('catalog_product_options','BLOCK');
	return false;
}

function catalog_shipping_options(){
	turn_all_off();
	showhide("catalog_shipping_address","BLOCK");
	set_step_image("4");
	catalog_ship_to_zip_form();
	return false;
}


function catalog_ship_to_zip_form(){
	try{
		var ship_to_zip = document.ship_to_zip_form.ship_to_zip.value;

		if (ship_to_zip != ""){
			document.getElementById("catalog_shipping_method").innerHTML = " <img src='/sites/39/images/loading3.gif'> Checking for available shipping methods...";
		} else {
			document.getElementById("catalog_shipping_method").innerHTML = "";
		}
	}catch(e){
		document.getElementById("catalog_shipping_method").innerHTML = "";
	}

	var url_string = "ms="+new Date().getTime() + "&ship_zip=Y";
	var html_string = "includes/ajax_return_ship_to_zip_form.php?" + url_string;
	return_options(html_string, "catalog_shipping_address","Y");
}

function catalog_get_shipping_methods(){
	var url_string = "ms="+new Date().getTime() + "&check_shipping=Y";
	var html_string = "includes/ajax_return_shipping_options.php?" + url_string;
	return_options(html_string, "catalog_shipping_method","Y");
}

function catalog_change_shipping(shipping_amount,ship_code,ship_method){
	var url_string = "ms="+new Date().getTime() + "&change_shipping=Y&shipping_amount="+shipping_amount+"&ship_code="+ship_code+"&ship_method="+escape(ship_method);
	var html_string = "includes/ajax_return_shipping_options.php?" + url_string;
	return_options(html_string, "no_display_change","Y");
}


function submit_ship_to(){
	var ship_to_address1= escape(document.ship_to_zip_form.ship_to_address1.value);
	var ship_to_address2 = escape(document.ship_to_zip_form.ship_to_address2.value);
	var ship_to_city = escape(document.ship_to_zip_form.ship_to_city.value);
	var ship_to_state = escape(document.ship_to_zip_form.ship_to_state.value);
	var ship_to_zip = escape(document.ship_to_zip_form.ship_to_zip.value);
	var url_string = "ms="+new Date().getTime() + "&check_shipping=Y&ship_to_address1=" + ship_to_address1 + "&ship_to_address2=" + ship_to_address2 + "&ship_to_city=" + ship_to_city +"&ship_to_state=" + ship_to_state +"&ship_to_zip=" + ship_to_zip   ;
	var html_string = "includes/ajax_return_ship_to_zip_form.php?" + url_string;
	return_options(html_string, "product_shipping_cost","Y");
	catalog_get_shipping_methods();
	return false;

}


function catalog_select_product(){
	turn_all_off();
	set_step_image("1");
	showhide("category_product_form","block");
	showhide("catalog_category_name","block");
	showhide("catalog_category_image","block");
	showhide("catalog_category_description","block");
	catalog_show_product_categories();
	return false;
}

function submit_ship_to_zip(){
	document.getElementById("catalog_shipping_method").innerHTML = "<img src='/sites/39/images/loading3.gif'> Retrieving Available Shipping Methods...";
	var ship_to_zip = document.ship_to_zip_form.ship_to_zip.value;
	var url_string = "ms="+new Date().getTime() + "&check_shipping=Y&ship_to_zip=" + ship_to_zip   ;
	var html_string = "includes/ajax_return_ship_to_zip_form.php?" + url_string;
	return_options(html_string, "product_shipping_cost","Y");
	catalog_get_shipping_methods();
	return false;

}

function catalog_product_options_change_custom_cut(product_option_id,custom_cut2){
	var custom_cut_select = document.product_options_form.custom_cut ;
	var custom_cut= custom_cut_select.options[custom_cut_select.selectedIndex].value;
	var custom_cut_width= document.product_options_form.custom_cut_width.value;
	var custom_cut_height= document.product_options_form.custom_cut_height.value;
	var url_string = "ms="+new Date().getTime() + "&change_custom_cut=Y&custom_cut="+custom_cut+"&custom_cut_width="+custom_cut_width+"&custom_cut_height="+custom_cut_height+"&product_option_id="+product_option_id;
	var html_string = "includes/ajax_set_custom_cut.php?" + url_string;
	return_options(html_string, "no_display_change","Y");


}


function catalog_product_form(category_id,stock_id,color_id,size_id){
	turn_all_off();
	set_step_image("1");
	showhide("catalog_product_form","block");
	set_to_loading("catalog_product_form","<div class='catalog_loading'>One moment while we load our product information.<P><img src='/sites/39/images/loading3.gif'> ",'');
	var url_string = "ms="+new Date().getTime() + "&category_id="+category_id  + "&stock_id="+stock_id  + "&color_id="+color_id  + "&size_id="+size_id;
	var html_string = "includes/ajax_product_form.php?" + url_string;
	return_options(html_string, "catalog_product_form","N");


}



function catalog_uds_stock_form(category_id,color_id,size_id,design_id){
	turn_all_off();
	showhide("catalog_uds_form","block");
	set_to_loading("catalog_uds_form","<div class='catalog_loading'>One moment while we load our stocks available.<P><img src='/sites/39/images/loading3.gif'> ",'');
	var url_string = "ms="+new Date().getTime() + "&category_id="+category_id   + "&color_id="+color_id  + "&size_id="+size_id+ "&design_id="+design_id;
	var html_string = "includes/ajax_return_stock_uds.php?" + url_string;
	return_options(html_string, "catalog_uds_form","N");

}



function catalog_stock_form(stock_id){
	turn_all_off();
	showhide("catalog_stock_form","block");
	set_to_loading("catalog_stock_form","<div class='catalog_loading'>One moment while load stock info.<P><img src='/sites/39/images/loading3.gif'> ",'');
	var url_string = "ms="+new Date().getTime() + "&stock_id="+stock_id;
	var html_string = "includes/ajax_stock_form.php?" + url_string;
	return_options(html_string, "catalog_stock_form","N");
}


function set_to_loading(div,info,image){
	document.getElementById(div).innerHTML = info;
}


//Catalog
function setJobName(new_job_name){
  new_job_name = escape(new_job_name);
	var url_string = "ms="+new Date().getTime() + "&label=job_name&info="+new_job_name;
	var html_string = "includes/ajax_change_job_info.php?" + url_string;
	return_options(html_string, "no_display_change","N");
}
function setJobNotes(new_job_notes){
  new_job_notes = escape(new_job_notes);
	var url_string = "ms="+new Date().getTime() + "&label=job_notes&info="+new_job_notes;
	var html_string = "includes/ajax_change_job_info.php?" + url_string;
	return_options(html_string, "no_display_change","N");
}


//Cart
function change_job_name(new_job_name,job_id){
	new_job_name = escape(new_job_name);
	var url_string = "ms="+new Date().getTime() + "&change_name=Y&new_job_name="+new_job_name+"&job_id="+job_id;
	var html_string = "includes/ajax_change_job_name.php?" + url_string;
	return_options(html_string, "no_display_change","N");
}
//Cart
function update_job_notes(cart_detail_id){

  var job_notes = escape(eval("document.form_"+cart_detail_id+".job_notes.value"));
	var job_notes_field = eval("document.form_"+cart_detail_id+".job_notes");
	
	var html_string = "includes/ajax_cart_update.php?ms="+new Date().getTime() + "&action=update_job_notes&cart_detail_id=" + cart_detail_id + "&job_notes=" + job_notes;
	return_options(html_string, "no_display_change","N");
		
}





function FuncShowHide(){
	var t= document.getElementById('table_price_grid').rows.length;
	for (var i=0; i<t; i++){
		if (document.getElementById('table_price_grid').rows[i].id == "trHIDE"){
			if (document.getElementById('table_price_grid').rows[i].style.display == document.getElementById('trVIEW').style.display){
				document.getElementById('table_price_grid').rows[i].style.display = "none";
				document.getElementById("catalog_price_grid_resize").innerHTML = "Click Here For Larger Quantities.";
			} else {
				document.getElementById('table_price_grid').rows[i].style.display = document.getElementById('trVIEW').style.display;
				document.getElementById("catalog_price_grid_resize").innerHTML = "Click Here To Hide Larger Quantities.";
			}
		}
	}


}


function ship_address_book(address_book_id, address_type){
	if (address_type == "ship_to_address"){
	             if (address_book_id == "0"){
		set_to_loading("ship_to_method","",'');
	             } else {
		set_to_loading("ship_to_method","<div class='catalog_loading'>Retrieving UPS Pricing...<P><img src='/sites/39/images/loading3.gif'> ",'');
	             }
	     }

	var url_string = "ms="+new Date().getTime() + "&change_address=Y&address_book_id="+address_book_id+"&address_type="+address_type;
	var html_string = "includes/ajax_change_ship_address_book.php?" + url_string;
	if (address_type == "ship_to_address"){
		return_options(html_string, "ship_to_method","Y");
		return true;
	} else {
		return_options(html_string, "no_display_change","Y");
		return true;
	}
}



function custom_address(address_form){

	var company= escape(eval("document."+address_form+".company.value"));
	var attention= escape(eval("document."+address_form+".attention.value"));
	var address1= escape(eval("document."+address_form+".address1.value"));
	var address2 = escape(eval("document."+address_form+".address2.value"));
	var city = escape(eval("document."+address_form+".city.value"));
	//var state =  escape(eval("document."+address_form+".state.value"));
	var zip =  escape(eval("document."+address_form+".zip.value"));
	var phone = escape(eval("document."+address_form+".phone.value"));
	
	var state_select =  eval("document."+address_form+".state");
	var state= state_select.options[state_select.selectedIndex].value;

	
	var country_select =  eval("document."+address_form+".country");
	var country= country_select.options[country_select.selectedIndex].value;

	var save_address = eval("document."+address_form+".save_address.checked");
	if (save_address == true){
	  save_address = "Y";
	} else {
	  save_address = "N";
	}
	
	
	if (address1 == ""){
		alert("Address 1 can not be blank.");
		return false;
	}
	if (city == ""){
		alert("City can not be blank.");
		return false;
	}
              if (state == ""){
		alert("State can not be blank.");
		return false;
	}
	  if (zip == ""){
		alert("Zip can not be blank.");
		return false;
	}
	var address_book_id = 0;
	var address_type = "custom";

	if (address_form == "ship_to_form_new"){
	  set_to_loading("ship_to_method","<div class='catalog_loading'>Retrieving UPS Pricing...<P><img src='/sites/39/images/loading3.gif'> ",'');
	}
	
	var url_string = "ms="+new Date().getTime() + "&check_shipping=Y&address_form="+address_form+"&address_book_id="+address_book_id+"&address_type="+address_type + "&company=" + company +"&attention=" + attention +"&address1=" + address1 + "&address2=" + address2 + "&city=" +city +"&state=" + state +"&zip=" +zip +"&country=" + country +"&phone=" + phone + "&save=" + save_address   ;
	var html_string = "includes/ajax_change_ship_address_book.php?" + url_string;

	return_options(html_string, "ship_to_method","Y");
	return true;
}



function set_step_image(image_id){
  if (image_id == "0"){
			  showhide("catalog_step","none");
		    set_to_loading("catalog_step","",'');
	       } else {
				
		   set_to_loading("catalog_step","<img src='sites/39/images/step"+image_id+".gif'>",'');
			 showhide("catalog_step","block"); 
	    }
	
}



function set_pms_color(id,color){
  var url_string = "ms="+new Date().getTime() + "&change_pms=Y&id="+id+"&color="+color;
	var html_string = "includes/ajax_set_pms.php?" + url_string;
	return_options(html_string, "no_display_change","N");
	return true;

}



function check_required_options(){  
  if (document.product_options_form.pms_color_1 == null || document.product_options_form.pms_color_1 == undefined) {
	  catalog_shipping_options();
    return true;
  } else {
	  var pms_1 = document.product_options_form.pms_color_1.value;
		if (pms_1 == ""){
			  alert("Need PMS Colors");
				return false;
  	} else {
	    // Passes So Far;
		}
  }
	
	
	 if (document.product_options_form.pms_color_2 == null || document.product_options_form.pms_color_2 == undefined) {
	  catalog_shipping_options();
    return true;
  } else {
	  var pms_2 = document.product_options_form.pms_color_2.value;
		if (pms_2 == ""){
			  alert("Need PMS Colors");
  	} else {
	    catalog_shipping_options();
      return true;
		}
  }
	
}

