/* 2nd deptsku page */

//get all departments
//get all products

//display departments intermingled with products

//dont repeat departments if there are multiple pages



function display_products_gen(Dept_products_gen,p_display_type){ 
	if (p_display_type==null){p_display_type=display_type;}
	if (Dept_products_gen.length >= 1){
		//heading for Product Selections
		document.write('<span class="heading"> </span>');
		
		var n_product=0;
		var atn;      
		document.write(p_top_HTML);
		document.write(style_UL_open);	
		for (atn=0;atn< Dept_products_gen.length ;atn++){
			if (n_product==0 || p_display_type != 4){document.write(style_LI_2_open + style_font_2_open);}
			if (page_option_5==1){
								
				//display a product
				drawAproduct(Dept_products_gen[atn]);
				
				n_product=n_product+1;
				if(p_display_type==4){
					if (n_product==dept_cols){
						n_product=0;
						document.write(style_LI_2_close);
					}else{
						document.write(style_font_2_close +" </TD><TD>" +style_font_2_open);
					}
				}else{
					document.write(style_LI_2_close);
				}					
			}
		} //end for loop
		document.write(style_UL_close);	
	}else{
		document.write(style_font_1_open + p_no_product_HTML + style_font_1_close);
	}
} //end display_products_gen



function display_dept_gen(display_dept_gen){  
	if (display_dept_gen.length >= 1){
		//heading for Collections
		document.write('<span class="heading"> </span>');
		
		var n_dept=0;
		var atn; 
		document.write(s_top_HTML);
		document.write(style_UL_open);	
		   
		for (atn=0;atn< display_dept_gen.length ;atn++){
			if (n_dept==0 || d_display_type!=4){document.write(style_LI_1_open + style_font_2_open);}
			n_dept=n_dept+1 ;
			
			//draw a department
			drawAdepartment(display_dept_gen[atn]);
			
			if(d_display_type==4){
				if (n_dept==dept_cols){
					n_dept=0;
					document.write(style_LI_1_close);
				}else{
					document.write(style_font_2_close +"</TD><TD>" + style_font_2_open);
				}
			}else{
				document.write(style_LI_1_close);
			}	
		} //end loop
		document.write(style_UL_close);
	}
} //end display_dept_gen 



function display_spanner_links(intCurrentPage,intMaxPages,spanner_links){document.write('<span class="PageSpanner"><font class="spanColor">&lt;</font>&nbsp;&nbsp;' + spanner_links + '&nbsp;&nbsp;<font class="spanColor">&gt;</font></span>');}


function drawAproduct(Dept_products_gen)
{
				if  (p_image_align=="CENTER"){          
					document.write("<TABLE width=100% BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" ALIGN=CENTER > <TR><TD ALIGN=CENTER >" + style_font_2_open);                    
				}
				if (Dept_products_gen.image!=""){
					document.write("<A HREF=\"#\" onClick=return(visitargs('product.asp','dept_id="+ Dept_products_gen.dept_id +"&pf_id="+Dept_products_gen.pf_id +"&"+ ptargetc +"','URL'));  target=_top >");
					document.write("<IMG ALIGN="+ p_image_align +" ");
					if(p_image_width==""){
						if (Dept_products_gen.image_width!=""){
							document.write(" WIDTH="+Dept_products_gen.image_width +" ");				
						}
					}else{
						document.write(" WIDTH ="+ p_image_width + " ");
					}
					document.write(" BORDER=0  VSPACE=5  HSPACE=5  ALT=\""+ Dept_products_gen.name +" \" ");  	
					document.write(" SRC=\"assets/product_images/"+ Dept_products_gen.image +"\"></A>");  	
					if  (p_image_align=="CENTER"){ 
						document.write(" </TD></TR> <TR><TD ALIGN=CENTER >"+ style_font_2_open);
					}
				}
				
				display_product_link("product.asp?s_id="+ s_id +"&dept_id="+ Dept_products_gen.dept_id +"&pf_id="+ Dept_products_gen.pf_id +"&"+ ptargetc,Dept_products_gen.name,Dept_products_gen.short_desc,Dept_products_gen.price_str,s_id,Dept_products_gen.dept_id,Dept_products_gen.pf_id,Dept_products_gen.enable_basket);
			   
				if( p_image_align=="CENTER"){document.write(" </TABLE>");}	  
}

function drawAdepartment(display_dept_gen)
{
			if (s_image_align=="CENTER"){             
				document.write("<TABLE width=100% BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" ALIGN=CENTER > <TR><TD ALIGN=CENTER >"+ style_font_2_open);
			}
			if (display_dept_gen.dept_image_1_file!=""){
				document.write("<A HREF=\"#\" onClick=return(visitargs('dept.asp','dept_id=" + display_dept_gen.dept_id +"&','URL')); class=\"deptlinkM\" target=_top >");
				document.write("<IMG ALIGN="+ s_image_align +" ");
				if(s_image_width==""){
					if (display_dept_gen.dept_image_1_width!=""){
						document.write(" WIDTH="+ display_dept_gen.dept_image_1_width +" ");				
					}
				}else{
					document.write(" WIDTH ="+ s_image_width + " ");
				}
				document.write(" BORDER=0  VSPACE=5  HSPACE=5  ALT=\""+ display_dept_gen.dept_name +"\" ");  	
				//if (s_image_src=="PRODUCT"){
					document.write(" SRC=\"assets/product_images/"+ display_dept_gen.dept_image_1_file +"\"></A>");  	
				//}else{
					//document.write(" SRC=\"assets/images/"+ display_dept_gen.dept_image_1_file +"\"></A>");  				    
				//}
				if (s_image_align=="CENTER"){ 
					document.write(" </TD></TR> <TR><TD ALIGN=CENTER >"+ style_font_2_open);
				}		
			}
			if(display_dept_gen.dept_disable_name=="" || display_dept_gen.dept_disable_name < 2){
				if (display_dept_gen.dept_display_type==1 || display_dept_gen.dept_display_type==4){
					document.write("<A HREF=\"#\" onClick=return(visitargs('dept.asp','dept_id="+ display_dept_gen.dept_id +"&','URL')); class=\"deptlinkM\" target=_top >"+ display_dept_gen.dept_name +"</A>");
				}else if (display_dept_gen.dept_display_type==2){
					document.write("<A HREF=\"#\" onClick=return(visitargs('frameset.asp','target="+ display_dept_gen.dept_hyperlink +"&','URL')); class=\"deptlinksub\" target=_top >"+ display_dept_gen.dept_name +"</A>");	
				}else{
					document.write("<A HREF=\"#\" onClick=return(visitargs('"+ display_dept_gen.dept_hyperlink +"','','URL')); class=\"deptlinkP\" target=_top >"+ display_dept_gen.dept_name +"</A>");							
				}
			}
			document.write(display_dept_gen.dept_short_description);
			
			if (display_dept_gen.attached_products!=null && display_dept_gen.attached_products.length>0){
				display_products_gen(display_dept_gen.attached_products,1);
			}
			if (display_dept_gen.attached_depts!=null && display_dept_gen.attached_depts.length>0){
				display_dept_2nd(display_dept_gen.attached_depts);
			}
			if  (s_image_align=="CENTER"){document.write(" </TABLE>");}
}
