/*================================================================================================================================
Company: Quadrant
Application: AJO web site
Author: 
Description: javascript utility, rollover buttons
Dates: 
==================================================================================================================================*/

function Rollover(Img, on) {
  var root = 'http://www.fedprac.com/images/rollover/';
  if (document.images) {
    if (on)
		document.images[Img].src = root + Img + "_on.gif";
    else {
		document.images[Img].src = root + Img + ".gif";
	}
  }
}


function ShowImage(img) {
	window.open('/include/ShowImg.asp?img='+img,'Img','width=1,height=1,scrollbars=1,top=30,left=30');
}


function ViewFullText(ArticleID) {
	var t = (screen.height - 580) / 2 - 20;
	var l = (screen.width - 770) / 2;
	window.open('http://cms.qhc.com/viewpdf.asp?PubCode=FP&ArticleID='+ArticleID,'PDFArticle','width=770,height=580,scrollbars=yes,resizable=yes, top='+t+',left='+l);
	//window.open('/asp/archive/viewpdf.asp?ArticleID='+ArticleID,'PDFArticle','width=770,height=580,scrollbars=yes,resizable=yes, top='+t+',left='+l);
}


function bookmark_site() {

  var sPlatform = navigator.platform;
  bMac = (sPlatform == "MacPPC")
  if (bMac)
    {
       alert('Mac Users: Please press CTRL+D to bookmark this site.' + '\n' + 'or select Navigator -> Bookmarks ->Add Bookmark.');
       return;
    }

    if (navigator.userAgent.indexOf("MSIE") != -1)
    {
       window.external.AddFavorite('http://fedprac.qhc.com','FedPrac');
    }
    else
    {
       alert('Netscape Users: Please press CTRL+D to bookmark this site.' + '\n' + 'or select Navigator -> Bookmarks ->Add Bookmark.');
       return;
    }
}


function offramp()  {
	var Msg = "You have selected a link that will take you outside of the Fed Prac Web site. \nFed Prac is not responsible for any content beyond this point."
	alert(Msg);
}




function ValidateReg(frm){

	if (frm.Email.value == "") {
		alert("Please enter your e-mail address.");
		frm.Email.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.Email.value))  {
		frm.Email.select();
		frm.Email.focus();
		return false;
	}

	if (frm.PWD.value == "") {
		alert("Please enter Password.");
		frm.PWD.focus();
		return false;
	}

	if (frm.PWD.value.length < 4) {
		alert("Password must be between 4 and 10 characters.");
		frm.PWD.focus();
		return false;
	}

	if (frm.PWD.value != frm.vPWD.value) {
	  alert("Please enter your password in the \"Verify Password\" field.");
	  frm.vPWD.select();
	  frm.vPWD.focus();
	  return false;
	}

	if (frm.FName.value == "") {
		alert("Please enter your first name.");
		frm.FName.focus();
		return false;
	}

	if (frm.LName.value == "") {
		alert("Please enter your last name.");
		frm.LName.focus();
		return false;
	}

	if (frm.SpeID.selectedIndex < 1) {
		alert("Please select your specialty.");
		frm.SpeID.focus();
		return false;
	}

	if (frm.ProfID.selectedIndex < 1) {
		alert("Please select your Profession.");
		frm.ProfID.focus();
		return false;
	}
	

	if (frm.FacilityName.value == "") {
		alert("Please enter your facility name.");
		frm.FacilityName.focus();
		return false;
	}

// for the free subscription requesters...
	if (frm.bSubs.value=='1') {	
		if (frm.BirthDate.value == "") {
			alert("Please enter your birth date.");
			frm.BirthDate.focus();
			return false;
		}
	
		if (frm.PersonalID.value == '') {
			alert("Please enter your city where you were born in.");
			frm.PersonalID.focus();
			return false;
		}
	}



	if ((frm.pg.value != '')) {
		if (frm.FacilityName.value == "") {
			alert("Please enter the name of facility.");
			frm.FacilityName.focus();
			return false;
		}
	
		if (frm.Address1.value == "") {
			alert("Please enter your address.");
			frm.Address1.focus();
			return false;
		}
	
		if (frm.City.value == "") {
			alert("Please enter your city.");
			frm.City.focus();
			return false;
		}
	
		if (frm.State.selectedIndex < 1) {
			alert("Please select your state.");
			frm.State.focus();
			return false;
		}
	
	
		if (frm.Country[frm.Country.selectedIndex].value == 'US') {
			if (frm.Zip.value == "") {
				alert("Please enter your zip/postal code.");
				frm.Zip.focus();
				return false;
			}
		}
		
		if (frm.Phone1.value == "") {
			alert("Please enter your office phone number.");
			frm.Phone1.focus();
			return false;
		}
		
	}
	
	frm.SpeStr.value = frm.SpeID[frm.SpeID.selectedIndex].text;
	frm.ProfStr.value = frm.ProfID[frm.ProfID.selectedIndex].text;
	
	return true;
}


// 10/14/2003 - added my account validation...
function ValidateAcct(frm){

	if (frm.Email.value == "") {
		alert("Please enter your e-mail address.");
		frm.Email.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.Email.value))  {
		frm.Email.select();
		frm.Email.focus();
		return false;
	}

	if (frm.PWD.value == "") {
		alert("Please enter Password.");
		frm.PWD.focus();
		return false;
	}

	if ((frm.PWD.value.length < 4) || (frm.PWD.value.length > 10)) {
		alert("Password must be between 4 and 10 characters.");
		frm.PWD.focus();
		return false;
	}

	if (frm.PWD.value != frm.VPWD.value ) {
		alert("Password is not verified.");
		frm.VPWD.focus();
		frm.VPWD.select();
		return false;
	}

	if (frm.FName.value == "") {
		alert("Please enter your first name.");
		frm.FName.focus();
		return false;
	}

	if (frm.LName.value == "") {
		alert("Please enter your last name.");
		frm.LName.focus();
		return false;
	}

	if (frm.SpeID.selectedIndex < 1) {
		alert("Please select your specialty.");
		frm.SpeID.focus();
		return false;
	}

	if (frm.ProfID.selectedIndex < 1) {
		alert("Please select your Profession.");
		frm.ProfID.focus();
		return false;
	}
	

	if (frm.FacilityName.value == "") {
		alert("Please enter your facility name.");
		frm.FacilityName.focus();
		return false;
	}

// for subscribers registration...
	if ((frm.bSubs.value=='True') || (frm.req.value=='1')) {	
	/*
		if (frm.Address1.value == "") {
			alert("Please enter your address.");
			frm.Address1.focus();
			return false;
		}
	
		if (frm.City.value == "") {
			alert("Please enter your city.");
			frm.City.focus();
			return false;
		}
	
		if (frm.State.selectedIndex < 1) {
			alert("Please select state/province.");
			frm.State.focus();
			return false;
		}
	
		if (frm.Zip.value == "") {
			alert("Please enter your zip/postal code.");
			frm.Zip.focus();
			return false;
		}
	
		if (frm.Phone1.value == "") {
			alert("Please enter your office phone number.");
			frm.Phone1.focus();
			return false;
		}
	*/
	}
	
	return true;
}





function ValidateSubsType(frm){
	if (!frm.Subscriber[0].checked && !frm.Subscriber[1].checked) {
		alert("Please select either Yes or No.");
		frm.Subscriber[0].focus();
		return false;
	}
	return true;
}


function ValidateSubsNum(frm){
	if (frm.SubsNum.value == "") {
		alert("Please enter Federal Practitioner subscriber number.");
		frm.SubsNum.focus();
		return false;
	}
	var MENumLen = 11;
	
//	if (frm.Profession[1].checked)
//		MENumLen = 8;
	
	if (frm.SubsNum.value.length < MENumLen) {
		alert("Federal Practitioner subscriber number must be " + MENumLen + " numeric digits.");
		frm.SubsNum.select();
		frm.SubsNum.focus();
		return false;
	}
	return true;
}


function ValidateLogin(frm){

	if (frm.Email.value == "") {
		alert("Please enter your email address");
		frm.Email.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.Email.value))  {
		frm.Email.select();
		frm.Email.focus();
		return false;
	}

	if (frm.PWD.value == "") {
		alert("Please enter Password");
		frm.PWD.focus();
		return false;
	}
	
	return true;
}

function ValidateForgotpwd(frm){

	if (frm.Email.value == "") {
		alert("Please enter your email address");
		frm.Email.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.Email.value))  {
		frm.Email.select();
		frm.Email.focus();
		return false;
	}

	return true;
}



function ValidateShare(frm){

	if (frm.FromEmail.value == "") {
		alert("Please enter your email address");
		frm.FromEmail.focus();
		return false;
	}
		                
	if (!CheckEmail(frm.FromEmail.value))  {
		frm.FromEmail.select();
		frm.FromEmail.focus();
		return false;
	}

	if (frm.ToEmail.value == "") {
		alert("Please enter your colleague's email address");
		frm.ToEmail.focus();
		return false;
	}
	
	if (!CheckEmail(frm.ToEmail.value))  {
		frm.ToEmail.select();
		frm.ToEmail.focus();
		return false;
	}
		                
	return true;
}



function ValidateFeed(frm){
	if (frm.Specialty.selectedIndex < 1) {
		alert("Please select your specialty");
		frm.Specialty.focus();
		return false;
	}

	if (frm.AgeGroup.selectedIndex < 1) {
		alert("Please select your age group");
		frm.AgeGroup.focus();
		return false;
	}

	if (frm.OnlineTime.selectedIndex < 1) {
		alert("Please select an option on how much time you spend online");
		frm.OnlineTime.focus();
		return false;
	}

	if (frm.SiteRate.selectedIndex < 1) {
		alert("Please select an option on how you rate this site");
		frm.SiteRate.focus();
		return false;
	}

	return true;
}

function ValidateSearch(frm){
	if ((frm.title.value == "") && (frm.author.value == "") && (frm.issueyear.value == "") &&  (frm.issueno.value == "") && (frm.pagination.value == "") && (frm.deptID.selectedIndex < 1) && (frm.collect.selectedIndex < 1)) {
		alert("Please enter or select one of the search criteria.");
		frm.title.focus();
		return false;
	}

	return true;
}




function CheckEmail(email) {

		var first = email.indexOf("@")
		var last = email.indexOf(".")
		var email_num = email.length;
		
		if (first != -1) {                // check @ duplicate
			mail_str = email;
			mail_str = mail_str.substr(first+1);
			second = mail_str.indexOf("@");
			if (second != -1)	{	
				alert("Unrecognized e-mail address format. Please check your e-mail and enter a valid e-mail address.");
				
				return false;
			}
		}

		for (var l = 0; l <= (email_num - 1); l++) {
			if (email.indexOf(" ") >= 0 ) {
				alert ("\"Space\" is not valid in e-mail address.");
		        
		        return false;
		    } 
		}

		if ((email.indexOf("/")) != -1)	{	
			alert ("\" / \" is not valid in e-mail address.");
			
			return false;
		}

		if ((email.indexOf(";")) != -1)	{	
			alert ("\" ; \" is not valid in e-mail address.");
			
			return false;
		}

		if ((email.indexOf(",")) != -1)	{	
			alert ("\" , \" is not valid in e-mail address.");
			
			return false;
		}

		if (email.search(/(\S+)@(\S+)\.(\S+)/) == -1) {
				alert("Unrecognized e-mail address format. Please check your e-mail and enter a valid e-mail address.");
			
			return false;
		}
	
		if (email.substring(0, 5) == "http:") {
			alert ("\" http: \" is not valid in e-mail address.");
			
			return false;
		} 

		if (email.lastIndexOf(".") == email_num-1) {
			alert ("\" . \" is not valid at the end of e-mail address.");
			
			return false;
		} 
	
	return true;
} // checkEMail ()


//8-4-2003 MK
function MM_jumpMenu(targ,selObj,restore){
	if (selObj.selectedIndex > 1) {
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) 
		selObj.selectedIndex=0;
	}
}


function GetDOB (frm) {
	var DOBMonth = frm.DOBMonth.options[frm.DOBMonth.selectedIndex].value;
	var DOBDate = frm.DOBDate.options[frm.DOBDate.selectedIndex].value;
	var DOBYear = frm.DOBYear.options[frm.DOBYear.selectedIndex].value;

	frm.DOB.value = DOBMonth + "/" + DOBDate + "/" + DOBYear;
}


//date validation
//8-18-2003
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true;
}

//9/24/2003 JP - validate subscription form...
function ValidateSubs1(frm){
	var checked = false;
	
	if (frm.pg.value == 'new') {
		for (var i=0;i<frm.SubsCountry.length;i++) {
			if (frm.SubsCountry[i].checked) {
				checked = true;
			}
		}
	
		if (!checked) {
			alert("Please select your country.");
			return false;
		}
	
		checked = false;
		for (var i=0;i<frm.Profession.length;i++) {
			if (frm.Profession[i].checked) {
				checked = true;
			}
		}
	
		if (!checked) {
			alert("Please select your profession.");
			return false;
		}
	}
	else if (frm.pg.value == 'main') {
		for (var i=0;i<frm.SubsCat.length;i++) {
			if (frm.SubsCat[i].checked) {
				checked = true;
			}
		}
	
		if (!checked) {
			alert("Please select a subscription category.");
			return false;
		}
	}
	else if (frm.pg.value == 'single') {
		if (frm.IssYear.value == '') {
			alert("Please enter Issue Year.");
			frm.IssYear.focus();
			return false;
		}
		if (frm.IssVol.value == '') {
			alert("Please enter Issue Volume.");
			frm.IssVol.focus();
			return false;
		}
		if (frm.IssNo.value == '') {
			alert("Please enter Issue Number.");
			frm.IssNo.focus();
			return false;
		}
		if (frm.Pagination.value == '') {
			alert("Please enter the starting page number.");
			frm.Pagination.focus();
			return false;
		}
	}
	else if (frm.pg.value == 'singleissue') {
		for (var i=0;i<frm.SubsType.length;i++) {
			if (frm.SubsType[i].checked) {
				checked = true;
			}
		}
	
		if (!checked) {
			alert("Please select a subscription category.");
			return false;
		}
		
		if (frm.IssueNo.value == '') {
			alert("Please enter issue number.");
			frm.IssueNo.focus();
			return false;
		}
		
	}
	else if (frm.pg.value == 'print'){
		if (frm.SubsType.length > 1) {
			for (var i=0;i<frm.SubsType.length;i++) {
				if (frm.SubsType[i].checked) {
					checked = true;
				}
			}
	
			if (!checked) {
				alert("Please select a subscription type.");
				return false;
			}
			
			
		}

		if (frm.Profession.value == 'ST') {
			if (frm.MedicalSchool.value == '') {
				alert("Please enter your medical school or institution.");
				frm.MedicalSchool.focus();
				return false;
			}
		}
	
	}
	else if (frm.pg.value == 'online') {
	
		if (frm.SubsType.length > 1) {
			for (var i=0;i<frm.SubsType.length;i++) {
				if (frm.SubsType[i].checked) {
					checked = true;
				}
			}
	
			if (!checked) {
				alert("Please select a subscription type.");
				return false;
			}
			
			
		}
	
		if (frm.SubsType[2].checked) {
			if (frm.MedicalSchool.value == '') {
				alert("Please enter your medical school or institution.");
				frm.MedicalSchool.focus();
				return false;
			}
		}
	}

	else if (frm.pg.value == 'dir') {
		if (frm.SubsType.length > 1) {
			for (var i=0;i<frm.SubsType.length;i++) {
				if (frm.SubsType[i].checked) {
					checked = true;
				}
			}
	
			if (!checked) {
				alert("Please select a subscription type.");
				return false;
			}
		}
	
/*		if (frm.DirYear.value == '') {
			alert("Please enter the year for the directory.");
			frm.DirYear.focus();
			return false;
		}
*/
	}

	else if (frm.pg.value == 'access') {
		if (frm.SubsType.length > 1) {
			for (var i=0;i<frm.SubsType.length;i++) {
				if (frm.SubsType[i].checked) {
					checked = true;
				}
			}
	
			if (!checked) {
				alert("Please select a subscription type.");
				return false;
			}
		}
	}




	return true;
}


