//Start Flotting panel
/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX =screen.width-300 //set x offset of bar in pixels
var startY = 130 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) 
{
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search)
		if (offset != -1) 
		{
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function closebar()
{
	if (persistclose)
		document.cookie="remainclosed=1"
	document.getElementById("topbar").style.visibility="hidden"
}

function staticbar()
{	
	barheight=document.getElementById("topbar").offsetHeight;
	
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id)
	{
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible";
		
		if(d.layers)el.style=el;
		
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
			el.y = startY;
		else
		{
			el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
			el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function()
	{
		if (verticalpos=="fromtop")
		{
			var pY = ns ? pageYOffset : iecompattest().scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else
		{
			var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("topbar");
	stayTopLeft();
}
/*if (window.addEventListener)
	window.addEventListener("load", staticbar, false);
else if (window.attachEvent)
	window.attachEvent("onload", staticbar);
else if (document.getElementById)
	window.onload=staticbar;
*///esnd floatting panel
// JavaScript Document
function goToCart(product,price,code,action)
{
	if(action=="add")
	{
		if(document.getElementById("qty_" + code).value==0)
		{
			alert('Please enter valid quantity.');
			return false;
		}
	}
	document.frm.code.value = code;
	document.frm.product.value = product;
	document.frm.price.value = price;
	document.frm.cartaction.value=action;	
	document.frm.action="shoppingcart.php";
	document.frm.submit();
	return true;	
}
function goToPage(frm,pagelink)
{
	document.frm.action=pagelink;
	document.frm.submit();
}
function replace(string,text,by) 
{
// Replaces text with by in string
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);

	return newstr;
}
function frmValidate()
{ 
	var e=document.frm;
	
	if(replace(e.od_shipping_first_name.value,' ','')=="")
	{
		alert("Shipping Full Name cannot be blank.")
		e.od_shipping_first_name.focus();
		return false;
	}
	if(replace(e.od_shipping_address1.value,' ','')=="")
	{
		alert("Shipping Address Line cannot be blank.")
		e.od_shipping_address1.focus();
		return false;
	}
	if(replace(e.od_shipping_city.value,' ','')=="")
	{
		alert("Shipping city cannot be blank.")
		e.od_shipping_city.focus();
		return false;
	}
	if(replace(e.od_shipping_state.value,' ','')=="")
	{
		alert("Shipping State cannot be blank.")
		e.od_shipping_state.focus();
		return false;
	}
	if(replace(e.od_shipping_postal_code.value,' ','')=="")
	{
		alert("Shipping Zip Code/PostCode cannot be blank.")
		e.od_shipping_postal_code.focus();
		return false;
	}
	if(replace(e.od_shipping_phone.value,' ','')=="")
	{
		alert("Shipping Phone Number cannot be blank.")
		e.od_shipping_phone.focus();
		return false;
	}
	if(replace(e.od_shipping_email.value,' ','')=="")
	{
		alert("Shipping Email Address cannot be blank.")
		e.od_shipping_email.focus();
		return false;
	}
	else
	{
		if(checkemail(e.od_shipping_email.value)==false)
		{
			alert("Invalid Email Address.")
			e.od_shipping_email.select();
			return false;
		}
	}

	if(replace(e.od_payment_first_name.value,' ','')=="")
	{
		alert("Full Name cannot be blank.")
		e.od_payment_first_name.focus();
		return false;
	}
	if(replace(e.od_payment_address1.value,' ','')=="")
	{
		alert("Address Line cannot be blank.")
		e.od_payment_address1.focus();
		return false;
	}
	if(replace(e.od_payment_city.value,' ','')=="")
	{
		alert("City cannot be blank.")
		e.od_payment_city.focus();
		return false;
	}
	if(replace(e.od_payment_state.value,' ','')=="")
	{
		alert("State cannot be blank.")
		e.od_payment_state.focus();
		return false;
	}
	if(replace(e.od_payment_postal_code.value,' ','')=="")
	{
		alert("ZipCode/PostCode cannot be blank.")
		e.od_payment_postal_code.focus();
		return false;
	}
	if(replace(e.od_payment_phone.value,' ','')=="")
	{
		alert("Phone Number cannot be blank.")
		e.od_payment_phone.focus();
		return false;
	}	
	if(replace(e.payment_method.value,' ','')=="0")
	{
		alert("Please select Payment Method.")
		e.payment_method.focus();
		return false;
	}
	if(trim(e.creditcard_number.value)=="")
	{
		alert("Please Enter CreditCard Number.");
		e.creditcard_number.focus();
		return false;
	}
	else if(isNaN(e.creditcard_number.value))
	{
		alert("CreditCard Number Should be Numeric Value. No Special Characters Allowed.");
		e.creditcard_number.focus();
		return false;
	}
	if(replace(e.creditcard_expiration_month.value,' ','')=="0")
	{
		alert("Please select CreditCard Expiration Month.")
		e.creditcard_expiration_month.focus();
		return false;
	}
	if(replace(e.creditcard_expiration_year.value,' ','')=="0")
	{
		alert("Please select CreditCard Expiration Year.")
		e.creditcard_expiration_year.focus();
		return false;
	}
	if(trim(e.cardholder_name.value)=="")
	{
		alert("Please Enter Credit Card Holder's Name.");
		e.cardholder_name.focus();
		return false;
	}
	if(trim(e.payment_cvv2.value)=="")
	{
		alert("Please Enter CVV2.");
		e.payment_cvv2.focus();
		return false;
	}
	else if(isNaN(e.payment_cvv2.value))
	{
		alert("CVV2 Should be Numeric Value. No Special Characters Allowed.");
		e.payment_cvv2.focus();
		return false;
	}

	return true;
}
function Validate()
{ 
	var e=document.frm;
	
	if(replace(e.your_name.value,' ','')=="")
	{
		alert("Name cannot be blank.")
		e.your_name.focus();
		return false;
	}
	
	if(replace(e.your_email.value,' ','')=="")
	{
		alert("Email Address cannot be blank.")
		e.your_email.focus();
		return false;
	}
	else
	{
		if(checkemail(e.your_email.value)==false)
		{
			alert("Invalid Email Address.")
			e.your_email.select();
			return false;
		}
	}
	if(replace(e.subject.value,' ','')=="")
	{
		alert("Subject cannot be blank.")
		e.subject.focus();
		return false;
	}	
	if(replace(e.your_comments.value,' ','')=="")
	{
		alert("Comments cannot be blank.")
		e.your_comments.focus();
		return false;
	}
	if(replace(e.txtCode.value,' ','')=="")
	{
		alert("Security Question cannot be blank.")
		e.txtCode.focus();
		return false;
	}
	
	return true;
}
function fillbilling()
{ 
	var e=document.frm;
	
	if(e.sameas.checked)
	{	
		e.od_payment_first_name.value=e.od_shipping_first_name.value;
		
		e.od_payment_address1.value=e.od_shipping_address1.value;
		
		e.od_payment_address2.value=e.od_shipping_address2.value;
		
		e.od_payment_city.value=e.od_shipping_city.value;
		
		e.od_payment_state.value=e.od_shipping_state.value;
		
		e.od_payment_postal_code.value=e.od_shipping_postal_code.value;
		
		e.od_payment_phone.value=e.od_shipping_phone.value;
		
		e.od_payment_country.value=e.od_shipping_country.value;
	}
	else
	{
		e.od_payment_first_name.value="";
		
		e.od_payment_address1.value="";
		
		e.od_payment_address2.value="";
		
		e.od_payment_city.value="";
		
		e.od_payment_state.value="";
		
		e.od_payment_postal_code.value="";
		
		e.od_payment_phone.value="";
		
		e.od_payment_country.value="";
	}
}
function CountWords (this_field, show_word_count, show_char_count) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (show_word_count & show_char_count) {
alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
}
else {
if (show_word_count) {
alert ("Word Count:  " + word_count + wordOrWords);
}
else {
if (show_char_count) {
alert ("Character Count:  " + char_count + charOrChars);
      }
   }
}
return word_count;
}
