function changeprice(divid,heading,price)
{	
	pr=document.getElementById("panelprice"+divid).value;	
	price1 = price.split("$");
	orgprice = price1[1];		
	final_price=pr * orgprice;	
	str = '';
	if(price)
	{
		val = pr + "(+$" + final_price + ")";		
	}
	else
	{
		val = pr;		
	}
	str = str + '<select name="' + heading + '"><option value="' + val + '">';
	str = str + val;
	str = str + '</option></select>';
	document.getElementById("pricechange"+divid).innerHTML = str;
}

function defaultoption(divid,heading,price)
{
	str = '';
	pr1 = document.getElementById("panelprice"+divid).value;
	
	price1 = price.split("$");
	orgprice = price1[1];	
	if(pr1 == 0)
	{
		orgprice = 0;
	}
	val1 = pr1 + "(+$" + orgprice + ")";
	str = str + '<select name="' + heading + '"><option value="' + val1 + '">' + val1 + '</option></select>';
	document.getElementById("pricechange"+divid).innerHTML = str;
}

function withoutprice(divid,heading)
{
	str = '';
	pr2 = document.getElementById("panelprice"+divid).value;
	str = str + '<select name="' + heading + '"><option value="' + pr2 + '">' + pr2 + '</option></select>';
	document.getElementById("pricechange"+divid).innerHTML = str;
}

function updatesaleprice(sprice,orprice)
{
	/*sprice1 = sprice.split("$");
	
	if(sprice1.length>1)
	{
		sprice2 = sprice1[1].split(")");
		fsprice = parseInt(sprice2[0]);	
		finalsprice = fsprice + orprice;
		spricestr = "<span>$" + finalsprice.toFixed(2) + "</span>";	
	}
	else
	{
		spricestr = "<span>$" + orprice.toFixed(2) + "</span>";	
	}*/
	
	var spricestr;
	frm = document.forms["submitform"];
	i = frm.elements.length;
	for(j=0;j<i;j++)
	{		
		if(frm.elements[j].type=="select-one")
		{		
			svalue = frm.elements[j].value;			
			sprice1 = svalue.split("$");
			if(sprice1.length>1)
			{
				sprice2 = sprice1[1].split(")");
				fsprice = parseFloat(sprice2[0]);
		
				orprice = orprice + fsprice;
		
				spricestr = "<span>$" + orprice.toFixed(2) + "</span>";	
			}
			else
			{
				spricestr = "<span>$" + orprice.toFixed(2) + "</span>";
			}
		}		
	}	
	
	document.getElementById("saleprice").innerHTML = spricestr;	
}

function validatesize()
{	
	frm = document.forms["submitform"];
	i = frm.elements.length;
	if(document.getElementById('coloroption'))
	{		
		colorstr = '';
		cvc = '';
		colorprice = 0;
		for(j=0;j<i;j++)
		{		
			if(frm.elements[j].type=="checkbox")
			{		
				if(frm.elements[j].checked == true)
				{
					coloropt = frm.elements[j].value;
					coloropt1 = coloropt.split('(');
					coloropt2 = coloropt1[1].split(')');
					fcoloropt = parseFloat(coloropt2[0]);
					colorprice = colorprice + fcoloropt;
					colorstr = colorstr + coloropt1[0] + ",";
				}				
			}
		}
		colorprice = colorprice - coloropt2[0];
		colorstr = colorstr.substring(0, colorstr.length - 1);
		colorstr = colorstr + "(+$" + colorprice + ")";
		var obj = new Option(colorstr);		
		document.getElementById('coloroption').options[0] = obj;		
	}
	for(j=0;j<i;j++)
	{		
		if(frm.elements[j].type=="select-one")
		{		
			if(frm.elements[j].value == "Select Color")
			{
				alert("Please Select Color");
				return false;
			}
			if(frm.elements[j].value == "Select Silk Color")
			{
				alert("Please Select Silk Color");
				return false;
			}
			if(frm.elements[j].value == "Select Pattern")
			{
				alert("Please Select Pattern");
				return false;
			}
			if(frm.elements[j].value == "Select Top Header Design")
			{
				alert("Please Select Top Header Design");
				return false;
			}
			if(frm.elements[j].value == "Select Finish")
			{
				alert("Please Select Finish");
				return false;
			}
			if(frm.elements[j].value == "Select Pole Size")
			{
				alert("Please Select Pole Size");
				return false;
			}
			if(frm.elements[j].value == "Select Adjustable Rode Set Size")
			{
				alert("Please Select Adjustable Rode Set Size");
				return false;
			}
			if(frm.elements[j].value == "Select Velvet Color")
			{
				alert("Please Select Velvet Color");
				return false;
			}
			if(frm.elements[j].value == "Select Linen Color")
			{
				alert("Please Select Color");
				return false;
			}
			if(frm.elements[j].value == "Select Sheer Color")
			{
				alert("Please Select Sheer Color");
				return false;
			}			
		}
	}	
}

/*function addprice(slprice)
{
	final_inp = '';
	
	pr_value = document.getElementById("inphide").value;
	pr_fprice = pr_value * slprice;
	alert(pr_value);
	final_inp = final_inp + '<input type="text" id="vwtext" name="vwquantity" value="' + pr_value + '">';
	document.getElementById("vwinp").innerHTML = final_inp;
	vwtext_val = document.getElementById("vwtext").value;
	alert(vwtext_val);
}*/

function swapimage(val) 
{
	for(i=1;i<=5;i++)
	{
		if(document.getElementById("div"+i))
		{
			if(val==i)
			{
				document.getElementById("div"+i).style.display='';
			}		
			else
			{
				document.getElementById("div"+i).style.display='none';
			}
		}
	}
}

function findimagepopup()
{
	for(i=1;i<=5;i++)
	{
		if(document.getElementById("div"+i))
		{
			divstyle = document.getElementById("div"+i).style.display;
			if(divstyle == '')
			{
				imagesrc = document.getElementById("mainimage"+i).src;
				lightBox("'"+imagesrc+"'",i);
			}
		}
	}
}

function showhidevideo(tagtype)
{
	if(tagtype == "video")
	{
		document.getElementById("imagelink").style.display = '';
		document.getElementById("videolink").style.display = 'none';
		document.getElementById("videodiv").style.display = '';
		document.getElementById("imagediv").style.display = 'none';
	}
	else
	{
		document.getElementById("videolink").style.display = '';
		document.getElementById("imagelink").style.display = 'none';
		document.getElementById("imagediv").style.display = '';
		document.getElementById("videodiv").style.display = 'none';
	}
}

/*Script for Recently view*/
var str1="Recent_HPD";
var newid = new Array();
var newmargin = new Array();
var newname = new Array();
var newprice = new Array();
var newsaleprice = new Array();
var neworderable = new Array();
var newimgpath = new Array();
var newstyle = new Array();
var price = '';

function createCookieRV(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function GetCookieRV(name) 
{  
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function checkCookieRV(id, name, imgpath, imgstyle)
{
	var i,count;
	totalcookie = GetCookieRV("Total_HPD_RV");

	if(totalcookie != null)
	{
		i = Number(totalcookie);
		count=0;
		for(j=1;j<=i;j++)
		{
			username = GetCookieRV(str1 + j + "_id");
			if(username == id)
			{
				count++;
			}
		}
		if(count == 0)
		{
			if(i == 7)
			{
				for(m=1;m<=7;m++)
				{
					username=GetCookieRV(str1 + m);
					newname[newname.length] = username;
	
					str=str1+m;
					str=str+"_id";
					username = GetCookieRV(str); 
					newid[newid.length] = username;

					
					str=str1+m;
					str=str+"_imgpath";
					username = GetCookieRV(str); 
					newimgpath[newimgpath.length] = username;
					
					str=str1+m;
					str=str+"_imgstyle";
					username = GetCookieRV(str); 
					newstyle[newstyle.length] = username;

				}
				
				for(m=1, n=1;m<7;m++, n++)
				{
					
					createCookieRV(str1+m, newname[n]); 
	
					str=str1+m;
					str=str+"_id";
					createCookieRV(str,newid[n]); 
					
					str=str1+m;
					str=str+"_imgpath";
					createCookieRV(str,newimgpath[n]);
					
					str=str1+m;
					str=str+"_imgstyle";
					createCookieRV(str,newstyle[n]);
					
				}
				cookie_store(m, id, name, imgpath, imgstyle);
			}
			else
			{
				i++;
				createCookieRV("Total_HPD_RV",i);
				cookie_store(i, id, name, imgpath, imgstyle);
			}
		}
	}
	else
	{
			i=1;
			createCookieRV("Total_HPD_RV",i);
			cookie_store(i, id, name, imgpath, imgstyle);
	}
}

function gc1()
{
	var i;
	totalcookie = GetCookieRV("Total_HPD_RV");

	if(Number(totalcookie) > 1)
	{
		if(document.getElementById("recent_title"))
		{
			document.getElementById("recent_title").style.display = "";
		}
		i = Number(totalcookie) - 1;
		newcount = 1;

		var ihtml = "";
		for(j = i; j > 0; j--)
		{
			id = GetCookieRV(str1 + j + "_id");
			name = GetCookieRV(str1 + j);
			imgpath = GetCookieRV(str1 + j + "_imgpath");
			imgstyle = GetCookieRV(str1 + j + "_imgstyle");
			str=str1;
			str=str+j;
			str=str+'_id';
			lp =GetCookieRV(str);
			
			ihtml += "<div class='product_listing_box'>";
			
			ihtml += "<div class='product_listing_item'><img src='http://site.halfpricedrapes.com/aug07/images/product_listing_item_bg_top.jpg' alt='Title Top' class='img_left'><a href='" + lp + ".html'><img src='" + imgpath + "' border='0' alt='" + name + "' style='" + imgstyle + "'></a><img src='http://site.halfpricedrapes.com/aug07/images/product_listing_item_bg_bottom.jpg' alt='Title Top' class='img_left'></div>";
			ihtml +="<div class='product_listing_text'><a href='" + lp + ".html'>" + name + "</a></div>";
			ihtml += "<div class='product_listing_new'><a href='" + lp + ".html'><img src='http://site.halfpricedrapes.com/aug07/images/view_detail_new.jpg' alt='View Detail' class='img_right'/></a></div></div>";
		}

		document.getElementById("recentdiv").innerHTML = ihtml;
	}
	else
	{

	}
}


function cookie_store(val, id, name, imgpath, imgstyle)
{

	createCookieRV(str1+val,name);
	
	str=str1+val;
	str=str+"_id";
	createCookieRV(str,id);
	
	str=str1+val;
	str=str+"_imgpath";
	createCookieRV(str,imgpath);

	str=str1+val;
	str=str+"_imgstyle";
	createCookieRV(str,imgstyle);
}

function del_cookie(name) {
document.cookie = name +
'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function gotosearch()
{
	keyword = document.getElementById('oneclicksearch').value;
	document.location.href = "oneclick-search.html?"+keyword;
}

/*Script for One Click Search*/
var dummy  = new Array();
var findab = new Array();
var final = new Array();
var srdata = new Array();
var pagenum = 1;

var ototal = 0;
strkey=document.location.search;
if (strkey.indexOf('?')!=-1) 
{
	strkey=strkey.substring(strkey.indexOf('?')+1);
}

function srdataadd(pid, pname, pimage, pabstract)
{
    this.pid = pid;
    this.productname = pname;
	this.image = pimage;
	this.abstract = pabstract;
}
function searchArray(srlen)
{
	dummy.length = 0;
	findab.length = 0;
	final.length = 0;
	splitkey = '';
	for(x=0;x<strkey.length;x++)
	{
		space = strkey.indexOf("%20");
		while(space >= 0)
		{
			strkey = strkey.replace("%20"," ");
			space = strkey.indexOf("%20");
		}
	}
	splitkey = strkey.split(" ");
	for(i=0;i<srdata.length;i++)
	{
		if(splitkey.length>0)
		{
			for(k=0;k<splitkey.length;k++)
			{
				if(splitkey[k] == '&' || splitkey[k] == '')
				{
				}
				else
				{
				if(srdata[i].abstract.search(splitkey[k]) >= 0)
				{
					findab[findab.length] = srdata[i];
				}
				}
			}
		}
		else
		{
			if(srdata[i].abstract.search(strkey) >= 0)
			{
				findab[findab.length] = srdata[i];
			}
		}
	}
	for(i=0; i<findab.length; i++)
	{
		bln = findElement(findab[i]);
		if(bln == true)
		{
			final[final.length] = findab[i];
		}
	}
	viewpaging(final.length,1)
}
function findElement(arrayobj)
{
	for(j=0; j<dummy.length; j++)
	{
		if(dummy[j] == arrayobj.pid)
		{
			return false;
		}
	}
	dummy[dummy.length] = arrayobj.pid;
	return true;
}

function viewpaging(findlen,curpage)
{
	pagenum=curpage;
		
	totalpage=Math.ceil(findlen / pno);		

	if(curpage > totalpage && curpage != 404)
	{
		curpage = totalpage;
	}
	
	startpos = (curpage - 1) * pno;
	endpos = (curpage * pno) - 1;	

	var count = 0;
	var itemno=0;
	
	if(curpage == 404)
	{
		ototal = findlen;
	}
	else
	{
		ototal = endpos - startpos;
	}
	
	var dhtml = "";
	itemno = 1;
	
	for(i=0;i<findlen;i++)
	{
		if((i>=startpos && i<=endpos) || (curpage==404))
		{
			dhtml = dhtml + "<div class='product_listing_box'>";
			
			if(final[i].productname.length > 50)
				productname = final[i].productname.substr(0, 48) + "...";
			else
				productname = final[i].productname;
			
			dhtml += "<div class='product_listing_item'><img src='http://site.halfpricedrapes.com/aug07/images/product_listing_item_bg_top.jpg' class='img_left'><div class='product_listing_1'><div class='img_center'><span></span><a href='" + final[i].pid + ".html'><img src='" + final[i].image + "' alt='" + final[i].productname + "' title='" + final[i].productname + "' border='0'></a></div></div><img src='http://site.halfpricedrapes.com/aug07/images/product_listing_item_bg_bottom.jpg' class='img_left'></div>";
			dhtml += "<div class='product_listing_text'><a href='"  + final[i].pid + ".html'>" + productname + "</a></div>";
			dhtml += "<div class='product_listing_new'><a href='" + final[i].pid + ".html'><img src='http://site.halfpricedrapes.com/aug07/images/view_detail.jpg' class='img_right'></a></div>";

			dhtml += "</div>";
		}
	}
	
	document.getElementById("main").innerHTML = dhtml;
	writepages(totalpage, startpos, endpos, findlen);
}

function writepages(totalpages, stpageno, endpageno, findlen)
{
	distxt= " ";
	var distxt = "";
	
	if(pagenum > 1 && (pagenum!=404))
	{
		distxt += "<strong><a href='javascript:viewpaging(" + findlen + ", " + (pagenum - 1) + ");'>< Prev</a></strong> ";
	}
	
	if(pagenum==404)
	{
		distxt += "<span>View All</span> [ ";
	}
	else
	{
    	distxt += "<a href=javascript:viewpaging(" + findlen + ",404); class='next_pre'>View all</a> [ ";
	}

	for(i=1; i <= totalpages; i++)
	{
		if(i == pagenum)
		{
			distxt += "<span>" + i + "</span>";
			if(i==totalpages)
			{						
			}
			else
			{
				distxt += " | ";
			}
		}
		else
		{
			distxt += "<strong><a href=javascript:viewpaging(" + findlen + "," + i + ");>" + i + "</a></strong>";
			if(i==totalpages)
			{						
			}
			else
			{
				distxt += " | ";
			}
		}
	}
	
	distxt += " ] ";
	if(pagenum < totalpages)
	{
		distxt += " <a href='javascript:viewpaging(" + findlen + ", " + (pagenum + 1) + ");'>Next ></a>";
	}
	if(endpageno > totalpages)
	{
		endpageno = totalpages;
	}
	else
	{
		endpageno++;
	}
	if(document.getElementById('page'))
	{
		document.getElementById('page').innerHTML=distxt;
	}
	if(document.getElementById('page2'))
	{
		   document.getElementById('page2').innerHTML=distxt;              
	}
}