// JavaScript Document

//bookmark button script

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

//end of bookmark button script

//beginning of viewproduct.php javacript

function open_win(abspath,qstring)
	{
		window.open(abspath+'viewenlarge.php?product='+qstring,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=600");
	}	
	function validatesearchtext_vprod(redirect_js,cateid_js)
	{
		if (trim(document.fmSearch_viewproduct.txtSearch_viewproduct.value)=='')
		{
			alert("Enter the text to be searched!");
			return false;
		}
		else
		{
			searchtext_js=URLEncode(document.fmSearch_viewproduct.txtSearch_viewproduct.value);
			searchtext_js=searchtext_js.replace("/"," ")
			window.location.href=""+redirect_js+cateid_js+"/"+searchtext_js+".htm";			
			return false;
		}
	}
	function validatesearchtext_vprod_2(redirect_js,cateid_js)
	{
		if (trim(document.fmSearch_viewproduct_2.txtSearch_viewproduct.value)=='')
		{
			alert("Enter the text to be searched!");
			return false;
		}
		else
		{
			searchtext_js=URLEncode(document.fmSearch_viewproduct_2.txtSearch_viewproduct.value);
			searchtext_js=searchtext_js.replace("/"," ")
			window.location.href=""+redirect_js+cateid_js+"/"+searchtext_js+".htm";			
			return false;
		}
	}
	function URLEncode(stringtoencode)
	{
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric

						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic

						"abcdefghijklmnopqrstuvwxyz" +

						"-_.!~*'()/\\";					// RFC2396 Mark characters

		var HEX = "0123456789ABCDEF";
		var plaintext = stringtoencode;
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					//alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
		return encoded;
	}
	function ValidateVariSel(actionpage) {
		doc=document.addtocart_vari;
		index=doc.SelectVari.selectedIndex;
		if (index=="-1") {
			alert("Select any one of the product options from the list and then add to cart!");
			return false;
		}
		index_value=doc.SelectVari.options[index].value;
		index_split=index_value.split("~|~");
		if (index_split.length==2) {
			redirecturl=actionpage+"?action=add&frm=vari&ASIN="+index_split[0]+"&off="+index_split[1];
			window.location.href=redirecturl;
		}
	}
//-->
//end of viewproduct.php javacript

//beginning of searchresult.php javacript

function open_win(abspath,qstring)
{
	window.open(abspath+'viewenlarge.php?product='+qstring,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=600");
}	

function validatesearchtext_vprod(redirect_js,cateid_js)
{
	if (trim(document.fmSearch_viewproduct.txtSearch_viewproduct.value)=='')
	{
		alert("Enter the text to be searched!");
		return false;
	}
	else
	{
		searchtext_js=URLEncode(document.fmSearch_viewproduct.txtSearch_viewproduct.value);
		searchtext_js=searchtext_js.replace("/"," ")
		window.location.href=""+redirect_js+cateid_js+"/"+searchtext_js+".htm";			
		return false;
	}
}

	function URLEncode(stringtoencode)
	{
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()/\\";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
	
		var plaintext = stringtoencode;
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					//alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
	
		return encoded;
	}
//-->

//end of searchresult.php javacript

//beginning of searchbox.php javascript

<!--
	function printdefaulttext(defaulttext)
	{
		txtSearch=document.fmSearch.txtSearch.value;
		if (txtSearch==defaulttext) {
			document.fmSearch.txtSearch.value='';
		}	
		else if (trim(txtSearch)=='') {
			document.fmSearch.txtSearch.value='LouisPurses';
		}
	}
	
	function trim(str)
	{
   		return str.replace(/^\s*|\s*$/g,"");
	}
	
	function validatesearchtext(redirect_page)
	{
		if (trim(document.fmSearch.txtSearch.value)=='')
		{
			alert("Enter the text to be searched!");
			return false;
		}
		else
		{
			cateid_js=document.fmSearch.optCategories.value;
            searchtext_js=document.fmSearch.txtSearch.value;
			searchtext_js=URLEncode(searchtext_js);
			searchtext_js=searchtext_js.replace("/"," ")
            //andrw
            searchtext_js = searchtext_js.replace(/\+/g, "-");
            searchtext_js=searchtext_js.replace(" ", "-");
			window.location.href=""+redirect_page+cateid_js+"/"+searchtext_js+".htm";			
			return false;
		}
	}
	
	function checkslash(strr)
	{
		for(i=0;i<strr.length;i++)
		{
			st=strr.charAt(i);
			if(st=="/")
			{
				return false;
			}
		}
		strr.value="";
		return true;
	}
	
	function URLEncode(stringtoencode)
	{
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()/\\";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
	
		var plaintext = stringtoencode;
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					//alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
	
		return encoded;
	}
//-->

//end of searchbox.php javascript
