// JavaScript Document
function trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}
function validateTextCheck_marker(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		document.getElementById(spanid).innerHTML ="<img src='images/checkmark.gif' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#99FF99";
		return false;
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FFFFFF";
		return false;
	}
}
function validateTextCheck_marker_small(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		document.getElementById(spanid).innerHTML ="<img src='images/checkmark_small.gif' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#99FF99";
		return false;
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FFFFFF";
		return false;
	}
}

function validateTextCountry_marker(value,spanid,tdid)
{
	if(trim(value)!=00)
	{
		document.getElementById(spanid).innerHTML ="<img src='images/checkmark.gif' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#99FF99";
		return false;
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FFFFFF";
		return false;
	}
}
function validateTextCountry_marker_small(value,spanid,tdid)
{
	if(trim(value)!=00)
	{
		document.getElementById(spanid).innerHTML ="<img src='images/checkmark_small.gif' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#99FF99";
		return false;
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FFFFFF";
		return false;
	}
}
 function validateTextCheck(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		document.getElementById(tdid).style.backgroundColor="#99FF99";
		return false;
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		
		document.getElementById(tdid).style.backgroundColor="#FFFFFF";
		return false;
	}
}

function validateTextCheck_marker11(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		document.getElementById(spanid).innerHTML ="<img src='images0707/tick.gif' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#99FF99";
		return false;
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FFFFFF";
		return false;
	}
}
function validate_email(email) 
{
	var rxp =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
	if(rxp.test(email)!=true) 
	{
		return false;
	} 
	else 
	{
		return true;
	}
}
function InputAplpha(str)
{
	if(str.match(/^[a-z\s]+$/i))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp
}
function validateText(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#E2F9E3";
		return false;
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
		return false;
	}
}
function validateTextYear(value,spanid,tdid)
{
	var d = new Date();
	var curr_year = d.getFullYear();
	var diffdate = curr_year-value;
	if(trim(value)!="" && diffdate>=18)
	{
		document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#E2F9E3";
		return false;
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
		return false;
	}
}
function validateGoalWeight(value,spanid,tdid)
{
	var currentweight=document.getElementById("curr_wt").value;
	if(trim(currentweight)=="")
	{
		if(trim(value)!="")
		{
			if(isNaN(value))
			{
				document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else
			{
				document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
				document.getElementById(tdid).style.backgroundColor="#E2F9E3";
				return false;
			}
		}
		else
		{
			document.getElementById(spanid).innerHTML ="";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
		}
	}
	if(trim(currentweight)!="")
	{
		if(trim(value)!="")
		{
			if(isNaN(value) || isNaN(currentweight))
			{
				document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else if(parseInt(currentweight)<=parseInt(value))
			{
				document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Goal weight should be less than current weight.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else
			{
				document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
				document.getElementById(tdid).style.backgroundColor="#E2F9E3";
				return false;
			}
		}
		else
		{
			document.getElementById(spanid).innerHTML ="";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
		}
	}
}
function validateCurrentWeight(value,spanid,tdid)
{
	var currentweight=document.getElementById("goal_wt").value;
	if(trim(currentweight)=="")
	{
		if(trim(value)!="")
		{
			if(isNaN(value))
			{
				document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else
			{
				document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
				document.getElementById(tdid).style.backgroundColor="#E2F9E3";
				return false;
			}
		}
		else
		{
			document.getElementById(spanid).innerHTML ="";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
		}
	}
	if(trim(currentweight)!="")
	{
		if(trim(value)!="")
		{
			if(isNaN(value) || isNaN(currentweight))
			{
				document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else if(currentweight>=value)
			{
				document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Goal weight should be less than current weight.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else
			{
				document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
				document.getElementById(tdid).style.backgroundColor="#E2F9E3";
				return false;
			}
		}
		else
		{
			document.getElementById(spanid).innerHTML ="";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
		}
	}
}
function validateTextNoNum(value,spanid,tdid)
{
	if(trim(value)!="" && InputAplpha(value))
	{
		//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#E2F9E3";
		return false;
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
		return false;
	}
}


function validateTextDD(value,spanid,tdid)
{
	if(trim(value)!="00" && trim(value)!="")
	{
		//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
		document.getElementById(tdid).style.backgroundColor="#E2F9E3";
		return false;
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
		return false;
	}
}
function validateNum(value,spanid)
{
	if(trim(value)!="")
	{
		if(isNaN(value))
		{
			//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
			return false;
		}
		else
		{
			//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
			return false;
		}
	}
}
function validateNumTD(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		if(isNaN(value))
		{
			//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else
		{
			//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
			document.getElementById(tdid).style.backgroundColor="#E2F9E3";
			return false;
		}
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
	}
}
function validatePhone(value,spanid,tdid)
{
	if(trim(value)!="")
	{
	var flag=0;
		var iChars = "1234567890- ";
		for (var i = 0; i < value.length; i++)
		{
			if (iChars.indexOf(value.charAt(i)) == -1)
			{
				var flag=1;
			}
		}
		if(parseInt(flag)==1)
		{
			alert("Please enter numeric value only.");
			//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else
		{
			//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
			document.getElementById(tdid).style.backgroundColor="#E2F9E3";
			return false;
		}
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
	}
}
function caZipValidatation(str)
{
	if(str.match(/^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}(\-| |){1}[0-9]{1}[a-zA-Z]{1}[0-9]{1}$/i))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function validateZip(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		var country=document.getElementById("country").value;
		if(country=="US")
		{
			if(value.length!=5)
			{
				alert("Postal code should be five characters.");
				//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Postal code should be five characters.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else
			{
				//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
				document.getElementById(tdid).style.backgroundColor="#E2F9E3";
				return false;
			}
		}
		else if(country=="CA")
		{
			if(!caZipValidatation(value))
			{
				alert("Please enter validate postal code.");
				//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter validate postal code.</span>";
				document.getElementById(tdid).style.backgroundColor="#FF9999";
				return false;
			}
			else
			{
				//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
				document.getElementById(tdid).style.backgroundColor="#E2F9E3";
				return false;
			}
		}
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
	}
}
function emailValidatorAjax()
{
	if(xmlHttp.readyState == 4)
	{
		var retStr = xmlHttp.responseText;
		retStrResult=retStr.split("++++");
		spanid=retStrResult[1];
		tdid=retStrResult[2];
		if(retStrResult[0]>0)
		{
			alert("Email address exists already.");
			//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Email address exists already.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
		return false;
		}
		else
		{
			//document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
			document.getElementById(tdid).style.backgroundColor="#E2F9E3";
			return false;
		}
	}
}
function emailValidator(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		if(!validate_email(value))
		{
			alert("Please enter correct email address.");
			//document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter correct email address.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else
		{
			xmlHttp = GetXmlHttpObject();
			var url = "getEmailfromDb.php";
			xmlHttp.open("POST", url, true);
			xmlHttp.onreadystatechange = emailValidatorAjax;
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			var cht = "value="+escape(value)+"&spanid="+escape(spanid)+"&tdid="+escape(tdid);
			xmlHttp.send(cht);
		}
	}
	else
	{
		//document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
	}
}
function validateCC(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		if(isNaN(value))
		{
			document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else if(value.length!=16)
		{
			document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Credit card number must be 16 digit.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else
		{
			document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
			document.getElementById(tdid).style.backgroundColor="#E2F9E3";
			return false;
		}
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
	}
}
function validateCVV(value,spanid,tdid)
{
	if(trim(value)!="")
	{
		if(isNaN(value))
		{
			document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>Please enter numeric value only.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else if(value.length!=3)
		{
			document.getElementById(spanid).innerHTML ="<span style='color:red; font-size:9px;'>CVV number must be 3 digit.</span>";
			document.getElementById(tdid).style.backgroundColor="#FF9999";
			return false;
		}
		else
		{
			document.getElementById(spanid).innerHTML ="<img src='images/tick.jpg' border='0' alt='Correct' />";
			document.getElementById(tdid).style.backgroundColor="#E2F9E3";
			return false;
		}
	}
	else
	{
		document.getElementById(spanid).innerHTML ="";
		document.getElementById(tdid).style.backgroundColor="#FF9999";
	}
}
