var ENABLE_COOKIE = "Um sich anzumelden, lassen Sie bitte an dieser Stelle Cookies zu und aktualisieren Sie diese Seite.";
var USERNAME_INVALID = "Der angegebene Benutzername ist ungültig.";
var PASSWORD_INVALID = "Das angegebene Passwort ist ungültig.";
var PROFESSION_INVALID = "Das Feld 'Beruf' ist nicht korrekt ausgefüllt.";
var EMAIL_REQUIRED = "Die Angabe Ihrer E-Mail-Adresse ist erforderlich.";
var EMAIL_INVALID = "Das Feld 'E-Mail-Adresse' ist nicht korrekt ausgefüllt.";
var FIRSTNAME_INVALID_CHAR = "Das Feld 'Vorname' enthält ungültige Zeichen.";
var FIRSTNAME_MIN_TWO_CHARS = "Das Feld 'Vorname' muss mindestens aus 2 Zeichen bestehen.";
var LASTNAME_INVALID_CHAR = "Das Feld 'Nachname' enthält ungültige Zeichen.";
var LASTNAME_MIN_TWO_CHARS = "Das Feld 'Nachname' muss mindestens aus 2 Zeichen bestehen.";
var PROFESSION_MANDATORY = "Die Angabe Ihres Berufes ist erforderlich.";
var EMAIL_MANDATORY = "Die Angabe Ihrer E-Mail-Adresse ist erforderlich.";
var COUNTRY_MANDATORY = "Die Angabe Ihres Landes ist erforderlich.";
var USERNAME_INVALID_CHAR = "Das Feld 'Benutzername' enthält ungültige Zeichen.";
var USERNAME_INVALID_LENGTH = "Das Feld 'Benutzername' muss zwischen 1 und 20 Zeichen lang sein.";
var PASSWORD_INVALID_CHAR = "Das Feld 'Passwort' enthält ungültige Zeichen.";
var PASSWORD_INVALID_LENGTH = "Das Feld 'Benutzername' muss zwischen 6 und 20 Zeichen lang sein.";
var PASSWORD_CONFIRM_INVALID_CHAR = "Das Feld 'Passwort Bestätigung' sollte identisch mit dem Feld 'Passwort' sein.";
var PASSWORD_CONFIRM_INVALID_LENGTH = "Das Feld 'Passwort Bestätigung' sollte identisch mit dem Feld 'Passwort' sein.";
var FORM_ERROR = "Ein Fehler ist mit der Form gefunden worden:";
var FORM_RESUBMIT = "Bitte geben Sie Ihre Daten erneut an und klicken Sie 'senden'";
var FORM_ENTRIES1 = "Die eingegebenen Zeichen müssen alphanumerisch sein und können Bindestriche beinhalten.";
var FORM_ENTRIES2 = "";
var REGISTER_AFTER_ACCEPTING = "Bitte bestätigen Sie den Datenschutz, um sich zu registrieren.";
var PAGE_EXPIRED = "Diese Seite ist abgelaugen.";
var REMOVE_YOURSELF = "Sind Sie sicher, dass Sie sich abmelden möchten?";
var BROWSER_NOT_SUPPORT_PRINT = "Ihr Browser unterstützt diese Druckmethode nicht.";
var BROWSER_NOT_SUPPORT_METHOD1 = "Ihr Browser unterstützt diese Methode nicht. Wenn Sie Netscape benutzen, dann können Sie diese Funktion hinzufügen.";
var BROWSER_NOT_SUPPORT_METHOD2 = "Um diese Seite zu Ihren Favoriten hinzuzufügen, drücken Sie Strg + D oder auf einem Mac Apfel + D.";
var SEARCH_CRITERIA_ENTER = "Bitte geben Sie einen Suchbegriff ein.";
var SEARCH_CRITERIA_MODIFY = "Die Liste der Antworten ist zu lang. Bitte grenzen Sie Ihre Suchkriterien ein.";
var SEARCH_CRITERIA_SEARCH_ENTIRE_SITE = "Sie haben keine Suchkriterien angegeben. Wollen Sie auf der ganzen Site suchen?";
var DUMM1_MANDATORY = "Das Feld 'Geburtsdatum' enthält ungültige Zeichen.";

/*
*-----------------------------------------------------------------------------------------------
*	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);
}


//%%% Change Start
//%%% Login Bypass Feature, Implemented by VinhLao July 24,2003
//%%% Functions to set bypass cookie
function loginByPass_CheckCookie() {
	if (Get_Cookie("LoginByPassed") == "yes")
		return true;
	else
		return false;
}

function loginByPass_SetCookie() {
	if (Get_Cookie("LoginByPassed") == "yes") {
		return true;
	}
	else {
		//%%% Modified by Vinh Lao July25,2003
		//%%% this expire the cookie in one year
		//var oneYear = 1 * 365 * 24 * 60 * 60 * 1000;
		//var expDate = new Date();
		//expDate.setTime(expDate.getTime() + oneYear);
		//Set_Cookie("LoginByPassed","yes",expDate,"/",null,false);
		
		//%%% this cookie is only valid during the session
		Set_Cookie("LoginByPassed","yes",null,"/",null,false);
		return true;
	}		
}	

function loginByPass_ClearCookie() {
	var threeDays = 3 * 24 * 60 * 60 * 1000;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() - threeDays);
	document.cookie = "LoginByPassed" + "=expired; expires=" + expDate.toGMTString();
}
//%%% Change End

// -----------------------------------------------------
// 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("cs_reminder.asp","Remind","width=500,height=400");
}


/**************************************** 
* 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;
	if (document.userdets.profession.type == 'hidden')
	{
		da_profession = document.userdets.profession.value;
	}
	else {
		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 {
			// BEGIN PROTOTYPE CHANGE (by VinhLao March 06,2003)		
			//window.open("/authfiles/PSV.asp", "popup", "menubar=no, location=no, resizable=no, scrollbars=yes, status=0, width=595, height=450, top=100, left=165");
			window.open("PSV.asp", "popup", "menubar=no, location=no, resizable=no, scrollbars=yes, status=0, width=595, height=450, top=100, left=165");
			// END PROTOTYPE CHANGE (by VinhLao March 06,2003)	
			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;

		// BEGIN PROTOTYPE CHANGE (by VinhLao March 18,2003)		
		// To make email a mandatory field
		//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;
		//		}
		//	}
		//}
		cont = 1;
		// END PROTOTYPE CHANGE (by VinhLao March 18,2003)	
	
	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 myDay = document.userdets.dummy1.value;
	var myMonth = document.userdets.dummy2.value;
	var myYear = document.userdets.dummy3.value;
	var err = 0;

	if (myDay == "-99" || myMonth == "-99" || myYear == "-99")  
	 {
     	missinginfo += "\n     -  " + DUMM1_MANDATORY;
     }	

    if (myDay==31 && (myMonth==4 || myMonth==6 || myMonth==9 || myMonth==11)) 
    	err=1

    if (myMonth==2) {
    	if ((myYear%4==0) && (myYear%100!=0 || myYear%400==0)) {
          	if (myDay>29) 
           		err=1
       	} 
       	else 
       	{
        	if (myDay>28) 
            	err=1
        }
     }
     if (myDay == "" || myMonth == "" || myYear == "") 
     	err=1
				
	 if (err==1) 
	 {
     	missinginfo += "\n     -  " + DUMM1_MANDATORY;
     }

     
	// BEGIN PROTOTYPE CHANGE (by VinhLao March 06,2003)	
	//var da_profession = document.userdets.profession[document.userdets.profession.selectedIndex].value;
	var da_profession;
	if (document.userdets.profession.type == 'hidden')
	{
		da_profession = document.userdets.profession.value;
	}
	else {
		da_profession = document.userdets.profession[document.userdets.profession.selectedIndex].value;
	}
	// END PROTOTYPE CHANGE (by VinhLao March 06,2003)	
	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;
	if (document.userdets.country.type == 'hidden')
	{
		da_country = document.userdets.country.value;
	}
	else {
		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 < 1) 
				{
					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 < 1)
				{
					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 {
				// BEGIN PROTOTYPE CHANGE (by VinhLao March 06,2003)
				//window.open("/authfiles/PSV.asp", "popup", "menubar=no, location=no, resizable=no, scrollbars=yes, status=0, width=595, height=450, top=100, left=165");
				window.open("PSV.asp", "popup", "menubar=no, location=no, resizable=no, scrollbars=yes, status=0, width=595, height=450, top=100, left=165");
				// END PROTOTYPE CHANGE (by VinhLao March 06,2003)	
				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);
}


