function InvalidEmail(email)
{
    var indat = email.indexOf("@");
    var inddot = email.indexOf(".", indat);
    if (indat > 0 && inddot > 0 && inddot > indat && email.length-1 > inddot)
    {
      return false;
    }
    else
    {
      return true;
    }
}

function HideErrorMessages()
{
   	$('.errormsg').hide();
	$('#errors').hide();
}

function CheckNewsletterForm()
{
	HideErrorMessages();
	var flag = 0;
	if (!$('#pp').is(':checked'))
       {
            	$('#must-accept').show();
            	flag = 1;
       }

       if (!$('#newsletter0').is(':checked') && !$('#newsletter1').is(':checked'))
       {
            	$('#one-newsletter').show();
            	flag = 1;
       }

       if ($('#txtName').val().trim() == "")
       {
            	$('#must-enter-name').show();
            	flag = 1;
       }

       if ($('#txtEmail').val().trim() == "" || InvalidEmail($('#txtEmail').val()))
       {
            	$('#valid-email').show();
            	flag = 1;
       }
 	
	if (flag == 0)
          	$('#ChronoContact_Newsletters').submit();
	else
		$('#errors').show();
}

function signup(){    
	$('#signupLabel').hide();
        
   	var regex=new RegExp("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}");
    	var name = $('#txtName').val();
     	var email = $('#txtEmail').val();
    	var msg ="";
     	count = 0;
    	if (name.length ==0 || name == ""){
      		$('#txtName').css({"border":"1px solid red"});
            	msg +="Please enter your name!<br>";
            	count++;
     	}
      	if (!regex.test(email)){
       	$('#txtEmail').css({"border":"1px solid red"});
            	msg +="Please enter valid email address!<br>";
            	count++;
    	}
       if (count >0){
     		$('#signupLabel').html(msg);
       	$('#signupLabel').show();
         	return;
     	}
     	window.location = "index.php?option=com_chronocontact&chronoformname=Newsletters&txtName="+encodeURIComponent(name)+"&txtEmail="+encodeURIComponent(email);
}
    
function searchTP(){    
	$('#tpLabel').hide();
        
	var tp = $('#txtTP').val();
        
	if (tp.length ==0 || tp == ""){
      		$('#txtTP').css({"border":"1px solid red"});
          	$('#tpLabel').html("Please enter either<br/> the test or procedure!");
            	$('#tpLabel').show();
            	$('#txtTP').focus();
            	return false;
	}
     

	//$("#tpForm").attr("action", 'index.php?option=com_informationlibrary&view=search&value='+tp+'&Itemid=46') ;
	$("#tpForm").attr("action", '/healthy-life-information-library.html?view=procedures&search_letter='+tp+'') ;
    	$('#tpForm').submit();
        
}
    
function searchConditions(){    
	$('#condLabel').hide();
     	
	var cond = $('#txtConditions').val();
     	
	if (cond.length ==0 || cond == ""){
       	$('#txtConditions').css({"border":"1px solid red"});
            	$('#condLabel').text("Please enter condition!");
            	$('#condLabel').show();
            	$('#txtConditions').focus();
            	return;
    	}

//    $("#cForm").attr("action", '/index.php?option=com_informationlibrary&view=conditionsearch&value='+cond+'&Itemid=46')    
    $("#cForm").attr("action", '/healthy-life-information-library/medical-conditions.html?view=conditions&search_field_name='+cond+'')    
	$('#cForm').submit();
        
}


function CheckContactUS()
{
       

$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator1').hide();
$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator2').hide();
$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator3').hide();
    var flag = 0;


       if ($('#fName').val().trim() == "")
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator1').show();
                flag = 1;
       }
       if ($('#lName').val().trim() == "")
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator2').show();
                flag = 1;
       }

       if ($('#email').val().trim() == "" || InvalidEmail($('#email').val()))
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator3').show();
                flag = 1;
       }
    if (flag == 0)
           $('#ChronoContact_ContactCML').submit();
    else
           return false;


}


function CheckFollowup()
{
       

$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator1').hide(); //name
$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator2').hide(); //phone
$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator3').hide(); //msg
$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator4').hide(); //reason
$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator6').hide(); //email
    var flag = 0;


       if ($('#TB_name').val().trim() == "")
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator1').show();
                flag = 1;
       }
       if ($('#TB_phone').val().trim() == "")
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator2').show();
                flag = 1;
       }

       if ($('#email').val().trim() == "" || InvalidEmail($('#email').val()))
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator6').show();
                flag = 1;
       }
       
       if ($('#TB_message').val().trim() == "")
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator3').show();
                flag = 1;
       }       
       
       if (!$('#purpose_0').is(':checked') && !$('#purpose_1').is(':checked'))
       {
				$('#ctl00_ContentPlaceHolder1_RequiredFieldValidator4').show();
            	flag = 1;
       }

    if (flag == 0)
           $('#ChronoContact_requestfollowup').submit();
    else
           return false;


}


