function addbookmark()
{
	var i = navigator.userAgent.indexOf("Netscape");
	if(i >= 0)
	{
		alert("Press Ctrl + D to Bookmark this Page");
	}
	else if (window.sidebar) // firefox
	{
		alert("Press Ctrl + D to bookmark");
	}
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',"http://www.halfpricedrapes.com");
		elem.setAttribute('title',document.title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
	{
		window.external.AddFavorite("http://www.halfpricedrapes.com", 'www.halfpricedrapes.com - ' + document.title);
	}
	else
	{
		alert("Press Ctrl + D to Bookmark this page");
	}
}

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")

		{

			if(frm.elements[j].style.display != 'none')

			{

				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" && frm.elements[j].style.display != 'none')

		{

			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;

			}

			if(frm.elements[j].value == "Select Size")

			{

				alert("Please Select Size");

				return false;

			}
			if(frm.elements[j].value == "Order Ready Made Size")

			{

				alert("Please Select Size");

				return false;

			}

		}

	}	

}



function updatesizemenu(paralen, orsprice)
{
	value = document.getElementById("headerdesign").selectedIndex;
	for(p=0;p<paralen;p++)
	{
		if(document.getElementById("topheadersize"+p))
		{
			if(p == value)
			{
				/*if(document.getElementById("topheader"+p))
				{
					document.getElementById("topheader"+p).style.display = '';
				}*/
				document.getElementById("topheadersize"+p).name = 'Select Size';
				document.getElementById("topheadersize"+p).style.display = '';
				document.getElementById("topheadersize"+p).style.visibility = 'visible';
			}
			else
			{
				/*if(document.getElementById("topheader"+p))
				{
					document.getElementById("topheader"+p).style.display = 'none';
				}*/
				document.getElementById("topheadersize"+p).name = '';
				document.getElementById("topheadersize"+p).selectedIndex = 0;
				document.getElementById("topheadersize"+p).style.display = 'none';
				document.getElementById("topheadersize"+p).style.visibility = 'hidden';				
			}
		}
	}
	mainsprice = "<span>$" + orsprice.toFixed(2) + "</span>";
	document.getElementById("saleprice").innerHTML = mainsprice;
}

function updatesilksizemenu(paralen, orsprice)
{
	value = document.getElementById("headerdesign").selectedIndex;
	for(p=0;p<paralen;p++)
	{
		if(document.getElementById("topheadersize"+p))
		{
			if(p == value)
			{
				if(document.getElementById("topheader"+p))
				{
					document.getElementById("topheader"+p).style.display = '';
				}
				document.getElementById("topheadersize"+p).name = 'Select Size';
				document.getElementById("topheadersize"+p).style.display = '';
				document.getElementById("topheadersize"+p).style.visibility = 'visible';
			}
			else
			{
				if(document.getElementById("topheader"+p))
				{
					document.getElementById("topheader"+p).style.display = 'none';
				}
				document.getElementById("topheadersize"+p).name = '';
				document.getElementById("topheadersize"+p).selectedIndex = 0;
				document.getElementById("topheadersize"+p).style.display = 'none';
				document.getElementById("topheadersize"+p).style.visibility = 'hidden';
			}
		}
	}
	mainsprice = "<span>$" + orsprice.toFixed(2) + "</span>";
	document.getElementById("saleprice").innerHTML = mainsprice;
}

/*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("morediv"+i))

		{

			if(val==i)

			{

				document.getElementById("morediv"+i).style.display='';

			}		

			else

			{

				document.getElementById("morediv"+i).style.display='none';

			}

		}

	}

}



function findimagepopup()

{

	for(i=1;i<=5;i++)

	{

		if(document.getElementById("morediv"+i))

		{

			divstyle = document.getElementById("morediv"+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_LFE";

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 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 checkCookie(id, name, imgpath,  price)
{
	var i,count;
	totalcookie = GetCookieRV("Total_LFE");
	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 == 4)
			{
				for(m=1;m<=4;m++)
				{
					username=GetCookieRV(str1 + m);
					newname[newname.length] = username;

					str=str1+m;
					str=str+"_price";
					username = GetCookieRV(str);
					newprice[newprice.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;
				}

				for(m=1, n=1;m<4;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+"_price";
					createCookieRV(str,newprice[n]);
				}
				cookie_store(m, id, name, imgpath,  price);
			}
			else
			{
				i++;
				createCookieRV("Total_LFE",i);
				cookie_store(i, id, name, imgpath,  price);
			}
		}
	}
	else
	{
			i=1;
			createCookieRV("Total_LFE",i);
			cookie_store(i, id, name, imgpath,  price);
	}
}

function gc1()
{
	var i;
	totalcookie = GetCookieRV("Total_LFE");

	if(Number(totalcookie) > 1)
	{
		document.getElementById("recentdiv").style.display = "";
//		document.getElementById("recent_title").style.display = "";
		//document.getElementById("country2").style.display = "";
		//document.getElementById("seperator").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");
			price = GetCookieRV(str1 + j + "_price");

			str=str1;
			str=str+j;
			str=str+'_id';
			lp =GetCookieRV(str); 	

			str=str1;
			str=str+j;
			str=str+'_id';
			lp =GetCookieRV(str); 
			if(j > 1)
			{
				ihtml += "<div class='recently-viewed-pro' > ";
			}
			else
			{
				ihtml += "<div class='recently-viewed-pro-none' > ";
			}
			ihtml += "<div class='recently-viewed-box-bg' >";

			ihtml += "<div class='recently-viewed-box'><a href='" + lp + ".html'><img src='" + imgpath + "' border='0' height='309' width='234' alt='" + name + "'></a></div>";
			
			ihtml +="<div class='recently-viewed-pro-text'><h2><a href='" + lp + ".html'>" + name + "</a></h2>";

			var saleprice = parseFloat(price);

			ihtml += "<div class='price'>Price: <span>$" + saleprice.toFixed(2) + "</span></div>";

			ihtml += '</div>';
			ihtml += '</div>';
			ihtml += '</div>';			
		}
		document.getElementById("recentdiv").innerHTML = ihtml;
	}
}

function cookie_store(val, id, name, imgpath, price)
{
	createCookieRV(str1+val,name);
	str=str1+val;
	str=str+"_price";
	
	createCookieRV(str,price);
	str=str1+val;
	str=str+"_id";
	
	createCookieRV(str,id);
	str=str1+val;
	str=str+"_imgpath";
	createCookieRV(str,imgpath);
}

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>";*/
			dhtml += "<div class='silk_box_bg'><div class='silk_box'><div class='silk_box_titel'><h4><a href='" + final[i].pid + ".html'>" + productname + "</a></h4></div><a href='" + final[i].pid + ".html'><img src='" + final[i].image + "' alt='" + final[i].productname + "' title='" + final[i].productname + "' border='0'></a></div></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;              

	}

}

/*Script for Newsletter*/
function nvalidateEmail(email)
{
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}


function nvalidate() {

if (document.newsletter.semail.value.length==0) {
alert("please enter your email address");
return false;
}
if(!nvalidateEmail(document.newsletter.semail.value)) {
    
alert("please enter your valid email address"); 
return false; 
}
else document.newsletter.submit()
return true;
}
function cleartext(val)
{
document.getElementById("semail").value="";
}
/**/

/*Script for Tell a friend*/
function reset() {
document.tellafriend.name.value="";
document.tellafriend.email.value="";
document.tellafriend.friendmail1.value="";
document.tellafriend.friendmail2.value="";
document.tellafriend.friendmail3.value="";
}

function validateEmail(email)
{
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function validate() {

if (document.tellafriend.name.value.length==0) {
alert("please enter your name");
return false;
}
if (document.tellafriend.email.value.length==0) {
alert("please enter your email address");
return false;
}
if(!validateEmail(document.tellafriend.email.value)) 
               { 
                 alert("please enter your valid email address"); 
                 return false; 
               }

if (document.tellafriend.friendmail1.value.length==0 && document.tellafriend.friendmail2.value.length==0 && document.tellafriend.friendmail3.value.length==0) {
alert("please enter your friend's email address");
return false;
}

if (!(document.tellafriend.friendmail1.value.length==0)){		
if(!validateEmail(document.tellafriend.friendmail1.value)) 
               { 
                 alert("please enter your valid email address of 'email-1'"); 
                 return false; 
               }
}	   
if (!(document.tellafriend.friendmail2.value.length==0)){		
if(!validateEmail(document.tellafriend.friendmail2.value)) 
               { 
                 alert("please enter valid email address of 'email-2'"); 
                 return false; 
               }
}	   

if (!(document.tellafriend.friendmail3.value.length==0)){		
if(!validateEmail(document.tellafriend.friendmail3.value)) 
               { 
                 alert("please enter valid email address of 'email-3'"); 
                 return false; 
               }
}	
document.tellafriend.submit()
return true;
}
/**/
