function setQueryStringParameter(name, value) {
	var regex = /[\?&]/
}

var regexAlphanumeric	= /^[\w]+$/;
var regexEmail			= /^[\w]+[\w.-]*@[\w-]+.[\w.-]+[\w]$/;
var regexIpAddress		= /^([\d]{1,3}|[*])\.([\d]{1,3}|[*])\.([\d]{1,3}|[*])\.([\d]{1,3}|[*])$/;
var regexFormedUrl		= /^(http:\/\/)([\w]+\.[\w.]+)[\w]$/i;
var regexUrl			= /^([\w]+\.[\w.]+)[\w]$/i;


function meetsComplexity(pwd, email)
{
   var isValid = false;

   // Check doesn't contain part of the username
   email = email.toLowerCase();
   if (pwd.length >= 7)
   {
      var found = false;
      for (i=0; i<=email.length-4; i++)
      {
         emailBits = email.substr(i,4);
         if (pwd.toLowerCase().indexOf(emailBits) > -1)
         {
            found = true;            break;

         }

      }
      if (!found)
      {
         // Check doesn't contain illegal characters
         var regexp = /[^a-zA-Z0-9+=_\-$%*!@#';:.,?<>"~&]/g;
         if (pwd.search(regexp) == -1)
         {
             // Check contains three of the four ranges

            var ranges = 0;
            var uppers = /[A-Z]/g;
            var lowers = /[a-z]/g;
            var numbers = /[0-9]/g;
            var symbols = /[+=_\-$%*!@#';:.,?<>"~&]/g;

            if (pwd.search(uppers) > -1) ranges++;

            if (pwd.search(lowers) > -1) ranges++;

            if (pwd.search(numbers) > -1) ranges++;

            if (pwd.search(symbols) > -1) ranges++;


            if (ranges >= 3) isValid = true;         }
      }

   }
   return isValid;
}


function isAlphanumeric(value) {
	if (value.match(regexAlphanumeric)) {
		return true;
	} else {
		return false;
	}
}

function openHelpWindow(url) {
	window.open(url, 'imipassporthelp', 'toolbar=yes,resizable=yes,width=600,height=400,scrollbars=yes');
}

function appendMessage(messages, message, divider) {
	if (messages == null || messages == "") {
		messages = message;
	} else {
		messages += divider + message;
	}
	return messages;
}

function isBlank(value) {
	return (trim(value) == "");
}

function isEmail(value) {
	if (value.match(regexEmail)) {
		return true;
	} else {
		return false;
	}
}

function isIpAddress(value) {
	var blocks, i, blockNum;
	if (value.match(regexIpAddress)) {
		blocks = value.split(".");
		for (i = 0; i < blocks.length; i++) {
			if (blocks[i] != "*") {
				blockNum = parseInt(blocks[i]);
				if (isNaN(blockNum)) {
					return false;
				} else {
					if (blockNum < 0 || blockNum > 255) {
						return false;
					}
				}
			}
		}
		return true;
	} else {
		return false;
	}
}

function isFullyFormedUrl(value) {
	if (value != null && value.match(regexFormedUrl)) {
		return true;
	} else {
		return false;
	}
}

function isValidUrl(value) {
	if (value != null && value.match(regexUrl)) {
		return true;
	} else {
		return false;
	}
}

function getFullyFormedUrl(value) {
	if (isFullyFormedUrl(value)) {
		return value;
	} else {
		if (isValidUrl(value)) {
			return "http://" + value;
		} else {
			return null;
		}
	}
}

function getSelectedOption(id) {
	var obj;
	obj = getElem(id);
	if (obj != null && obj.options != null) {
		var i;
		for (i = 0; i < obj.options.length; i++) {
			if (obj.options[i].selected) {
				if (obj.options[i].value != "") {
					return obj.options[i].value;
				} else {
					return obj.options[i].text;
				}
			}
		}
		return null;
	} else {
		return null;
	}
}


function disableElem(id, disable) {
	var obj;
	obj = getElem(id);
	if (obj != null) {
		if (disable != null) {
			obj.disabled = disable;
		} else {
			obj.disabled = !obj.disabled;
		}
	}
}

function getElem(id) {
	if (document.layers){
		return eval('document.' + id);
	}
	if (document.getElementById){
		return eval('document.getElementById("' + id + '")');
	}
	if (document.all){
		return eval('document.all.' + id);
	}
}

function setElemDisplay(id, display) {
	var obj;
	obj = getElem(id);
	if (obj != null && obj.style != null) {
		if (display == null) {
			var currentDisplay = obj.style.display;
			if (currentDisplay == null) {
				obj.style.display = "none";
			} else if (currentDisplay.toLowerCase() == "none") {
				obj.style.display = "block";
			} else {
				obj.style.display = "none";
			}
		} else {
			if (display) {
				obj.style.display = "block";
			} else {
				obj.style.display = "none";
			}
		}
	}
}








// temporary borrowed random password generator

var passwordChars = new Array ("A", "C", "E", "F", "G", "H", "K", "M", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "d", "e", "h", "m", "p", "q", "r", "t", "1", "2", "3", "4", "5", "6", "7", "8", "9", "@", "#", "~", "+", "_", "=", "*", "%", "$", "&")

function generatePassword() {
    var length=8;
    var sPassword = "";
    var noPunction = true;
    for (i=0; i < length; i++) {
        numI = parseInt(Math.random() * 47);
        sPassword = sPassword + passwordChars[numI];
    }

    // Check contains three of the four ranges
    var ranges = 0;    var uppers = /[A-Z]/g;
    var lowers = /[a-z]/g;
    var numbers = /[0-9]/g;
    var symbols = /[+=_\-$%*!@#';:.,?<>"~&]/g;

    if (sPassword.search(uppers) > -1) ranges++;

    if (sPassword.search(lowers) > -1) ranges++;

    if (sPassword.search(numbers) > -1) ranges++;

    if (sPassword.search(symbols) > -1) ranges++;


    if (ranges < 3) sPassword = generatePassword();
    return sPassword;
}
/*
function getRandomNum() {
    // between 0 - 1
    var rndNum = Math.random();
    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);
    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;
    return rndNum;
}

function checkPunc(num) {
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    return false;
}
*/
















// string functions
function trim(inputString) {
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	return retValue;
}


String.prototype.trim = String_trim;
String.prototype.isBlank = String_isBlank;
String.prototype.startsWith = String_startsWith;
String.prototype.endsWith = String_endsWith;


function String_isBlank() {
	return (this.trim() == "");
}

function String_trim() {
	var retValue = this.toString();
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	return retValue;
}


function String_startsWith(match) {
	if (typeof(match) == "string") {
		var value = this.toString();
		if (match.length <= value.length) {
			if (value.substring(0, match.length) == match) {
				return true;
			}
		}
	}
	return false;
}

function String_endsWith(match) {
	if (typeof(match) == "string") {
		var value = this.toString();
		if (match.length <= value.length) {
			if (value.substr(value.length - match.length) == match) {
				return true;
			}
		}
	}
	return false;
}

















function getObj(id) {
	if (document.layers){
		// Netscape 4.x
		return eval('document.' + id);
	}
	if (document.getElementById){
		// Netscape 6.x, IE 5+, W3CDOM
		return eval('document.getElementById("' + id + '")');
	}
	if (document.all){
		// IE 4+
		return eval('document.all.' + id);
	}
}

//																									scroll code
var agt = navigator.userAgent.toLowerCase();
var isOpera = ( (agt.indexOf("opera") != -1)
                 && document.getElementById   ) ? 1 : 0;
var isNav4 = (document.layers && !isOpera) ? 1 : 0;
var isIE4  = (document.all && !isOpera) ? 1 : 0;
var isMoz  = ( document.getElementById && !(isNav4 || isIE4 | isOpera) ) ? 1 : 0;

var hScrollWatch;
var scrollTop, lastScrollTop, scrollDirection, topYPos, floaterYPos, resized;
// Scroll Directions up: -1 | down: 1 | neutral: 0

scrollTop = 0;
lastScrollTop = 0;
topYPos = 0;
floaterYPos = 0;

function startScrollWatch() {
	if (!isIE4) {
		hScrollWatch = setInterval('scrollWatch()', 5);
	}
}
function resizeScrollWatch() {
	resized = true;
	scrollWatch();
	resized = false;
}
function scrollWatch() {
	lastScrollTop = scrollTop;
	scrollTop = getYOffset();
	if (scrollTop > lastScrollTop) {
		scrollDirection = 1;
	} else if (scrollTop < lastScrollTop) {
		scrollDirection = -1;
	} else {
		scrollDirection = 0;
	}
	doScroll();
}
function getYOffset() {
	if ( window.pageYOffset || window.pageYOffset == 0 ) {
		// Navigator
		return window.pageYOffset;
	} else if ( document.body.scrollTop || document.body.scrollTop == 0) {
		if ( document.documentElement ) {
			if ( document.documentElement.scrollTop || document.documentElement.scrollTop == 0 ) {
				// IE 6
				return document.body.scrollTop + document.documentElement.scrollTop;
			}
		} else {
			// IE 4+
			return document.body.scrollTop;
		}
	}
}
function getWindowHeight() {
	if (window.innerHeight || window.innerHeight == 0) {
		return window.innerHeight;
	} else	if (document.body.clientHeight || document.body.clientHeight == 0) {
		return document.body.clientHeight ;
	}
}
function getObjHeight(obj) {
	if(obj.clientHeight || obj.clientHeight == 0) {
		return obj.clientHeight;
	} else if(obj.offsetHeight || obj.offsetHeight == 0) {
		return obj.offsetHeight;
	}
}
function setTop(layer, t) {
	if(t > topYPos) {
		layer.style.top = t + "px";
	} else {
		layer.style.top = topYPos + "px";
	}
}
function doScroll() {
	var obj, screenHeight, floaterHeight;
	obj = getObj("leftbar");
	screenHeight = getWindowHeight();
	floaterHeight = getObjHeight(obj);
	if (obj) {
		if (floaterYPos < scrollTop) {
			if (screenHeight > floaterHeight) {
				floaterYPos = scrollTop;
				setTop(obj, floaterYPos);
			} else if (scrollTop + screenHeight > floaterHeight + floaterYPos && (scrollDirection == 1 || resized)) {
				floaterYPos = scrollTop + screenHeight - floaterHeight;
				setTop(obj, floaterYPos);
			}
		} else if (floaterYPos > scrollTop) {
			if (screenHeight > floaterHeight) {
				if (scrollTop >= topYPos) {
					floaterYPos = scrollTop;
					setTop(obj, floaterYPos);				
				} else {
					floaterYPos = topYPos;
					setTop(obj, floaterYPos);
				}
			} else if (scrollDirection == -1) {

				if (scrollTop >= topYPos) {
					floaterYPos = scrollTop;
					setTop(obj, floaterYPos);				
				} else {
					floaterYPos = topYPos;
					setTop(obj, floaterYPos);
				}
			}
		}
	}
}

var popupShowing;

function showHelpPopup(helpDivName)
{
   var helpDiv = document.all ? document.all[helpDivName] : document.getElementById(helpDivName);
   if (popupShowing != null & popupShowing != helpDiv)
   {
      popupShowing.style.visibility = 'hidden';
      popupShowing = null;
   }
   if (helpDiv.style.visibility == 'visible')
      helpDiv.style.visibility = 'hidden';
   else
      helpDiv.style.visibility = 'visible';
   popupShowing = helpDiv;
}

function hideHelpPopup(helpDivName)
{
   var helpDiv = document.all ? document.all[helpDivName] : document.getElementById(helpDivName);
   helpDiv.style.visibility = 'hidden';
   popShowing = null;
}

function helpPopup_mouseDown(closeImg)
{
   closeImg.src = '/images/close_down.gif';
}

function helpPopup_mouseUp(closeImg)
{
   closeImg.src = '/images/close_up.gif';
}
