var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
theme_path = '/Skins/1.3';
// This is a sample comment. 

var cartcount = 0; 

$(document).ready(function() {
	
	
	highlight_current_links(); 
	processPage(PageName);
	
	
	$('a.menunavigationclickstyle').mouseover(function() {
		$(this).next().show();	
	});
	
	// Set the Navigation To Drop Down and Start the Timer
	$('#ultopnav > li').bind('mouseover', jsddm_open);
   	$('#ultopnav > li').bind('mouseout',  jsddm_timer);
	document.onclick = jsddm_close;
	
	// Overide Search Box Default Inputs
	
	
	search_mod();
	//js_monitor_search();

	// Mailing List Setup 
	$('#mc-embedded-subscribe').click(function() {
		mailchimp_subscribe();	
	});
	

	// Just incase some Bad HTML exists, make sure the Footer is under the Content Part
	$('#contentPart').after($('#footerPart'));
	
	// General Error Catcher
	
	// Check Login
	if($('#Logout_Header0__QLink').html()=="Login") {
		$('#HLink3_head0__QLink').html("Register");
	}
	
	
	//$('#ShoppingBagLogo_head0__QLink').html($('#ShoppingBagLogo_head0__QLink').html()+' ('+get_cart_count()+')');
	
	presentError();
	
	zip_navigation();
	
	
	
	
	
});


// One Page Checkout
function page_onepagecheckout() {
	
	// Add Header Labels to each of the Formfields
	$('.methodofpaymentelementfields').prepend("<h2>Method of Payment</h2>");
	$('.billingaddresstitlestyle').prepend("<h2>Billing Address</h2>");
	$('.shippingaddresscontrolfields').prepend("<h2>Shipping Address</h2>");
	
	$('.dvBillingAddressTemplateDisplay').each(function() { 
		$('span:first',$(this)).remove();
	});
	
	$('#BillingAddressDetail_m_AddressList').parent().attr("style",'');
	$('#CheckOutBillingAddressContainer h2').append($('#EditBillingAddress1_EditBillingAddress1'));
	$('#QShippingControl1_dvshippingaddress').append($('#QShippingControl1_dvEditAlternateAddress'));
	$('#SingleShipToAddressContainer h2').append($('#MultipleShipping_MultipleShipping'));
	
	showCheckoutProcess('payment-type');
	$('#CreditCardInfo_txtCreditCardSecurityNumber').focus();
	
		$('fieldset.sourcecodefields').prepend("<h2></h2>");
	$('fieldset.sourcecodefields h2').append($('.sourcecodetitle')); 
	$('fieldset.discountelementfields').prepend("<h2>Have a Gift Certificate?</h2>");
	
	
}


// Login and Account Page
function page_onepageaccount() {
//	loadjscssfile('http://commerceapi.com/themes/zipproducts-v1.2/controllers/onepageaccount.js',"js");
	
	// Comment out this line when the site has been live long enough, that previous users have new passwords.
	
	//$('#ui_account_container').prepend("<div id='new-system-email'>Notice: We have recently upgraded our website software, if you have ordered with us before you have been issued a new password. <a href='"+$('#ForgotPassword0__QLink').attr('href')+"'> Please click here to receive it.</a></div>");
	
	
	$('.loginfields').append($('#btnLogIn input'));
	$('.loginfields').append($('#ForgotPassword0__QLink'));
	$('fieldset.billingaddressfields').prepend("<h2>Billing Address</h2>");
	
	$('fieldset.sourcecodefields').prepend("<h2></h2>");
	$('fieldset.sourcecodefields h2').append($('.sourcecodetitle')); 
	$('fieldset.discountelementfields').prepend("<h2>Have a Gift Certificate?</h2>");
	
	$('#dvShippingAddress').prepend($('#ShippingMethodViewContainer'));
	// Determine what the ACTION is. Check out or My Account
	if(getURLParam('Action')!=null) {
		var action = getURLParam('Action');
		if(action=="MYACCOUNT") {
			$('#CreditCardPanel span').each(function() {
				updatedLabel = $(this).html().replace("*","");
				$(this).html(updatedLabel);
				
			});
			
			insertBreadcrumb("My Account");
			$('#Continue_Continue').val("Create Account");
			$('#CreditCardPanel').prepend("<h2>Optional for Faster Checkout</h2>");
		}	else {
			insertBreadcrumb("Check Out");
			$('#Continue_Continue').val("Continue with Checkout");
			$('#CreditCardPanel').prepend("<h2>REQUIRED for Checkout</h2>");
		}
	}
	
	// Preselect Country - Default to USA 
	$('#Country__BillingAddressCountryData option').each(function() {
		if($(this).html()=="United States") {
			$(this).attr('selected',true);	
			loadStateProvince();
			OnCountryChangeNotify($(this).val());
		} else { 
			$(this).removeAttr('selected');
		}
		
	});
	
	$('#POBoxAddress').parent().addClass('POBoxLabel');

	$('#PreferredShipmetTypeText').parent().addClass("shipping-required");
	
	shipping_same_old = $('#CHBSSB').parent("div");
	$('#CHBSSB').parent("div").before("<div id='shipping_same_container'></div>");
	$('#shipping_same_container').append($('#CHBSSB'));
	shipping_same_old.remove();
	
	
	$('.shippingaddresseditfields').height($('.billingaddressfields').height());
	
	/// Set The Limit on the Number of Emails that the User has to populate
	// Copy Email Addresses 
	$('#Email').keyup(function() {
		$('#AddressEmail').val($(this).val()); 	
		$('#ReenterEmail').val($(this).val()); 	
	});
	
	$('#ReenterEmail').parent().hide();

	var objForm = document.forms[0]; 

	// Set the Event if the user hits ENTER while in the password field - then submit the login form.
	$('#txtPassword').keypress(function(e) {
		if (e.keyCode == 13) {
			if(ValidateLogIn())
				{__doPostBack('btnLogIn$EventHandler','')
			}
			return false;
		}
	});
	
	/// Lets try to automatically select some things
	$(document).ready(function() {
		$('#CHBSSB').click();	
		
		// Preselect Country - Default to USA 
		
		
		
	});
	
	$(document).ready(function() {
			$('.billingaddresstextfieldstyle option').each(function() {
				if($(this).html()=="Ground") {
					$(this).attr('selected',true);	
				} else { 
				//	$(this).removeAttr('selected');
				}
				
			});
		});



}

// HOME 
function page_homepage() {
	
	$('.Products').productClean();	
	
	
	/// Clean up the RSS Feed Descriptions 
	
	$('.feed-description').each(function() {
		newdescription = $(this).html();
		lastspace = newdescription.lastIndexOf(" ");
		newdescription = $(this).html().substr(0,lastspace);
		$(this).html(newdescription+'...');
	});
	
}

// Shopping Cart
function page_shoppingcart() {
	$('.Products').productClean();	
	
	$('td[colspan=10]').parent().addClass("empty");
	$('#SubTotal').parent().parent().addClass("subtotal-row");
	
	if($('#InnerTableShoppingcart').length==0) {
		// Its an Empty Cart;
		$('#ui_buttons').hide();	
	}
	
	$('.item_number').each(function() {
		sku = $(this).html().replace("Item # ","");
		$(this).html('<a href="/VP.aspx?number='+sku+'">'+sku+'</a>');	
	});
	
	set_cart_count($('.item_title').length);
	
	showCheckoutProcess('view-cart');
	
	$('div.shoppingcart #InnerTableShoppingcart tr').addClass('active_row');
	
	/// Fix Input Fields
	
	$('.shoppingcartqty input.shoppingcarttextstyle').each(function() {
		$(this).after(" <a href='#' class='update-qty'>Update</a>");
		$('.update-qty',$(this).parent()).click(function() {
			
			 canSubmit = validateAllQuantities();
				if( canSubmit )
				{
					IsFormSubmitted = true;
					__doPostBack('UpdateQty','');
				}
				else
				{
					return false;
				}

		});
	});
	
	
	$('.shoppingcartmove').each(function() {
		
		//$('a',$(this)).eq(1).remove();
		removelink = $('a',$(this)).eq(0);
		$(this).html("");
		$(this).append(removelink);
		
	});
	
	$('#InnerTableShoppingcart').attr("cellspacing",0);
	$('#InnerTableShoppingcart').attr("cellpadding",5);
	$('#InnerTableShoppingcart td').attr("valign","middle");
	js_fix_broken_images('small');	
}

function page_multipleshipping() {
	showCheckoutProcess('payment-type');
	
}

// Style Master Item
function page_stylemasteritem() {
	js_product();
}

// Physical Item
function page_physicalitem() {
	js_product();
	
}

function page_statickititem() {
	page_configurablekititem();

}



function page_configurablekititem() { 
	
	
	
	// Clean up Descriptions
	$('.kit-component-description').each(function() {
		$('div',$(this)).each(function(i) {
			$(this).addClass('div-'+i);
		});
	});
	
	$('.kit-component-quantity input').each(function() {
			$(this).after("<span class='qty-string'>"+$(this).val()+"</span>");	
	});
	
	$('.kit-component-quantity .kitcomplabelstyle').hide();
	
	js_product();

}


function page_grouplevel2() {
	js_group();	

}
function page_grouplevel1() {
	js_group();	
}
function page_groupresults() {
	js_group();	
}

function set_cart_count(num) {
	setCookie_minutes("cartcount",num,30);	
	return num;
}

function get_cart_count() {
	cartcount =  readCookie("cartcount");	
	
	if(!cartcount) {
		set_cart_count('0');
		return '0';	
	} else {
		return cartcount;
	}
}	

function page_catalogrequest() {
	if($('.texterrormessage').html().length>0) {
			
	}	
	
	$('#textQCSMiddleName').parent().hide();
	
	// Auto Select US
	
	$('#Country__BillingAddressCountryData option').each(function() {
		if($(this).html()=="United States") {
			$(this).attr('selected',true);	
			loadStateProvince();
			
		} else { 
			$(this).removeAttr('selected');
		}
		
	});
	
}


/*
 * Called for the Style Master and Static Detail Pages
 */
function js_product() {
	js_breadcrumb();
	personalization_cleaner();
	js_fix_broken_images();	
	$('#ItemNumberContainer').prepend("<label>Item Number:</label> ");
	
	$('.docdocumentcontentstyle').documentsToThumbs();
	
	 $("#AddToBag_AddToBag").hover(
      function () {
        $(this).addClass("transparent");
      }, 
      function () {
        $(this).removeClass("transparent");
      }
    );

	$('table').attr("cellspacing",0);
	
	$('.Products .product').each(function() {
		
		// For each Product List on this page, Append the Title to the Top of the Product Block
	//	$(this).append($('h3',this));
			
	});
	
	
	//$('.Products').productClean();	
	
	
}


function js_group() {
	
	js_breadcrumb();
		js_fix_broken_images("small");

	$('table.Products').productClean();	
	
	// Remove Previous NExt Container if there are none; 
	if($('#PreviousNextContainer').html().length<20) {
		$('.previousnextblock').hide();	
	}
	
	// Add Text Links to the Side of the Page
	$('#ui_group_side_links_0').append("<ul id='subgroup_link_items'></ul>");
	if ($('.subgroup_text_link').length > 0) {
		$('.subgroup_text_link').each(function(){
			$('#subgroup_link_items').append("<li></li>");
			newlink = "<a href='" + $(this).attr('href') + "'>" + $(this).html() + "</a>";
			$('#subgroup_link_items li:last').append(newlink);
		});
		
		
	} else {
		$('#ui_group_side_links').remove();
		$('#ui_sub_groups td:first').remove();
	}
	
	$('#GroupDescriptioncontainer br:first').remove();
	
	if(!$('#PreviousNextContainer div:first').is(":visible")) {
		$('#PreviousNextContainer').hide();	
	} else {
		newcode = $('#PreviousNextContainer .span_previousnext_container').eq(1).html().replace(/\|/gi,"");
	
		$('#PreviousNextContainer .span_previousnext_container').eq(1).html(newcode);	
	}
}


/* SEARCH RESULTS */
function page_searchresults() {

	insertBreadcrumb($('.querydisplaytext').html());
	js_group();
	js_pagination($('#SearchResultContainer'));
		
}



function page_myaccount() {
	insertBreadcrumb("My Account");
	
}

function page_updatebillinginformation() {
	insertBreadcrumb("Update Billing Information");
	$('.billingaddressfields').prepend("<h2>Billing Address</h2>");
	$('.methodofpaymentelementfields').prepend("<h2>Method of Payment</h2>");
		
}

function page_vieworderhistory() {
	insertBreadcrumb("Order History");	
}

function page_revieworder() {
	showCheckoutProcess('review-order');	
	
	
	$('table td').each(function() {
		if($(this).html()=="") { 
			$(this).addClass("empty");
		}
	});
	
}

function page_orderconfirmation() { 
	set_cart_count(0);
}

function page_changelogin() { 

	$('#contentPart').prepend('<div id="change_account"><div class="selector" id="change_email_selector"><label id="change_email_checkbox">Change Email Address</label> <div id="change_email_fields" class="field"></div></div><div class="selector" id="change_password_selector"><label id="change_password_checkbox">Change Password</label><div class="field" id="change_password_fields"></div><div class="field" id="change_password_fields"></div></div></div>');
	$('#easy_changeaccount').append('<h1>Update your Account</h1>');
	$('#easy_changeaccount').append("<div id='change_email'></div>");
	
	page_title = "Change my Email or Password";
	stub = '<div id="content_header"><h1>'+page_title+'</h1><div class="content"><a href="'+$('#HLink3_head0__QLink').attr('href')+'">Back to Account Settings</a></div>';
	$('#contentPart').prepend(stub);
	
	$('#change_password_checkbox').prepend($('#changePwdRadio'));
	$('#change_email_checkbox').prepend($('#changeEmailRadio'));
	
	$('#change_email_fields').append('<label>New Email</label>');
	$('#change_email_fields').append($('#textEmailId').css('width','95%'));
	$('#change_email_fields').append('<label>Repeat New Email</label>');
	$('#change_email_fields').append($('#textReenterEmailId').css('width','95%'));
	
	$('#change_password_fields').append('<label>New Password</label>');
	$('#change_password_fields').append($('#textNewPassword').css('width','95%'));
	$('#change_password_fields').append('<label>Repeat New Password</label>');
	$('#change_password_fields').append($('#textReenterNewPassword').css('width','95%'));
	
	$('#changePwdRadio').click(function() {
		$('#change_password_fields').show();
		$('#change_password_fields').append($('#btnSubmit_btnSubmit').val('Update Password'));
		$('#change_email_fields').hide();
	});
	
	$('#changeEmailRadio').click(function() {
		$('#change_password_fields').hide();
		$('#change_email_fields').show();
		$('#change_email_fields').append($('#btnSubmit_btnSubmit').val('Update Email'));
	});
	
	$('#changeEmailRadio').click();
	$('fieldset.changeloginfields').hide();


}

// End Page Specific  Functions

function search_mod() { 
	
	yearselect = "<select id='year_selector' name='year_selector'><option value='' selected='selected'>Select Year</option>";
	for(i=1953;i<2011;i++) {
		if (i != 1983) {
			yearselect = yearselect + "<option value='" + i + "'>" + i + "</option>";
		}
	}
	yearselect = yearselect+"</select>";

	$('#BasicSearchBox .searchtextboxstyle').keyup(function(e) {
		if(e.keyCode=="13") {
		
			do_search_with_year();
			
		}	
	});

	$('#basicSearchLabel').after(yearselect);
	
	$('#BasicSearchBox input.basicsearchbuttonstyle').hide().after('<a href="#" id="ui_search_link">Search</a>');
	
	$('#ui_search_link').click(function() { 
		
		do_search_with_year();
	
	});
	
	// Making Year Sticky
	cookieYear = readCookie("year");
	
	if(cookieYear!=null) {
	
		$('#year_selector option').each(function() {
			if($(this).html()==cookieYear) {
				$(this).attr("selected","selected");	
			} else {
				$(this).removeAttr("selected");
			}	
		});	
	}
	
	$('#year_selector').change(function() {
		createCookie("year",$('#year_selector :selected').html(),100);	
		//alert(readCookie("year"));
	});
	
	
}
function do_search_with_year() {
	
	currentsearchstring = $('#BasicSearchBox .searchtextboxstyle').val();	
	currentsearchstring.replace($('#year_selector option:selected').val(),'');
	
	if($('.searchtextboxstyle').val()=="Description or Item#") {
		$('#BasicSearchBox .searchtextboxstyle').val(currentsearchstring);	
	} else {
		$('#BasicSearchBox .searchtextboxstyle').val($('#year_selector :selected').val()+" "+currentsearchstring);
	}
	
	return SearchItem('txtSearchCategoryHeader', 'isVirtualDirectoryEnabledHeader');
	
}

function js_pagination() { 
		$('#PreviousNextContainer').html($('#PreviousNextContainer').html().replace("|",""));

}


/*
 * DROP
 * DOWN
 * MENU
 */

function dropdown_menu(id) {
	
}



function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul');
 
   ddmenuitem.show();
   menuleft = $(this).position().left+10;
 
  ddmenuitem.css({left:menuleft+"px"});
  	$(this).find('a:first').addClass('hovered');
  }

function jsddm_close()
{  if(ddmenuitem) {
		
		 ddmenuitem.hide();
		 ddmenuitem.parent().find('a:first').removeClass("hovered");
		
	}
	
}

function jsddm_timer()
{  

closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}


/*
 * HELPER
 * FUNCTIONS
 */

function js_fix_broken_images(size) { 
	$('img').each(function() {
		src = $(this).attr('src');
		src = src.replace(/\\Small/,"");
		var temp = new Array();
		temp = src.split('Blobs\\');
		
		filetype = src.match(/(JPG|GIF|PNG)/gi);
		
		if(filetype==null) {
			if(size==null) {
				$(this).attr('src','/Skins/1.3/images/missing-big-picture.gif'); 	
				$(this).attr('width','300'); 	
			} else if(size=="big") {
				$(this).attr('src','/Skins/1.3/images/missing-big-picture.gif'); 	
				$(this).attr('width','300'); 	
			} else if(size=="small") {
				$(this).attr('src','/Skins/1.3/images/missing-small-picture.gif'); 	
			}
		}

	});
	
}

function presentError() {
	if ($('#TextErrorContainer .texterrormessage').length > 0) {
		if ($('#TextErrorContainer .texterrormessage').html().replace(" ", "").length > 0) {
			$('#TextErrorContainer').addClass("ShowError");
			//$('#contentPart').prepend($('#TextErrorContainer'));
		}
		else {
			//$('#TextErrorContainer').hide();
		}
	}
}

function insertBreadcrumb(title) {
	html ='<div id="BreadCrumbContainer" class="breadcrumbblock"><ul><li class="first"><a href="/" class="breadcrumblink" id="ctl05__NavigationBar_Repeater_ctl01__NavigationCrumb_Link">Home</a><span id="ctl05__NavigationBar_Repeater_ctl01__NavigationCrumb_Label"/></li><li class="last"><a id="ctl05__NavigationBar_Repeater_ctl02__NavigationCrumb_Link"/><span class="breadcrumblink" id="ctl05__NavigationBar_Repeater_ctl02__NavigationCrumb_Label" <strong>"'+title+'"</strong></span></li></ul></div><div style="clear:both;"></div>';
	$('#contentPart').prepend(html);	
}

function js_breadcrumb() {
	$('#BreadCrumbContainer ul li:first').addClass('first');
	$('#BreadCrumbContainer ul li:last').addClass('last');	
}

function js_monitor_search() {
	
	
	
	defaultMessage = " ";
	input = $('#BasicSearchBox .searchtextboxstyle');

	input.addClass('inactive');
	input.val(defaultMessage);
	
	input.focus(function() {
		if($(this).val()==defaultMessage) {
			$(this).val("").removeClass('inactive');
		}	
	});
	
	input.blur(function() {
		
		if($(this).val()==defaultMessage||$(this).val()=="Description or Item#"||$(this).val()=="") {
			$(this).val(defaultMessage).addClass('inactive');
		}
		
		
			
	});
	
}



// Function to change any text to Proper Case (e.g. picco -> Picco)
String.prototype.toProperCase = function() 
{
    return this.charAt(0).toUpperCase() + this.substring(1,this.length).toLowerCase();
}


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


/*********************
//* jQuery Multi Level CSS Menu (horizontal)- By Dynamic Drive DHTML code library: http://www.dynamicdrive.com
//* Menu instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
//* Last modified: Sept 6th, 08'. Usage Terms: http://www.dynamicdrive.com/style/csslibrary/tos/
*********************/

//Specify full URL to down and right arrow images (25 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', 'arrow-down.gif', 25], right:['rightarrowclass', 'arrow-right.gif']}

var jquerycssmenu={

fadesettings: {overduration: 350, outduration: 100}, //duration of fade in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					$targetul.css({left:menuleft+"px"}).fadeIn(jquerycssmenu.fadesettings.overduration)
				},
				function(e){
					$(this).children("ul:eq(0)").fadeOut(jquerycssmenu.fadesettings.outduration)
				}
			) //end hover
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="myjquerymenu" on page:
jquerycssmenu.buildmenu("myjquerymenu", arrowimages);





/*
 * Product Cleanup Function
 * Takes a featured Product control and Applies some mods to it.
 */
$.fn.productClean = function() { 
		//alert($(this).attr("class"));
		// Remove Col Spaned TRs
		//title = $('h2 span',this).html();
		//$('h2 span',this).parent().parent().remove();
		//$('td[colspan]',this).remove();
		id=Math.floor(Math.random()*11)+"-Products";
		//stub = "<div class='Products ProductsContainer' id='"+id+"'></div>";
		//$(this).after(stub);
		//$(this).attr('style','');
	//	$('#'+id).append($(this));
	//	if(title!=null) {
		//	$('#'+id).prepend("<h2>"+title+"</h2>");	
	//	}
		table = this;
		$('.searchresulttitle',this).parent().parent().parent().hide();
		$('.product',table).each(function() {
			$('img',this).parent().addClass('real-image-link');
			//$(this).prepend($('h3',this));	
		});
		
		if($('.product',table).length==0) {
			$('#'+id).append("<div class='empty_results'></div>");
			//alert("Empty");
			table.parent().hide();
		}
		
		
		
		
	}
	
	


function personalization_cleaner() { 
	if($('#QBasicPersonalization1_dvPersonalizationContainer').html()!=null) {
	
		//alert("It has Personalization");
		//if($('.basicpersonalizationtitlestyle input').eq(0).attr('disabled')) {
			// If we are here its a manditory Personalization
			//$('#QBasicPersonalization1_dvPersonalizationHeaderDetailColumn').show();
			//$('.basicpersonalizationtitlestyle').parent().parent().remove();
		//}
	}
}

function zip_navigation() {
	// A function to remove Duplicate Titles from the Navigation based on the parent. 
	$('a.menunavigationclickstyle').each(function() {
		group1label = $('span',this).html(); 
		
		subgroups = $('ul li a',$(this).parent());
		subgroups.each(function() {
			$(this).html($(this).html().replace(group1label,''));
		});
			
	});
		
}

function highlight_current_links(){

	// Highlight the First Page Tab
	$('#ui_page_tabs a:first').addClass("currentlink");
	$('#ui_page_tabs td:first').addClass("currentlink");

    $("a").each(function(){
        var current_href = $(this).attr("href");
        if (!$.browser.msie) {
            //current_href = base_url + current_href;
        }
        if (document.location == current_href) {
            $(this).addClass("currentlink");
        }
    });
    
}

function mailchimp_subscribe() {

	$('body').append('<form action="http://zip-products.us1.list-manage.com/subscribe/post?u=8cfccb4cce8bee74f2151de52&amp;id=c3e5ac5f82" method="post" id="mailchimp-form" name="mc-embedded-subscribe-form" class="validate" target="_blank"></form>');
	$('#mailchimp-form').append($('#mc_embed_signup'));
	$('#mailchimp-form').submit();
	$('#contact_information').append($('#mc_embed_signup'));
	return false; 	
}

$.fn.documentsToThumbs = function() { 
   container = $(this);

	// Loop Over each of the Links
	$('a',this).each(function() {
		fileurl = $(this).attr('href');
		imagereg = /jpg|gif|jped|png|tiff/gi;
		pdfreg = /pdf/gi;
		flvreg = /flv/gi;
		htmlreg = /html/gi;
	//	alert("Image");
		
		if (fileurl.match(imagereg)!=null) {
			$(this).html("<img  height='50' src='" + fileurl + "' class='photo_swatch_img' />");
			$(this).addClass("lightbox");
		} else if(fileurl.match(pdfreg)!=null) {
			//alert("found pdf " + theme.config.get('theme_path'));
			//$(this).html("<span class='photo_swatch'><a href='" + fileurl + "' class='document_link' title='"+$(this).html()+"'><img src='"+theme.config.get('theme_path')+"/images/page_white_acrobat.png' border='0' align='absmiddle' style='text-decoration:none' style='margin-right:5px;' /> "+clean_name($(this).html())+"</a></span>");
			
		} else if(fileurl.match(htmlreg)!=null) {
			//alert("found pdf " + theme.config.get('theme_path'));
			$(this).html("<span class='photo_swatch'><a href='" + fileurl + "' class='document_link flash_video_link' target='_blank' title='"+$(this).html()+"'><img src='"+theme.config.get('theme_path')+"/images/camera.png' border='0' align='absmiddle' style='text-decoration:none' style='margin-right:5px;' /> Watch the Video</a></span>");
			$.get(fileurl, function(data){
			  $('#ProductDescription_QProductLabel').append("<br />" + data);
			});

			$(this).html("");
			
		}
		
	});
	
	
}

function showCheckoutProcess(step) {
	html="<div id='checkout-steps'><div class='step' id='view-cart'><a href='/ShoppingCart/QShoppingCart.aspx?' title='View your Shopping Cart'>View Cart</a></div><div class='step' id='payment-type'>Billing & Shipping</div><div class='step' id='review-order'>Review Order</div><div class='step' id='order-complete'>Order Complete</div></div>";
	$('#bodyPart').prepend(html);
	$('#checkout-steps #'+step).addClass('active');
	if($('#Logout_Header0__QLink').html()=="Login") {
		$('#view-cart').after("<div class='step' id='login-Register'><a href='https://www.zip-corvette.com/CreateNewAccount/QOnePageAccount.aspx?Action=MYACCOUNT&' title='Register Login'>Register/Login</a></div>")
	}
}

function setCookie_minutes( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


var lhs1 = "technical";
var rhs1 = "zip-corvette.com";

function print_mail_technical() 
{
   document.write("<A HREF=\"mailto");
   document.write(":" + lhs1 + "@");
   document.write(rhs1 + "\">" + "<\/a>");
}
 

var lhs2 = "customerservice";
var rhs2 = "zip-corvette.com";

function print_mail_customerservice() 
{
   document.write("<A HREF=\"mailto");
   document.write(":" + lhs2 + "@");
   document.write(rhs2 + "\">" + "<\/a>");
}

var lhs11 = "webmaster";
var rhs11 = "zip-corvette.com";

function print_mail_webmaster() 
{
   document.write("<A HREF=\"mailto");
   document.write(":" + lhs11 + "@");
   document.write(rhs11 + "\">" + "<\/a>");
}
//-->

