$(document).ready(function() {
//**** SITE SPECIFIC ****//
//-----------------------//
 
//------> end site specific

//**** TESTING NEW FEATURES ****//
//-----------------------------//

//------> 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('1635');

//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 ($('#s1').length){
$('#s1').after('<div id="nav">').cycle({ 
    fx:     'fade', 
    speed:  500,
	pause: 1,
    timeout: 7000, 
    pager:  '#nav'
});
}
//----->>

//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:				true,	//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:		"list.aspx",	//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:				["19311|Per copy","19132|Per copy"],  //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: 			["19311|1","19132|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:			["19311|1","19132|1"],  //set qty fields to no-display per product - ["3629|3","1234|2","4567|4","3628|5"] - ["productid|qtyfield"] - 0=off
	setQtyMath:					["19311|Q2*Q3:Q1","19132|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:				false, //true/false, displays shiping date on calc 
	beforeShipDateText:			"Ships by...",
	printerGMT: 				0, //set the printers GMT EST = -5, CST = -6, MST = -7, PST = -8 -- 0 = off
	setCutoffTime: 				0, //military time 13 = 1pm
	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:				true,	//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:		"list.aspx",	//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:				["19311|Per copy","19132|Per copy"],  //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: 			["19311|1","19132|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:			["19311|1","19132|1"],  //set qty fields to no-display per product - ["3629|3","1234|2","4567|4","3628|5"] - ["productid|qtyfield"] - 0=off
	setQtyMath:					["19311|Q2*Q3:Q1","19132|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:				false, //true/false, displays shiping date on calc 
	beforeShipDateText:			"Ships by...",
	printerGMT: 				0, //set the printers GMT EST = -5, CST = -6, MST = -7, PST = -8 -- 0 = off
	setCutoffTime: 				0, //military time 13 = 1pm
	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 formProcessNotice---->>

//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()}); };
}
