function isEmail(entry){
	var rex= /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/	
	return rex.test(entry);
}

function rgbToHex(rgb) { 
	if (!/^rgb\(/.test(rgb)) return rgb;
	var rgbvals = /rgb\((.+),(.+),(.+)\)/i.exec(rgb); 
	var rval = parseInt(rgbvals[1]); 
	var gval = parseInt(rgbvals[2]); 
	var bval = parseInt(rgbvals[3]); 
	return '#' + ( 
		(rval < 10 ? '0' : '') + rval.toString(16) + 
		(gval < 10 ? '0' : '') + gval.toString(16) + 
		(bval < 10 ? '0' : '') + bval.toString(16) 
	).toUpperCase(); 
}
var imageWin = null;
function showImage(image_url, image_width, image_height){
	image_width = image_width == "" ? 400 : image_width;
	image_height = image_height == "" ? 380 : image_height;

	var w = screen.width;
	var h = screen.height;
	var ww = image_width * 1 + 30;
	var wh = image_height * 1 + 45;
	var wx = (w - ww)/2;
	var wy = (h - wh)/2;
	
	if(imageWin != null){
		imageWin.close();
	}
	imageWin = null;
	imageWin = window.open(
		"", 
		"ProductImageWindow", 
		"titlebar=yes, toolbar=no, menubar=no, status=no, directories=no, resizable=yes, scrollbars=yes, top=" + wy.toString() + ", left=" + wx.toString() + ", width=" + ww.toString() + ", height=" + wh.toString() + ""
	);
	while(imageWin==null);
	imageWin.focus();
	
	imageWin.document.body.innerHTML = "";
	imageWin.document.write('<body style="padding:5px;margin:0px">');
	imageWin.document.write('<div align="center"><img hspace="0" vspace="0" src="' + image_url + '"></div><br/>');
	imageWin.document.write('<div align="center" style="font-family:arial;font-color:black;font-size:11px;"><a href="javascript:window.close();" style="color:#0000AA;">Close Window</a></div>');
	imageWin.document.write('</body>');
	imageWin.width = ww;
	imageWin.height = wh;
}

function showPrinterPage(url){
	var prWin = null;
	prWin = window.open(
		url,
		"PrintVer", 
		"titlebar=yes, toolbar=no, menubar=yes, status=yes, directories=no, resizable=yes, scrollbars=yes, top=20, left=20, width=810, height=600"
	);
	while(prWin==null);
	prWin.focus();
}

function ShowPopup(src){
	var bWin = null;
	bWin = window.open(
		src, 
		"PopupWind", 
		"titlebar=no, toolbar=no, menubar=no, status=no, directories=no, resizable=no, scrollbars=no, top=20, left=20, width=320, height=240"
	);
	while(bWin==null);
	bWin.focus();
}

function ConfirmLogout(){
	if(orderItemsCount > 0){
		if(confirm("You have items in your cart. Logging out will empty your cart\nAre you sure want to continue?")){
			document.location = urlLogout;
		}
	}
	else{
		if(confirm("Do you really want to logout?")){
			document.location = urlLogout;
		}
	}
}

function CartConfirmDeleteItem(ocid){
	if(confirm(msg.confirm_delete_item)){
		document.location = CartDeleteItemUrl + '&ocid=' + ocid;
	}
}
function CartConfirmEmpty(){
	if(confirm(msg.confirm_empty_cart)){
		document.location = CartEmptyUrl;
	}
}

/**
219 *
* @access public
* @return void
**/
function doMfgrSearch(dropdn){
 var mid = dropdn.options[dropdn.selectedIndex].value;
 if (mid != 0) {
 var mfgrStr = dropdn.options[dropdn.selectedIndex].text;
 mfgrStr = mfgrStr.replace(/\s/g, "-");
 document.location = "/mfgr/" + mid + "/" + mfgrStr + ".htm";
 }
}

$(document).ready(function(){
	var catalogProductImageWidth = $('.catalog-product-image').width();
	$('.catalog-product-image img').each(function(){
		if ($(this).width() > catalogProductImageWidth)
		{
			$(this).css('width', catalogProductImageWidth - 5);
		}
	});
});


	

		function s_loadCat(element, catid)
		{
			$("#content").html("<img src='images/icons/al.gif' />");
			$("[id^='s_acc_cat_a']").removeClass("current");
			//Clear old cats & load new one
			$("#content").load("index.php?p=catalog&parent=" + catid + "&s_qm=co");
			//Add current to the category we know
			$(element).addClass("current");
			$(element).parents().filter("li,[id^='s_cat_li-1']").children("h6").children("a").addClass("current");
			$(".refinement").slideDown();

		}
		function s_loadCatID(catid, pg)
		{
			$("#content").html("<img src='images/icons/al.gif' />");
			$("[id^='s_acc_cat_a']").removeClass("current");

			//Clear old cats & load new one
			$("#content").load("index.php?p=catalog&parent=" + catid + "&pg=" + pg + "&s_qm=co");
			//Add current to the category we know
			$("[id^='s_acc_cat_a'][id*='_"+catid+"_']").addClass("current");
			$("[id^='s_acc_cat_a'][id*='_"+catid+"_']").parents().filter("li,[id^='s_cat_li-1']").children("h6").children("a").addClass("current");
			$(".refinement").slideDown();
			//$('#content,img').each(function (i) { $(this).css("border", "0px"); });
		}


		function s_loadManu(mid, pg)
		{
			$("#content").html("<img src='images/icons/al.gif' />");
			//Clear old cats & load new one
			$("#content").load("index.php?p=catalog&mode=manufacturer&mid=" + mid + "&pg=" + pg + "&s_qm=co");
			$(".refinement").slideDown();
			$("#refinement_brand").slideUp();
			//$('#content,img').each(function (i) { $(this).css("border", "0px"); });
		}

		function s_loadProduct(pid, parent)
		{
			$(".refinement").slideUp();
			$("#content").html("<img src='images/icons/al.gif' />");
			//Clear old cats & load new one
			$("#content").load("index.php?p=product&id=" + pid + "&parent=" + parent + "&s_qm=co");
			//$('#content,img').each(function (i) { $(this).css("border", "0px"); });
		}

		function s_loadCart()
		{
			$(".refinement").slideUp();
			$("#content").html("<img src='images/icons/al.gif' />");
			//Clear old cats & load new one
			$("#content").load("index.php?p=cart&s_qm=co", function (){ $('#content,tr').each(function (i) { $(this).css("border", "0px"); });$('#content,table').each(function (i) { $(this).css("border", "0px"); });$('#content,td').each(function (i) { $(this).css("border", "0px"); }); });

		}

		function s_loadSearch(search, pg)
		{
			$("#content").html("<img src='images/icons/al.gif' />");
			$("#content").load("index.php?p=catalog&mode=search&search_in=all&search_str=" + search + "&pg="+pg+"&s_qm=co");
			$(".refinement").slideDown();
		}

		function s_loadLanding(catid)
		{
			$("#content").html("<img src='images/icons/al.gif' />");
			$("[id^='s_acc_cat_a']").removeClass("current");
			//Clear old cats & load new one
			$("#content").load("index.php?p=catalog&mode=landing&parent=" + catid + "&s_qm=co");
			//Add current to the category we know
			$(element).addClass("current");
			$(element).parents().filter("li,[id^='s_cat_li-1']").children("h6").children("a").addClass("current");
		}

		function s_loadPage(page)
		{

			$("#content").html("<img src='images/icons/al.gif' />");
			$("[id^='s_acc_cat_a']").removeClass("current");
			$(".refinement").slideUp();

			$("#content").load("index.php?p=page&page_id=" + page + "&s_qm=co");

		}

	// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash) {
		// hash doesn't contain the first # character.
		if($.browser.msie) {
				// jquery's $.load() function does't work when hash include special characters like ???.
				hash = encodeURIComponent(hash);
			}
			
		if(hash != "") {
			// restore ajax loaded state
			
			document.title = "CarefreeCasuals.com";
			pageTracker._trackPageview(hash);
			s_ph_i(hash, 0);
		} else {
			//document.location = document.location.replace("#", "");
			//window.location.reload();
			window.location = window.location.href.replace( /#.*/, "");
		}
	}


	function s_ph(hash, doLoad, element)
	{
		$.historyLoad(hash);
	}

	function s_ph_i(hash)
	{
		var el = [];
		el = hash.split("~");
		switch (el[0])
		{
			case "catalog":
				s_loadCatID(el[1], el[2]);
				break;
			case "manufacturer":
				s_loadManu(el[1], el[2]);
				break;
			case "product":
				s_loadProduct(el[1], el[2]);
				break;
			case "cart":
				s_loadCart();
				break;
			case "search":
				s_loadSearch(el[1], el[2]);
				break;
			case "landing":
				s_loadLanding(el[1]);
				break;
			case "catalog-filter":
				s_loadCatFilter(el[1], el[2]);
				break;

			case "page":
				s_loadPage(el[1]);
				break;
		}
	}

	function s_loadCatFilter(catid, filterstr)
	{
		var filter = [];
		filter = filterstr.split("*");

		var caturl = "index.php?p=catalog&parent=" + catid + "&pg=1&s_qm=co";

		if(filter[0] == "mid")
		{
			caturl = caturl + "&s_filter_mid=" + filter[1];
		}

		$("#content").html("<img src='images/icons/al.gif' />");
		$("[id^='s_acc_cat_a']").removeClass("current");

		//Clear old cats & load new one
		$("#content").load(caturl);
		//Add current to the category we know
		$("[id^='s_acc_cat_a'][id*='_"+catid+"_']").addClass("current");
		$("[id^='s_acc_cat_a'][id*='_"+catid+"_']").parents().filter("li,[id^='s_cat_li-1']").children("h6").children("a").addClass("current");
		$(".refinement").slideDown();
		//$('#content,img').each(function (i) { $(this).css("border", "0px"); });
	}

	function s_pf(t,f)
	{
		$("#content").html("<img src='images/icons/al.gif' />");
		$("#content").load(f + "&s_qm=co");
	}

	/*
	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash.
		$.historyInit(pageload, CurrentPageName());
		
		/*$.history.init(function(hash){
        if(hash == "") {
            // initialize your app
        } else {
            // restore the state from hash
			s_ph(hash);
        }
		},
		{ unescape: ",/" });*/
	/*

		// set onlick event for buttons - flagged with autohistory
		$("a[rel='history']").click(function(){
			//
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page.
			// pageload is called at once.
			// hash don't contain "#", "?"
			$historyLoad(hash);
			return false;
		});

		$('#search_string').keyup(function(e) {
			//alert(e.keyCode);
			if(e.keyCode == 13) {
				e.preventDefault();
				s_ph('search~' + $('#search_string').val().replace(/\s/, '+'));
			}
		});
		
		$('#search_form_button').click(function(e) {
			s_ph('search~' + $('#search_string').val().replace(/\s/, '+'));
		});
	});

	*/

	function CurrentPageName() {
	  return document.location.href.substring(
		document.location.href.length
		, document.location.href.lastIndexOf('/') + 1
	  );
	}

