function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//------------------------------------------------------------------------------------
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//------------------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z0-9][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}
//=====================================================================
//=========Open a new window pop up with specific height and width=====
//=====================================================================
function showWindow(pageName, intWidth, intHeight)
{
	window.open(pageName, '', 'width='+intWidth+',height='+intWidth+',left=200,scrollbars=1,top=50,toolbar=0,menubar=0,location=0');
}
//------------------------------------------------------------------------------------
function NewWindow(pageName)
{
	window.open(pageName, '', 'width=520,height=600,toolbar=0,menubar=0,location=0,left=0,top=0,scrollbars=1');
}
//==========================================
//=========Fade in and Fade out effects=====
//==========================================
var op = 0;
var delay = 5;
function fadeIn()
{
	if(op == 0) ad.style.visibility = 'visible';
	op += 2;
	ad.style.filter = 'alpha(opacity=' + op + ')';
	ad.style.opacity = op / 100;
	if(op < 100)
		setTimeout('fadeIn()', delay);
}
function fadeOut()
{
	op -= 2;
	ad.style.filter = 'alpha(opacity=' + op + ')';
	ad.style.opacity = op / 100;
	if(op > 0)
		setTimeout('fadeOut()', delay);
	else
		ad.style.visibility = 'hidden';
}
//==========================================
//=========  Add To Cart  ==================
//==========================================
function addToCart(productID)
{
	//alert(productID);
	obj.action='cart_process.php?opt=add&pid='+productID;
	obj.submit();
}
//Refresh Captcha
function refreshCaptcha(imgid)
{
	var newimg = new Image();
	newimg.src = 'includes/captcha/captcha.php?hash='+parseInt(Math.random() * 10000000000);
	newimg.onload = function(){document.getElementById(imgid).src = newimg.src;}
}
//Checks promo code
function chkPromo(tmpStr)
{
	var promo_pat = /^[A-Z0-9]+$/;
	return(promo_pat.test(tmpStr));
}
function addOption(selectbox, optionValue, optionText)
{
	var optn = document.createElement("OPTION");
	optn.text = optionText;
	optn.value = optionValue;
	selectbox.options.add(optn);
}
//----------------------------------------
//Auto Fill The Ship Information
//----------------------------------------
function fillShipTo(chk)
{
	if(chk.checked)
	{
		//============copy Billing Address into Shipping Address fields============
		obj.s_first_name.value = obj.b_first_name.value;
		obj.s_last_name.value = obj.b_last_name.value;
		obj.s_company_name.value = obj.b_company_name.value;
		obj.s_address.value = obj.b_address.value;
		obj.s_address_2.value = obj.b_address_2.value;
		obj.s_city.value = obj.b_city.value;
		obj.s_state.selectedIndex = obj.b_state.selectedIndex;
		obj.s_country.selectedIndex = obj.b_country.selectedIndex;
		obj.s_zip.value = obj.b_zip.value;
		obj.s_phone.value = obj.b_phone.value;
		obj.s_fax.value = obj.b_fax.value;
		obj.s_email.value = obj.b_email.value;
	}
	else
	{
		//============erase the fields============
		obj.s_first_name.value = '';
		obj.s_last_name.value = '';
		obj.s_company_name.value = '';
		obj.s_address.value = '';
		obj.s_address_2.value = '';
		obj.s_city.value = '';
		obj.s_state.selectedIndex = 0;
		obj.s_country.selectedIndex = 0;
		obj.s_zip.value = '';
		obj.s_phone.value = '';
		obj.s_fax.value = '';
		obj.s_email.value = '';
	}
}
