function resizeTxt(action){ 
	var plusSize = $("#mid_con").css("font-size");
	var minusSize = $("#mid_con").css("font-size"); // the same value but fixes an IE error with switch statement
	if(action == "minus"){
		switch(minusSize){
			case "10px":
				$("#mid_con").css("font-size", "10px");
				$("h2").css("font-size", "11px");
				break;
			case "12px":
				$("#mid_con").css("font-size", "10px");
				$("h2").css("font-size", "12px");
				break;
			case "13px":
				$("#mid_con").css("font-size", "12px");
				$("h2").css("font-size", "15px");
				break;
			case "14px":
				$("#mid_con").css("font-size", "13px");
				$("h2").css("font-size", "16px");
				break;
			case "16px":
				$("#mid_con").css("font-size", "14px");
				$("h2").css("font-size", "18px");
				break;
			case "18px":
				$("#mid_con").css("font-size", "16px");
				$("h2").css("font-size", "20px");
				break;
			case "20px":
				$("#mid_con").css("font-size", "18px");
				$("h2").css("font-size", "22px");
				break;
			default:
				$("#mid_con").css("font-size", "13px");
				$("h2").css("font-size", "16px");
		}
	}else if(action == "plus"){
		switch(plusSize){
			case "10px":
				$("#mid_con").css("font-size", "12px");
				$("h2").css("font-size", "15px");
				break;
			case "12px":
				$("#mid_con").css("font-size", "13px");
				$("h2").css("font-size", "16px");
				break;
			case "13px":
				$("#mid_con").css("font-size", "14px");
				$("h2").css("font-size", "18px");
				break;
			case "14px":
				$("#mid_con").css("font-size", "16px");
				$("h2").css("font-size", "20px");
				break;
			case "16px":
				$("#mid_con").css("font-size", "18px");
				$("h2").css("font-size", "22px");
				break;
			case "18px":
				$("#mid_con").css("font-size", "20px");
				$("h2").css("font-size", "24px");
				break;
			case "20px":
				$("#mid_con").css("font-size", "20px");
				$("h2").css("font-size", "24px");
				break;
			default:
				$("#mid_con").css("font-size", "13px");
				$("h2").css("font-size", "16px");
		
		}
	}
}


function bookmark(title,url){
	var brVar = "none";
	jQuery.each(jQuery.browser, function(i) {
		//alert("I = " + i);
		if($.browser.msie){
			brVar = 'internet explorer';
		}
		if($.browser.safari){
			brVar = 'safari';
		}
		if($.browser.mozilla){
			brVar = 'firefox';
		}
		if($.browser.opera){
			brVar = 'opera';
		}
		
    });

	var FF = brVar.search('firefox');
	var MSIE = brVar.search('internet explorer');
	var OP = brVar.search('opera');
	var SA = brVar.search('safari');
	
	if(FF >= 0){ // firefox
		window.sidebar.addPanel(title, url, "");
	}else if(OP >= 0){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}else if(MSIE >= 0){ // IE
		window.external.AddFavorite(url, title);
	}else if(SA >= 0){ // Safari
		alert('If you are using Safari click command + D to bookmark.');
	}else{
		alert('Your browser does not support javascript bookmarking.');
	}
}


function slideTestimonial(direction){
	var cur = $("#currentTestimonial").val() | 0; // the OR (|) 0 casts this var as an integer
	//alert(cur);
	
	if(direction == "left"){
		switch (cur) {
			case 1: 
				// get in the starters box
				$("#testimonial3").hide();
				$("#testimonial3").css("left", "-915px");
				$("#testimonial3").show();
				
				//exit the stage
				$("#testimonial1").animate({ 
					left: "915px",
					opacity: 0
				}, 1500 );

				//enter the stage
				$("#testimonial3").animate({ 
					left: "0px",
					opacity: 1
				}, 1600 );

				// set new value
				$("#currentTestimonial").val("3");
				break;
			case 2: 
				// get in the starters box
				$("#testimonial1").hide();
				$("#testimonial1").css("left", "-915px");
				$("#testimonial1").show();
				
				//exit the stage
				$("#testimonial2").animate({ 
					left: "915px",
					opacity: 0
				}, 1500 );

				//enter the stage
				$("#testimonial1").animate({ 
					left: "0px",
					opacity: 1
				}, 1600 );

				// set new value
				$("#currentTestimonial").val("1");
				break;
			default: 
				// get in the starters box
				$("#testimonial2").hide();
				$("#testimonial2").css("left", "-915px");
				$("#testimonial2").show();
				
				//exit the stage
				$("#testimonial3").animate({ 
					left: "915px",
					opacity: 0
				}, 1500 );

				//enter the stage
				$("#testimonial2").animate({ 
					left: "0px",
					opacity: 1
				}, 1600 );

				// set new value
				$("#currentTestimonial").val("2");
		}// end switch
	}
	
	if(direction == "right"){
		switch (cur) {
			case 1: 
				// get in the starters box
				$("#testimonial2").hide();
				$("#testimonial2").css("left", "915px");
				$("#testimonial2").show();
				
				//exit the stage
				$("#testimonial1").animate({ 
					left: "-915px",
					opacity: 0
				}, 1500 );

				//enter the stage
				$("#testimonial2").animate({ 
					left: "0px",
					opacity: 1
				}, 1500 );

				// set new value
				$("#currentTestimonial").val("2");
				break;
			case 2: 
				// get in the starters box
				$("#testimonial3").hide();
				$("#testimonial3").css("left", "915px");
				$("#testimonial3").show();
				
				//exit the stage
				$("#testimonial2").animate({ 
					left: "-915px",
					opacity: 0
				}, 1500 );

				//enter the stage
				$("#testimonial3").animate({ 
					left: "0px",
					opacity: 1
				}, 1500 );

				// set new value
				$("#currentTestimonial").val("3");
				break;
			default: 
				// get in the starters box
				$("#testimonial1").hide();
				$("#testimonial1").css("left", "915px");
				$("#testimonial1").show();
				
				//exit the stage
				$("#testimonial3").animate({ 
					left: "-915px",
					opacity: 0
				}, 1500 );

				//enter the stage
				$("#testimonial1").animate({ 
					left: "0px",
					opacity: 1
				}, 1500 );

				// set new value
				$("#currentTestimonial").val("1");
		}// end switch
	}
	/*
	$("#block").animate({ 
		width: "70%",
		opacity: 0.4,
		marginLeft: "0.6in",
		fontSize: "3em", 
		borderWidth: "10px"
	}, 1500 );
	*/
}

function imgSwitch(id,file){
	document.getStarted.src='img/'+file;
	$("#"+id).css("cursor", "pointer");
	//$("#"+id).html("<img src=\"img/"+file+"\" name=\"getStarted\" width=\"200\" height=\"33\" border=\"0\">");
}

function stepByStep(dir){
	var current = $("#stepByStepVal").val();
	current = current * 1;

	if(dir == "left"){
		switch (current) {
			case 1: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step4").hide();
				$("#step3").hide();
				$("#step2").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step5.jpg)");
				$("#stepByStepVal").val("5");
				
				// get in the starters box
				$("#step5").css("left", "-610px");
				$("#step5").show();
				
				//exit the stage
				$("#step1").animate({ 
					left: "610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step5").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				
				break;
			case 2: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step4").hide();
				$("#step3").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step1.jpg)");
				$("#stepByStepVal").val("1");
				
				// get in the starters box
				$("#step1").css("left", "-610px");
				$("#step1").show();
				
				//exit the stage
				$("#step2").animate({ 
					left: "610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step1").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			case 3: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step4").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step2.jpg)");
				$("#stepByStepVal").val("2");
				
				// get in the starters box
				$("#step2").css("left", "-610px");
				$("#step2").show();
				
				//exit the stage
				$("#step3").animate({ 
					left: "610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step2").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			case 4: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step3").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("background-image","url(img/steps/step3.jpg)");
				$("#stepByStepVal").val("3");
				
				// get in the starters box
				$("#step3").css("left", "-610px");
				$("#step3").show();
				
				//exit the stage
				$("#step4").animate({ 
					left: "610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step3").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			default: 
				// hide divs off the stage
				$("#step4").hide();
				$("#step3").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step4.jpg)");
				$("#stepByStepVal").val("4");
				
				// get in the starters box
				$("#step4").css("left", "-610px");
				$("#step4").show();
				
				//exit the stage
				$("#step5").animate({ 
					left: "610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step4").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
		}// end switch
	}
	
	if(dir == "right"){
		switch (current) {
			case 1: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step4").hide();
				$("#step3").hide();
				$("#step2").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step2.jpg)");
				$("#stepByStepVal").val("2");
				
				// get in the starters box
				$("#step2").hide();
				$("#step2").css("left", "610px");
				$("#step2").show();
				
				//exit the stage
				$("#step1").animate({ 
					left: "-610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step2").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			case 2: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step4").hide();
				$("#step3").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step3.jpg)");
				$("#stepByStepVal").val("3");
				
				// get in the starters box
				$("#step3").hide();
				$("#step3").css("left", "610px");
				$("#step3").show();
				
				//exit the stage
				$("#step2").animate({ 
					left: "-610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step3").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			case 3: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step4").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step4.jpg)");
				$("#stepByStepVal").val("4");
				
				// get in the starters box
				$("#step4").hide();
				$("#step4").css("left", "610px");
				$("#step4").show();
				
				//exit the stage
				$("#step3").animate({ 
					left: "-610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step4").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			case 4: 
				// hide divs off the stage
				$("#step5").hide();
				$("#step3").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// hide divs off the stage
				$("#step5").hide();
				$("#step3").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("background-image","url(img/steps/step5.jpg)");
				$("#stepByStepVal").val("5");
				
				// get in the starters box
				$("#step5").css("left", "610px");
				$("#step5").show();
				
				//exit the stage
				$("#step4").animate({ 
					left: "-610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step5").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
				break;
			default: 
				// hide divs off the stage
				$("#step4").hide();
				$("#step3").hide();
				$("#step2").hide();
				$("#step1").hide();
				
				// set background
				$("#stepByStep").css("backgroundImage","url(img/steps/step1.jpg)");
				$("#stepByStepVal").val("1");
				
				// get in the starters box
				$("#step1").hide();
				$("#step1").css("left", "610px");
				$("#step1").show();
				
				//exit the stage
				$("#step5").animate({ 
					left: "-610px",
					opacity: 0
				}, 750 );

				//enter the stage
				$("#step1").animate({ 
					left: "20px",
					opacity: 1
				}, 750 );
		}// end switch
	}
}


function clearField(el){
	$("#"+el).val("");	
	//document.getElementById(el).maxLength = 5;
}


// ============================================================================================
function checkOrderInfo(){
	
	var err = 0;
	var err_msg = 'Please correct the following: \r\n';
		
	if ($("#beneficiary_first_name").val() == ''){
		err = 1;
		err_msg += ' - Enter the beneficiary\'s first name.\r\n';
	}
	
	if ($("#beneficiary_last_name").val() == ''){
		err = 1;
		err_msg += ' - Enter the beneficiary\'s last name.\r\n';
	}	
	
	if ($("#beneficiary_relationship").val() == ''){
		err = 1;
		err_msg += ' - Enter the beneficiary\'s relationship with the purchaser.\r\n';
	}

	if ($("#beneficiary_address").val() == ''){
		err = 1;
		err_msg += ' - Enter the beneficiary\'s address.\r\n';
	}

	if ($("#beneficiary_city").val() == ''){
		err = 1;
		err_msg += ' - Enter the beneficiary\'s city.\r\n';
	}	

	if ($("#qwp_state").val() == ''){
		err = 1;
		err_msg += ' - Select the beneficiary\'s state.\r\n';
	}

	if ($("#beneficiary_zip").val().length < 5){
		err = 1;
		err_msg += ' - Enter a beneficiary\'s zip of at least 5 digits.\r\n';
	}
	
	if ($("#beneficiary_phone").val().length < 10){
		err = 1;
		err_msg += ' - Enter a beneficiary\'s phone of at least 10 characters.\r\n';
	}
	
	
	var ve = validEmail($("#beneficiary_email").val());
	if (ve == false){
		err = 1;
		err_msg += ' - Enter a valid beneficiary\'s email address.\r\n';		
	}
	
	
	if ($("#purchaser_first_name").val() == ''){
		err = 1;
		err_msg += ' - Enter the purchaser\'s first name.\r\n';
	}
	
	if ($("#purchaser_last_name").val() == ''){
		err = 1;
		err_msg += ' - Enter the purchaser\'s last name.\r\n';
	}	
	
	if ($("#purchaser_address").val() == ''){
		err = 1;
		err_msg += ' - Enter the purchaser\'s address.\r\n';
	}

	if ($("#purchaser_city").val() == ''){
		err = 1;
		err_msg += ' - Enter the purchaser\'s city.\r\n';
	}	

	if ($("#purchaser_state").val() == ''){
		err = 1;
		err_msg += ' - Select the purchaser\'s state.\r\n';
	}

	if ($("#purchaser_zip").val().length < 5){
		err = 1;
		err_msg += ' - Enter a purchaser\'s zip of at least 5 digits.\r\n';
	}
	
	if ($("#purchaser_phone").val().length < 10){
		err = 1;
		err_msg += ' - Enter a purchaser\'s phone of at least 10 characters.\r\n';
	}
	
	
	var ve = validEmail($("#purchaser_email").val());
	if (ve == false){
		err = 1;
		err_msg += ' - Enter a valid purchaser\'s email address.\r\n';		
	}	

	
	if (err > 0){
		alert(err_msg);
		return false;
	}
}



// ============================================================================================
function copyBeneficiaryInformation(el){
	
	var assocArr = new Array();
	assocArr["purchaser_first_name"] = "beneficiary_first_name";
	assocArr["purchaser_last_name"] = "beneficiary_last_name";
	assocArr["purchaser_address"] = "beneficiary_address";
	assocArr["purchaser_city"] = "beneficiary_city";
	assocArr["purchaser_state"] = "beneficiary_state";
	assocArr["purchaser_zip"] = "beneficiary_zip";
	assocArr["purchaser_phone"] = "beneficiary_phone";
	assocArr["purchaser_email"] = "beneficiary_email";	

	var x;	
	if ($("#"+el).is(":checked")){
		
		for (x in assocArr){			
			$("#"+x).val( $("#"+assocArr[x]).val() );
		}						
	}else{
		for (x in assocArr){			
			$("#"+x).val('');
		}
	}
}

// ============================================================================================
function calculateTotalDue(el, outputID, inputID){
		
	var product_ids = $("#cart_product_ids").val().split('|');	
	var totalDueNow = 0.00;
	
	for (i=0; i<product_ids.length; i++){
		var selectVal = $("#payment_option_"+product_ids[i]).val();
		
		if (selectVal == 'pay_in_full'){
			var fullPrice = $("#full_product_price_"+product_ids[i]).val();			
			totalDueNow = totalDueNow + parseFloat(fullPrice);
		}else{
			var downPayment = $("#down_payment_"+selectVal).val();
			totalDueNow = totalDueNow + parseFloat(downPayment);
		}
	}	
	
	$("#"+outputID).html('$' + CommaFormatted(totalDueNow));
	$("#"+inputID).val(totalDueNow);	
}



/* ============================================================================================
	CHANGES A NUMERIC VALUE INTO A MONEY FORMAT LIKE 23.00
	EXAMPLE:
		var value = 23;
		value = formatAsMoney(value);
		
		#value will now be 23.00
=============================================================================================== */
function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.ceil(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.ceil(mnt*10)) ? 
                       mnt + '0' : mnt);
}



/* ============================================================================================
	ADDS COMMAS TO NUMBERS GREATER THAN 999
=============================================================================================== */
function CommaFormatted(amount)
{
	// first, make sure it is a value with 2 decimal places
	amount = formatAsMoney(amount).toString();
	
	
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}


// ============================================================================================
function checkPaymentForm(){
	
	var err = 0;
	var err_msg = 'Please correct the following: \r\n';
		
	var ccCheck = checkCreditCard ($("#cardNumber").val(), $("#cardType").val());
	var ccDateCheck = checkccdate($("#cardExpYear").val(), $("#cardExpMonth").val());	
	//alert(ccCheck);
	
	if (ccCheck == false){
		err = 1;
		err_msg += ' - Enter a valid credit card number.\r\n';
	}
	
	if (ccDateCheck == false){
		err = 1;
		err_msg += ' - Enter a valid credit card expiration date.\r\n';
	}	
	
	
	if (err > 0){
		alert(err_msg);
		return false;
	}
}


// ============================================================================================
function checkCremationLead(){

	var err = 0;
	var err_msg = 'Please correct the following: \r\n';
	
	if ($("#first_name").val().length < 1){
		err = 1;
		err_msg += ' - Enter your first name.\r\n';
	}
	
	if ($("#last_name").val().length < 1){
		err = 1;
		err_msg += ' - Enter your last name.\r\n';
	}	

	var ve = validEmail($("#email").val());
	if (ve == false){
		err = 1;
		err_msg += ' - Enter a valid email address.\r\n';
	}
	
	if ($("#Phone").val().length < 10){
		err = 1;
		err_msg += ' - Enter a phone number of at least 10 characters.\r\n';
	}	
	
	if (err > 0){
		alert(err_msg);
		return false;
	}	
}

// ==================================================== 
function isAlphanumeric(str){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(str.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}

// ==================================================== 
function salesRepCheck(skipCCcheck, isAdmin, recordID){
	var err = 0;
	var err_msg = 'Please correct the following: \r\n\r\n';
	
	if ( (!isAdmin) || (isAdmin == null) ){
		var ajaxFile = 'salesAgentDupCheck.lasso';
	}else{
		var ajaxFile = '../nep/salesAgentDupCheck.lasso';		
	}
	
	if ($('#officeLocationID').val() == ''){
		err = 1;
		err_msg += '- Select an office.\r\n';
	}
	
	if ( ($('#sales_rep_url').val() == '') || (isAlphanumeric($('#sales_rep_url').val()) == false) ){
		err = 1;
		err_msg += '- Enter a valid sales rep url. Only alphanumeric characters.\r\n';
	}else{
		
		if(typeof(recordID) === 'undefined') {
			var queryStr = "col=sales_rep_url&colValue="+$('#sales_rep_url').val();			
		}else{
			var queryStr = "col=sales_rep_url&colValue="+$('#sales_rep_url').val()+"&record_id="+recordID;
		}
		
		var checkURLDup  = $.ajax({
							   async: false,
							   type: "GET",
							   url: ajaxFile,
							   data: queryStr
							 }).responseText; 
							 
		if (checkURLDup == 'true'){
			err = 1;
			err_msg += '- That sales rep url has already been taken.  Please enter a different value.\r\n';
		}
	}
	

	if ($('#sales_rep_password').val().length < 6){
		err = 1;
		err_msg += '- Enter a password of at least 6 characters.\r\n';
	}
	
	if ( $('#sales_rep_password').val() != $('#confirm_password').val() ){
		err = 1;
		err_msg += '- Password confirmation must match your password.\r\n';
	}		
	
	if ($('#sales_rep_fname').val() == ''){
		err = 1;
		err_msg += '- Enter a first name.\r\n';
	}	

	if ($('#sales_rep_lname').val() == ''){
		err = 1;
		err_msg += '- Enter a last name.\r\n';
	}
	
	if ($('#sales_rep_job_title').val() == ''){
		err = 1;
		err_msg += '- Select a title.\r\n';
	}
	
	if ($('#sales_rep_phone').val().length < 10){
		err = 1;
		err_msg += '- Enter a full phone number.\r\n';
	}
	
	if (checkmail($('#sales_rep_email').val()) == false){
		err = 1;
		err_msg += '- Enter a valid email address.\r\n';
	}else{
		
		if(typeof(recordID) === 'undefined') {
			var queryStr2 = "col=sales_rep_email&colValue="+$('#sales_rep_email').val();			
		}else{
			var queryStr2 = "col=sales_rep_email&colValue="+$('#sales_rep_email').val()+"&record_id="+recordID;
		}
		
		var checkEmailDup  = $.ajax({
							   async: false,
							   type: "GET",
							   url: ajaxFile,
							   data: queryStr2
							 }).responseText;
							 
		if (checkEmailDup == 'true'){
			err = 1;
			err_msg += '- That email address is already registered in our system.\r\n';
		}		
	}
	
	if ($('#sales_rep_intro').val() == ''){
		err = 1;
		err_msg += '- Enter a bio.\r\n';
	}
	
	if ($('#languages').val() == null){
		err = 1;
		err_msg += '- Select at least one language.\r\n';
	}

	
	if ( (!skipCCcheck) || (skipCCcheck == null) ){
		var ccCheck = checkCreditCard ($("#cardNumber").val(), $("#cardType").val());
		var ccDateCheck = checkccdate($("#cardExpYear").val(), $("#cardExpMonth").val());	
		//alert(ccCheck);
		
		if (ccCheck == false){
			err = 1;
			err_msg += '- Enter a valid credit card number.\r\n';
		}
		
		if (ccDateCheck == false){
			err = 1;
			err_msg += '- Enter a valid credit card expiration date.\r\n';
		}
	}
	
	if (err > 0){
		alert(err_msg);
		return false;
	}
}

/*------------------------------------------------------------------------------------------------
	CHECKS TO SEE IF A STRING IS FORMATTED AS A VALID EMAIL ADDRESS
-------------------------------------------------------------------------------------------------*/
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
	var returnval=emailfilter.test(e);
	return returnval;
}


/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function toggleCCInfo(a){
	
	var t = a.value;
	
	if (t == 'newCard'){
		$('#newCCInfo').show();
	}else{
		$('#newCCInfo').hide();
	}
}


/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function checkUpdateSalesAgent(id){	
	
	var checkedVal = $('input[name=payment]:checked').val();	
	
	if (checkedVal == 'newCard'){		
		return salesRepCheck(null, null, id);
	}else{
		return salesRepCheck('skipCCcheck', null, id);
	}
}


/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function sendApproval(sID){
	
	var answer = confirm("Are you sure you want to trigger this email?")
	if (answer){		
		window.open ("/nep/customCommerceAdmin/sendSalesAgentNotification.lasso?sales_rep_id="+sID+"&type=approve","mywindow","status=0,toolbar=0,width=200,height=80"); 
	}
}


/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function sendDenial(sID){
	var answer = confirm("Are you sure you want to trigger this email?")
	if (answer){		
		window.open ("/nep/customCommerceAdmin/sendSalesAgentNotification.lasso?sales_rep_id="+sID+"&type=deny","mywindow","status=0,toolbar=0,width=200,height=80"); 
	}
}


/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function toggleEle(id){
	var d = document.getElementById(id);
	
	if (d.style.display == 'none'){
		$('#'+id).show();
	}else{
		$('#'+id).hide();
	}
}

/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function elementChanged(){ 	
	$('#fieldChanged').val('1');		
	//alert('detail modified');
}


/*------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------*/
function bssbs(theName,theExtras,theLink,theExt,theDomain) {
	var theEmail = theName+"@"+theDomain+"."+theExt;
	if (theName == ""){
		theName = "ERROR";
		theLink = "ERROR";
		myEmail = theName;
		myLink = theLink;
	}else{
		if ((theExtras == "") && (theLink =="")){
			myEmail = theEmail;
			myLink = theEmail;
		}
		if ((theLink == "") && (theExtras != "")){
			myLink = theEmail;
			myEmail = theEmail+theExtras;
		}
		if ((theLink != "") && (theExtras != "")){
			myLink = theLink;
			myEmail = theEmail+theExtras;
		}
		if ((theLink != "") && (theExtras == "")){
			myLink = theLink;
			myEmail = theEmail;
		}
	}
	document.write('<a href=mailto:' + myEmail + '>' + myLink + '</a>');
}






//** Form field Limiter v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com
//** Feb 25th, 09'- Script creation date
//** This notice must stay intact for legal use

var fieldlimiter={

defaultoutput: "<b>[int]</b> characters remaining in your text limit of [totalMax].", //default message that gets output to statusid element

uncheckedkeycodes: /(8)|(13)|(16)|(17)|(18)/, //keycodes that are not checked, even when limit has been reached. See http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml for avail keycodes

limitinput:function(e, config){
	var e=window.event || e
	var thefield=config.thefield
	var keyunicode=e.charCode || e.keyCode
	if (!this.uncheckedkeycodes.test(keyunicode)){
		if (thefield.value.length>=config.maxlength){
			if (e.preventDefault)
				e.preventDefault()
			return false
		}
	}
},

showlimit:function(config){
	var thefield=config.thefield
	var statusids=config.statusids
	var charsleft=config.maxlength-thefield.value.length
	if (charsleft<0) //if user has exceeded input limit (possible if cut and paste text into field)
		thefield.value=thefield.value.substring(0, config.maxlength) //trim input
	for (var i=0; i<statusids.length; i++){
		var statusdiv=document.getElementById(statusids[i])
		if (statusdiv){ //if status DIV defined
			var update = this.defaultoutput.replace("[int]", Math.max(0, charsleft));
			statusdiv.innerHTML=update.replace("[totalMax]", config.maxlength);
		}
	}
	config.onkeypress.call(thefield, config.maxlength, thefield.value.length)
},

cleanup:function(config){
	for (var prop in config){
		config[prop]=null
	}
},


addEvent:function(targetarr, functionref, tasktype){
	if (targetarr.length>0){
		var target=targetarr.shift()
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
			target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})
		this.addEvent(targetarr, functionref, tasktype)
	}
},

setup:function(config){
	if (config.thefield){ //if form field exists
		config.onkeypress=config.onkeypress || function(){}
		config.thefield.value=config.thefield.value
		this.showlimit(config)
		this.addEvent([window], function(e){fieldlimiter.showlimit(config)}, "load")
		this.addEvent([window], function(e){fieldlimiter.cleanup(config)}, "unload")		
		this.addEvent([config.thefield], function(e){return fieldlimiter.limitinput(e, config)}, "keypress")
		this.addEvent([config.thefield], function(){fieldlimiter.showlimit(config)}, "keyup")
	}
}

}



// ====================================================
function removeFromArr(arr, element){
	
	var ind = arr.indexOf(element);
	arr.splice(ind,1);
	
	return arr;
}


// ====================================================
function toggleSearch(el){

	var divArr = Array( 'zipCodeSearch', 'stateSearch', 'citySearch', 'countySearch', 'marketSearch', 'locationIdSearch', 'areaCodeSearch', 'marketCodeSearch' );
	var divToShow = $('#'+el).val();
	$('#'+divToShow).show();
	
	for ( var i=0; i < divArr.length; i++ ){
		if( divArr[i] != divToShow){
			//alert(divArr[i]);
			$('#'+divArr[i]).hide();
		}
	}				
}

// ====================================================
function OLDtoggleSearch(el){

	var divArr = Array( 'zipCodeSearch', 'stateSearch', 'citySearch', 'countySearch', 'marketSearch', 'locationIdSearch', 'areaCodeSearch', 'marketCodeSearch' );
	var divToShow = $('#'+el).val();
	
	$('#'+divToShow).show();

	var divsToHide = removeFromArr(divArr, divToShow);
	
	for ( var i=0; i < divsToHide.length; i++ ){
		$('#'+divsToHide[i]).hide();
	}				
}

// ====================================================
function toggleBulkUpdate(formID){
	var fm = document.getElementById(formID);
	var checkedCount = 0;
	
	// If there is only 1 company/check box on the list (search result, for example)
	if (fm.zipcode_id.length == undefined){
		
		if (fm.zipcode_id.checked == true){
			checkedCount = 1;
		}
	}else{
		for (i=0; i < fm.zipcode_id.length; i++) {
			if (fm.zipcode_id[i].checked == true){
				checkedCount++
			}
		}
	}
					
	if (checkedCount > 0){	
		document.getElementById('bulkUpdateTable').style.display = 'block';
	}else{
		document.getElementById('bulkUpdateTable').style.display = 'none';
	}
}


// ====================================================
function toggleSelect(el, i){
	
	var val = el.value;
	
	if (val == 'active'){
		$('#'+i).val('');
		$('#'+i).attr('disabled', true);
	}else{
		$('#'+i).attr('disabled', false);
	}
}


// ====================================================
function checkZipUpdate(radioName, reasonID){
	
	var err = 0;
	var err_msg = 'Please correct the following:\r\n\r\n';
		
	var dmStatus = $("input[name='"+radioName+"']:checked").val();
	var dmReason = $('#'+reasonID).val(); 	
	
	if ( (dmStatus == 'inactive') && (dmReason == '') ){
		err = 1;
		err_msg += '- If the DM Status is inactive, you must provide a reason.';
	}
	
	if (err > 0){
		alert(err_msg);
		return false;	
	}		
}

// ====================================================
function getSubUniverse(site, skip, place){
	$("#newSubUniverse").hide();
  	$('#newPutSubUniverse').html("");
  	
	if(place == 'bottom'){
		var val = $("#new_market_id").val();
	}else{
		var val = $("#market_id").val();
	}
	
	$.post('../'+site+'/customCommerceAdmin/sub_universe.lasso', { market_id: val, skip: skip, place: place }, function(html) {
  		if(place == 'bottom'){
  			if(html.length > 0){
  				$("#newSubUniverse").show();
  				$('#newPutSubUniverse').html(html);
  			}
  		}else{
  			$('#putSubUniverse').html(html);
  		}
	});

}

// ====================================================
function selectSubUniverse(v,place){
	if(place == 'bottom'){
		var val = $(v).val();
		$("#new_sub_universe").val(val);
	}else{
		var val = $("#subuniverse").val();
		$("#sub_universe").val(val);
	}
}














