$(document).ready(function() {
//Remove line breaks in file upload fields  
$("#ctl00_ContentPlaceHolder1_panelFileUpload br").remove();

//home page splash transition
$(function() {
    // run the code in the markup!
    $('div pre code').each(function() {
        eval($(this).text());
    });
});

//switch cart image from empty to full when cart has products
  var idValue = $("#printerId").text();
  var cartValue = $("#abreviatedCart").text();
    if (cartValue != 0){
        $("#cartimage").attr("src", "/sites/" + idValue + "/website/store_images/cartpic2.png");
    }

//make portal form submit when enter is pressed 
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=" + $('#printerId').text() + "&userEmail=" + $('#portUserName').val() + "&userPassword=" + $('#portPassword').val()
			return false;
		} else {
			return true;
		}
    });
});
};
//Submit portal information to url and redirect page 
if ($('#submit-port').length){
        $("#submit-port").click(function(e) {   
			e.preventDefault();
				window.location="http://www.printerorder.com/login.aspx?pid=" + $('#printerId').text() + "&userEmail=" + $('#portUserName').val() + "&userPassword=" + $('#portPassword').val()
		}); 
};

//product detail, notice for no file uploaded
if ($('#ctl00_ContentPlaceHolder1_lblUploadInstructions').length){
 	if ($("#ctl00_ContentPlaceHolder1_lblUploadInstructions").attr("style")){
 			alert('This Product Requires that you upload a file. Please select your file or files to be uploaded for this order and then click "Add to Cart."');
 		}	
};
						   
//conformation alert for edoc builder
 $(function() {
 $("#ctl00_ContentPlaceHolder1_btnAddToCart").click(function() {   
			var box = $("#ctl00_ContentPlaceHolder1_CheckBox1"); 
				if ($("#ctl00_ContentPlaceHolder1_EDocClient_lblInstructions").css("color") == "red"){
 			alert('Items marked with an asterisk (*) are not optional. Please enter information for all required items and click "Update Preview" error1');
 					}
				else if ($("#ctl00_ContentPlaceHolder1_EDocClient_lblInstructions").is(":contains('Please')")){
			alert('Items marked with an asterisk (*) are not optional. Please enter information for all required items and click "Update Preview" error2');
					}
        else if (confirm("By approving this document you are indicating that you understand and agree that we will produce what you have seen in the preview as the final proof before your job is produced. What you have approved is what you will get.Any errors or omissions which are the result of incomplete or inaccurate entries are the sole responsibility of you, the author, and said errors or omissions in now way relieve you of your responsibility to pay for this product according to our normal terms and conditions."))
          {
            box.checked = true;
          }
          else{
            return false;
          }
		}); 
});
/*
By approving this document you are indicating that you understand and agree
that we will produce what you have seen in the preview as the final proof
before your job is produced. 

What you have approved is what you will get.

Any errors or omissions which are the result of incomplete or inaccurate
entries are the sole responsibility of you, the author, and said errors or
omissions in now way relieve you of your responsibility to pay for this
product according to our normal terms and conditions.
*/					   
 });
/* ----------------------------------------------------------------- */
/* ***********  FORM VALIDATION - upload file form  ************* */
/*----------------------------------------------------------------- */
/* ***********  FORM VALIDATION - all custom forms  ****************   
$(document).ready(function() {
	$("fieldset li").each(function (i) {
        if ($(this).find("input").hasClass("required") || $(this).find("select").hasClass("required") || $(this).find("textarea").hasClass("required")) {
		$(this).find("span").css('display','inline');
        } else {
         $(this).find("span").css('display','none');
        }
      });
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

    $("#aspnetForm").validate({
		ignore: ".notrequired",
		success: "valid", 
		rules: {
			ctl00$ContentPlaceHolder1$txtContactName: {
				required: true,
				minlength: 2
			},
			ctl00$ContentPlaceHolder1$txtCompany: {
				required: true,
				minlength: 2
			},
			ctl00$ContentPlaceHolder1$txtContactPhone: {
				required: true,
				phoneUS: true
			},
			ctl00$ContentPlaceHolder1$txtContactEmail: {
				required: true,
				email: true
			},
			ctl00_ContentPlaceHolder1_RadUpload1file0: {
				required: true
			},
			_emailMe_FirstName: {
				required: true,
				minlength: 2
			},
			_emailMe_LastName: {
				required: true,
				minlength: 2
			},
			_emailMe_CompanyName: {
				required: true,
				minlength: 2
			},
			_emailMe_WorkPhone: {
				required: true,
				phoneUS: true
			},
			_emailMe_FAX: {
				required: true,
				phoneUS: true
			},
			_emailMe_Address: {
				required: true
			},
			_emailMe_Address2: {
				required: true
			},
			_emailMe_City: {
				required: true
			},
			_emailMe_Zip: {
				required: true,
				number: true,
				minlength: 5
			},
			_emailMe_Comments: {
				required: true
			},
			_emailMe_Email: {
				required: true,
				email: true
			}
			
		},
		messages: {
			ctl00$ContentPlaceHolder1$txtContactName: {
				required: "Please enter a contact name",
				minlength: jQuery.format("At least {0} characters required!")
			},
			ctl00$ContentPlaceHolder1$txtCompany: {
				required: "Please enter your company",
				minlength: jQuery.format("At least {0} characters required!")
			},
			ctl00$ContentPlaceHolder1$txtContactPhone: {
				required: "Please enter a valid phone number"
			},
			ctl00$ContentPlaceHolder1$txtContactEmail_emailMe_Email: {
				required: "Please enter a valid email"
			},
			_emailMe_FirstName: {
				required: "Please enter a first name",
				minlength: jQuery.format("At least {0} characters required!")
			},
			_emailMe_LastName: {
				required: "Please enter a last name",
				minlength: jQuery.format("At least {0} characters required!")
			},
			_emailMe_CompanyName: {
				required: "Please enter a username",
				minlength: jQuery.format("At least {0} characters required!")
			},
			_emailMe_WorkPhone: {
				
				required: "Please enter a valid phone number"
			},
			_emailMe_FAX: {
				
				required: "Please enter a valid fax number"
			},
			_emailMe_Address: {
				required: "Please enter a valid address"
			},
			_emailMe_Address2: {
				required: "Please enter a valid address"
			},
			_emailMe_City: {
				required: "Please enter a valid city"
			},
			_emailMe_Zip: {
				required: "Please enter a valid zip code",
				number: "Numbers only please",
				minlength: jQuery.format("At least {0} characters required!")
			},
			_emailMe_Comments: {
				required: "Please enter a message"
			},
			_emailMe_Email: {
				required: "Please enter a valid email"
			}
			 
		}  
	});
});
*/
//Plugin to detect the current url parameters
jQuery.fn.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* To get the document params:
* @example value = $(document).getUrlParam("paramName");
* 
* To get the params of a html-attribut (uses src attribute)
* @example value = $('#imgLink').getUrlParam("paramName");
*/ 
getUrlParam: function(strParamName){strParamName = escape(unescape(strParamName));var returnVal = new Array();var qString = null;if ($(this).attr("nodeName")=="#document") {
  //document-handler
if (window.location.search.search(strParamName) > -1 ){qString = window.location.search.substr(1,window.location.search.length).split("&");}} else if ($(this).attr("src")!="undefined") {
var strHref = $(this).attr("src")
if ( strHref.indexOf("?") > -1 ){var strQueryString = strHref.substr(strHref.indexOf("?")+1);qString = strQueryString.split("&");}} else if ($(this).attr("href")!="undefined") {
var strHref = $(this).attr("href")
if ( strHref.indexOf("?") > -1 ){var strQueryString = strHref.substr(strHref.indexOf("?")+1);qString = strQueryString.split("&");}} else {return null;}
if (qString==null) return null;
for (var i=0;i<qString.length; i++){
if (escape(unescape(qString[i].split("=")[0])) == strParamName){returnVal.push(qString[i].split("=")[1]);}}
if (returnVal.length==0) return null;else if (returnVal.length==1) return returnVal[0];else return returnVal;}});