// JavaScript Document

var step=0
var curr=0; 
var next

function nextSlide(){

	if (step<15)
	step++
	else
	step=0

	next = step;
	
	document.getElementById( curr ).setAttribute( "class", "slidelabel");
	document.getElementById( curr ).setAttribute( "className", "slidelabel");
	
	document.getElementById( next ).setAttribute( "class", "slidelabel_highlighted");
	document.getElementById( next ).setAttribute( "className", "slidelabel_highlighted");

	curr = next;
	
    var img = document.createElement('img');
	
    img.onload = function (evt) {
        document.getElementById('slide').src=this.src;
        document.getElementById('slide').width=this.width;
        document.getElementById('slide').height=this.height;
	}
	
    if (step == 0 ) {
		img.src = "image/intro.jpg";
		document.getElementById('sound').innerHTML='<embed id="audio" name="audio" src="audio/intro.wmv" width="280px" height="280px" autostart=true loop=false>';
	} else {
		img.src = "image/slide"+step+".jpg";
		document.getElementById('sound').innerHTML='<embed id="audio" name="audio" src="audio/slide'+step+'.wmv" width="280px" height="40px" autostart=true loop=false><br/>Audio Only';
	}

    return false;
}

function display ( slide ){ 
	step = slide -1 ;
	return nextSlide();
}


var cookie_name = "BHLDOWNLOAD";

function checkCookie1()
{

	username=getCookie( cookie_name );
	if (username!=null && username!="")
	{
		window.location = 'article.html';

	}
	else 
	{
		return; 
	}
}

function checkCookie2()
{
	username=getCookie( cookie_name );
	if (username!=null && username!="")
	{
		return;
	}
	else 
	{
		window.location = 'download.html';
	}
}

function setCookie( value )
{
	var exdate=new Date();
	exdate.setDate( exdate.getDate()+ 1 );
	document.cookie=cookie_name+"=" +escape( value )+";"; //expires="+exdate.toGMTString();
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
  	{
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1)
    	{ 
    		c_start=c_start + c_name.length+1; 
    		c_end=document.cookie.indexOf(";",c_start);
    		if (c_end==-1) c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	} 
  	}
	return "";
}


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("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
	   alert("Invalid E-mail ID")
	    return false
	}
		
	if (str.indexOf(" ")!=-1){
	   alert("Invalid E-mail ID")
	   return false
	}

 	return true					
}

// validates that the entry is formatted as an email address

function isEMailAddr( str ) {
	//var str = elem.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (!str.match(re)) {
        	return false;
    	} else {
        	return true;
    	}
}

//validates that the entry is formatted as alphanumeric and underscores

function isAlphNum( str ) {
	var reg = /^[A-Za-z0-9_]+$/;
	if (!str.match(reg)) {
		return false;
	} else {
		return true;
	}
}


function ValidatePriceForm(){

	var nameID=document.price.name;
	if ( checkEmpty(nameID, 'Please enter your name')==false )
		return false;

	var titleID=document.price.title;
	if ( checkEmpty(titleID, 'Please enter your title')==false )
		return false;

	var emailID=document.price.email;
	
    	if (checkEmpty(emailID, "Please enter your email")==false)
		return false;
	
	if (isEMailAddr(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

	var phoneID=document.price.phone;
	if ( checkEmpty(phoneID, 'Please enter your phone')==false )
		return false;

	var orgID=document.price.organization;
	if ( checkEmpty(orgID, 'Please enter your organization')==false )
		return false;

	var programID=document.price.program;
	if ( checkEmpty(programID, 'Please enter your types of programs offered')==false )
		return false;

	return true
}

function ValidateAddForm(){
	var nameID=document.payer.name;
    	if (checkEmpty(nameID, "Please enter your health plan name")==false)
		return false;
	
	
	var memberID=document.payer.member;
   	if (checkEmpty(memberID, "Please enter sample member number")==false)
		return false;
		
	var serviceID=document.payer.service;
   	if (checkEmpty(serviceID, "Please enter primary member service number")==false)
		return false;
	
	var abuseID=document.payer.abuse;
	if ( checkEmpty(abuseID, "Please enter behavioral health and substance abuse service number ")== false )
		return false;

	return true
}

function ValidateForm(){
	var emailID=document.user.email;
	
    	if (checkEmpty(emailID, "Please enter your email")==false)
		return false;
	
	if (isEMailAddr(emailID.value)==false){
		alert("Please enter valid email address.");
		emailID.value=""
		emailID.focus()
		return false
	}
	
	var firstID=document.user.first;
	if ( checkEmpty(firstID, "Please enter your first name")== false )
		return false;
	if ( isAlphNum(firstID.value)== false ) {
		alert("please enter correct first name.")
		firstID.value=""
		firstID.focus()
		return false
	}
		
	var lastID=document.user.last;
	if ( checkEmpty(lastID, "Please enter your last name")== false )
		return false;
	if ( isAlphNum(lastID.value)== false ) {
		alert("please enter correct last name.")
		lastID.value=""
		lastID.focus()
		return false
	}
	
	var orgID=document.user.org;
	if ( checkEmpty(orgID, "Please enter your organization")== false )
		return false;

	setCookie( firstID );
	var openID=document.user.open;
	if (openID.value == 'yes') {
	   window.open('downloads/FREE Payer Services.pdf','','menubar=yes,toolbar=yes,location=no,status=yes,resizable=yes,scrollbars=yes');
	}
	return true
}



function checkEmpty( name, msg ){
	
	if ((name.value==null)||(name.value=="")){
		alert( msg );
		name.focus();
		return false;
	}
	return true;
}

function openWindow(url) {
  popupWin = window.open(url, 'remote',  'resizable,width=700,height=450,left=50,top=50');
}

function openWindow1(url) {
  username=getCookie( cookie_name );
  	if (username!=null && username!="")
  	{
		popupWin = window.open(url,'','menubar=yes,toolbar=yes,location=no,status=yes,resizable=yes,scrollbars=yes');
  
  	}
  	else 
  	{
  		return; 
	}
}