function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function preloadMainMenu() {
	MM_preloadImages('images/general/mainmenu/mm_store_active.gif','images/general/mainmenu/mm_aboutsake_active.gif','images/general/mainmenu/mm_shop_active.gif','images/general/mainmenu/mm_order_active.gif','images/general/mainmenu/mm_inthenews_active.gif','images/general/mainmenu/mm_events_active.gif')
}

function popup_order_window() {
    /* Open the Order Window as a popup and set focus to it.  */
    /* If it already exists, this will give focus to the existing window (and refresh the form) */
    var win = window.open('order.php','sakaya_order','scrollbars=yes,resizable=yes,width=500');
    win.focus();
}

function popup_tastings_window() {
    /* Open the Tastings Window as a popup and set focus to it.  */
    /* If it already exists, this will give focus to the existing window (and refresh the form) */
    var win = window.open('tastings.php','sakaya_tastings','scrollbars=yes,resizable=yes,width=500');
    win.focus();
}

function popup_instore_window() {
    /* Open the Tastings Window as a popup and set focus to it.  */
    /* If it already exists, this will give focus to the existing window (and refresh the form) */
    var win = window.open('in-store_tastings.php','sakaya_tastings','scrollbars=yes,resizable=yes,width=500');
    win.focus();
}

function popup_club_window() {
    /* Open the Tastings Window as a popup and set focus to it.  */
    /* If it already exists, this will give focus to the existing window (and refresh the form) */
    var win = window.open('club.php','sakaya_club','scrollbars=yes,resizable=yes,width=500');
    win.focus();
}

function popup_japanese_window() {
    /* Open the Japanese Window as a popup and set focus to it.  */
    /* If it already exists, this will give focus to the existing window (and refresh the form) */
    var win = window.open('japanese.php','sakaya_japanese','scrollbars=yes,resizable=yes,width=500');
    win.focus();
}


function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isValidPositiveInteger(inpString) {
   return /^\d+$/.test(trim(inpString));
}

function verify_subscribe_email() {
	$valid = isValidEmail(document.form_subscribe.subscribe_email.value);
	
	if (!$valid) { alert("Please enter your email address"); }
	return $valid;
}

function do_submit_subscribe() {

	if (!verify_subscribe_email()) return false;
	document.form_subscribe.submit();	
}

/* String utilities */
function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}


