/* ==== Get Interior, exterior colors, brands, style by selected vertical id========= */ 
var selected_id = new Array();
var selected_brand = new Array();
var selected_brandname = new Array();
var optionproductrelation = new Array();
var alloptions = new Array(); //For achieving options selected issue.
var allpopularoptions = new Array(); //For achieving options selected issue.
var all_product_rows = new Array(); //For achieving options selected issue.
var picture_image_set = "";
var performance_data_set = "";
var warranty_set = "";
var how_to_measure_set = "";
var how_to_install_set = "";
var testimonials_set = "";
var sort_by = "";
var bHarshal = "";

function get_data(){
		
	vertical_id = $('vertical').value;
	interior_color = $('interior_colors').value;
	exterior_color = $('exterior_colors').value;
	brand_id = $('brands').value;
		
	new ajax('ajax.php', {postBody: 'method=get_data&vertical_id='+vertical_id+'&interior_color='+interior_color+'&exterior_color='+exterior_color+'&brand_id='+brand_id, onComplete: get_data_callback});
	$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	$("WAIT").toggle();
	$("COVER").toggle();
	$("COVER").style.height = Screen.getDocumentHeight()+'px';
		
}
function get_data_callback(request){

	$("WAIT").toggle();
	$("COVER").toggle();
//alert(request.responseText);
	vertical_cmb = $('vertical');
	int_color_cmb = $('interior_colors');
	ext_color_cmb = $('exterior_colors');
	brand_cmb = $('brands');
	style_cmb = $('styles');
	callout_cmb = $('callouts');
	
	int_color_index = int_color_cmb.selectedIndex;
	ext_color_index = ext_color_cmb.selectedIndex;
		
	if(request!=null){

		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			int_cmb = int_color_cmb.options.length;
			for(i=0; i< int_cmb; i++){
				int_color_cmb.options[0] = null;
			}
			ext_cmb = ext_color_cmb.options.length;
			for(i=0; i< ext_cmb; i++){
				ext_color_cmb.options[0] = null;
			}
			br_cmb = brand_cmb.options.length;
			for(i=0; i< br_cmb; i++){
				brand_cmb.options[0] = null;
			}
			st_cmb = style_cmb.options.length;
			for(i=0; i< st_cmb; i++){
				style_cmb.options[0] = null;
			}

			if(response.RESULT=="OK"){
				if(response.INTERIOR_ID.length>0){
					
					for(i=0; i<response.INTERIOR_ID.length; i++){
						var optn = new Option();
						optn.value = response.INTERIOR_ID[i];
						optn.text = response.INTERIOR_VALUES[i];
						if(response.INTERIOR_VALUES[i] == "White")
							optn.selected = " Selected";
						int_color_cmb.options[int_color_cmb.options.length] = optn;
					}
				}else{
						var optn = new Option();
						optn.value = 0;
						optn.text = "No Color Found";
						int_color_cmb.options[int_color_cmb.options.length] = optn;
				}
				if(response.EXTERIOR_ID.length>0){
					
					for(i=0; i<response.EXTERIOR_ID.length; i++){
						var optn = new Option();
						optn.value = response.EXTERIOR_ID[i];
						optn.text = response.EXTERIOR_VALUES[i];
						if(response.EXTERIOR_VALUES[i] == "White")
							optn.selected = " Selected";
						ext_color_cmb.options[ext_color_cmb.options.length] = optn;
					}
				}else{
						var optn = new Option();
						optn.value = 0;
						optn.text = "No Color Found";
						ext_color_cmb.options[ext_color_cmb.options.length] = optn;
				}
				if(response.BRAND_ID.length>0){
					
					if(response.BRAND_ID.length > 1){
						var optn = new Option();
						optn.value = '0';
						optn.text = 'All Brands';
						brand_cmb.options[brand_cmb.options.length] = optn;
					}
					for(i=0; i<response.BRAND_ID.length; i++){
						var optn = new Option();
						optn.value = response.BRAND_ID[i];
						optn.text = response.BRAND_VALUES[i];
						brand_cmb.options[brand_cmb.options.length] = optn;
					}
				}else{
						var optn = new Option();
						optn.value = 0;
						optn.text = "No Brand Found";
						brand_cmb.options[brand_cmb.options.length] = optn;
				}
				if(response.STYLE_ID.length>0){
					
					for(i=0; i<response.STYLE_ID.length; i++){
						var optn = new Option();
						optn.value = response.STYLE_ID[i];
						optn.text = response.STYLE_VALUES[i];
						style_cmb.options[style_cmb.options.length] = optn;
					}
				}else{
						var optn = new Option();
						optn.value = 0;
						optn.text = "No Style Found";
						style_cmb.options[style_cmb.options.length] = optn;
				}//alert(response.CALLOUT);
				if(response.CALLOUT != ""){
					$('callout').style.display = "block";
					$('nocallout').style.display = "none";
					if(response.CALLOUT.length>0){
						
						for(i=0; i<response.CALLOUT.length; i++){//alert(response.CALLOUT[i]);
							var optn = new Option();
							optn.value = response.CALLOUT[i];
							optn.text = response.CALLOUT[i];
							if(i == 0)
								optn.selected = " Selected";
							callout_cmb.options[callout_cmb.options.length] = optn;
						}
					}else{
							var optn = new Option();
							optn.value = 0;
							optn.text = "No Callout Found";
							callout_cmb.options[callout_cmb.options.length] = optn;
					}
					setWHValueFromCallOut(response.CALLOUT[0]);
/*					var firstCallout = response.CALLOUT[0];
					var partCallout = firstCallout.split("W");
					var w = partCallout[0];
					var partCalloutH = partCallout[1].split("H");
					var h = partCalloutH[0];
					$('width').value = w;
					$('height').value = h;
					$('widthTempToShow').innerHTML = w;
					$('heightTempToShow').innerHTML = h;
*/				}else{
					$('callout').style.display = "none";
					$('nocallout').style.display = "block";
					$('width').value = 24;
					$('height').value = 35;
					get_price_list();
				}
			}
		}
	}
}


/* ======================================================================== */

/* ============ Get Exterior Colors list from selected interior color ========= */
function get_exterior_colors(){
	
	interior_color = $('interior_colors').value;
	vertical_id = $('vertical').value;
	
	new ajax ('ajax.php', {postBody: 'method=get_exterior_colors&int_color='+interior_color+'&vertical_id='+vertical_id, onComplete: get_exterior_colors_callback });
	$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	$("WAIT").toggle();
	$("COVER").toggle();
	$("COVER").style.height = Screen.getDocumentHeight()+'px';
}
	
function get_exterior_colors_callback(request){
	$("WAIT").toggle();
	$("COVER").toggle();
	combo = $('exterior_colors');
	brand_cmb = $('brands');
	//alert(request.responseText);
	if(request!=null){
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			current_option = combo.options.length;
			for(i=0; i< current_option; i++){
				combo.options[0] = null;
			}
			brand_cmb_option = brand_cmb.options.length;
			for(i=0; i< brand_cmb_option; i++){
				brand_cmb.options[0] = null;
			}
			if(response.RESULT=="OK"){
				for(i=0; i<response.EXTERIOR_ID.length; i++){
					var optn = new Option();
					optn.value = response.EXTERIOR_ID[i];
					optn.text = response.EXTERIOR_VALUES[i];
					if(response.EXTERIOR_VALUES[i] == "White")
							optn.selected = " Selected";
					combo.options[combo.options.length] = optn;
				}
				if(response.BRAND_ID.length > 0){
					if(response.BRAND_ID.length > 1){
						var optn = new Option();
						optn.value = '0';
						optn.text = 'All Brands';
						brand_cmb.options[brand_cmb.options.length] = optn;
					}
					for(i=0; i<response.BRAND_ID.length; i++){
						var optn = new Option();
						optn.value = response.BRAND_ID[i];
						optn.text = response.BRAND_LIST[i];
						brand_cmb.options[brand_cmb.options.length] = optn;
					}
				}else{
						var optn = new Option();
						optn.value = "";
						optn.text = "No Brand Found";
						brand_cmb.options[brand_cmb.options.length] = optn;
				}
			}
		}
	}
	get_price_list();
}
/* ======================================================================== */

/* =================== Get Brand list from interior and exterior colors  =========== */
function get_brand_list(){
	
	interior_color = $('interior_colors').value;
	exterior_color = $('exterior_colors').value;
	vertical_id = $('vertical').value;
	
	new ajax ('ajax.php', {postBody: 'method=get_brand_name&int_color='+interior_color+'&ext_color='+exterior_color+'&vertical_id='+vertical_id, onComplete: get_brand_list_callback});
	$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	$("WAIT").toggle();
	$("COVER").toggle();
	$("COVER").style.height = Screen.getDocumentHeight()+'px';
}
	
function get_brand_list_callback(request){
	
	$("WAIT").toggle();
	$("COVER").toggle();
	
	combo = $('brands');
	
	//alert(request.responseText);
	if(request!=null){

		if(request.responseText.isJSON()){	

			response = request.responseText.evalJSON();
			current_option = combo.options.length;
			for(i=0; i< current_option; i++){
				combo.options[0] = null;
			}
			if(response.RESULT=="OK"){
				if(response.BRAND_ID.length > 0){
					if(response.BRAND_ID.length > 1){
						var optn = new Option();
						optn.value = '0';
						optn.text = 'All Brands';
						combo.options[combo.options.length] = optn;
					}
					for(i=0; i<response.BRAND_ID.length; i++){
						var optn = new Option();
						optn.value = response.BRAND_ID[i];
						optn.text = response.BRAND_LIST[i];
						combo.options[combo.options.length] = optn;
					}
				}else{
						var optn = new Option();
						optn.value = "";
						optn.text = "No Brand Found";
						combo.options[combo.options.length] = optn;
				}
			}
		}
	}
	get_price_list();
}
/* =============================================================================== */

/* ============= get the list of the produt and display in the middle area =========== */

function get_price_list(){
	state_val = $('state').value;
	vertical_id = $('vertical').value;
	interior_color = $('interior_colors').value;
	exterior_color = $('exterior_colors').value;
	brand_id= $('brands').value;
	app_id = $('app').value;
	style_id = $('styles').value;
	width_val = $('width').value;
	width_inch_val = $('width_inch').value;
	height_val = $('height').value;
	height_inch_val = $('height_inch').value;
	min_price_val = $('demo_from').value;
	max_price_val = $('demo_to').value;
	
	//alert('get_product&vertical_id='+vertical_id+'&interior_color='+interior_color+'&exterior_color='+exterior_color+'&brand_id='+brand_id+'&app_id='+app_id+'&style_id='+style_id+'&width='+width_val+'&width_inch='+width_inch_val+'&height='+height_val+'&height_inch='+height_inch_val+'&state_id='+state_val);
	
	if(state_val==0){
		alert('Please select State Value');
		return false;
	}else{
		takealloptions();
		new ajax ('ajax.php', {postBody: 'method=get_product&vertical_id='+vertical_id+'&interior_color='+interior_color+'&exterior_color='+exterior_color+'&brand_id='+brand_id+'&app_id='+app_id+'&style_id='+style_id+'&width='+width_val+'&width_inch='+width_inch_val+'&height='+height_val+'&height_inch='+height_inch_val+'&state_id='+state_val+'&min_price_val='+min_price_val+'&max_price_val='+max_price_val , onComplete: get_price_list_callback , userVariable:Array(width_val,height_val,interior_color,exterior_color,min_price_val,max_price_val,width_inch_val,height_inch_val,vertical_id)});
		$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		$("WAIT").toggle();
		$("COVER").toggle();
		$("COVER").style.height = Screen.getDocumentHeight()+'px';
	}
}

function get_price_list_callback(request , variable){

	$("WAIT").toggle();
	$("COVER").toggle();
	//alert(request.responseText);
	var width = variable[0];
	var height = variable[1];
	var interior_color = variable[2];
	var exterior_color = variable[3];
	// PRICES FROM SLIDER
	var min_price = variable[4];
	var max_price = variable[5];
	var width_inch = variable[6];
	var height_inch = variable[7];
	var vertical_id = variable[8];	
	var final_width = parseFloat(width)+parseFloat(width_inch);
	var final_height = parseFloat(height)+parseFloat(height_inch);
	var temp_maximum_price=0;
	var temp_minimum_price=0;
	var totalproductloop=0;
	var fraction_final_width = convertToFraction(final_width);
	var fraction_final_height = convertToFraction(final_height);
	/**** variable to display tab in option popup ***/
	/*wholesale = false;
	crystal = false;
	simonton = false;
	lang = false;*/
	/***********************************************/
	//alert("HP");
	//alert(request.responseText);
	//alert(response);
	$('product_data').update("");

	if(request!=null){
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			if(response.RESULT=="OK"){	
				
				// MAKE NONE FOR DYNAMIC TAB 
				var num_total_brand_in_table = parseInt(response.ALL_BRAND_OF_TABLE.length) + 1;
				//alert(num_total_brand_in_table);
				for(q = 1; q < num_total_brand_in_table; q++)
				{
					//alert('TOP1-'+q+$(q+'__1'));alert('TOP2-'+q+$(q+'__2'));
					if(($(q+'__1') != null && $(q+'__2') != null) || ($(q+'__1') == "block" && $(q+'__2') == "block"))
					{	
						$(q+'__1').style.display = "none";
						$(q+'__2').style.display = "none";
					}
				}
	
				//alert(response.ALL_BRAND[0].name);
				var brand_name_exist = new Array();
					for(iloop=0; iloop<response.ALL_BRAND.length; iloop++){
						var brand_name = response.ALL_BRAND[iloop].name;//alert(response.ALL_BRAND[i].id);
						brand_name_exist[brand_name.toLowerCase()] = brand_name.toLowerCase();//alert(brand_name_exist);
						brand_name_exist[brand_name.toLowerCase()] = false;//alert(brand_name_exist);
					}
					// Reset the Global Array
					optionproductrelation = new Array();
					for(x=0; x<response.HP.length; x++){
						optionproductrelation[x] = response.HP[x];
						//alert(optionproductrelation[x]);
						//var brand_name = response.ALL_BRAND[i].name;
						//brand_name_exist[brand_name.toLowerCase()] = brand_name.toLowerCase();//alert(brand_name_exist);
						//brand_name_exist[brand_name.toLowerCase()] = false;//alert(brand_name_exist);
					}
				picture_image_set = "<link href=\"thumbnailviewer.css\" rel=\"stylesheet\" type=\"text/css\"><script src=\"thumbnailviewer.js\" language=\"javascript\" type=\"text/javascript\"></script>";
				performance_data_set = "[";
				warranty_set = "[";
				how_to_measure_set = "[";
				how_to_install_set = "[";
				testimonials_set = "[";

				var tempHtml = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
				if(!Object.isArray(response.PRODUCT)){ 
					selected_brand = new Array();
					formdata = new Array();
					var m=0;
					var h=0;
					var i=0;
					var z=0;
					var dynamictabid="";
					//var x=0;
					selected_id = new Array();
					for(var prop in response.PRODUCT){
						//var selected_brand = new Array();
						selected_brand[h]=prop;//h++;
						//alert(selected_brand[h]+"=="+h);
						//alert(prop);
						for(i=0; i<response.PRODUCT[prop].length; i++){
							id= response.PRODUCT[prop][i].id;
							vsku= response.PRODUCT[prop][i].vsku; 
							image= response.PRODUCT[prop][i].vimage;
							prfm_data= response.PRODUCT[prop][i].prfm_data;
							var parts = prfm_data.split('.');
							if(parts[parts.length-1] == "pdf")
							{
								var prfm_datafinal = '<a href="documents/'+prfm_data+'" onclick="return GB_showCenter(\'Performance Data\', this.href, 600, 700)">';
								var pfmd = 'documents/'+prfm_data;
							}else{
								var prfm_datafinal = '<a href="images/vinyl-windows-pictures/'+prfm_data+'" onclick="return GB_showImage(\'Performance Data\', this.href)">';
								var pfmd = 'images/vinyl-windows-pictures/'+prfm_data;
							}
							warranty= response.PRODUCT[prop][i].warranty;
							measure= response.PRODUCT[prop][i].measure;
							install= response.PRODUCT[prop][i].install;
							testimonial= response.PRODUCT[prop][i].testimonial;
							brochure= response.PRODUCT[prop][i].brochure;
							vdesc= response.PRODUCT[prop][i].vdesc;
							vproduct = response.PRODUCT[prop][i].vproduct;						
							ratings = response.PRODUCT[prop][i].ratings;
							quality1 = response.PRODUCT[prop][i].quality;
							price = response.PRODUCT[prop][i].price;
							// FOR CALLOUT VERTICAL ID 3 & 7
							framesizewidth = response.PRODUCT[prop][i].framesizewidth;
							framesizeheight = response.PRODUCT[prop][i].framesizeheight;
							roughopeningwidth = response.PRODUCT[prop][i].roughopeningwidth;
							roughopeningheight = response.PRODUCT[prop][i].roughopeningheight;
							// SET MINIMUM PRICE AND MAXIMUM PRICE FOR SLIDER
							//alert("PRICE: "+price);
							if((parseFloat(price) >= parseFloat(temp_maximum_price)) || temp_maximum_price == 0)
							{//alert("MAX PRICE: "+temp_maximum_price);
								temp_maximum_price = parseFloat(price);
								//alert("NOW MAX PRICE: "+temp_maximum_price);
							}
							if((parseFloat(price) <= parseFloat(temp_minimum_price)) || temp_minimum_price == 0)
							{//alert("MIN PRICE: "+temp_minimum_price);
								temp_minimum_price = parseFloat(price);
								//alert("NOW MIN PRICE: "+temp_minimum_price);
							}
							// FOR SHOWING PROJECTION RANGE
							proj_range = response.PRODUCT[prop][i].proj_range;
							if(proj_range != "no" && proj_range != "0" && proj_range != "" && proj_range != " ")
							{
								projection_range = "<b>Projection Range:</b> "+proj_range;
							}
							else
							{
								projection_range = "";
							}
							brand_id = response.PRODUCT[prop][i].brand_id;//alert(brand_id);
							brand_name = response.PRODUCT[prop][i].brand_name;//alert(brand_name);
							selected_id[z] = prop+":"+id+":"+price;
							z++;
							// FOR SHOWING THE MULTIPLE IMAGE AND PDFS
							//var image_set = [{'caption': 'Flower', 'url': 'http://static.flickr.com/119/294309231_a3d2a339b9.jpg'},{'caption': 'Nice waterfall', 'url': 'http://www.widerange.org/images/large/plitvicka.jpg'}];
							//picture_image_set += "{'caption': '"+vsku+"', 'url': '../images/vinyl-windows-pictures/"+image+"'}, ";
							picture_image_set += '<a href="images/vinyl-windows-pictures/'+image+'" rel="thumbnail" title="'+vsku+'"><img src="images/vinyl-windows-pictures/'+image+'" style="width: 50px; height: 50px; border:0" /></a>';
							performance_data_set += "{'caption': '"+vsku+"', 'url': '../"+pfmd+"'}, ";
							warranty_set += "{'caption': '"+vsku+"', 'url': '../documents/"+warranty+"'}, ";
							how_to_measure_set += "{'caption': '"+vsku+"', 'url': '../documents/"+measure+"'}, ";
							how_to_install_set += "{'caption': '"+vsku+"', 'url': '../documents/"+install+"'}, ";
							testimonials_set += "{'caption': '"+vsku+"', 'url': '../documents/"+testimonial+"'}, ";

							//alert(picture_image_set);
							//alert(z+"=="+prop+"=="+id+"==key="+prop+":"+id);
							//alert(i);
							if(m%2 == 0){
								bg = '';				
							}else{
								bg = '#F3F3FF';						
							}//alert(parseFloat(price));alert(parseFloat(min_price));alert(parseFloat(max_price));
							//alert(brand_id);
							//if((parseFloat(price) >= parseFloat(min_price)) && (parseFloat(price) <= parseFloat(max_price))){ // this if is used for display record as per price. 
							//dynamictabid += brand_id+"::";
							//Start Show tab as per the product.
							//alert('SECOND1-'+brand_id+$(brand_id+'__1'));alert('SECOND2-'+brand_id+$(brand_id+'__2'));
							if($(brand_id+'__1') != null && $(brand_id+'__2') != null)
							{
								
								$(brand_id+'__1').style.display = "block";
								$(brand_id+'__2').style.display = "block";
							}
							//$(brand_id+'__3').class.name = "button_all";
							//End
							tempHtml += '<tr><td><div id="ppp'+totalproductloop+'" title="'+totalproductloop+'"><table>';
							tempHtml += '<tr id="product_row_price'+totalproductloop+'" name="product_row_price[]" title="'+price+'-'+brand_id+'"><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr bgcolor="'+bg+'">'+
										'<td width="647" align="left" valign="top" class="content_3" style="padding:5px 0px 5px 0px"><strong>'+vsku+'&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>'+
										'<td width="165" align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_3"></td>'+
										'<td width="108" align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_3"><div id="option_'+prop+'_'+id+'_price" ><strong>$ '+price+'</strong></div></td>'+
										'</tr>'+
										
										'<tr bgcolor='+bg+'><td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2"><strong>Product Description: </strong>'+vdesc+' </td><td width="165" rowspan="2" align="center" valign="middle"><!--<img src="images/best_valuelogo.jpg" width="118" height="52" />-->&nbsp;</td><td align="left" valign="top" class="content_2"><a href="javascript:;" onclick=\'show_add_to_cart_popup("'+id+'","'+prop+'","'+final_width+'","'+final_height+'","'+interior_color+'","'+exterior_color+'","'+response.ADDITIONAL_INFO+'");\'><strong>Add To Cart</strong></a></td></tr>';
							if(vertical_id == 3 || vertical_id == 7){			
								tempHtml += '<tr bgcolor='+bg+'><td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2"><strong>Callout Desc:	</strong>'+final_width+'W'+final_height+'H&nbsp; <strong>Interior color:	</strong> '+interior_color+' &nbsp; <strong>Exterior Color:	</strong>'+exterior_color+' &nbsp; '+projection_range+'</td><td align="left" valign="top">&nbsp;</td></tr>';
								tempHtml += '<tr bgcolor='+bg+'><td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2">';
								if(vertical_id == 7){
									tempHtml += '<strong>Frame Size W x H (Inches):	</strong>'+framesizewidth+' x '+framesizeheight+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ';
								}
								tempHtml += '<strong>Rough Opening W x H (Inches):	</strong> '+roughopeningwidth+' x '+roughopeningheight+'</td><td align="left" valign="top">&nbsp;</td></tr>';
							}else{
								tempHtml += '<tr bgcolor='+bg+'><td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2"><strong>Width:	</strong>'+fraction_final_width+' &nbsp; <strong>Height:	</strong>'+fraction_final_height+' &nbsp; <strong>Interior color:	</strong> '+interior_color+' &nbsp; <strong>Exterior Color:	</strong>'+exterior_color+' &nbsp; '+projection_range+'</td><td align="left" valign="top">&nbsp;</td></tr>';
							}
							tempHtml += '<!--<tr bgcolor='+bg+'><td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2"><strong>Interior color:	</strong> '+interior_color+' &nbsp; <strong>Exterior Color:	</strong>'+exterior_color+' </td><td align="left" valign="top">&nbsp;</td></tr>-->'+
										'<tr bgcolor='+bg+'><td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2"><div id="option_'+prop+'_'+id+'" ><strong>OPTIONS:	</strong></div></td><td>&nbsp;</td><td align="left" valign="top">&nbsp;</td></tr>'+
										'<tr bgcolor='+bg+'><td align="left" valign="top" style="padding:5px 0px 5px 0px" class="content_2" colspan="3"><table border="0" cellspacing="0" cellpadding="0">'+
												'<tr><!--<td class="content_2"><strong>PERFOMANCE DATA:</strong> '+vproduct+'</td>--><td class="content_2" colspan=2><strong>Quality :</strong> '+quality1 +' &nbsp;&nbsp;&nbsp;</td><td>&nbsp;<!--<img src="images/star_'+ratings+'.jpg" width="87" height="17" />--></td>'+
												'</tr>'+
											'</table></td></tr>'+
										'<!--<tr bgcolor='+bg+'><td align="left" valign="top" style="padding:5px 0px 5px 0px" class="content_2">'+
											'<table width="250" border="0" cellspacing="0" cellpadding="0">'+
												'<tr><td class="content_2"><strong> Quality :</strong> '+quality1 +' </td><td><img src="images/star_'+ratings+'.jpg" width="87" height="17" /></td>'+
												'</tr>'+
											'</table></td>'+
											'<td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2">&nbsp;</td>'+
											'<td align="left" valign="top"  style="padding:5px 0px 5px 0px"class="content_2">&nbsp;</td>'+
										  '</tr>-->'+
										  '<tr bgcolor='+bg+'><td colspan="3" align="left" valign="top" class="content_2" style="padding:5px 0px 5px 0px">'+prfm_datafinal+'Performance Data</a> | <a href="images/vinyl-windows-pictures/'+image+'" onclick="return GB_showImage(\''+vsku+'\', this.href)">Pictures</a> | <a href="documents/'+warranty+'"  onclick="return GB_showCenter(\'Warranty\', this.href, 600, 700)">Warranty</a> | <a href="documents/'+measure+'"  onclick="return GB_showCenter(\'How to measure\', this.href, 600, 700)">How to measure</a> | <a href="documents/'+install+'" onclick="return GB_showCenter(\'How to Install\', this.href, 600, 700)">How to install</a> | <a href="documents/'+testimonial+'"  onclick="return GB_showCenter(\'Testimonials\', this.href, 600, 700)">Testimonials</a> | <a href="documents/'+brochure+'"  onclick="return GB_showCenter(\'Brochure\', this.href, 600, 700)">Brochure</a></td></tr>'+
										  '<tr><td colspan="3"><hr /></td></tr></table></td></tr>';
							tempHtml += '</table></div></td></tr>';			  
							totalproductloop++;										  
							
							//}// this is end of price related record display
							
							/**** select tab according to availalbe product in the middle part ***/
							//var brand_name_exist = brand_name.toLowerCase();
							brand_name_exist[brand_name.toLowerCase()] = true;//alert(brand_name_exist);
							/***********************************************/
							
							
					/******* code for brand tabs and options inside each brand tab in option popup ******/
							var bstr = brand_name.toLowerCase();
							// NULL THE WHOLE BOTTOM OPTIONS OTHER THAN POPULAR OPTIONS
							//$('yuitabview'+bstr).innerHTML = "";
							chkTemp2 = document.getElementsByName('chk');
								for (iloopone = 0; iloopone < chkTemp2.length; iloopone++){
									chkTemp2[iloopone].checked = false;
								}
							////////////////
							//formdata[bstr] =	bstr+"_opt_pop_html";
							formdata[bstr] = "<form name='"+bstr+"' >";
							formdata[bstr] += '<ul class="yui-nav">';

					/******* code to generate tabs inside each brand in option popup ******************/			 

									if(!Object.isArray(response.OPT_GROUP_NAME)){
										for(var ogn in response.OPT_GROUP_NAME){
											if(ogn == prop){ 
												for(k=0; k<response.OPT_GROUP_NAME[ogn].length; k++){
													 formdata[bstr] +='<li><a href="#'+bstr+'tab'+(k+1)+'"><em>'+response.OPT_GROUP_NAME[ogn][k]+'</em></a></li>';
												}
											}
										}
									}
									
					/******* end of  code to generate tabs inside each brand in option popup ******************/			 									
					
								formdata[bstr] += '</ul>';
								formdata[bstr] += '<div class="yui-content">';//alert(formdata);
								/// For removing the popular options run time.
								chkTemp = document.getElementsByName('popular_options');
								for (ilooptwo = 0; ilooptwo < chkTemp.length; ilooptwo++){
									chkTemp[ilooptwo].checked = false;
								}
								///////////////////popular options removing end///////////////////////	
					/******* code to generate options checkbox inside each options of each brand in option popup ******************/			 
	
			
							if(!Object.isArray(response.OPT_GROUP_NAME)){
								
								for(var ogn in response.OPT_GROUP_NAME){
									
									if(ogn == prop){//alert(prop);

										for(k=0; k<response.OPT_GROUP_NAME[ogn].length; k++){
									
											formdata[bstr] += '<div id="#'+bstr+'tab'+(k+1)+'"><p>'+
											  '<table>';
		
												if(!Object.isArray(response.OPT_NAME)){
													for(var on in response.OPT_NAME){
														
														if(on == prop){
														
															for(j=0; j<response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]].length; j++){
																var tempstr = response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_name;
																//alert(tempstr+" == "+prop+" == "+id+" == "+tempstr.replace(" ","-"));
																//optionproductrelation[x] = prop+"="+id+"="+tempstr;
																//x++;
																//alert(tempstr+" == "+prop+" == "+id+" == "+tempstr);
																formdata[bstr] +='<tr>'+
																	  '<td style="cursor:pointer;"><input type="checkbox" name="chk" value="'+response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_id+'_'+response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_popular+'"></td>'+
																	  '<td class="content_3"><span><strong>'+
																		response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_name +
																		'</strong></span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Starting at $'+
																		response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_price+' &nbsp;&nbsp;'+ 
																		response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_unit+' )'+
																		' &nbsp;&nbsp;<a href="javascript:void(0)" class="link" onclick=show_option_desc_popup("'+escape(response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_name)+'","'+escape(response.OPT_NAME[on][response.OPT_GROUP_NAME[ogn][k]][j].opt_desc)+'"); >More Info</a>'+
																		'</td>'+
																		'</tr>';
															}
														}
													}
											}
											formdata[bstr] +='</table>'+
																	'</p>'+
																'</div>';
										}
										
										formdata[bstr] +=  '</div> </form>';
										//alert(formdata[bstr]);
											//n = h + 2;	
										//alert(bstr);
										$('yuitabview'+bstr).innerHTML = formdata[bstr];
										//alert($('yuitabview'+bstr).innerHTML);
										//alert("ok");
										    (function() { 
							                    var cn = document.body.className.toString();
							                    if (cn.indexOf('yui-skin-sam') == -1) {
								                      document.body.className += " yui-skin-sam";
							                    }
						                  })();
				                  
                							  var yuitabview2 = new YAHOO.widget.TabView('yuitabview'+bstr);
											  //alert("after var");
									}
								}
							}
							
				m++;
				}
				//selected_brandname = new Array();
				selected_brandname[h] = brand_name;
				//alert(selected_brandname[h]+"="+h);
				h++;
								/*chkTemp1 = document.getElementsByName('chk');
								for (i = 0; i < chkTemp1.length; i++)
									alert(i + "_" + chkTemp1[i].checked + "_" + chkTemp1[i].value);
								for (j = 0; j < alloptions.length; j++)
									alert(j + "_" + alloptions[j]);*/
				
				/******* end of code to generate options checkbox inside each options of each brand in option popup ******************/			 
							
	/******* end of code for option tabs and options inside each tab in option popup ******/
					$('final_min_price').innerHTML = temp_minimum_price;
					$('final_max_price').innerHTML = temp_maximum_price;
					$('demo_from').value = temp_minimum_price;
					$('demo_to').value = temp_maximum_price;
					$('temp_demo_from').value = temp_minimum_price;
					$('temp_demo_to').value = temp_maximum_price;
					$('totalproductloop').value = totalproductloop;
					$('temp_panes').value = response.PANES;
					}
					var noproduct = "no";
				}else{
					$('final_min_price').innerHTML = 0;
					$('final_max_price').innerHTML = 5000;
					$('demo_from').value = 0;
					$('demo_to').value = 5000;
					$('temp_demo_from').value = 0;
					$('temp_demo_to').value = 5000;
					var noproduct = "yes";
					tempHtml += '<tr align="center" class="content_3" style="font-size:20px"><td><br><br><br>Your search criteria did not yield any results.<br><br> Perhaps we do not carry the product or the sizes you have selected.<br><br> Please change your search criteria to re-run the or contact our office<br><br> at 8665899367 or sales@customorderonline.com for assistance.</td></tr>';
				}
				//START FOR DYNAMIC TAB
				/*splitids = dynamictabid.split("::");
				for(c=0;c<splitids.length-1;c++)
				{
					$(splitids[c]+'__1').style.display = "block";
					$(splitids[c]+'__2').style.display = "block";
				}*/
				//END
				//picture_image_set = picture_image_set.substr(0,picture_image_set.length-2);
				//picture_image_set += "];";	//alert(picture_image_set);				  
				//$('picture_gallery_data').innerHTML = picture_image_set;
				performance_data_set = performance_data_set.substr(0,performance_data_set.length-2);
				performance_data_set += "];"; //alert(performance_data_set);
				warranty_set = warranty_set.substr(0,warranty_set.length-2);
				warranty_set += "];"; //alert(warranty_set);
				how_to_measure_set = how_to_measure_set.substr(0,how_to_measure_set.length-2);
				how_to_measure_set += "];"; //alert(how_to_measure_set);
				how_to_install_set = how_to_install_set.substr(0,how_to_install_set.length-2);
				how_to_install_set += "];"; //alert(how_to_install_set);
				testimonials_set = testimonials_set.substr(0,testimonials_set.length-2);
				testimonials_set += "];"; //alert(testimonials_set);

				//picture_image_set = '+picture_image_set+';
				if(performance_data_set != "];")
				{

tempHtml +='<tr><td><script type="text/javascript">performance_data_set = '+performance_data_set+';warranty_set = '+warranty_set+';how_to_measure_set = '+how_to_measure_set+';how_to_install_set = '+how_to_install_set+';testimonials_set = '+testimonials_set+';</script></td></tr></table>';
				}
				//alert(tempHtml);
				put_pictures(picture_image_set);
				$('product_data').update(tempHtml);
				$('product_data').show();
				$('middle_portion_for_replace').style.display = "block";
				var blocknonebrand = new Array();
				for(iloopthree=0; iloopthree<selected_brand.length; iloopthree++){
					//alert(selected_brand[i]);
					blocknonebrand[selected_brand[iloopthree]] = selected_brand[iloopthree];
					//alert(blocknonebrand[selected_brand[i]]);
				}
				//alert(selected_brand.length);
				/**** Display or hide the tab of option popup according to the product displayed in the middle *******/
					//response.ALL_BRAND_OF_TABLE.length
					for(iloopfour=0; iloopfour<response.ALL_BRAND_OF_TABLE.length; iloopfour++){
						var brand_name = response.ALL_BRAND_OF_TABLE[iloopfour].name;
						if($(brand_name.toLowerCase()+'_tab') != null)
						{
							$(brand_name.toLowerCase()+'_tab').style.display = "none";
						}
					}
					for(iloopfive=0; iloopfive<response.ALL_BRAND.length; iloopfive++){
						var brand_name = response.ALL_BRAND[iloopfive].name;//alert(i);alert($(brand_name.toLowerCase()+'_tab'));
						if($(brand_name.toLowerCase()+'_tab') != null)
						{//alert(blocknonebrand.length);
							//if(blocknonebrand.length > 0)
							//{
								//alert(response.ALL_BRAND[i].prefix);
								if(response.ALL_BRAND[iloopfive].prefix == blocknonebrand[response.ALL_BRAND[iloopfive].prefix])
								{//alert(response.ALL_BRAND[i].prefix+"--"+blocknonebrand[response.ALL_BRAND[i].prefix]+"=if"+brand_name.toLowerCase());
									$(brand_name.toLowerCase()+'_tab').style.display = "";//alert("block"+brand_name.toLowerCase());
									//alert(response.ALL_BRAND[i].prefix+"--"+blocknonebrand[response.ALL_BRAND[i].prefix]+"=ifend"+brand_name.toLowerCase());
								}
								else 
								{//alert(response.ALL_BRAND[i].prefix+"--"+blocknonebrand[response.ALL_BRAND[i].prefix]+"=else"+brand_name.toLowerCase());
									$(brand_name.toLowerCase()+'_tab').style.display = "none";//alert("none"+brand_name.toLowerCase());
									//alert(response.ALL_BRAND[i].prefix+"--"+blocknonebrand[response.ALL_BRAND[i].prefix]+"=elseend"+brand_name.toLowerCase());
								}
							//}
							/*else if(selected_brand.length != 1)
							{alert(response.ALL_BRAND[i].prefix+"--"+selected_brand[i]+"=elseif"+brand_name.toLowerCase());
								$(brand_name.toLowerCase()+'_tab').style.display = "";
								alert(response.ALL_BRAND[i].prefix+"--"+selected_brand[i]+"=elseifend"+brand_name.toLowerCase());
							}*/
						}
					}
				
				/*************************************************************************************************/
	
				
			}
		}else{
			alert('An error occurred while searching. Please contact our office at 8665899367 or email sales@customorderonline.com for assistance');
			return false;
		}
	}
	if(noproduct != "yes"){
		placealloptions();
		take_all_row_for_sort(totalproductloop,sort_by);
	}
}
/*function takealloptions(){
	chkTemp1 = document.getElementsByName('chk');//alert(chkTemp1);
	for (iloopsix = 0; iloopsix < chkTemp1.length; iloopsix++){
		alloptions[iloopsix] = chkTemp1[iloopsix].checked;
		alert(chkTemp1[iloopsix].value);
	}
	chkTemp = document.getElementsByName('popular_options');
	for (iloopseven = 0; iloopseven < chkTemp.length; iloopseven++){
		allpopularoptions[iloopseven] = chkTemp[iloopseven].checked;
		//alert(chkTemp[iloopseven].value);
	}
}
function placealloptions(){
	chkTemp1 = document.getElementsByName('chk');
	//if(chkTemp1.length == alloptions.length){
		for (iloopeight = 0; iloopeight < chkTemp1.length; iloopeight++){
			chkTemp1[iloopeight].checked = alloptions[iloopeight];
			//alert(chkTemp1[iloopeight].value);
		}
		chkTemp = document.getElementsByName('popular_options');
		if(chkTemp.length == allpopularoptions.length){
			for (iloopnine = 0; iloopnine < chkTemp.length; iloopnine++){
				chkTemp[iloopnine].checked = allpopularoptions[iloopnine];
				//alert(chkTemp[iloopnine].value);
			}
		}
		apply_options();	
	//}
}*/
function takealloptions(){
/*	chkTemp1 = document.getElementsByName('chk');//alert(chkTemp1);
	for (iloopsix = 0; iloopsix < chkTemp1.length; iloopsix++){
		if(chkTemp1[iloopsix].checked == true){	
			alloptions[iloopsix] = chkTemp1[iloopsix].value;
		}
	}
*/	chkTemp = document.getElementsByName('popular_options');
	for (iloopseven = 0; iloopseven < chkTemp.length; iloopseven++){
		if(chkTemp[iloopseven].checked == true)
		allpopularoptions[iloopseven] = chkTemp[iloopseven].value;
		//alert(chkTemp[iloopseven].checked);
		//alert(chkTemp[iloopseven].value);
	}
}
function placealloptions(){
	chkTemp1 = document.getElementsByName('chk');
	//if(chkTemp1.length == alloptions.length){
		for (iloopeight = 0; iloopeight < chkTemp1.length; iloopeight++){
			for(iloopeight2 =0;iloopeight2 < allpopularoptions.length;iloopeight2++){
				//alert(chkTemp1[iloopeight].value);
				var pop_opt_val = chkTemp1[iloopeight].value;
				var sel_pop_opt = pop_opt_val.split("_");
				if(parseInt(sel_pop_opt[1]) == parseInt(allpopularoptions[iloopeight2])){
					chkTemp1[iloopeight].checked = true;
				}
				//alert(allpopularoptions[iloopeight].value);
				//alert(allpopularoptions[iloopeight]);
				//alert(allpopularoptions[iloopeight].checked);
			}
			//alert(chkTemp1[iloopeight].value);
		}
		chkTemp = document.getElementsByName('popular_options');
		//if(chkTemp.length == allpopularoptions.length){
			for (iloopnine = 0; iloopnine < chkTemp.length; iloopnine++){
				for(iloopnine2 =0;iloopnine2 < allpopularoptions.length;iloopnine2++){
				//alert(chkTemp1[iloopeight].value);
					//var pop_opt_val = chkTemp1[iloopnine].value;
					//var sel_pop_opt = pop_opt_val.split("_");
					if(parseInt(chkTemp[iloopnine].value) == parseInt(allpopularoptions[iloopnine2])){
						chkTemp[iloopnine].checked = true;
					}
				//alert(allpopularoptions[iloopeight].value);
				//alert(allpopularoptions[iloopeight]);
				//alert(allpopularoptions[iloopeight].checked);
				}
				//alert(chkTemp[iloopnine].value);
			}
		//}
		apply_options();	
	//}
}
function removealloptions(){
	chkTemp1 = document.getElementsByName('chk');
	//if(chkTemp1.length == alloptions.length){
		for (iloopeight = 0; iloopeight < chkTemp1.length; iloopeight++){
			//for(iloopeight2 =0;iloopeight2 < allpopularoptions.length;iloopeight2++){
				////alert(chkTemp1[iloopeight].value);
				//var pop_opt_val = chkTemp1[iloopeight].value;
				//var sel_pop_opt = pop_opt_val.split("_");
				//if(parseInt(sel_pop_opt[1]) == parseInt(allpopularoptions[iloopeight2])){
					chkTemp1[iloopeight].checked = false;
				//}
				//alert(allpopularoptions[iloopeight].value);
				//alert(allpopularoptions[iloopeight]);
				//alert(allpopularoptions[iloopeight].checked);
			//}
			//alert(chkTemp1[iloopeight].value);
		}
		chkTemp = document.getElementsByName('popular_options');
		//if(chkTemp.length == allpopularoptions.length){
			for (iloopnine = 0; iloopnine < chkTemp.length; iloopnine++){
				//for(iloopnine2 =0;iloopnine2 < allpopularoptions.length;iloopnine2++){
				//alert(chkTemp1[iloopeight].value);
					//var pop_opt_val = chkTemp1[iloopnine].value;
					//var sel_pop_opt = pop_opt_val.split("_");
					//if(parseInt(chkTemp[iloopnine].value) == parseInt(allpopularoptions[iloopnine2])){
						chkTemp[iloopnine].checked = false;
					//}
				//alert(allpopularoptions[iloopeight].value);
				//alert(allpopularoptions[iloopeight]);
				//alert(allpopularoptions[iloopeight].checked);
				//}
				//alert(chkTemp[iloopnine].value);
			}
		//}
		apply_options();	
	//}
}
function take_all_row_for_sort(totalproductloop,sort_by){
	sort_by = sort_by;
	s = sort_by;
	all_product_rows = new Array();
	tempArray = new Array();
	//alert(totalproductloop);
			for (iloopten = 0; iloopten < totalproductloop; iloopten++){
				val = "ppp" + iloopten;
				all_product_rows[iloopten] = $(val).innerHTML;
			}

			for (iloopten = 0; iloopten < totalproductloop; iloopten++){
				for (iloopten1 = 0; iloopten1 < totalproductloop; iloopten1++){
					val = "ppp" + iloopten;
					var a = all_product_rows[iloopten1];
					if(a.search("product_row_price" + iloopten) != "-1"){
						tempArray[iloopten] = all_product_rows[iloopten1];
						iloopten1 = 1000;
					}
					//alert(all_product_rows[iloopten1]);
				}
			}

			for (iloopten = 0; iloopten < totalproductloop; iloopten++){
				all_product_rows[iloopten] = tempArray[iloopten];
			}

			do_sorting(s);
}
function do_sorting(s){
	rowTemp = all_product_rows.length; 	
	//alert(rowTemp);
	var iloopten, rowTemp;
	var price_array = new Array();
	var my_array = new Array();
			for (iloopeleven = 0; iloopeleven < rowTemp; iloopeleven++){
				valTemp = $('product_row_price'+iloopeleven).title;
				priceTemp = valTemp.split("-");
				price_array[iloopeleven] = parseFloat(priceTemp[0]);
				my_array[iloopeleven] = iloopeleven;
				//alert(price_array[iloopeleven]);
			}
	var lenloop = price_array.length, ilooptwelve, iloopthirteen, stoploop;
		
			for (ilooptwelve=0; ilooptwelve < lenloop; ilooptwelve++){
				for (iloopthirteen=0, stoploop=lenloop-ilooptwelve; iloopthirteen < stoploop; iloopthirteen++){
					if(s == 'desc'){
						if (price_array[iloopthirteen] < price_array[iloopthirteen+1]){
							swap(price_array, iloopthirteen, iloopthirteen+1);
								firstIndex = iloopthirteen;
								secondIndex = iloopthirteen+1;
								var temp = my_array[firstIndex];
								my_array[firstIndex] = my_array[secondIndex];
								my_array[secondIndex] = temp;
								//alert(" >> "+firstIndex+" >>> "+my_array[firstIndex]);alert(" >> "+secondIndex+" >>> "+my_array[secondIndex]);
						}
					}else{
						if (price_array[iloopthirteen] > price_array[iloopthirteen+1]){
							swap(price_array, iloopthirteen, iloopthirteen+1);
							firstIndex = iloopthirteen;
							secondIndex = iloopthirteen+1;
						    var temp = my_array[firstIndex];
							my_array[firstIndex] = my_array[secondIndex];
							my_array[secondIndex] = temp;
							//alert(" >> "+firstIndex+" >>> "+my_array[firstIndex]);alert(" >> "+secondIndex+" >>> "+my_array[secondIndex]);
						}
					}
					//alert(">>Price = "+iloopthirteen+"--"+price_array[iloopthirteen]);
					//alert(">>Id = "+iloopthirteen+"--"+my_array[iloopthirteen]);
				}
			}
					for (iloopten = 0; iloopten < price_array.length; iloopten++){
						var val = "ppp" + iloopten;
						$(val).innerHTML = all_product_rows[my_array[iloopten]];
					}
}
function swap(items, firstIndex, secondIndex){
    var temp = items[firstIndex];
    items[firstIndex] = items[secondIndex];
    items[secondIndex] = temp;
}

function swapIndex(items, firstIndex, secondIndex){
    var temp = firstIndex;
    items[firstIndex] = secondIndex;
    items[secondIndex] = temp;
}
/* =============================================================================== */


/* ==== Show option popup to display the options availalbe for specific brands ==== */

function show_option_popup(){
	if($('product_data').innerHTML.length < 200) {
		alert('Please select Product first.');
		return false;
	}
/*	var arr = $$('#popular_options');
	for(k=0;k<arr.length;k++){
		arr[k].checked = false;			
	}
*/	yuitabview1.set('activeIndex','0');

	$("option_popup").style.left = (Screen.getViewportWidth()/2 - (800/2))+"px";
	$("option_popup").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-250)+"px";
	$("option_popup").toggle();
	$("option").toggle();
	$("option").style.height = Screen.getDocumentHeight()+'px';
}
/* =============================================================================== */

/* ==== Hide option popup which displays the options availalbe for specific brands ==== */

function hide_option_popup(){
	
	$("option_popup").toggle();
	$("option").toggle();
}
/* =============================================================================== */

/* ======== To displays the description (popup) about options (More Info)  =============== */

function show_option_desc_popup(opt_name,opt_desc){
	opt_name = unescape(opt_name);
	opt_desc = unescape(opt_desc);
	$("option_desc_popup").style.left = (Screen.getViewportWidth()/2 - (400/2))+"px";
	$("option_desc_popup").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-150)+"px";
	$("opt_name").innerHTML = "<strong>"+opt_name+"</strong>";
	$("opt_desc").innerHTML = opt_desc;
	$("option_desc_popup").toggle();
	$("option_desc").toggle();
	//$("option_desc").style.height = Screen.getDocumentHeight()+'px';
}
/* =============================================================================== */

/* ======== Hide the description (popup) about options (More Info)  =============== */

function hide_option_desc_popup(){
	
	$("option_desc_popup").toggle();
	$("option_desc").toggle();
}
/* =============================================================================== */


function select_by_popular_option(chkbox){

	var val = chkbox.value;
	var flag = false;
	if(chkbox.checked == true)
		flag = true;
	else
		flag = false;

	for(j=0;j<document.forms.length;j++){

		for(i=0;i<document.forms[j].length;i++){
			var opt_id = document.forms[j].chk[i].value;
			var myopt_id = opt_id.split("_");
			if(myopt_id[1] == val){
						
				document.forms[j].chk[i].checked = flag;
			}
		}
	}
}

function apply_options(){
	var optname;
	var final_price;	
	var h;
	var m;
	var i;
	var j;
	var k;
	var n;
	var price;
	var optprice;
	var temp_maximum_price=0;
	var temp_minimum_price=0;
		$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		$("WAIT").toggle();
		$("COVER").toggle();
		$("COVER").style.height = Screen.getDocumentHeight()+'px';
		//alert(selected_brand[h]+"="+selected_id[selected_brand[h]+":"+h]);
		//alert(selected_id.length);
		for(m=0;m<selected_id.length;m++){//alert(m);
			//alert(selected_id[selected_brand[h]+":"+m]);
			optname="<strong>Options: </strong> <span style='color:#600'>";
			final_price="<strong>$ ";
			var sel_id = selected_id[m].split(":");
			price = parseFloat(sel_id[2]);
			if(document.getElementById('option_'+sel_id[0]+'_'+sel_id[1]) != null){
				for(j=0;j<document.forms.length;j++){//alert(document.forms.length+"First");
					for(i=0;i<document.forms[j].length;i++){//alert(document.forms[j].length+"Second");
						for(k=0;k<selected_brandname.length;k++){	//alert(selected_brandname.length);alert(k);
							if(document.forms[j].name == selected_brandname[k].toLowerCase() && sel_id[0] == selected_brand[k]){									                                //alert("yes"+selected_brandname[k]);
								if(document.forms[j].chk[i].checked == true){
									//var optname = selected_brand[k]+"_html";
									var firsttemp = document.forms[j].chk[i].value;
									var secondtemp = firsttemp.split("_");
									var tempformval = secondtemp[0];
									for(n=0;n<optionproductrelation.length;n++){//alert(optionproductrelation);
									//OPTIONDATA : wwh_16_26_6.97_1_2009 Stimulus Tax Credit for Windows
									// 5th argument Option Unit....1=per sq.ft,2=per window,3=per UI,4=per sash,5=Percent
										var option_data = optionproductrelation[n].split("_");
										if(tempformval == option_data[2])
										{
											if(sel_id[0] == option_data[0])
											{
												if(sel_id[1] == option_data[1])
												{
													// Options values set from here
													//optname += tempformval +", " ;//alert(optname);alert(option_data[4]);
													optname += option_data[5] +", " ;
													// Price calculation goes here.
													if(option_data[4] == 1)
													{
														var fixval = 144;
														var wi = parseFloat($('width').value)+parseFloat($('width_inch').value);
														var he = parseFloat($('height').value)+parseFloat($('height_inch').value);
														var multwh = parseFloat(wi)*parseFloat(he);
														var sqft = parseFloat(multwh)/parseFloat(fixval);
														optprice = parseFloat(sqft)*parseFloat(option_data[3]);
													}
													else if(option_data[4] == 2)
													{
														optprice = parseFloat(option_data[3]);
													}
													else if(option_data[4] == 3)
													{
														var wi = parseFloat($('width').value)+parseFloat($('width_inch').value);
														var he = parseFloat($('height').value)+parseFloat($('height_inch').value);
														var ui = parseFloat(wi)+parseFloat(he);
														optprice = parseFloat(ui)*parseFloat(option_data[3]);
													}
													else if(option_data[4] == 4)
													{
														optprice = parseFloat(option_data[3])*parseFloat($('temp_panes').value);
													}
													else if(option_data[4] == 5)
													{
														optprice = (parseFloat(price)*parseFloat(option_data[3]))/100;
													}
													else
													{
														optprice = parseFloat(option_data[3]);
													}
													price = parseFloat(price)+parseFloat(optprice);//alert(price);
												}
											}
										}
									}
								}
							}
						}
					}
				}
		}
		optname = optname.substr(0,optname.length-2);
		optname += "</span>";//alert('option_'+sel_id[0]+'_'+sel_id[1]+'_price == ');
		var final_set_price = price.toFixed(2);
		final_price += final_set_price+"</strong>";
		if($('option_'+sel_id[0]+'_'+sel_id[1]) != null)
			$('option_'+sel_id[0]+'_'+sel_id[1]).update(optname);
		if($('option_'+sel_id[0]+'_'+sel_id[1]+'_price') != null)	
			$('option_'+sel_id[0]+'_'+sel_id[1]+'_price').update(final_price);
		// SET SLIDER AS PER OPTION CHANGES START	
		//alert(m);alert($('product_row_price'+m).title);	
		var price_brand = $('product_row_price'+m).title;
		var dash_price_brand = price_brand.split("-");
		$('product_row_price'+m).title = final_set_price+"-"+dash_price_brand[1];
		//alert($('product_row_price'+m).title);
		//SET MIN AND MAX VALUE OF SLIDER
		if((parseFloat(final_set_price) >= parseFloat(temp_maximum_price)) || temp_maximum_price == 0)
		{//alert("MAX PRICE: "+temp_maximum_price);
			temp_maximum_price = parseFloat(final_set_price);
			//alert("NOW MAX PRICE: "+temp_maximum_price);
		}
		if((parseFloat(final_set_price) <= parseFloat(temp_minimum_price)) || temp_minimum_price == 0)
		{//alert("MIN PRICE: "+temp_minimum_price);
			temp_minimum_price = parseFloat(final_set_price);
			//alert("NOW MIN PRICE: "+temp_minimum_price);
		}
		
		$('final_min_price').innerHTML = temp_minimum_price;
		$('final_max_price').innerHTML = temp_maximum_price;
		$('demo_from').value = temp_minimum_price;
		$('demo_to').value = temp_maximum_price;
		$('temp_demo_from').value = temp_minimum_price;
		$('temp_demo_to').value = temp_maximum_price;

		// SET SLIDER AS PER OPTION CHANGES END
	}
	$("WAIT").toggle();
	$("COVER").toggle();
	take_all_row_for_sort(all_product_rows.length,sort_by);
	//do_sorting();
}
/* ======== To displays the add to cart (popup) about options (More Info)  =============== */

function show_add_to_cart_popup(id,brand,w,h,int_color,ext_color,additional_info){//return false;
	//opt_name = unescape(opt_name);
	//opt_desc = unescape(opt_desc);
	//alert(id+" : "+brand+" : "+w+" : "+h+" : "+int_color+" : "+ext_color);
	$("qty").value = "1";
	$('consumable_1').value = "0";	
	$('consumable_2').value = "0";	
	$('consumable_3').value = "0";		
	var id_ac = unescape(id);
	var brand_ac = unescape(brand);
	var w_ac = unescape(w);
	var h_ac = unescape(h);
	var int_color_ac = unescape(int_color);
	var ext_color_ac = unescape(ext_color);
	var additional_info_ac = unescape(additional_info);	
	var temp_popup_price = "option_"+brand_ac+"_"+id_ac+"_price";
	var temp1_popup_price = $(temp_popup_price).innerHTML;
	var temp2_popup_price = temp1_popup_price.split(' ');
	var temp3_popup_price = temp2_popup_price[1];
	var temp4_popup_price = temp3_popup_price.split('<');
	var popup_price = temp4_popup_price[0];
	//alert(additional_info_ac);
	if(additional_info_ac == "1")
	{
		$("operating_pane_show_hide").style.display = "block";
	}
	if(additional_info_ac == "2")
	{
		$("proporation_show_hide").style.display = "block";
	}
	if(additional_info_ac == "3")
	{
		$("select_handling").style.display = "block";
		$("handling_option1").checked = true;
	}else{
		$("handling_option1").checked = false;
		$("handling_option2").checked = false;
		$("handling_option3").checked = false;
		$("handling_option4").checked = false;
	}
	$("add_to_cart_popup").style.left = (Screen.getViewportWidth()/2 - (400/2))+"px";
	$("add_to_cart_popup").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-150)+"px";
	//$("opt_name").innerHTML = "<strong>"+opt_name+"</strong>";
	//$("opt_desc").innerHTML = opt_desc;
	//alert(id_ac+" : "+brand_ac+" : "+w_ac+" : "+h_ac+" : "+int_color_ac+" : "+ext_color_ac);
	$("id_ac").value = id_ac;
	$('brand_ac').value = brand_ac;
	$('w_ac').value = w_ac;
	$('h_ac').value = h_ac;
	$('int_color_ac').value = int_color_ac;
	$('ext_color_ac').value = ext_color_ac;
	$('additional_info_ac').value = additional_info_ac;
	$('popup_price_ac').value = popup_price;	
	$('popup_price').innerHTML = popup_price;	
	$("add_to_cart_popup").toggle();
	$("add_to_cart").toggle();
	//$("add_to_cart").style.height = Screen.getDocumentHeight()+'px';
}
/* =============================================================================== */

/* ======== Hide the description (popup) about options (More Info)  =============== */

function hide_add_to_cart_popup(){
	
	$("add_to_cart_popup").toggle();
	$("add_to_cart").toggle();
}
/* =============================================================================== */

function add_to_cart(){ 

	var id_ac = $('id_ac').value;
	var brand_ac = $('brand_ac').value;
	var w_ac = $('w_ac').value;
	var h_ac = $('h_ac').value;
	var int_color_ac = $('int_color_ac').value;
	var ext_color_ac = $('ext_color_ac').value;
	var additional_info_ac = $('additional_info_ac').value;
	
	var options_ac = $('option_'+brand_ac+'_'+id_ac).innerHTML;
	var price_ac = $('option_'+brand_ac+'_'+id_ac+'_price').innerHTML;
	var state_ac = $('state').value;
	var app_ac = $('app').value;
	//var quality_ac = $('quality').value;
	//var ext_color_ac = $(+'ext_color_ac').value;option_wwh_16_price    option_wwh_16

	var qty = $('qty').value;
	//var consumable = $('consumable').value;
	//var consumable = '1';
	var consumable_1 = $('consumable_1').value;
	var consumable_price_1 = $('consumable_price_1').value;
	var consname_1 = $('consname_1').value;
	var consumable_2 = $('consumable_2').value;
	var consumable_price_2 = $('consumable_price_2').value;
	var consname_2 = $('consname_2').value;
	var consumable_3 = $('consumable_3').value;
	var consumable_price_3 = $('consumable_price_3').value;
	var consname_3 = $('consname_3').value;
	var operating_pane = $('operating_pane').value;
	var proporation = $('proporation').value;
	if($('handling_option1').checked == true)
		var handling_option = $('handling_option1').value;
	else if($('handling_option2').checked == true)
		var handling_option = $('handling_option2').value;
	else if($('handling_option3').checked == true)
		var handling_option = $('handling_option3').value;
	else if($('handling_option4').checked == true)
		var handling_option = $('handling_option4').value;
	else	
		var handling_option = "";
	//alert(handling_option);return false;	
	var location = $('location').value;
	if(qty == "" || qty <= 0){
		alert('Please enter proper Value');
		return false;
	}else{
		new ajax ('ajax.php', {postBody: 'method=add_to_cart&product_master_id='+id_ac+'&brand_prefix='+brand_ac+'&width='+w_ac+'&height='+h_ac+'&interior_color='+int_color_ac+'&exterior_color='+ext_color_ac+'&quantity='+qty+'&options_ac='+options_ac+'&price_ac='+price_ac+'&state_id='+state_ac+'&app_id='+app_ac+'&operating_pane='+operating_pane+'&proporation='+proporation+'&handling_option='+handling_option+'&additional_info='+additional_info_ac+'&consumable_1='+consumable_1+'&consumable_price_1='+consumable_price_1+'&consname_1='+consname_1+'&consumable_2='+consumable_2+'&consumable_price_2='+consumable_price_2+'&consname_2='+consname_2+'&consumable_3='+consumable_3+'&consumable_price_3='+consumable_price_3+'&consname_3='+consname_3+'&location='+location , onComplete: add_to_cart_callback , userVariable:Array()});
		$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		$("WAIT").toggle();
		$("COVER").toggle();
		$("COVER").style.height = Screen.getDocumentHeight()+'px';
	}
}

function add_to_cart_callback(request , variable){
	$("WAIT").toggle();
	$("COVER").toggle();
	//alert(request.responseText);
	//alert(variable);
	if(request!=null){
	//alert(request.responseText.isJSON());
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			//alert(response.FINALCARTPRICE);
			if(response.RESULT=="OK"){
					//alert(variable);
					$('final_price_cart').innerHTML = "$ "+response.FINALCARTPRICE;
			}
		}
	}
	
}

function shopping_cart(del_id){
		
	new ajax('ajax.php', {postBody: 'method=shopping_cart&del_id='+del_id, onComplete: shopping_cart_callback});
		
}
function shopping_cart_callback(request){
//alert(request.responseText);
	//$("WAIT").toggle();
	//$("COVER").toggle();

		
	if(request!=null){
//alert(request.responseText.isJSON());
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			//alert(request.responseText);
			if(response.RESULT=="OK"){
					//$('middle_portion_for_replace').innerHTML = response.CARTPRODUCTLIST;
					$('product_data').innerHTML = response.CARTPRODUCTLIST;
					$('middle_portion_for_replace').style.display = "none";
					$('product_data').style.display = "block";
					$('final_price_cart').innerHTML = "$ "+response.FINALCARTPRICE;
			}
		}
	}

}

function put_pictures(val){
	//alert(val);	
	vertical_id = $('vertical').value;
	interior_color = $('interior_colors').value;
	exterior_color = $('exterior_colors').value;
	brand_id = $('brands').value;
		
	new ajax('ajax.php', {postBody: 'method=put_pictures&val='+val, onComplete: put_pictures_callback});
	$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	$("WAIT").toggle();
	$("COVER").toggle();
	$("COVER").style.height = Screen.getDocumentHeight()+'px';
		
}
function put_pictures_callback(request){
//alert(request);
	$("WAIT").toggle();
	$("COVER").toggle();

		
	if(request!=null){
//alert(request.responseText.isJSON());
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			//alert(request.responseText);
			if(response.RESULT=="OK"){

			}
		}
	}

}

function confDelete(del_id){
	if(confirm("Are you sure you want to Delete this product from Shopping Cart?"))
	{
		shopping_cart(del_id);	
	}
}

function calculateCart(){//alert("1");
	var fp = $('final_price').value;//alert("2");
	var sc = $('shipping_charge').value;//alert("3");
	if($('lift_gate_service').checked == true)
	{//alert("4");
		var lgs = "48.00";	
	}
	else
	{//alert("5");
		var lgs = "0.00";			
	}
	if($('inside_delivery_service').checked == true)
	{//alert("6");
		var ids = "98.00";	
	}
	else
	{//alert("7");
		var ids = "0.00";			
	}
	var ot = parseFloat(fp)+parseFloat(sc)+parseFloat(lgs)+parseFloat(ids);//alert("8");
	$('lift_service').value = lgs;//alert("9");
	$('lift_service_val').innerHTML = "<b>$ "+lgs+"</b>";//alert("10");
	$('inside_service').value = ids;//alert("11");
	$('inside_service_val').innerHTML = "<b>$ "+ids+"</b>";//alert("12");
	$('order_total').value = ot;//alert("13");
	$('order_total_val').innerHTML = "<b>$ "+ot.toFixed(2)+"</b>";//alert("14");

//$ot = $('order_total').value;
}
/* ======================================================================== */
/* ======== To displays the more info on clicking on question mark  =============== */

function show_moreinfo_popup(info_name,info_desc){
	info_name = unescape(info_name);
	info_desc = unescape(info_desc);
	$("moreinfo_popup").style.left = (Screen.getViewportWidth()/2 - (400/2))+"px";
	$("moreinfo_popup").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-150)+"px";
	$("info_name").innerHTML = "<strong>"+info_name+"</strong>";
	$("info_desc").innerHTML = info_desc;
	$("moreinfo_popup").toggle();
	$("moreinfo").toggle();
	//$("option_desc").style.height = Screen.getDocumentHeight()+'px';
}
/* =============================================================================== */

/* ======== Hide displays the more info  =============== */

function hide_moreinfo_popup(){
	
	$("moreinfo_popup").toggle();
	$("moreinfo").toggle();
}
/* =============================================================================== */

/* ======== Copy Line Functionality =============== */

function copy_line(id){
		new ajax ('ajax.php', {postBody: 'method=copy_line&id='+id , onComplete: copy_line_callback , userVariable:Array()});
		$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		$("WAIT").toggle();
		$("COVER").toggle();
		$("COVER").style.height = Screen.getDocumentHeight()+'px';
}
function copy_line_callback(request , variable){
	$("WAIT").toggle();
	$("COVER").toggle();
	//alert(request.responseText);
	if(request!=null){
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			if(response.RESULT=="OK"){	
				//alert("Copy Line Successfully");	
			}
		}
	}
}
/* =============================================================================== */

// FUNCTIONS USED IN THE EDIT ORDER PAGE 
/* =====Update Order(when we change height/width at the time of edit order,From here basic product price is calculated.)====== */
function calculate_product_price(){ 

	var temp_state_id = $('temp_state_id').value;
	var width_ft = $('width_ft').value;
	var width_inch = $('width_inch').value;
	var height_ft = $('height_ft').value;
	var height_inch = $('height_inch').value;
	var temp_brand_prefix = $('temp_brand_prefix').value;
	var prod_master_id = $('prod_master_id').value;
	var isize_range_type = $('isize_range_type').value;
//alert(temp_state_id);alert(width_ft);alert(width_inch);alert(height_ft);alert(height_inch);alert(temp_brand_prefix);alert(prod_master_id);alert(isize_range_type);
		new ajax ('ajax.php', {postBody: 'method=calculate_product_price&temp_state_id='+temp_state_id+'&width_ft='+width_ft+'&width_inch='+width_inch+'&height_ft='+height_ft+'&height_inch='+height_inch+'&temp_brand_prefix='+temp_brand_prefix+'&prod_master_id='+prod_master_id+'&isize_range_type='+isize_range_type, onComplete: calculate_product_price_callback , userVariable:Array()});
//		$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
//		$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
//		$("WAIT").toggle();
//		$("COVER").toggle();
//		$("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function calculate_product_price_callback(request , variable){
//	$("WAIT").toggle();
//	$("COVER").toggle();
	//alert(request.responseText);
	//alert(variable);
	if(request!=null){
	//alert(request.responseText.isJSON());
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			//alert(response.FINALCARTPRICE);
			if(response.RESULT=="OK"){
					//alert(response.FINALPRICE);
					$('product_price').value = response.FINALPRICE;
					calculateChangeOrder();
			}		
		}
	}
	
}
/* ======================================================================== */


function calculateChangeOrder(){//alert(document.frmChangeOrder.options);
	var qty = $('quantity').value;
	var price = 0;
	var optname = "";
	if(document.frmChangeOrder.options != null && document.frmChangeOrder.options != "" && document.frmChangeOrder.options != "undefined"){
		var num = document.frmChangeOrder.options.length;
	}else{
		var num = 0;
		var price = 0;
		var optname = "";
	}
	for(i=0;i<num;i++)
	{	
		if(document.frmChangeOrder.options[i].checked == true)
		{
			var val = document.frmChangeOrder.options[i].value;
			var option_data = val.split("_-_");
			optname += option_data[1] +", " ;
			if(option_data[2] == "sq.ft")
			{
				var fixval = 144;
				var wi = parseFloat($('width_ft').value)+parseFloat($('width_inch').value);
				var he = parseFloat($('height_ft').value)+parseFloat($('height_inch').value);
				var multwh = parseFloat(wi)*parseFloat(he);
				var sqft = parseFloat(multwh)/parseFloat(fixval);
				optprice = parseFloat(sqft)*parseFloat(option_data[3]);
			}
			else if(option_data[2] == "per window")
			{
				optprice = option_data[3];
			}
			else if(option_data[2] == "per UI")
			{
				var wi = parseFloat($('width_ft').value)+parseFloat($('width_inch').value);
				var he = parseFloat($('height_ft').value)+parseFloat($('height_inch').value);
				var ui = parseFloat(wi)+parseFloat(he);
				optprice = parseFloat(ui)*parseFloat(option_data[3]);
			}
			else if(option_data[2] == "per sash")
			{
				optprice = parseFloat(option_data[3])*parseFloat($('temp_panes_edit').value);
			}
			else if(option_data[2] == "Percent")
			{
				optprice = (parseFloat(price)*parseFloat(option_data[3]))/100;
			}
			else
			{
				optprice = option_data[3];
			}
			price = parseFloat(price)+parseFloat(optprice);//alert(price);
		}
	}
	var consum_price = (parseFloat($('fprice_0').value)*parseFloat($('consumable_0').value))+(parseFloat($('fprice_1').value)*parseFloat($('consumable_1').value))+(parseFloat($('fprice_2').value)*parseFloat($('consumable_2').value))
	var final_price = (parseFloat($('product_price').value)+parseFloat(price)+parseFloat(consum_price))*$('quantity').value;
	$('amount').innerHTML = final_price.toFixed(2);
	$('final_amount').value = final_price.toFixed(2);
	$('final_options').value = optname.substr(0,optname.length-2);
	$('final_consumables').value = $('consname_0').value+"( "+$('consumable_0').value+" ), "+$('consname_1').value+"( "+$('consumable_1').value+" ), "+$('consname_2').value+"( "+$('consumable_2').value+" )#:#"+$('consumable_0').value+"-|-"+$('consumable_1').value+"-|-"+$('consumable_2').value;
}

/* VALIDATION WHEN SOMEBODY CLICKS ON GET PRICE WITHOUT SELECTING STATE AND PRODUCT DATA */
function checkProductInfo(){
	if($('state').value==0){
		alert('Please select State Value');
		return false;
	}
	else if($('product_data').innerHTML.length < 200) {
		alert('Please select Product first.');
		return false;
	}
	else
	{
		return true;
	}
}
/*-----------------------------------------------------------------------------------------*/
// Show hide the middle portion and its menu tab
function entryValue(){
	$('middle_portion_for_replace').style.display = "none";
	$('product_data').style.display = "block";	
}
// For enable disable submit button
function agreeTerms(){
  	if($('agreement').checked == true)
	{
		$('btn_save').disabled = false;
	}
	else
	{
		$('btn_save').disabled = true;	
	}
}
// For adding data into Search
function add_search(){
	state_val = $('state').value;
	vertical_id = $('vertical').value;
	interior_color = $('interior_colors').value;
	exterior_color = $('exterior_colors').value;
	brand_id= $('brands').value;
	app_id = $('app').value;
	style_id = $('styles').value;
	width_val = $('width').value;
	width_inch_val = $('width_inch').value;
	height_val = $('height').value;
	height_inch_val = $('height_inch').value;
	min_price_val = $('demo_from').value;
	max_price_val = $('demo_to').value;

	if(state_val==0){
		return false;
	}else{
		new ajax ('ajax.php', {postBody: 'method=add_search&vertical_id='+vertical_id+'&interior_color='+interior_color+'&exterior_color='+exterior_color+'&brand_id='+brand_id+'&app_id='+app_id+'&style_id='+style_id+'&width='+width_val+'&width_inch='+width_inch_val+'&height='+height_val+'&height_inch='+height_inch_val+'&state_id='+state_val+'&min_price_val='+min_price_val+'&max_price_val='+max_price_val , onComplete: add_search_callback , userVariable:Array()});
//		$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
//		$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
//		$("WAIT").toggle();
//		$("COVER").toggle();
//		$("COVER").style.height = Screen.getDocumentHeight()+'px';
	}
}
function add_search_callback(request){ //alert(request.responseText);
	if(request!=null){
	//alert(request.responseText.isJSON());
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			//alert(response.FINALCARTPRICE);
			if(response.RESULT=="OK"){
					//alert(response.FINALPRICE);
			}		
		}
	}
}

function show_brandwise_data(brandpass){
		if(document.getElementById("state").value != 0)
		{
			//alert($('product_row_price').length);
			//alert(document.frm_product["product_row_price[]"].length);
			//document.getElementById("product_row_price").style.display = "none";
			//get_price_list();
			for(i=0;i<document.getElementById("totalproductloop").value;i++)
			{
				var price_brand = document.getElementById("product_row_price"+i).title;
				var brand = price_brand.split("-");//alert(price_brand);
				if(brand[1] == brandpass || brandpass == 0)
				{
					document.getElementById("product_row_price"+i).style.display = "block";
				}
				else
				{
					document.getElementById("product_row_price"+i).style.display = "none";
				}	
				//alert(document.getElementById("product_row_price["+i+"]").style.display);
			}
		}	
}
function get_colorimages(){
	vertical_id = $('vertical').value;
	new ajax('ajax.php', {postBody: 'method=get_colorimages&vertical_id='+vertical_id, onComplete: get_colorimages_callback});
//	$("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
//	$("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
//	$("WAIT").toggle();
//	$("COVER").toggle();
//	$("COVER").style.height = Screen.getDocumentHeight()+'px';
}
function get_colorimages_callback(request){
//	$("WAIT").toggle();
//	$("COVER").toggle();
	//alert(request.responseText);
	//alert(variable);
	if(request!=null){
	//alert(request.responseText.isJSON());
		if(request.responseText.isJSON()){	
			response = request.responseText.evalJSON();
			//alert(response.FINALCARTPRICE);
			if(response.RESULT=="OK"){
					//alert(variable);
					$('img_color_all').innerHTML = response.ALL_IMAGES;
			}
		}
	}
		
}
function calculate_addtocart_popup_dynamic(){
	 var tot_price = parseFloat($('popup_price_ac').value)*parseFloat($('qty').value);	
	 var cons_1 = parseFloat($('consumable_price_1').value)*parseFloat($('consumable_1').value);
	 var cons_2 = parseFloat($('consumable_price_2').value)*parseFloat($('consumable_2').value);
	 var cons_3 = parseFloat($('consumable_price_3').value)*parseFloat($('consumable_3').value);
	 var tot_cons = parseFloat(cons_1) + parseFloat(cons_2) + parseFloat(cons_3); 
	 var tot = parseFloat(tot_price) + parseFloat(tot_cons);
	 $('popup_price').innerHTML = tot.toFixed(2);
}
function validateValues(){
	if($("qty").value == "" || isNaN($("qty").value) || $("qty").value == "0")
	{
		$("qty").value = "1";
		alert("Please enter Quantity in Number Greater than 0");	
		$("qty").focus();
		return false;
	}
	if($("consumable_1").value == "" || isNaN($("consumable_1").value))
	{
		$("consumable_1").value = "0";
		alert("Please enter Consumables in Number");	
		$("consumable_1").focus();
		return false;
	}
	if($("consumable_2").value == "" || isNaN($("consumable_2").value))
	{
		$("consumable_2").value = "0";
		alert("Please enter Consumables in Number");	
		$("consumable_2").focus();
		return false;
	}
	if($("consumable_3").value == "" || isNaN($("consumable_3").value))
	{
		$("consumable_3").value = "0";
		alert("Please enter Consumables in Number");	
		$("consumable_3").focus();
		return false;
	}
	calculate_addtocart_popup_dynamic();
}
function convertToFraction(val){
	if ((val % 1)!=0) { 
		var val1 = val.toString();
		newval = val1.split(".");
		if(parseInt(newval[1]) == parseInt("125"))
			return newval[0]+' 1/8';
		if(parseInt(newval[1]) == parseInt("25"))
			return newval[0]+' 1/4';
		if(parseInt(newval[1]) == parseInt("375"))
			return newval[0]+' 3/8';
		if(parseInt(newval[1]) == parseInt("5"))
			return newval[0]+' 1/2';
		if(parseInt(newval[1]) == parseInt("625"))
			return newval[0]+' 5/8';
		if(parseInt(newval[1]) == parseInt("75"))
			return newval[0]+' 3/4';
		if(parseInt(newval[1]) == parseInt("875"))
			return newval[0]+' 7/8';
	}else{
		return val;
	}

}
function setWHValueFromCallOut(val){
	var firstCallout = val;//alert(val);//response.CALLOUT[0];
	var partCallout = firstCallout.split("W");
	var w = partCallout[0];
	var partCalloutH = partCallout[1].split("H");
	var h = partCalloutH[0];
	$('width').value = w;
	$('height').value = h;
	//$('widthTempToShow').innerHTML = w;
	//$('heightTempToShow').innerHTML = h;
	
	get_price_list();
}
function setWHValueFromCallOutForEditOrder(val){//alert(val);
	var firstCallout = val;//response.CALLOUT[0];
	var partCallout = firstCallout.split("W");
	var w = partCallout[0];
	var partCalloutH = partCallout[1].split("H");
	var h = partCalloutH[0];//alert(w);alert(h);
	$('width_ft').value = w;
	$('height_ft').value = h;
	
	calculate_product_price();
}