/* checks that dimensions are between 1 and 99
Original:  Nannette Thacker http://www.shiningstar.net  */


function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + "." + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";
var code = $('#code').val();

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval) && code !='123CUST')
{
alertsay = "If you would like to order more than 100 catalogs,\n"
alertsay = alertsay + "please call 1-800-977-0025.\n"
alert(alertsay);
return (false);
}
}

//FORM VALIDATION


function ship_to(){ 
	if($("#ship_to_bill").attr('checked') != true){
		$('#billing_info').show();
	}else{
		$('#billing_info').hide();
	}
}

function validate_form1(){
var error = '';
$('error_box').hide();

if($('#f_school_name').val() == ''){
	error = error + 'School Name is required<br />';
}
if($('#f_group_name').val() == ''){
	error = error + 'Group Name is required<br />';
}	

if($('#f_number_of_catalogs').val() == ''){
	error = error + 'Number of Catalogs is required<br />';
}	

if($('#fs_school_name').val() == ''){
	error = error + 'Shipping School Name is required<br />';
}	

if($('#fs_advisor').val() == ''){
	error = error + 'Advisor Name is required<br />';
}
	
if($('#fs_group_name').val() == ''){
	error = error + 'Group Name is required<br />';
}	

if($('#fs_address1').val() == ''){
	error = error + 'Shipping Address is required<br />';
}	

if($('#fs_city').val() == ''){
	error = error + 'Shipping City is required<br />';
}	

if($('#fs_state').val() == ''){
	error = error + 'Shipping State is required<br />';
}	

if($('#fs_zip').val() == ''){
	error = error + 'Shipping Postal Code is required<br />';
}	

if($('#fs_phone').val() == ''){
	error = error + 'Shipping Phone is required<br />';
}	

if($('#fs_email').val() == ''){
	error = error + 'Shipping Email is required<br />';
}	

if($('#f_image').val() ==''){
	error = error + 'Please click the Preview My Catalog button again before submitting. If you have made any changes to the catalog, make sure they are displayed on the catalog image to the left.<br />';
}

if(error != ''){
	$('#error_box').html(error);
	$('#error_box').show();
	//$(...).scrollTo( '#error_box', 1000 );
	$('html, body').animate({scrollTop:0}, 'slow'); 
	return false;
}else{
	return true;
			
}

}


function validate_form2()
{
	var error = '';
	$('error_box').hide();
	
	if($('#school_name').val() == '' || $('#school_name').val() == 'Your School Name Here'){
		error = error + 'School Name is required in the Catalog Preview area.<br />';
	}
	if($('#group_name').val() == 'Group Name'){
		error = error + 'Group Name must be blank or filled in with your group name in the Catalog Preview area.<br />';
	}	
	
	if($('#number_of_catalogs').val() == ''){
		error = error + 'Number of Catalogs is required<br />';
	}	
	
	if($('#s_school_name').val() == ''){
		error = error + 'Shipping School Name is required<br />';
	}	
	
	if($('#s_advisor').val() == ''){
		error = error + 'Advisor Name is required<br />';
	}
		
	if($('#s_group_name').val() == ''){
		error = error + 'Group Name is required<br />';
	}	
	
	if($('#s_address1').val() == ''){
		error = error + 'Shipping Address is required<br />';
	}	
	
	if($('#s_city').val() == ''){
		error = error + 'Shipping City is required<br />';
	}	
	
	if($('#s_state').val() == ''){
		error = error + 'Shipping State is required<br />';
	}	
	
	if($('#s_zip').val() == ''){
		error = error + 'Shipping Postal Code is required<br />';
	}	
	
	if($('#s_phone').val() == ''){
		error = error + 'Shipping Phone is required<br />';
	}	
	
	if($('#s_email').val() == ''){
		error = error + 'Shipping Email is required<br />';
	}	
	
	if($('#r_image').val() ==''){
		error = error + 'Please click the &quot;See Your Custom School Cover&quot; button before submitting. If you have made any changes to the catalog, make sure they are displayed on the catalog image to the left.<br />';
	}
	
	if($('#ship_to_bill').attr('checked') != true){
	
			if($('#b_school_name').val() == ''){
				error = error + 'Billing School Name is required<br />';
			}	
			
			if($('#b_advisor').val() == ''){
				error = error + 'Advisor Name is required<br />';
			}
				
			if($('#b_group_name').val() == ''){
				error = error + 'Group Name is required<br />';
			}	
			
			if($('#b_address1').val() == ''){
				error = error + 'Billing Address is required<br />';
			}	
			
			if($('#b_city').val() == ''){
				error = error + 'Billing City is required<br />';
			}	
			
			if($('#b_state').val() == ''){
				error = error + 'Billing State is required<br />';
			}	
			
			if($('#b_zip').val() == ''){
				error = error + 'Billing Postal Code is required<br />';
			}	
			
			if($('#b_phone').val() == ''){
				error = error + 'Billing Phone is required<br />';
			}	
			
			if($('#b_email').val() == ''){
				error = error + 'Billing Email is required<br />';
			}	
		
	}
	
	if($('#confirm_order').attr('checked') != true){
		error = error + 'You must confirm the preview is approved for printing.<br />';
	}
	
	if(error != '')
	{
		$('#error_box').html(error);
		$('#error_box').show();
		//$(...).scrollTo( '#error_box', 1000 );
		$('html, body').animate({scrollTop:0}, 'slow'); 
		return false;
	}
	else
	{
		/// verfiy customer wants to leave lines 3, 4, and 5 and blank
		if($('#line_three').val()+$('#line_four').val()+$('#line_five').val()=='')
		{
			var answer = confirm('Are you sure you want to leave the reasons for your fundraiser blank\n on the front cover? (lines 3, 4, and 5)');
			
			if (answer==0) 
			{ 
				$('#line_three').focus();
				return false;
			} 
			
		}
		return true;
	}

}

function PreviewCatalog(){
var school_name = $('#school_name').val();
var group_name = $('#group_name').val();
var line_three = $('#line_three').val();
var line_four = $('#line_four').val();
var line_five = $('#line_five').val();
	 	$.ajax({
	    type: "POST",
   		url: "Catalog.php",
 		data: "school_name_catalog="+escape(school_name)+"&group_name_catalog="+escape(group_name)+"&line_3_catalog="+escape(line_three)+"&line_4_catalog="+escape(line_four)+"&line_5_catalog="+escape(line_five),
   		success: function(msg){
     		//$('#catalog').hide('fast');
			  $('#catalog').attr("src",msg);
			  $('#image').val(msg);
			  
			  $('#f_image').val(msg);
			   $('#f_school_name').val(school_name);
			   $('#f_group_name').val(group_name);

			   $('#f_line_3').val(line_three);
			   $('#f_line_4').val(line_four);
			   $('#f_line_5').val(line_five);

			   $('#r_line_3').val(line_three);
			   $('#r_line_4').val(line_four);
			   $('#r_line_5').val(line_five);


			  $('#r_image').val(msg);
			   $('#r_school_name').val(school_name);
			   $('#r_group_name').val(group_name);
			   
			   
			   $('#printCatalog').show();
			 // $('#catalog').show('slow');
	   		}
 		});
}

function combine(){
	school_name = $('#school_name').val();
	group_name = $('#group_name').val();

	 $('#line_four').val(school_name+" "+group_name);
}	 


function CatalogPrint() {
image = $('#catalog').attr('src');
window.open( "PrintCatalog.php?i="+image, "printWindow","status = 1, height = 540, width = 420, resizable = 0,scrollbars=yes" )
}

