var domainnode 	= 'www.healthy.net';
var domain 		= 'http://www.healthy.net';
var workingDir 	= '/scr/';

//this will open page in a new window if frames from another site are used. 
if (top.frames.length==2) {
	var opts = 'menubar=1,directories=1,location=1,status=1,scrollbars=1,toolbar=1,resizable=1,width=804,height=600';
	var thiswin = window.open(window.location, 'newwin', opts );
	thiswin.focus();
}

function openwin(newwin,winname,HeightofWindow, WidthofWindow)
 {
	if (WidthofWindow=="") {
		WidthofWindow	= 400;
		HeightofWindow	= 600;
		Scrl='yes';
	}
	else	
		Scrl='no';
	var msg = window.open(newwin,winname,"height=" + HeightofWindow + ",width=" + WidthofWindow + ",scrollbars=" + Scrl);
	msg.focus();
}

function ValidateEmail(em) {
		if (em == "") 
			return "\n     -  Email Address" ;
		else {
			if (em.length < 6 || em.indexOf('@')==-1 || em.indexOf('@')==0 || em.indexOf('.')==-1) 
				return "\n     -  Invalid Email Address";
			else
				return '';
		}	
}		

function CheckEmail(path) {
	var msg='';
	var em = path.Email.value;
	
	if (em=='') 
		msg = 'Please enter your email address';
	else
		msg = ValidateEmail(em);
	
	if (msg=='')
		return true;
	else {
		alert(msg);
		return false;
	}		
}			

function changeMap(imageID, source)
	{
		url = domain + "/images/leftmenu/" + source + ".gif";
		imageID.src = url;
	}

function jumpUrl(route,url) {
	if (route==1)
		location.href=url;
	else	
		location.href='/clinic/dandc/' + url;
}

function checkSignUpFields( path )
{
	var msg = "";
	if ( path.newsletter.checked == false && path.shopping.checked == false)
	{
		alert('Please select at least one newsletter');
		return false;
	}
	msg += ValidateEmail(path.Email.value);
		
	if ( trim(path.FirstName.value) == "" )
		msg += "\n  First Name is required ";		

	if ( path.gender[0].checked ==false && path.gender[1].checked == false)
		msg += "\n  Gender is required ";		
	
	if ( path.pract[0].checked ==false && path.pract[1].checked == false)
		msg += "\n  Consumer or Practitioner required ";		

	if ( path.Age.value == "" )
		msg += "\n  Age is required ";		
	
	if (msg != "") 
	{
		msg = msg + "\n" + "\nPlease re-enter data!";
		alert(msg);
		return false;
	}
		else return true;
}

function checkSignUp (form)	{
	var msg = "";

	msg += ValidateEmail(form.EmailAddress.value);
	if ( trim(form.FirstName.value)=='')
		msg += "\n  - FirstName ";		
	if ( form.gender[0].checked ==false && form.gender[1].checked == false)
		msg += "\n  - Gender ";		
	if ( form.pract[0].checked ==false && form.pract[1].checked == false)
		msg += "\n  - Consumer or Practitioner ";		
	if ( form.Age.value == "" )
		msg += "\n  - Age ";		
	if (msg != "") 
	{
		msg = "\nThe following fields are required\n" + msg + "\nPlease re-enter data!";
		alert(msg);
		return false;
	}
		else return true;
}

// used in contact us 
function checkContactUs(path)	{
	var msg = "";
	msg += ValidateEmail(path.email.value);
		
	if ( path.subject.value=='')
		msg += "\n  - Subject is required ";		
	
	if ( path.message.value == "" )
		msg += "\n  - Message text is required ";		
	
	if ( path.subject.value=='Medical')
		msg = "\n  Please see notice below about Medical Questions";		

	if (msg != "") 
	{
		if (path.subject.value!='Medical') 
			msg = "\nThe following fields need to be corrected before sending \n" + msg + "\n\nPlease re-enter!";
	
		alert(msg);
		return false;
	}
		else	
		{	
			path.reAction.value='go';
			return true;
		}	
}

function stripscript(theField)	{

	var astr = theField.value;
	astr = astr.replace(/script/gi, '');
	astr = astr.replace(/.js/gi, '');
	astr = astr.replace(/http/gi, '');
	astr = astr.replace(/</g, '');
	astr = astr.replace(/>/g, '');
	theField.value = astr;
}

function checkQuiz(form)  {
	var valid = false;
	for (var i = 1; i <= form.Qcnt.value; i++) {
		for (var j = 0; j <= eval('QuizScore.Acnt'+i+'.value')-1; j++) {
//			alert(i+' : '+j);
			if (eval('QuizScore.Poll'+i+'['+j+'].checked')==true)
				valid=true;				
		}
		if (valid==false) {
			alert ('Please fill in one answer for each question');
			return false;
		}
		else
			valid = false;				
	}
	return true;
}

function checkContactUs2(path)	{
	var msg = "";
	msg += ValidateEmail(path.email.value);
		
	if ( path.name.value=='')
		msg += "\n    -  Name ";		
	
	if ( path.phone.value=='')
		msg += "\n    -  Phone ";		

	if ( path.message.value == "" )
		msg += "\n    -  Message text ";		
	
	if (msg != "") 
	{
		msg = "\nThe following fields need to be corrected before sending \n" + msg + "\n\nPlease re-enter!";
		alert(msg);
		return false;
	}
	else	
	{	
//		path.reAction.value='go';
		return true;
	}	
}

//used in newsletter send
function ld(val) {
	popunder=domain + '/asp/setnl.asp?em=' + val;
	win2=window.open(popunder,"hwqq",'scrollbars=no,resizable=no,toolbar=no,menubar=no,location=no,status=no,left=0,top=20000,height=10,width=10');
}
//uncertain of use
function thisemail(val) {
	popunder=domain + '/asp/setnl.asp?em=' + val;
	win2=window.open(popunder,"hw",'scrollbars=no,resizable=no,toolbar=no,menubar=no,location=yes,status=no,left=20000,top=0,height=10,width=10');
	win2.blur();
	window.focus();
}

function TestNLx() {
//	SaveCookie('healthy.nl','<%=Email%>'
	alert(getCookie ('healthy.nl'));
	showWin('newspop','','');
}

function OpenLinkUpdate(LinkType, Id, Prod )
{
	LinkURL = workingDir + 'WebFormLinks.asp?LinkType=' + LinkType + '&Id=' + Id + '&Prod=' + Prod;	
	window.open (LinkURL, LinkType, 'scrollbars=1,titlebar=1,status=1,resizable=1,ll;l, height=410, width=804');
}
function NewsletterCheckNow() {
	var email  		= getCookie('healthy.nl');
	var cookiedate  = getCookie('when');
	var today  		= new Date();
	var openup		= true; 
	var firsttime 	= 0;
	var when;

//	alert('  email=' + email + '\n cookiedate=' + cookiedate);		

	if (email==null || email=='')	{
		if (cookiedate==null) 	{
			firsttime = 1;
			when   		= new Date();			
			when.setMonth(when.getMonth()+1);
//alert('welcome');			
			SavePopCookie('when', when,365 * 10);	
//			alert('new when set:'+getCookie('when'));	
		}	
		else		{
			when   		= new Date(cookiedate);	
			if (when >= today) 
				openup = false;
			else	{
				when.setMonth(when.getMonth()+1);
				SavePopCookie('when', when,365 * 10);		
			}
		}

		if (openup==true) {	
			var URL = domain + '/asp/newsletter/nlSignUp.asp?ft='+firsttime;	
			openwin(URL,'newsup',500, 480);
		}	
	}	
}

function ltrim ( s )
{
	return s.replace( /^\s*/, "" );
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}


//NewsletterCheckNow();
