


function validateEmail(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 addFavoritesToCart() {
}

function setWishlistStatus(status) {
	return;
	var url = '';
	new Ajax(url, {
		method: 'get'
	}).request();
}

function sendWishlist(email) {
	//verify email
	
	if (validateEmail(email)) {
		
	} else {
		alert ('Email address is invalid!');
	}
		
}

function addToFavorites(id) {
	return;
	var url = '';
	new Ajax(url, {
		method: 'get'
	}).request();
}

function addToWishlist(id) {
	return;
	var url = '';
	new Ajax(url, {
		method: 'get'
	}).request();
}

function removeFavorites(id) {
	return;
	var url = '';
	new Ajax(url, {
		method: 'get'
	}).request();
}

function removeWishlist(id) {
	return;
	var url = '';
	new Ajax(url, {
		method: 'get'			
	}).request();
}

function openPopupWindow(id, qty, options)
{
	if (options) {
		doCart('cart2.php?action=add&item_id=' + id + '&qty=' + qty + '&options=' + options);
	} else {
		doCart('cart2.php?action=add&item_id=' + id + '&qty=' + qty);
	}
}

function updatePopupWindow(id, field)
{
	var qty = field.value;
	doCart('cart2.php?action=modify&item_id=' + id + '&qty=' + qty);
}

function RepeatOrder(ids, qtys)
{
	doCart('cart2.php?action=repeat&item_id=' + ids + '&qty=' + qtys);
}

/*
function updatePopupReserved(id, field)
{
	
	var qty = field.value;
	
	if(id == 0)
		xmlHttp.open('get', 'cart2.php');
	else
		xmlHttp.open('get', 'cart2.php?action=modifyr&item_id=' + id + '&qty=' + qty);
	
	xmlHttp.onreadystatechange = handlexmlHttp;
	xmlHttp.send(null);
	
	updateWindow();
}
*/

function RemoveProduct(id)
{
	doCart('cart2.php?action=remove&item_id=' + id);
}

function RemoveReserved(id)
{
	doCart('cart2.php?action=remover&item_id=' + id);
}

function RemoveGift(id)
{
	doCart('cart2.php?action=removeg&item_id=' + id);
}

function addProduct()
{
	
	//send cart
		
	var theform = document.getElementById('form3');
	var item_id = escape(theform.item_id.value);
	var qty = escape(theform.qty.value);
	
		
	var opArray = new Array();
	var x=0;
	$$('.options').each(function(el, pos) {
			x++;
			var option = new Object;
			var name = el.getProperty('name');
			name = name.split('options[').join('');
			name = name.split(']').join('');
			
			//console.debug(pos);
			option.option = name;
			option.value = el.value;
			
			opArray[pos] = option;
			
	});
	
	
		//console.debug(opArray);
		var json = JSON.encode(opArray);
		openPopupWindow(item_id, qty, json);
		
	/*
	if (testIsValidObject(theform.sizing)) {
		sizing = escape(theform.sizing.value);
	} else {
		sizing = '';	
	}
	if (testIsValidObject(theform.color)) {
		color = escape(theform.color.value);
	} else {
		color = '';	
	}	
	openPopupWindow(item_id, qty, sizing, color);
	*/
}

function addGiftCertificate(id, qty)
{
	if (!qty) qty = 0;
	//theform = document.getElementById('gift');
	//gift_cert = escape(theform.gift_cert.value);
	
	if (id > 0) {
		addGiftToCart(id, qty);
	} else {
		if (isNumeric(qty) && qty >= 10 && qty <= 1000) {
			addGiftToCart(id, qty);
		} else {
			alert('Please enter a valid amount between 10 and 1000.');
		}
	}
}

function addGiftToCart(id, qty)
{
	
	if(id == 0) {
		//window.location = 'cart2.php';
		//xmlHttp.open('get', 'cart2.php');
		doCart('cart2.php');
	} else {
		//window.location = 'cart2.php?action=addgift&gid=' + id;
		//xmlHttp.open('get', 'cart2.php?action=addgift&gid=' + id);
		doCart('cart2.php?action=addgift&gid=' + id + '&qty=' + qty);
	}
	
}

function isNumeric(sText)

{
   var ValidChars = "0123456789.";
   var isNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && isNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         isNumber = false;
         }
      }
   return isNumber;
   
   }

/*

var xmlHttp = createRequestObject();


function handlexmlHttp()
{
	
	if(xmlHttp.readyState == 1 || xmlHttp.readyState == 2 || xmlHttp.readyState == 3)
	{
		//document.getElementById('shopping_cart').innerHTML = 'Updating...';
	}
	if(xmlHttp.readyState == 4)
	{
		var response = xmlHttp.responseText;
		//alert(response);
		dd.elements.popwin.write(response);
	}
	
	
}
*/

/*
function closePopupWindow()
{
	dd.elements.popup_window.hide(true);
	document.getElementById('popup_window').style.display='none';
	document.getElementById('fade').style.display='none'
}
*/

/*
function change_qty(id)
{
	var element = document.getElementById("addProd");
	var num = document.getElementById("qty").value;
	
	element.innerHTML="<input type='image' src='Images/add_to_cart2.gif' name='Submit' value='Submit' title='Add to Cart' onclick='openPopupWindow(" + id + "," + num + ")' />";
	//alert(element.innerHTML);
}


function isOldIE() {
	var browsername = navigator.appVersion;
	var pattern = /MSIE\s\d\.\d/gi;
	var result = browsername.match(pattern);
	if(result){
		return parseFloat(result.toString().substr(5));
	} else return 7;
}

function printOrder(id) {
	var sWinName = "Order";
	var cScroll = 1;
	var cResize = 1;
	var sWinopts = 'width='+600+', height='+500+', left='+200+', top='+10+', scrollbars='+cScroll+', resizable='+cResize;
	window.open('print-order.php?id=' + id,sWinName,sWinopts);
}
*/

function testIsValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;
}



