var ENABLE_COOKIE = "Please enable cookies for logging\nin to this site and refresh this page.";
var USERNAME_INVALID = "Username is invalid.";
var PASSWORD_INVALID = "Password is invalid.";
var PROFESSION_INVALID = "Profession is invalid.";
var EMAIL_REQUIRED = "E-mail address is required.";
var EMAIL_INVALID = "E-mail address is invalid.";
var FIRSTNAME_INVALID_CHAR = "First name -- Invalid character entry.*";
var FIRSTNAME_MIN_TWO_CHARS = "First name -- Must be at least 2 characters long.";
var LASTNAME_INVALID_CHAR = "Last name -- Invalid character entry.*";
var LASTNAME_MIN_TWO_CHARS = "Last name -- Must be at least 2 characters long.";
var PROFESSION_MANDATORY = "Profession not selected -- This is a mandatory field.";
var EMAIL_MANDATORY = "E-mail address -- Required.";
var COUNTRY_MANDATORY = "Country not selected -- This is a mandatory field.";
var USERNAME_INVALID_CHAR = "Username -- Invalid character entry.*";
var USERNAME_INVALID_LENGTH = "Username -- Your username must be between 6 and 20 characters long.";
var LICENSE_INVALID_CHAR = "License number -- Invalid character entry.*";
var LICENSE_INVALID_LENGTH = "License number -- Your license number must be at least 3 characters long.";
var PASSWORD_INVALID_CHAR = "Password -- Invalid character entry.*";
var PASSWORD_INVALID_LENGTH = "Password -- Your password must be between 6 and 20 characters long.";
var PASSWORD_CONFIRM_INVALID_CHAR = "Password Confirmation -- Invalid character entry.*";
var PASSWORD_CONFIRM_INVALID_LENGTH = "Password Confirmation -- Your password confirmation MUST match your password.";

var ADDRESS_ONE_MANDATORY = "Address 1 -- This is a mandatory field.";
var ADDRESS_ONE_INVALID_CHAR = "Address 1 -- Invalid character entry.*";
var ADDRESS_ONE_MIN_TWO_CHARS = "Address 1 -- Must be at least 2 characters long.";

var CITY_MANDATORY= "City -- This is a mandatory field.";
var CITY_INVALID_CHAR = "City -- Invalid character entry.*";
var CITY_MIN_TWO_CHARS = "City -- Must be at least 2 characters long.";

var POSTAL_MANDATORY = "Postal Code -- This is a mandatory field.";
var POSTAL_SIXCHARS = "Postal Code -- Must be 6 characters long.";
var POSTAL_INVALID_CHAR = "Postal Code -- Invalid character entry.*";

var FORM_EXTRA_ERROR = "An error has been found with the introductory offer portion of the form:";

var FORM_ERROR = "An error has been found with the form:";
var FORM_RESUBMIT = "Please re-enter and submit again!";
var FORM_ENTRIES1 = "*) Entries must be alphanumeric and MAY include hyphens.";
var FORM_ENTRIES2 = "Do not use any punctuation or non-alphanumeric character.";
var REGISTER_AFTER_ACCEPTING = "You can only register after accepting the privacy statement.";
var PAGE_EXPIRED = "This page has expired!";
var REMOVE_YOURSELF = "Are you sure you want to remove yourself?";
var BROWSER_NOT_SUPPORT_PRINT = "Your browser doesn\'t support this print method.";
var BROWSER_NOT_SUPPORT_METHOD1 = "Your browser doesn\'t  support this method.\n\nIf you are using Netscape you can add this";
var BROWSER_NOT_SUPPORT_METHOD2 = "to your favourites by pressing \"Ctrl + D\", on a Mac press \"Command + D\".";
var SEARCH_CRITERIA_ENTER = "Please enter some search criteria.";
var SEARCH_CRITERIA_MODIFY = "There is too much data to bring back everything, please modify your search criteria!";
var SEARCH_CRITERIA_SEARCH_ENTIRE_SITE = "You haven\'t selected anything to search. Do you want to search the entire site?";
var DUMM1_MANDATORY = "";

/*
*-----------------------------------------------------------------------------------------------
*	Change on include of javascript blocks. 
*	all javascripts are consolidated into one new javascript called "functions.js"
*	this script replaces: quicklogin.js, registration.js, homepage.js, cookie.js
*	
*	Bas van de Sande, 27-03-2003
*	see Functional Design "Javascript with constants" for further information.
*-----------------------------------------------------------------------------------------------
*	 
*	For backwards compatibility several "not used" functions reactivated. These functions
*	will be marked as being not used. Future analyes need to point out if the functions may
*	be deeactivated permanently
* 
*	Bas van de Sande, 27-03-2003
*-----------------------------------------------------------------------------------------------
*	Change on password validation
*	Validation on password with minimal 6 characters changed to 1 character.
*
*	By Harold van Herksen
*	Date: 01-04-03
*-----------------------------------------------------------------------------------------------
*/

// -----------------------------------------------------
// COOKIE.JS
// -----------------------------------------------------

function Get_Cookie(name) {
     var start = document.cookie.indexOf(name+"=");
     var len = start+name.length+1;
     if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
     if (start == -1) return null;
     var end = document.cookie.indexOf(";",len);
     if (end == -1) end = document.cookie.length;
     return unescape(document.cookie.substring(len,end));
 }


 function Set_Cookie(name,value,expires,path,domain,secure) {
     document.cookie = name + "=" +escape(value) +
	 ( (expires) ? ";expires=" + expires.toGMTString() : "") +
	 ( (path) ? ";path=" + path : "") +
	 ( (domain) ? ";domain=" + domain : "") +
	 ( (secure) ? ";secure" : "");
 }


 function Delete_Cookie(name,path,domain) {
     if (Get_Cookie(name)) document.cookie = name + "=" +
	( (path) ? ";path=" + path : "") +
	( (domain) ? ";domain=" + domain : "") +
	";expires=Thu, 01-Jan-70 00:00:01 GMT";
 }



 var today = new Date();
 var zero_date = new Date(0,0,0);
 today.setTime(today.getTime() - zero_date.getTime());

 var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
 var expires_date = new Date(todays_date.getTime() + (8 * 7 * 86400000));



 function storeMasterCookie() {
     if (!Get_Cookie('MasterCookie'))
	 Set_Cookie('MasterCookie','MasterCookie');
 }


 function storeIntelligentCookie(name,value) {
     if (Get_Cookie('MasterCookie')) {
	 var IntelligentCookie = Get_Cookie(name);
	 if ((!IntelligentCookie) || (IntelligentCookie != value)) {
	     Set_Cookie(name,value,expires_date);
	     var IntelligentCookie = Get_Cookie(name);
	     if ((!IntelligentCookie) || (IntelligentCookie != value))
		 Delete_Cookie('MasterCookie');
	 }
     }
 }


var src_loaded = true;


<!-- Scripts to determine which javascript version is supported -->
jsver = "1.0"; // set javascript version to 1.0
jsver = "1.1"; // set javascript version to 1.1
jsver = "1.2"; // set javascript version to 1.2
jsver = "1.3"; // set javascript version to 1.3


var cookies_ses_on = false;
if (src_loaded) storeMasterCookie();
if (Get_Cookie('MasterCookie')) {
  var cookies_ses_on = true;
}


var cookies_pc_on = false;
if (src_loaded) storeIntelligentCookie('IntelligentCookie','IntelligentCookie');
if (Get_Cookie('IntelligentCookie')) {
  var cookies_pc_on = true;
}


//if (cookies_pc_on == false || cookies_ses_on == false) {
//	alert(ENABLE_COOKIE);
//}


// -----------------------------------------------------
// HOMEPAGE.JS
// -----------------------------------------------------

function showCookies() {
	alert(document.cookie);
}

/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function setCookie(url)
{
		cookie_name = "MSCSFirstRequestedURL"
		//document.cookie = cookie_name + "=";
		//document.cookie = 
		document.cookie = cookie_name + "= http://www.psychiatrymatters.md" + url;
	return false;
}



function popWin() {
	window.open("/authfiles/cs_reminder.asp","Remind","width=500,height=300");
}


/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function makehomepage() {
	if (document.all) {
		window.external.setHomePage('http://www.psychiatrymatters.md');
	} else {
		strAlert = BROWSER_NOT_SUPPORT_PRINT;
		alert(strAlert);
	}
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  var thewin = window.open(theURL,winName,features);
 	 thewin.focus;
}


/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function addtofavs() {
	if (document.all) {
		window.external.AddFavorite('http://www.psychiatrymatters.md','PsychiatryMatters.md');
	} else {
		strAlert = BROWSER_NOT_SUPPORT_METHOD1;
		strAlert = strAlert + BROWSER_NOT_SUPPORT_METHOD2;
		alert(strAlert);
	}
}



function printpage() {
	if (window.print) {
		window.print();
    } else {
        alert(BROWSER_NOT_SUPPORT_PRINT);
    }           
}


/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function check_searchcriteria(val) {

		// check it is not zero length
		if (val.length == "0") {
			alert(SEARCH_CRITERIA_ENTER);
			return false;
		}
		
		// check it is not only *'s in the field
		var stars = 0;  // this will change to one if something other than a * is found
		for (var i=0;i<val.length;i++) {
			if (val.charAt(i) != "*") {
				stars = 1;
			}
		}
		
		if (stars == "0") {
			//nothing else found other than stars
			alert(SEARCH_CRITERIA_MODIFY);
			return false;
		}

return true;
}



/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function check_searchareas() {
	amount = document.searchpage.searchlist.length;
		cont = 0; //continue
		for (i=0;i<=amount;i++) {
			what = document.searchpage.elements[i].type;
			if (what == "checkbox") {
				if (document.searchpage.elements[i].checked) {
					cont = 1;
				}
			}
		}

	//check that cont is 1, if not then they havent selected anything
	if (cont == "0") {
		var ans = confirm(SEARCH_CRITERIA_SEARCH_ENTIRE_SITE);
		if (ans) {
			// check all the checkboxes and submit the form
			for (i=0;i<=amount;i++) {
				what = document.searchpage.elements[i].type;
				if (what == "checkbox") {
					document.searchpage.elements[i].checked = true;
				}
			}
		} else {
			return false;
		}
	} 
	return true;
}



/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function move_page(where) {
	self.location = "#"+where;
}


/**************************************** 
* NOT USED???
* need further analyses
****************************************/
// global variable to store the xml file name
xml_file_name = "";


/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function store_xml_filename(xmlfile) {
	xml_file_name = xmlfile;
	alert(xml_file_name);
}



/**************************************** 
* NOT USED???
* need further analyses
****************************************/
function MM_openBrWindowPrint(theURL,winName,features) { //v2.0
// alert(xml_file_name);
 theURL= theURL + xml_file_name;
// alert(theURL);
 var thewin = window.open(theURL,winName,features);
 	 thewin.focus;
}





// -----------------------------------------------------
// REGISTRATION.JS
// -----------------------------------------------------

var blnPSAccepted = "" ;


function asc(each_char,i)	{
		if (i == 1) {
			var char_str = charSetStr2();
		} else {
			var char_str = charSetStr();
		}
		for (i = 0; i < char_str.length; i++) {
			if (each_char == char_str.substring(i, i+1)) {
				return 1;
			}
		}
	return 0;
}
	
function charSetStr()	{
	//*** REMOVED !,#,$,-,_,~ from check to allow a few more symbols in login name
	//*** Modified by Dennis van Heezik on 8th April 2003 - Verified with Harold Herksen and Michel Schipper
	var str = ' "%&' + "" + '()*+,/;:<=>?[\\]^`{|}';
	return str;
}

function charSetStr()	{
	//var str = ' !"#$%&' + "" + '()*+,-/;:<=>?[\\]^_`{|}~';
	var str = ' "%&' + "" + '()*+,/;:<=>?[\\]^`{|}';
	return str;
}



function charSetStr2()	{
	var str = '!"#$%&' + "" + '()*+,/;:<=>?[\\]^_`{|}~';
	// this one just doesn't have a space or hyphen
	return str;
}


function validfield(formfield,i) {
	for (var a = 0; a < formfield.length; a++)	{
		var each_char = formfield.charAt(a);
		var x = asc(each_char,i)
			if (x == 1) {
				return 1;
			}
	}
	return 0;
}


function ValidateUsernamePassword(un,pw) {

	var da_un_valid = validfield(un,0);
	
	if ((da_un_valid > 0) || (un.length < 1)) {
		alert(USERNAME_INVALID); 
		return false;
	}
	var da_pw_valid = validfield(pw,0);
	if ((da_pw_valid > 0) || (pw.length < 1)) {
		alert(PASSWORD_INVALID); 
		return false;
	}	
	return true;

}





function validateaccount() {
	var un = document.checkpassword.usr_login.value;
	var pw = document.checkpassword.usr_passwd.value;

	return ValidateUsernamePassword(un,pw);
}


function validateprofession(blnPSV) {

	var da_profession = document.userdets.profession[document.userdets.profession.selectedIndex].value;
	if (da_profession == "-88") {
		alert(PROFESSION_INVALID);
		return false;
	}
	var pw = document.userdets.usr_passwd.value;
	var da_pw_valid = validfield(pw,0);
	if ((da_pw_valid > 0) || (pw.length < 1)) {
		alert(PASSWORD_INVALID); 
		return false;
	}
	if (blnPSV != 'yes') {
		return true;
	} else {
		if (blnPSAccepted == true) { 
			//alert(blnPSAccepted);
			//blnPSAccepted = false;
			return true;
		} else {
			window.open("/authfiles/PSV.asp", "popup", "menubar=no, location=no, resizable=no, scrollbars=yes, status=0, width=595, height=450, top=100, left=165");
			return false;
		}
	}	

}	


function set_email_value()
{
	document.delsubscr.email.value = document.userdets.email.value;
}


function validate_email() {
	
	var da_email
	
	if (document.name == "userdets") {
		da_email = document.userdets.email.value;
	} else {
		da_email = document.delsubscr.email.value;
	}

		// if cont = 1 then the email address is required!
		if (da_email.length == "0") {
			alert(EMAIL_REQUIRED);
			return false;
		}
							
		if (da_email.length != "0") {
		   if (da_email.indexOf("@")<2)  {
				alert(EMAIL_INVALID);
				return false;
			} else {
				if (da_email.indexOf(".",da_email.indexOf("@")) < da_email.indexOf("@")) {
					alert(EMAIL_INVALID);
					return false;
				}
			}			
		}
		
	if (document.name == "userdets") {
		return true;
	} else {
		document.delsubscr.submit();
	}
	
}	


function noEntry(blnPSV) {

	var missinginfo = '';

	// find out if any of the ealerts have been selected, if they have then the email address becomes required
	var amount = document.userdets.elements.length;

		cont = 0; //continue
		for (i=0;i<amount;i++) {
			what = document.userdets.elements[i].type;
			if (what == "checkbox") {
				if (document.userdets.elements[i].checked) {
					cont = 1;
				}
			}
		}
	
	var da_firstname = document.userdets.usr_firstname.value;
	var da_firstname_valid = validfield(da_firstname,1);
	
		if (da_firstname_valid > 0) {
			//Error - invalid chars found
			missinginfo += "\n     -  " + FIRSTNAME_INVALID_CHAR;
		}
		if (da_firstname.length < 2) 	{
				missinginfo += "\n     -  " + FIRSTNAME_MIN_TWO_CHARS;
		}
	
	var da_lastname = document.userdets.usr_lastname.value;
	var da_lastname_valid = validfield(da_lastname,1);
	
		if (da_lastname_valid > 0) {
			//Error - invalid chars found
			missinginfo += "\n     -  " + LASTNAME_INVALID_CHAR;
		}
		if (da_lastname.length < 2) 	{
		   missinginfo += "\n     -  " + LASTNAME_MIN_TWO_CHARS;
		}
		
	var da_profession = document.userdets.profession[document.userdets.profession.selectedIndex].value;
	if (da_profession == "-88") {
		missinginfo += "\n     -  " + PROFESSION_MANDATORY;
	}		
	var da_email = document.userdets.email.value;

		// if cont = 1 then the email address is required!
		if (cont == "1" && da_email.length == "0") {
			missinginfo += "\n     -  " + EMAIL_MANDATORY;
		}
							
		if (da_email.length != "0") {
		   if (da_email.indexOf("@")<2)  {
				missinginfo += "\n     -  " + EMAIL_INVALID + "*";
			} else {
				if (da_email.indexOf(".",da_email.indexOf("@")) < da_email.indexOf("@")) {
					missinginfo += "\n     -  " + EMAIL_INVALID + "*";
				}
			}			
		}
						
	var da_country = document.userdets.country[document.userdets.country.selectedIndex].value;
	if (da_country == "-99") {
		missinginfo += "\n     -  " + COUNTRY_MANDATORY;
	}
			
		var da_username = document.userdets.usr_login.value;
		var da_username_valid = validfield(da_username);
		
			if (da_username_valid > 0) {
				//Error - invalid chars found
				missinginfo += "\n     -  " + USERNAME_INVALID_CHAR;
			}
			if (da_username.length < 2) 
				{
					missinginfo += "\n     -  " + USERNAME_INVALID_LENGTH;
				}   
		
		var da_passwd = document.userdets.usr_passwd.value;
		var da_passwd_valid = validfield(da_passwd)
		
			if (da_passwd_valid > 0) {
				//Error - invalid chars found
				missinginfo += "\n     -  " + PASSWORD_INVALID_CHAR;
			}
			if (da_passwd.length < 2)
				{
					missinginfo += "\n     -  " + PASSWORD_INVALID_LENGTH;
				}
				
		var da_passwdTwo = document.userdets.usr_passwd2.value;
		var da_passwdTwo_valid = validfield(da_passwdTwo)
		
			if (da_passwdTwo_valid > 0) {
				//Error - invalid chars found
				missinginfo += "\n     -  " + PASSWORD_CONFIRM_INVALID_CHAR;
			}
			 if (da_passwdTwo != da_passwd) {
			 	missinginfo += "\n     -  " + PASSWORD_CONFIRM_INVALID_LENGTH;
			}
														      
	if (missinginfo != "") {
		missinginfo ="______________________________________________________________________________\n" +
		FORM_ERROR + "\n" +
		missinginfo + "\n____________________________________________________________________________" +
		"\n" + FORM_RESUBMIT + "\n" +
		"\n" + FORM_ENTRIES1 +
		"\n" + FORM_ENTRIES2;
		alert(missinginfo);
		return false;
	} else {
		if (blnPSV != 'yes') {
			return true;
		} else {
			if (blnPSAccepted == true) { 
				//alert(blnPSAccepted);
				//blnPSAccepted = false;
				return true;
			} else {
				window.open("/authfiles/PSV.asp", "popup", "menubar=no, location=no, resizable=no, scrollbars=yes, status=0, width=595, height=450, top=100, left=165");
				return false;
			}
		}	
	}
}


function ValidatePrivacyStatement() {
	if (document.PSValidation.CheckBoxPSV.checked == false){
		alert(REGISTER_AFTER_ACCEPTING);
		return false;
	} else {
		blnPSAccepted = true
		if (typeof(window.opener)== "object"){
			self.close();
			if (typeof(window.opener.document.userdets)== "object"){
				window.opener.document.userdets.submit();
			} else {
				alert(PAGE_EXPIRED);
				self.close();
			}
		}
	}
}


function submit_deluser() {
	if (confirm(REMOVE_YOURSELF)) {
		document.deluser.submit();
	}
}


// -----------------------------------------------------
// QUICKLOGIN.JS
// -----------------------------------------------------

function validatequicklogin() {

	var un = document.quicklogin.frmUsername.value;
	var pw = document.quicklogin.frmPassword.value;

	return ValidateUsernamePassword(un,pw);
}


function validateloginblock() {

	var un = document.loginblock.frmUsername.value;
	var pw = document.loginblock.frmPassword.value;

	return ValidateUsernamePassword(un,pw);
}


function validateexternallogin() {

	var un = document.quicklogin.frmUsername.value;
	var pw = document.quicklogin.frmPassword.value;

	return ValidateUsernamePassword(un,pw);
}

