/**
* @author Cristian Ciobanu
*/
function openWindow(URL,width,height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 50,top = 50');");
}

function swapPIC(id, source) {
	document.getElementById(id).src = source;
	return false;
}

function trim(a) {
	a = a.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
}

function IsNumeric(sText, accept) {
	var ValidChars = accept;
	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;
}

function isEmail(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	
	if (str.indexOf(at)==-1){
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true;
}

function validateQty(frm, qty, store, flag) {
	var myFrm = document.getElementById(frm);
	var myQty = document.getElementById(qty).value;
	if (!IsNumeric(myQty, '0123456789') || myQty.length == 0) {
		alert('Please enter a valid quantity!');
		document.getElementById(qty).value = 1;
		document.getElementById(qty).focus();
	}
	else {
		if (flag.length > 0) {
			if (store != flag) {
				var agree=confirm("You can only order from one store at a time. If you add a pizza from this store, any pizzas currently in your shopping cart from other stores will be removed from your order. Do you wish to continue?");
				if (agree) {
					myFrm.submit();
				}
			} else {
				myFrm.submit();
			}
		} else {
			myFrm.submit();
		}
	}
}