$(document).ready(function() {
//**** SITE SPECIFIC ****//
//-----------------------//
 var cartValue = $('#cartvalue').html();
if(cartValue > 0){$('#cart').show();}

//------> 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('269');

//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();
}

});//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();

}// .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="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()}); };
}