// this function is for the home links
function viewLink(linkName)
{
	if (linkName == 'home')
	{
		location = SGL_JS_WEBROOT + "/index.php";
	}
	else if (linkName.indexOf('register') == 0)
	{
		location = SGL_JS_WEBROOT + "/index.php/user/" + linkName;
	}
	else
	{
		location = SGL_JS_WEBROOT + "/index.php/user/login/action/" + linkName;
	}
	return false;
}

function submitLoginPage()
{
//	if (document.frmLogin.frmUsername.value=="" || document.frmLogin.frmPassword.value=="")
//	{
//		alert("Please enter userid and password!");
//	}
//	else
//	{
		document.frmLogin.submit();
//	}
}

function submitLogin2Page()
{
//	if (document.frmLogin.frmUsername.value=="" || document.frmLogin.frmPassword.value=="")
//	{
//		alert("Please enter userid and password!");
//	}
//	else
//	{
		document.frmLogin2.submit();
//	}
}


function clearData(recordNum)
{
	if (recordNum == '0')
	{
		var index;
		for (index=1; index<=5; index++)
		{
			document.frmForm.elements['rx_'+index].value = '';
			document.frmForm.elements['description_'+index].value = '';
		}
	}
	else
	{
		document.frmForm.elements['rx_'+recordNum].value = '';
		document.frmForm.elements['description_'+recordNum].value = '';
	}
}

function submitEasyRefill()
{
	var requestEmpty = 1;

	for (index=1; index<=5; index++)
	{
		if (document.frmForm.elements['rx_'+index].value != '' || document.frmForm.elements['description_'+index].value != '')
		{
			requestEmpty = 0;
			// stop running - not empty
			index = 6;
		}
	}
	
	if (requestEmpty)
		alert('Please fill in either prescription number or medicine description');
	else
		document.frmForm.submit();
}










function echeck(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("Please input a valid eMail address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please input a valid eMail address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please input a valid eMail address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please input a valid eMail address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please input a valid eMail address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please input a valid eMail address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please input a valid eMail address.")
		    return false
		 }

 		 return true					
	}

function ValidateForm()
{
	var emailID=document.frmLogin2.member_email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
}

function memberSubmit()
{
	if (document.frmLogin2.member_name.value == '' || document.frmLogin2.member_address.value == '' || document.frmLogin2.member_email.value == '')  
	{
		alert('Please fill in your name, address and eMail address info');
	}
	else
	{
		//if (document.frmForm.mail.checked || document.frmForm.email.checked)
		
		if (ValidateForm())
		{
			document.frmLogin2.submit();
		}
		//else
		//	alert('Please select Mail, eMail or both');
	}
}






// for GHP User
function viewUserLink(linkName)
{
	//alert(SGL_JS_WEBROOT + "/index.php/user/" + linkName);
	location = SGL_JS_WEBROOT + "/index.php/user/" + linkName;
}

// for GHP User
function refillStatus()
{
	//alert(document.frmForm.refill_status.value);
	if (document.frmForm.refill_status.value != "0")
		location = SGL_JS_WEBROOT + "/index.php/user/account/action/refill/status/" + document.frmForm.refill_status.value;
	else
		alert("Select either Pending or Completed refills");
}

function linkRefill(linkURL)
{
	location = SGL_JS_WEBROOT + "/index.php/user/account/action/refill" + linkURL;
}

function submitRefill()
{
	var agree=confirm("Update refill order?");
	
	if (agree)
		document.frmForm.submit();
}


/*
function submitLoginPage()
{
//	if (document.frmLogin.frmUsername.value=="" || document.frmLogin.frmPassword.value=="")
//	{
//		alert("Please enter userid and password!");
//	}
//	else
//	{
		document.frmLogin.submit();
//	}
}

function submitLogin2Page()
{
//	if (document.frmLogin.frmUsername.value=="" || document.frmLogin.frmPassword.value=="")
//	{
//		alert("Please enter userid and password!");
//	}
//	else
//	{
		document.frmLogin2.submit();
//	}
}
			

function minimizeThis(arg)
{ 
	if (document.getElementById(arg).style.display == 'none')
	{ 
		document.getElementById(arg).style.display = ''; 
	}
	else
	{ 
		document.getElementById(arg).style.display = 'none'; 
	} 
} 
*/
