//path="http://localhost/lok/ng/ver3/ver2";
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_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_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 checkform(form)
{
	if (form.name.value=="")
	{
		alert("請輸入姓名");
		form.name.focus();
		return false;
	}
	if (form.email.value=="" && form.tel.value=="")
	{
		alert("請輸入電郵地址或電話號碼");
		return false;
	}
	if (form.email.value!="")
	{
		if (!isEmail(form.email.value))
		return false;
	}
	if (form.enquiry.value=="")
	{
		alert("請輸入內容");
		form.enquiry.focus();
		return false;
	}
	if (form.enquiry.value.length>400)
	{
		alert("內容不可多於400字");
		form.enquiry.focus();
		return false;
	}
		fmtHTMLChar(form);
		return true;
}
function checkform2(form)
{
	if (form.name.value=="")
	{
		alert("請輸入姓名");
		form.name.focus();
		return false;
	}
	if (form.email.value=="")
	{
		alert("請輸入電郵地址");
		return false;
	}
	if (form.email.value!="")
	{
		if (!isEmail(form.email.value))
		return false;
	}
	if (form.address.value=="")
	{
		alert("請輸入內容");
		form.address.focus();
		return false;
	}
		fmtHTMLChar(form);
		return true;
}

function fmtHTMLChar(form) {
	var len = form.elements.length
	for (var i = 0; i<len; i++) {
		var thisform = form.elements[i]
		while (thisform.value.indexOf("'") != -1 ||
				thisform.value.indexOf("<") != -1 ||
				thisform.value.indexOf(">") != -1 ||
				thisform.value.indexOf("%") != -1) {
			thisform.value = thisform.value.replace("'", "&#39;").replace("%", "&#37;").replace("<", "&lt;").replace(">", "&gt;");
		}
	}
}

// all pop-up functions
function goto(url,win)
{
	window.open(url,win,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=680,height=500,top=0,left=0');
}

function goto2(url,win)
{
	window.open(url,win,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=540,height=400,top=0,left=0');
}

function goto3(url,win) //popup of the front page 
{
	window.open(url,win,'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=850,top=0,left=0');
}

function popup(url,win)
{
	window.open(url.win);
}

function popup2(url,win) //pop-up function for aa_promotion index which back to nutrigreen mainpage
{
	window.open(url,win);
}

function popup3(url,win,feature) //popup function for aa_promotion index which popup new window

{
	window.open(url,win,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,top=0,left=0');
	
}

function popup_aa(url, win, feature) //pop up for aa_promotion
{
	window.open(url, 'aa_promotion', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, width=1007,height=725,top=0,left=0');
}

function dlcoupon(url, win, feature) //outdated at 20051201
{
	window.open(url, 'dl', 'toolbar=1, scrollbars=0, location=0, statusbar=0, menubar=0, width=830,height=212,top=0,left=0');
}


function coupon()
{
	window.open('coupon.html','WIN2','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=592,height=520,top=0,left=0');
}

//-----------------------------------------------------------------------------------------------------------------------------------

function isEmail(email)
{
	var emailPattern = /^\w+[\w\.-]+@[\w\.-]+\.\w+$/g
	if (emailPattern.test(email)) 
	return true;	
	alert("請輸入正確電郵地址");
	return false;
}

function isEmptyInForm(formStr,value) {  // to see if the form is empty
	if ((formStr.type=="text") || (formStr.type=="password") || (formStr.type=="select-one") || (formStr.type=="textarea") )
	{  // check for the textfield and pull down menu and textarea
		if (formStr.value == "" || formStr.value == null) {
		alert("請選擇"+value);  // the alert statement
		select(formStr);
		return true
		}
	}  
	else if (formStr[0].type=="radio")
	{ // check for the radio button
	Notok=true;
		for (var i=0; i < formStr.length; i++)
  	 	{
   			if (formStr[i].checked)
      		{
     		 	Notok=false;
     		}
		}
		if (Notok)
		{
			alert("請選擇"+value);   // the alert statement
		}
		return Notok
	}
}


function checkLogin()
{
	if (form.login.value=="")
	{
		alert("請輸入姓名");
		form.login.focus();
		return false;
	}
	if (form.password.value!="")
	{
		alert("請輸入密碼");
		form.password.focus();
		return false;
	}
}

