$(document).ready(function() {
//**** SITE SPECIFIC ****//
//-----------------------//
if($('#tabs').length){$(function() {$("#tabs").tabs();});}
/*PSS Feature page toggle */
featuresList();

// Disclosure Boxes - toggle opn/closed a div with class .disclosure content
function featuresList(){
	prepFeatures(); // get interface ready
	
	$('a.toggle').click(function(){
		$(this).parent().next('.featureinfo').slideToggle("slow");
		$(this).toggleClass('featureactive');
		return false;
	});
}

var cartValue = $('#abreviatedCart').html();
if(cartValue > 0){$('#cart').show();}

// Close all featureinfo boxes by default 
// Wrap all feature spans with an anchor tag to trigger interaction
function prepFeatures(){
	$('.featureinfo').css({'display':'none'});
	$('.featuretoggle').wrapInner('<a href="#" class="toggle" title="click to open"></a>');
}
//------> end site specific

//**** TESTING NEW FEATURES ****//


$('#splashslides').before('<ul id="nav2010">').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 7000,
        pause: true,
        pager:  '#nav2010',
        
        // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="#" class="' + slide.id + 'pointer"></a></li>'; 
    }
});

//-----------------------------//
/*
var tinput = $('#tshirt-input');
var smallinput = $('#ctl00_ContentPlaceHolder1_PriceCalcCtl1_ddCalcParm_Color');

colorvalue = $(document).getUrlParam("color");
smallinput.val(colorvalue);
javascript:setTimeout('AjaxNS.AR(\'ctl00$ContentPlaceHolder1$PriceCalcCtl1$tbQuantity\',\'\', \'ctl00_ContentPlaceHolder1_RadAjaxPanel1\', event)', 0)

tinput.keyup(function(){
var value = $(this).val();
smallinput.val(value);
});
*/

//------> end testing new features

//superfish dropdown menu
if($('.sf-menu').length){$("ul.sf-menu").superfish().find('ul').bgIframe({opacity:false});}

//call newsletter sign up put div "news-signup" on page 
ccNewsletter('1102000675072', 'Enter Email...', '#999', '#000');

//default text for search box
searchBoxText('Search...');

//iplocation using google api
//googleIpLoacator();

//change cart pic when it has items
if($('#cartpic').length){cartPicChange();}

//navigation active page determination
navActive();

//make portal form submit when enter is pressed -site number argument
portalFormSubmit('952'); 

//conformation alert for edoc builder
if ($('body').hasClass('productCustomize')){
	//edocConfirmationNotice();
}

//******* StoreForm Page functions ********//
if ($('body').hasClass('storeForm')){

	//Remove line breaks in file upload fields and other places
	formBrCleanup();
	
	//captcha check //needs getUrlParam plugin
	formCaptchaCheck();

}// .eof store form page functions

//home page splash transition
if ($('#s2').length){
$('#s2').cycle({ 
    fx:     'fade', 
    speed:  500,
	pause: 1,
    timeout: 9000
});
}
//----->>

//home page slider transition 
/*
if ($('#s2').length){
$('#s2').after('<div id="thumbNav">').cycle({ 
    fx:     'scrollHorz', 
    speed:  500,
	pause: 1,
    timeout: 7000,
    next:   '#next', 
    prev:   '#prev',
    pager:  '#thumbNav'
});
}
//---->>
*/


if ($("#ctl00_ContentPlaceHolder1_lnkNewAccount").length){$("#ctl00_ContentPlaceHolder1_lnkNewAccount").text("Create an Account");}//text change on login page
if ($('body').hasClass('checkout')){$("#ctl00_ContentPlaceHolder1_lblInformation").hide();}

//******* ProductDetail Page functions ********// 
if ($('body').hasClass('productDetail')){
$('.productDetail').pssDetail( {
	estShippingInputText:		"Enter Zip Code",
  	estShippingDefaultTextColor:"#999",
  	estShippingActiveTextColor:	"#000",
	pageTitleMenu:				false,	//true/false, toggle navigation in the product detail menu
	pageTitleMenuHeading:		"All Products",	//text, pagetitle roll over activation link text
	addToCartAgreement:			true,	//true/false, toggle text next to the add to cart/customize button
	addToCartAgreementLink:		"storePage.aspx?id=1213",	//text, link to agreement information page
	addToCartAgreementLinkText: "Terms Of Use",	//text, agreement link text
	detailToolTips: 			true,	//true/false, toggle tooltips
	spotColorsOnInfo: 			true,	//true/false, toggle spot colors on info buttons
	setMinimumQuantity: 		0,	//digit, set qty field 1 to a minimum number 0 = off
	enhancedPricing:			true,	//true/false, toggle enhanced pricing
	totalCostText:				"Total Cost",
	unitPriceText:				["17093|Price Per Copy", "16057|Price Per Copy", "16043|Price Per Pad"],  //set unit price text per product - ["3629|Per copy","1234|Per Page","4567|Per stack"] - ["productid|text"] - 0=off
	youSavedTest:				"You Saved",
	everyDayPriceText:			"Low Everyday Price",
	unitPriceQuantity: 			["16057|1", "17093|3", "19551|1"],	//set unit price divider per product - ["3629|3","1234|2","4567|1","3628|5"] - ["productid|qtyfield"] - 0=off
	setMinimumPurchasePrice:    0,	//set a minimum purchase price - ["3629|25.00","1234|36.00","4567|124.00","3628|25.00"] - ["productid|minprice"] - 0=off
	minimumPurchaseAlertText:	"The minimum purchase amount for this product is $price please adjust your calculator.",//min price alert statement use - price - to report the min price
	setQtyNoDisplay:			["16057|1", "17093|3", "19551|1", "19551|4", "19551|5"],   //set qty fields to no-display per product - ["3629|3","1234|2","4567|4","3628|5"] - ["productid|qtyfield"] - 0=off
	setQtyMath:					["16057|Q2*Q3:Q1", "17093|Q1*Q2:Q3", "19551|Q2*Q3:Q1"],  //set math for qty fields per product - ["17370|(Q2+Q3)*Q4:Q5", "17124|(Q2+Q3)*Q4:Q5"] - ["productid|math:reportfield"] - 0=off
	noFileUploadAlertText:		"This Product Requires that you upload a file. Please select your file(s) then click",
	useGetShipDate:				true, //true/false, displays shiping date on calc
	beforeShipDateText:			"Ships by...",
	setMinimumPrice:			["19551|57.00:Q4"],
	debug: false
});
}


});//eof .ready()/////////////////////////////////////////////////////////////////////////////////////  

//printerorder function for calc hook // repeats calcjunk call, price label remove, tooltips, calcColorI, shipdate function  
function HandleRadAjaxPanel1(sender, arguments) {

if($('#ctl00_ContentPlaceHolder1_txtPostalCode').length){
 AjaxNS.AR('ctl00$ContentPlaceHolder1$btnShipCost', '', 'ctl00_ContentPlaceHolder1_RadAjaxPanel2', event);
}

//******* ProductDetail Page functions ********//
$('.productDetail').pssDetail( {
	estShippingInputText:		"Enter Zip Code",
  	estShippingDefaultTextColor:"#999",
  	estShippingActiveTextColor:	"#000",
	pageTitleMenu:				false,	//true/false, toggle navigation in the product detail menu
	pageTitleMenuHeading:		"All Products",	//text, pagetitle roll over activation link text
	addToCartAgreement:			true,	//true/false, toggle text next to the add to cart/customize button
	addToCartAgreementLink:		"storePage.aspx?id=1213",	//text, link to agreement information page
	addToCartAgreementLinkText: "Terms Of Use",	//text, agreement link text
	detailToolTips: 			true,	//true/false, toggle tooltips
	spotColorsOnInfo: 			true,	//true/false, toggle spot colors on info buttons
	setMinimumQuantity: 		0,	//digit, set qty field 1 to a minimum number 0 = off
	enhancedPricing:			true,	//true/false, toggle enhanced pricing
	totalCostText:				"Total Cost",
	unitPriceText:				["17093|Price Per Copy", "16057|Price Per Copy", "16043|Price Per Pad"],  //set unit price text per product - ["3629|Per copy","1234|Per Page","4567|Per stack"] - ["productid|text"] - 0=off
	youSavedTest:				"You Saved",
	everyDayPriceText:			"Low Everyday Price",
	unitPriceQuantity: 			["16057|1", "17093|3", "19551|1"],	//set unit price divider per product - ["3629|3","1234|2","4567|1","3628|5"] - ["productid|qtyfield"] - 0=off
	setMinimumPurchasePrice:    0,	//set a minimum purchase price - ["3629|25.00","1234|36.00","4567|124.00","3628|25.00"] - ["productid|minprice"] - 0=off
	minimumPurchaseAlertText:	"The minimum purchase amount for this product is $price please adjust your calculator.",//min price alert statement use - price - to report the min price
	setQtyNoDisplay:			["16057|1", "17093|3", "19551|1", "19551|4", "19551|5"],   //set qty fields to no-display per product - ["3629|3","1234|2","4567|4","3628|5"] - ["productid|qtyfield"] - 0=off
	setQtyMath:					["16057|Q2*Q3:Q1", "17093|Q1*Q2:Q3", "19551|Q2*Q3:Q1"],  //set math for qty fields per product - ["17370|(Q2+Q3)*Q4:Q5", "17124|(Q2+Q3)*Q4:Q5"] - ["productid|math:reportfield"] - 0=off
	noFileUploadAlertText:		"This Product Requires that you upload a file. Please select your file(s) then click",
	useGetShipDate:				true, //true/false, displays shiping date on calc
	beforeShipDateText:			"Ships by...",
	setMinimumPrice:			["19551|57.00:Q4"],
	debug: false
});
	

	
}// .eof HandleRadAjaxPanel1


//navigation active page determination //needs getUrlParam plugin
function navActive(){
	var storePageParam = $(document).getUrlParam("id");
	var productPageParam = $(document).getUrlParam("p");
	var catPageParam = $(document).getUrlParam("c");
	$('.navlinks a').each(function(){
		var navLinkHref = $(this).attr('href').match(/\d+/);
		if (navLinkHref == null){}
		else if (navLinkHref == storePageParam || navLinkHref == productPageParam || navLinkHref == catPageParam){
			$(this).addClass('navActive');
		}
	})
}
//------>

//switch cart image from empty to full when cart has products
function cartPicChange(){
var cartValue = $("#abreviatedCart").text().match(/\d+/);
if (cartValue > 0){$("#cartpic").removeClass().addClass("cartpic2");}
}
//----->>

//google ip locator
function googleIpLoacator(){
if(google.loader.ClientLocation){ visitor_lat = google.loader.ClientLocation.latitude;visitor_lon = google.loader.ClientLocation.longitude;visitor_city = google.loader.ClientLocation.address.city;visitor_region = google.loader.ClientLocation.address.region;visitor_country = google.loader.ClientLocation.address.country;visitor_countrycode = google.loader.ClientLocation.address.country_code;
	$("#mainwrapper").append("<div id='ipinfo'><ul><li><strong>Customer Info:</strong></li><li>Latitude: " + visitor_lat + " <\/li><li>Longitude: " + visitor_lon + " <\/li><li>City: " + visitor_city + " <\/li><li>Region: " + visitor_region + " <\/li><li>Country: " + visitor_country + " <\/li><li>Country Code: " + visitor_countrycode + " <\/li><\/ul><\/div>");
}
else{$("#main").append("<div id='ipinfo' class='sideNav'><div style='padding:10px;'>No ip info found.<\/div><\/div>");
}
}
//.eof google ip locator---->>

//newsletter signup ,Enter Your Email, #999, #000 //needs autofill function also
function ccNewsletter(siteNumber, ccTextValue, ccTextColor, ccActiveTextColor){
if ($('#news-signup').length){
$('#news-signup').html('<fieldset><ul><li><input id="news-text" type="text" name="userName" /><input id="news-submit" type="submit" name="news-submit" value="Go" /><input id="news-id" type="hidden" name="userName" value="' + siteNumber + '" /></li><li><div> <a href="http://www.constantcontact.com/safesubscribe.jsp" target="_blank"> <img src="http://img.constantcontact.com/ui/images1/safe_subscribe_logo.gif" border="0" width="168" height="14" alt=""/></a> </div></li></ul></fieldset>');
//newsletter text change in input box - uses autofill function
$('#news-text').autofill({value: ccTextValue,defaultTextColor: ccTextColor,activeTextColor: ccActiveTextColor});
if ($('#news-text').length){$(function() {$("#news-text").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
window.open("http://visitor.constantcontact.com/d.jsp?m=" + $('#news-id').val() + "&p=oi&ea=" + $('#news-text').val())
return false;} else {return true;}});});};
//Submit newsletter sign up 
$("#news-submit").click(function(e) {e.preventDefault();window.open("http://visitor.constantcontact.com/d.jsp?m=" + $('#news-id').val() + "&p=oi&ea=" + $('#news-text').val())});
};}
//--->

//search box default text
function searchBoxText(defaultText){				   
var clearMePrevious = defaultText; $('#ctl00_searchBox').val(defaultText);
// clear input on focus
$('#ctl00_searchBox').focus(function(){if($(this).val()== defaultText){clearMePrevious = $(this).val();$(this).val("");}});
// if field is empty afterward, add text again
$('#ctl00_searchBox').blur(function(){if($(this).val()==""){$(this).val(clearMePrevious);}});
}
//---->>

//make portal form submit when enter is pressed
function portalFormSubmit(siteNumber){
if ($('#port-login input').length){$(function() {$("#port-login input").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
window.location="http://www.printerorder.com/login.aspx?pid=" + siteNumber + "&userEmail=" + $('#portUserName').val() + "&userPassword=" + $('#portPassword').val()
return false;} else {return true;}});});};
//Submit portal information to url and redirect page 
if ($('#port-login-submit').length){$("#port-login-submit").click(function(e) {   e.preventDefault();
window.location="http://www.printerorder.com/login.aspx?pid=" + siteNumber + "&userEmail=" + $('#portUserName').val() + "&userPassword=" + $('#portPassword').val()}); };
}