var webname="http://www.feldmanfurniture.com/"
//var webname="http://localhost/"
var staticTypeDisc=0;
var staticAvail=0;

function popUp(url) {
   sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
   self.name = "mainWin";
}

function resetAvail(numval, availdescr)
{
	if (numval>staticAvail) 
	{
		staticAvail=numval;
		avldscr.innerText=availdescr;
	}
   
} 




function validateForm(form)
{
	var searchString = form.qu.value;
	form.qu.value = searchString == null ? "" :
		         searchString.replace(/[\xA0-\xBF]|#|`|™/g,'').replace(/“|”|„/g,'"').replace(/‘|’|‚/g,"'");

    if( form.qu.value.length < 2 )
	{
        alert("Please enter keyword 2 letters or more");
        return false;
    }
}

  
function printit(){  
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}
function OpenLP()
{
	window.open ('http://server.iad.liveperson.net/hc/47786206/?cmd=file&file=visitorWantsToChat&site=91070226&referrer='+document.location,'chat91070226','width=472,height=320');
 

}
function OpenLPVoice()
{
  window.open ('http://www.liveperson.com/visitor/livetalk/call3?site=47786206&skill=1&identifier=1','chat47786206','width=472,height=320');
}

 

function scbg(objRef, state)
   {
	objRef.style.backgroundColor = (1 == state) ? '#EEEEEE' : '#FFFFFF';
	return;
   }
function EnlargeAndOpen(lpimagename, lpprodname)
{
	var myString = lpimagename
        lpimagename=myString.substr(myString.lastIndexOf("/")+1)
	window.open (webname + '/lrg_img_pop.asp?imagename='+lpimagename+'&productname='+lpprodname,"","width=620,height=570,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
}

function EnlargeAndOpenEx()
{
	var carImage1=new Image()
	carImage1=document.getElementById('bigpic');
	myString=carImage1.src;
 
        var lpprodname=carImage1.alt;
	
        lpimagename=myString.substr(myString.lastIndexOf("/")+1)
	window.open (webname + 'templates/item_templates/lrg_img_pop.asp?imagename='+lpimagename+'&productname='+lpprodname,"","width=620,height=570,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
}

function popUpPM(lwidth, lheight, pagename) 
{
  window.open (webname + pagename+'',"",'width=' + lwidth + ',height=' + lheight + ',toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
 
}
function popUpPMEx(lpimagename, lpprodid)
{

	window.open (webname + 'templates/item_templates/i_price_match_pop.asp?imagename='+lpimagename+'&lpprodid='+lpprodid,"","width=430,height=600,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");

} 
function EmailFriend(lpimagename, lpprodid)
{

	window.open (webname + 'templates/item_templates/emailfrind_pop.asp?imagename='+lpimagename+'&lpprodid='+lpprodid,"","width=430,height=540,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");

}
function SendUsEmail(lpimagename, lpprodid)
{
	window.open (webname + 'templates/item_templates/emailus_pop.asp?imagename='+lpimagename+'&lpprodid='+lpprodid,"","width=425,height=510,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
}

function GenPopUpL(lwidth, lheight, pagename)
{
	window.open (webname + 'templates/item_templates/'+pagename+'',"",'width=' + lwidth + ',height=' + lheight + ',toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no');
}
function GenPopUpEx(lwidth, lheight, pagename, vscrols)
{
	window.open (webname + 'templates/item_templates/'+pagename+'',"",'width=' + lwidth + ',height=' + lheight + ',toolbar=no,menubar=no,location=no,scrollbars=' + vscrols + ',resizable=no');
}
function GenPopUpExWP(lwidth, lheight, pagename, vscrols,lpimagename, lpprodid)
{
	window.open (webname + 'templates/item_templates/'+pagename+'?imagename='+lpimagename+'&lpprodid='+lpprodid+'',"",'width=' + lwidth + ',height=' + lheight + ',toolbar=no,menubar=no,location=no,scrollbars=' + vscrols + ',resizable=no');
}
function GenPopUpExPRINT(lwidth, lheight, pagename, lpprodid)
{
	window.open (webname + 'templates/'+pagename+'?prodid='+lpprodid+'',"",'width=' + lwidth + ',height=' + lheight + ',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}
function PrintPage(domainname, lpprodid)
{
	window.open (domainname + '/templates/item_details_print_temp_init.asp?prodid='+lpprodid+'',"",'width=800,height=600,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}
   function addtofavorites()
   {
      var bookmarkurl=window.document.location;
      var bookmarktitle=window.document.title;   

	if (document.all) 
	{
		window.external.addFavorite(bookmarkurl,bookmarktitle);
	}
     }


function parseelement(numval)
    {
        var prefix="$"
        var wd
        wd="w"
 
        
        var tempnum="" + numval + ""
 
	for (i=0;i<tempnum.length;i++)
	 {
		
		if (tempnum.charAt(i)==".")
	    {
		    wd="d"
		    break
      }
    }
	if (wd=="w")
	   {
	   	    
	      tempnum=prefix+tempnum +".00"
	   }
	else
	    {
 
		if (tempnum.charAt(tempnum.length-2)==".")
	          {
                    tempnum=prefix+tempnum+"0"
                  }
	else
	          {
		    tempnum=Math.round(tempnum*100)/100
		    tempnum=prefix+tempnum
                  }
             }         
        
        
        return tempnum;    
    }

function ResetSelectvalue(atributeid, valueindex)
{
	//alert(valueindex );
	var thisSelect=document.getElementById(atributeid); 
	thisSelect.selectedIndex=valueindex;
	
	//alert(thisSelect.selectedIndex );
 
	return;
	}
function checkPrice()
{
var i=0,j=0,b=0,msum=0,disc=0, usm=0;

var allselects=document.getElementsByTagName("SELECT"); //get all dropdowns
        //need to find what the discount is
         //alert(cp.baseprice);
        disc=eval(cp.itd);
        msum=eval(cp.baseprice);
        //alert(cp.innerText);
	//cp.innerText=eval(cp.baseprice); //reset base price
	for (j=0;j<allselects.length;j++){
		var oneselect=allselects(j);
		if (oneselect.st){
			if (oneselect.st=='pa'){
				for (i=0;i<oneselect.children.length;i++){
					var opt=oneselect.children(i);
					if (opt.selected==true)
					{
							if (opt.src)
							{
								previewimg.src=opt.src;
							}
							b=eval(msum)+eval(opt.adj);
							
							msum=b;
							b=b-(b/100*disc);
							usm=eval(msum)-eval(b);
							cp.innerText=parseelement(b);
							usm=Math.round(usm*100)/100
							if(disc!==0)
							{
							 us.innerText=parseelement(usm);
							 lp.innerText=parseelement(msum);
							}
							
							break;
					}
				}
			}
		}
	}

}
 
function set_values(atrid, prodatrid)
   {
    document.forms['additems'].atrid.value=atrid;
    document.forms['additems'].prodatrid.value=prodatrid;
    document.forms['additems'].action= "recalculate_meta.asp";
    document.forms['additems'].submit();
    //alert(document.forms['additems'].atrid.value+' '+document.forms['additems'].prodatrid.value)
    
   }

function Validate(myForm) 
{	 
	myForm.action = "templates/multy_items_init.asp";
	myForm.submit();	       
}



function ValidateEmailForm(form)
{
	var emailID=form.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}  
	

function validateZIP(field) 
{
var valid = "0123456789-";
var hyphencount = 0;

		if (field.length!=5 ) 
		{
		   alert("Please enter your 5 digit zip code.");
		   return false;
	  }
		for (var i=0; i < field.length; i++) 
		{
				temp = "" + field.substring(i, i+1);
				if (temp == "-") hyphencount++;
				if (valid.indexOf(temp) == "-1") 
				{
						alert("Invalid characters in your zip code.  Please try again.");
						return false;
        }
	      if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
	      {
	          alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
	          return false;
	      }
     }
     return true;
}


function newWin(url,w,h){
	window.open(url,'_blank','resizable=yes,scrollbars=yes,location=yes,status=yes,width=' + w + ',height=' + h);
}

 

function makeSortUrl(base,ap,vt,sb){
	var surl = base.href+'&ap='+ap+'&vt='+vt+'&sb='+sb;
	base.href = surl;
}

function makeViewUrl(base,ap,vt){
	var surl = base.href+'&ap='+ap+'&sb=&vt='+vt;
	base.href = surl;
}
