// JavaScript Document

function ClearMemberField(field, member) {
	var name = field.name;
	switch (name)
	{
		case "sMemberId":
			if (field.value == member) {
				memberVal = field.value;
				field.value = "";
			}
			break;
	}

/*	var name = field.name;
	switch (name) {
		case "sUser":
			if (field.value == "email" || field.value == "nom d'utilisateur") {
				userVal = field.value;
				field.value = "";
			}
			break;
		case "sPass":
			var passdiv = document.getElementById('passwordarea');
			if ((field.value == "password") && field.type=='text') {
				passVal = field.value;
				passdiv.innerHTML = "<input type='password' class='textbox' value='' id='sPass' name='sPass' onfocus='ClearField(this);' onblur='RestoreField(this);' />";
				window.setTimeout("document.getElementById('sPass').focus()",1);
			}
			break;
	}	*/
}
function ClearField(field) {
	var name = field.name;
	switch (name)
	{
		case "sUser":
			if (field.value == "email") {
				userVal = field.value;
				field.value = "";
			}
			break;
		case "sMemberId":
			if (field.value == "Member ID") {
				memberVal = field.value;
				field.value = "";
			}
			break;
		case "password":
			if ((field.value == "password") && field.type=='text') {
			var detect = navigator.userAgent.toLowerCase();

				if (document.all) { // && !detect.indexOf("opera")) {
					//alert("HERE");
					var passdiv = document.getElementById('passwordarea');
					passVal = field.value;
					passdiv.innerHTML = "<input type='password' class='textbox' value='' id='password' name='password' onfocus='ClearField(this);' onblur='RestoreField(this);' />";	//	 onChange='updatePass(this);'
					window.setTimeout("document.getElementById('password').focus()",1);

				} else {
					//alert("HERE2");
					passVal = field.value;
					field.value = "";
					field.type = "password";

				}
			}
			break;
	}

/*	var name = field.name;
	switch (name) {
		case "sUser":
			if (field.value == "email" || field.value == "nom d'utilisateur") {
				userVal = field.value;
				field.value = "";
			}
			break;
		case "sPass":
			var passdiv = document.getElementById('passwordarea');
			if ((field.value == "password") && field.type=='text') {
				passVal = field.value;
				passdiv.innerHTML = "<input type='password' class='textbox' value='' id='sPass' name='sPass' onfocus='ClearField(this);' onblur='RestoreField(this);' />";
				window.setTimeout("document.getElementById('sPass').focus()",1);
			}
			break;
	}	*/
}

function RestoreField(field) {


	var val = trim(field.value);
	if (val.length==0) {
		switch (field.name) {
			case "sUser":
				field.value = "email";
				break;
			case "sMemberId":
				field.value = "Member ID";
				break;
			case "password":
				if (document.all) { // && !detect.indexOf("opera")) {
					var passdiv = document.getElementById('passwordarea');
					passdiv.innerHTML = "<input type='text' name='password' size=\"16\" id='password' class='textbox' value='password' onfocus='ClearField(this);' />";
				} else {
					field.value = "password";
					field.type = "text";
				}
				break;
		}
	} else if (field.name == "password")
	{
		document.login.sPass.value = field.value;
	}
}

function RestoreMemberField(field, member) {


	var val = trim(field.value);
	if (val.length==0) {
		switch (field.name) {
			case "sMemberId":
				field.value = member;
				break;
		}
	}
}

// when the form is submitted update the
function updatePass() {

	document.login.sPass.value = document.login.password.value;

}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

/*
var win = null;
function newWindow(url,title,height,width,scrolls,parent,img) {//opens a new window with custome height and width
	var scrollbars="no";
	if (scrolls)
		scrollbars="yes";
	if (!parent) {
		if (img) {
			imgPath = img;
		}

		if (win) {
			try {
				win.window.close();
			}
			catch (error) {

			}
		}


		win = window.open(url,title,"height="+height+",width="+width+",resizable=no,scrollbars="+scrollbars);

		win.focus();

	}
	else
		self.opener.location.href = url;

	return false;
}*/

function newWindow(url,name,width,height,tools)
{
	var features = "";
	var posX = (screen.width - width) / 2;
	var posY = ((screen.height - height) / 2) - 100;

	features += "width="+width+",";
	features += "height="+height+",";
	features += "left="+posX+",";
	features += "top="+posY+",";
	features += "screenX="+posX+",";
	features += "screenY="+posY+",";

	if (tools == "full")
		features += "toolbar=yes,menubar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes";
	else if (tools == "half")
		features += "toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes";
	else if (tools == "custom")
		features += "toolbar=yes,location=no,status=no,scrollbars=no,resizable=yes";
	else
		features += "toolbar=no,menubar=no,location=no,status=no,scrollbars=no,resizable=no";

	url = url;
	name = name;

	launch = window.open(url,name,features);
}
