/*

if((zone=="east")||(zone=="unsupported"))
{

}
else if(zone=="west")
{

}
*/
//http://stackoverflow.com/questions/877328/jquery-disable-select-options-based-on-radio-selected-need-support-for-all-brows
//change the pulldown options based upon the radio value changes
jQuery.fn.filterOn = function(radio, values) {
    return this.each(function() {
        var select = this;
        var options = [];
        $(select).find('option').each(function() {
            options.push({value: $(this).val(), text: $(this).text()});
        });
        $(select).data('options', options);
        $(radio).click(function() {
            var options = $(select).empty().data('options');
            var haystack = values[$(this).attr('id')];
			
            $.each(options, function(i) {
                var option = options[i];
				
                if($.inArray(option.value, haystack) !== -1) {
                    $(select).append(
                    $('<option>').text(option.text).val(option.value)
                    );
                }
            });
        });            
    });
};
$(function() {
	if(pId==3)
	{//based upon a given layout selection, different options are available in the move name drop down. that ishandled here.
	
		$('#attrib-13').filterOn('input:radio[name=id[52]]', {
			'150': ['59','60','63'],
			'151': ['59','60','61','62','63'],
			'152': ['59','60','63'],
			'153': ['59','60','61','62','63'],
			'154': ['59','60','63'],
			'155': ['59','60','63']
		});
	}//end is headshots
	if(pId==5)
	{
		$('#attrib-13').filterOn('input:radio[name=id[52]]', {
			'150': ['59','60','63'],
			'151': ['59','60','61','62','63'],
			'152': ['59','60','61','62','63'],
			'153': ['59','60','61','62','63'],
			'154': ['59','60','63'],
			'155': ['59','60','63']
		});
	}//end is bc
	if(pId==4)
	{
		$('#attrib-13').filterOn('input:radio[name=id[52]]', {
			'150': ['59','60','63'],
			'151': ['59','60','61','62','63'],
			'152': ['60'],
			'153': ['59','60','61','62','63'],
			'154': ['59','60','63'],
			'155': ['59','60','63']
		});
	}//end is bc
})
function ensureDropDowns()
{
	//$("input[name='id[52]']").getValue().click();
	$("input[name='id[52]']:checked").click();
	
	
	
}
//150 Vertical With Boarder
//151 Vertical Borderless
//152 Horizontal with Borders
//153 Horizonal Borderless
//154 Horizontal on Vertical Border
//155 Horizontal on Vertical Bleed

var currentLayoutChoice=false;
function validateForm(divout,divin,template_name)
{
	/*
	if(template_name=="headshots_design_layout")
	{
		$(".wiz_DIL_cont").show();
		$(".wiz_body_cont").css({"width":"575px"});		
	}
	if(template_name=="headshots_upload")
	{
		$(".wiz_DIL_cont").hide();
		$(".wiz_body_cont").css({"width":"100%"});		
	}
	*/
	
	var pass=false;
	if(pId!=0)
	{

		if(template_name=="headshots_select")
		{
			//if paper choice not selected show error
			if(pId==3)
			{
				if(($("input[name='id[1]']").getValue())==""){$("#id_1_error").show();pass=false;}else{$("#id_1_error").hide();pass=true;}
				
				if((zone=="east")||(zone=="unsupported"))
				{
					if((($("#id_2").val())=="")&&(($("#id_3").val())=="")){$("#id_3_error").show();pass=false;}else{$("#id_3_error").hide();pass=true;}
				}
				else if(zone=="west")
				{
					if((($("#id_36").val())=="")&&(($("#id_37").val())=="")){$("#id_37_error").show();pass=false;}else{$("#id_37_error").hide();pass=true;}
				}
			}
			if(pId==5)
			{
				if((zone=="east")||(zone=="unsupported"))
				{
					if((($("#id_33").val())=="")){$("#id_3_error").show();pass=false;}else{$("#id_3_error").hide();pass=true;}
				}
				else if(zone=="west")
				{
					
					if((($("#id_38").val())=="")){$("#id_3_error").show();pass=false;}else{$("#id_3_error").hide();pass=true;}
				}
			}
			if(pId==4)
			{
				if((zone=="east")||(zone=="unsupported"))
				{
					if((($("#id_34").val())=="")){$("#id_3_error").show();pass=false;}else{$("#id_3_error").hide();pass=true;}
				}
				else if(zone=="west")
				{
					if((($("#id_40").val())=="")){$("#id_3_error").show();pass=false;}else{$("#id_3_error").hide();pass=true;}
				}
				//check headshot type choice
				
				if( ( ($("input[name='id[25]']").getValue())=="")){$("#id_25_error").show();pass=false;}else{$("#id_25_error").hide();if(pass!=false){pass=true;}}
				
				
				if($("input[name='id[25]']").getValue()==47)
				{//2 sided, set the maxupload to 2
					maxUploadFiles=2;
				}
				else
				{
					maxUploadFiles=1;
				}
				
			}
			if(pId==6)
			{//compcards
				if((zone=="east")||(zone=="unsupported"))
				{
					if((($("#id_32").val())=="")){$("#id_3_error").show();pass=false;}else{$("#id_3_error").hide();pass=true;}
				}
				
				
				
			}
			
		}//end tab 1
		if(template_name=="headshots_upload")
		{
			if((fileUploaded==true)||($("input[name='id[txt_7]']").getValue()!=""))
			{
				
				if(($("input[name='id[txt_9]']").getValue()!=""))
				{
					var pass=true;
					$("#id_9_error").hide(); 
				}
				else
				{
					$("#id_9_error").show(); var pass=false;	
				}
				$("#id_6_48_error").hide();
			}
			else
			{
				if(  $("input[name='id[6][48]']").getValue()=="")
				{
					
					$("#id_6_48_error").show(); var pass1=false;
				}
				else
				{
					$("#id_6_48_error").hide(); var pass1=true;
				}
				if($("input[name='id[txt_8]']").getValue()=="")
				{
					
					$("#id_8_error").show(); var pass2=false;
				}
				else
				{
					$("#id_8_error").hide(); var pass2=true;
				}
				if($("input[name='id[txt_9]']").getValue()=="")
				{
					$("#id_9_error").show(); var pass3=false;
				}
				else
				{
					$("#id_9_error").hide(); var pass3=true;
				}
				if((pass1==true)&&(pass2==true)&&(pass3==true))
				{
					pass=true;
					
				}
				else
				{
					pass=false;
				}
			}
			if((pId==7)&&(pass==true))
			{//if retouching product, send prompt for review page
				$("#cart_quantity").attr("action","sessionManager.php");
				$("#cart_quantity").attr("target","sessionManagerFrame");
				document.forms.cart_quantity.queryZC.value=1;
				setTimeout("document.forms.cart_quantity.submit()",100);
			}
			
		}//end tab 2
		
		if(template_name=="headshots_design_layout")
		{//setupDIL
			
			ensureDropDowns();
			if($("input[name='id[52]']").getValue()=="")
			{
				$("#id_52_error").show(); pass=false;
			}
			else
			{
				$("#id_52_error").hide(); pass=true;
				prepareDILform();
			}
		}
		if(template_name=="headshots_design_customize")
		{
			if(  ($("input[name='id[txt_16]']").getValue()=="") ||($("input[name='id[txt_18]']").getValue()==""))
			{
				$("#id_16_error").show(); pass=false;
			}
			else
			{
				$("#id_16_error").hide(); pass=true;
			}
		}
		if(template_name=="headshots_design_about")
		{
			
			pass=true;
			if($("input[name='id[5]']").getValue()==25)
			{
				$("#wizard_3_4_reorder").show();
			}
			else
			{
				$("#wizard_3_4_reorder").hide();
			}
		}
		if((divout==3)&&((divin==4)))
		{
			
			pass=true;
		}
		if(template_name=="headshots_review_retouching")
		{
			if(pId==7)
			{//is retouching, perform extra validation
				if($("input[name='id[41]']").getValue()==125)
				{//if yes, require input
					pass=true;
					$("#retouch_choice_error").hide();
					//if retouching review doesn't exist perform the review check here
					if($("#id_45_error").length > 0)
					{//proof page exists
					
					}
					else
					{//doesn't send review
						//done at end of upload
						//$("#cart_quantity").attr("action","sessionManager.php");
						//$("#cart_quantity").attr("target","sessionManagerFrame");
						//document.forms.cart_quantity.queryZC.value=1;
						//setTimeout("document.forms.cart_quantity.submit()",100);
						
						
					}
				}
				else
				{//no, show error
					$("#retouch_choice_error").show();
					pass=false;
				}
			}
			else
			{//not retouching as a product
				pass=true;
				
				//if retouching review doesn't exist perform the review check here
				if($("#id_45_error").length > 0)
				{//proof page exists
				
				}
				else
				{//doesn't send review
					$("#cart_quantity").attr("action","sessionManager.php");
					$("#cart_quantity").attr("target","sessionManagerFrame");
					document.forms.cart_quantity.queryZC.value=1;
					setTimeout("document.forms.cart_quantity.submit()",100);
					
				}
			}
		}
		if(template_name=="headshots_review_bdr")
		{
			//pass=true;
			
			if($("input[name='id[46]']").getValue()==144)
			{//if yes, require input
				if( ($("input[name='id[47]']").getValue()=="") )
				{
					$("#bdr_error").show();
					pass=false;
				}
				else
				{
					$("#bdr_error").hide();
					//if retouching review doesn't exist perform the review check here
					if($("#id_45_error").length > 0)
					{//proof page exists
					
					}
					else
					{//doesn't send review
						$("#cart_quantity").attr("action","sessionManager.php");
						$("#cart_quantity").attr("target","sessionManagerFrame");
						document.forms.cart_quantity.queryZC.value=1;
						setTimeout("document.forms.cart_quantity.submit()",100);
						
					}
					
					pass=true;	
				}
			}
			else
			{
				$("#bdr_error").hide();
				//if retouching review doesn't exist perform the review check here
				if($("#id_45_error").length > 0)
				{//proof page exists
				
				}
				else
				{//doesn't send review
					$("#cart_quantity").attr("action","sessionManager.php");
					$("#cart_quantity").attr("target","sessionManagerFrame");
					document.forms.cart_quantity.queryZC.value=1;
					setTimeout("document.forms.cart_quantity.submit()",100);
					
				}
				pass=true;	
			}
			if((pId==9)&&(pass==true))
			{//if bdr, submit the review screen now
				$("#cart_quantity").attr("action","sessionManager.php");
				$("#cart_quantity").attr("target","sessionManagerFrame");
				document.forms.cart_quantity.queryZC.value=1;
				//alert('here');
				setTimeout("document.forms.cart_quantity.submit()",100);	
				
			}
			
			//if this is bdr require a yes
			if(pId==9)
			{//this is a bdr
			//alert($("input[name='id[47]']").getValue());
				if(($("input[name='id[46]']").getValue()!=144)||($("input[name='id[47]']").getValue()==""))
				{
					pass=false;
					if($("input[name='id[46]']").getValue()!=144)
					{
						$("#bdr_choice_error").show();
					}
					else
					{
						$("#bdr_choice_error").hide();
					}
						
					if($("input[name='id[47]']").getValue()=="")
					{
						$("#bdr_error").show();
					}
					else
					{
						$("#bdr_error").hide();	
					}
				}
				else
				{
					
					$("#cart_quantity").attr("action","sessionManager.php");
					$("#cart_quantity").attr("target","sessionManagerFrame");
					document.forms.cart_quantity.queryZC.value=1;
					setTimeout("document.forms.cart_quantity.submit()",100);
					$("#bdr_choice_error").hide();
					pass=true;
				}
			}
		}
		if(template_name=="headshots_review_proof")
		{
			if($("input[name='id[45]']").getValue()=="")
			{
				$("#id_45_error").show();pass=false;
			}
			else
			{
				$("#id_45_error").hide();pass=true;
			}
			$("#cart_quantity").attr("action","sessionManager.php");
			$("#cart_quantity").attr("target","sessionManagerFrame");
			document.forms.cart_quantity.queryZC.value=1;
			//alert('here');
			setTimeout("document.forms.cart_quantity.submit()",100);
			//setTimeout("document.forms.cart_quantity.queryZC.value=0",400);
			//alert($("#cart_quantity").serialize());
			
		}
		
		if(template_name=="headshots_review_submit")
		{
			//pass=true;
			
			if($("input[name='id[txt_50]']").getValue()=="")
			{
				$("#id_50_error").show();
				pass=false;
			}
			else
			{
				
				$("#loadingScreen").dialog("open");
				$("#id_50_error").hide();
				$("#cart_quantity").attr("action","../index.php?main_page=product_info&cPath=2_3&products_id="+pId+"&number_of_uploads=1&action=add_product");
				$("#cart_quantity").attr("target","_top");
				document.forms['cart_quantity'].submit();
				
			}
		}
	
		
		/*if((pass==true)&&(divout==2)&&(isReorder==true))
		{//is a reorder, skip steps
			divout=2;
			divin=3;
			//alert('here');
			loadnext('sub_3_1','sub_3_2');
			setTimeout("loadnext('sub_3_2','sub_3_3')",1);
			setTimeout("loadnext('sub_3_3','sub_3_4')",2);
			setTimeout("loadnext("+divout+","+divin+")",3);
			return;
		}*/
		
		
		if((pass==true)||(ignoreValidation==true))
		{
			loadnext(divout,divin);	
		}
	//
	}// end have pId
}//end validate form

function resetSubTabs()
{//return subtabs to original state
	
	

	
	
}



