function requestFormCheck() {
	var form = document.forms["RequestForm"];
	var fElements = form.elements;
	var allFilled = true;
	for (var i = 0; i < form.elements.length; i++) {
		if (fElements[i].value == ""
				&& fElements[i].name != 'accountStreetAddress2') {
			allFilled = false;
		}
	}
	if (!allFilled)
		alert("Please fill out all the fields");
	return allFilled;
}

function checkAllZones(str_chk1, str_chk2, str_chk3, str_chk4, str_chk5, me) {
	var setTo = true;
	if (!document.getElementById(me).checked)
		setTo = false;
	var chk = document.getElementById(str_chk1);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk2);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk3);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk4);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk5);
	chk.checked = setTo;
}

function uncheckAllZones(str_chk1, str_chk2, str_chk3, str_chk4, str_chk5,
		str_chk6, me) {
	var setTo = false;
	// if (!document.getElementById(me).checked) setTo =false;
	var chk = document.getElementById(str_chk1);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk2);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk3);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk4);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk5);
	chk.checked = setTo;
	var chk = document.getElementById(str_chk6);
	chk.checked = setTo;
}

function setPassword() {
	document.ApproveForm.userPassword.value = getPassword(8, true, true, true,
			true, true, true, true, true);
}

// -----------------------------------------------------------------------

// Password generator

//

// -----------------------------------------------------------------------

// Begin

function getRandomNum(lbound, ubound) {

	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);

}

function getRandomChar(number, lower, upper, other, extra) {
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
	var charSet = extra;
	if (number == true)
		charSet += numberChars;
	if (lower == true)
		charSet += lowerChars;
	if (upper == true)
		charSet += upperChars;
	if (other == true)
		charSet += otherChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length, extraChars, firstNumber, firstLower, firstUpper,
		firstOther, latterNumber, latterLower, latterUpper, latterOther) {
	var rc = "";
	if (length > 0)
		rc = rc
				+ getRandomChar(firstNumber, firstLower, firstUpper,
						firstOther, extraChars);
	for (var idx = 1; idx < length; ++idx) {
		rc = rc
				+ getRandomChar(latterNumber, latterLower, latterUpper,
						latterOther, extraChars);
	}

	return rc;

}

// End

function verifyPassword() {
	var radiobox = document.getElementById('type');
	var txt_pass_1 = document.getElementById('newpass');
	var txt_pass_2 = document.getElementById('newpassagain');
	// alert(radiobox.checked);
	if (radiobox.checked) {
		var pass = getPassword(8, true, true, true, true, true, true, true,
				true);
	} else {
		var pass = new String(txt_pass_1.value);
		if (txt_pass_1.value != txt_pass_2.value) {
			alert('The two passwords do not match!');
			txt_pass_1.value = "";
			return false;
		} else if (pass.length < 8) {
			alert('The passwords length is less then 8 characters!');
			return false;
		} else if (!checkPassword(pass)) {
			alert('The has to contain at least one number,\none uppercase letter, and one lowercase letter!');
			return false;
		}
		txt_pass_1.value = pass;
	}
	txt_pass_1.value = pass;
	txt_pass_2.value = pass;
	return true;
}

function checkPassword(pass) {
	// ToDo: code to check for strong password
	return true;
}

// -----------------------------------------------------------------------

function showElement(theVar) {

	document.getElementById(theVar).style.display = "inline";
	return false;
}
function showListItem(theVar) {

	document.getElementById(theVar).style.display = "list-item";
	return false;
}
function hideElement(theVar) {

	document.getElementById(theVar).style.display = "none";
	return false;
}
function emptyElement(theVar) {

	document.getElementById(theVar).value = "";

}
function addValue(theElement, theValue) {

	document.getElementById(theElement).value += theValue + ";";
	// alert(document.getElementById(theElement).value);
}
//-------------------------------------------------------------------------------------------------------------------
/**
 * addEvent - simple window.onload event loader.
 */
function addEvent(o, evt, f) {
	var r = false;
	if (o.addEventListener) {
		o.addEventListener(evt, f, false);
		r = true;
	} else if (o.attachEvent)
		r = o.attachEvent("on" + evt, f);
	return r;
}

function printObject(obj) {
	var str = ""; // variable which will hold property values
	for (var prop in obj)
		if (obj[prop]) {
			str += prop + " value :" + obj[prop] + "\n";// Concate prop and its
														// value from object
		}
	alert(str);
}

function getTarget(e) {
	var targ;
	if (!e)
		var e = window.event;
	if (e.target)
		targ = e.target;
	else if (e.srcElement)
		targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function getKeyCharPressed(e) {
	var code;
	if (!e)
		var e = window.event;
	if (e.keyCode)
		code = e.keyCode;
	else if (e.which)
		code = e.which;
	var character = String.fromCharCode(code);
	return character;
}
function getKeyCodePressed(e) {
	var code;
	if (!e)
		var e = window.event;
	if (e.keyCode)
		code = e.keyCode;
	else if (e.which)
		code = e.which;
	return code;
}

function getMouseButton(e) {
	var rightclick;
	if (!e)
		var e = window.event;
	if (e.which)
		rightclick = (e.which == 3);
	else if (e.button)
		rightclick = (e.button == 2);
	return (rightclick) ? "right" : "left"; // true or false
}




//--------------------------------------------------------------------------------------------------------------------
function arrayDistinct(arryA,arryB){
      for(var i=0;i<arryA.length;i++){
            for(var j=0;j<arryB.length;j++){
                  if(arryA[i]===arryB[j])
                        return true;
            }
      }
      return false;
}
function arrayContains(arry,value){
      for(var i=0;i<arry.length;i++){
              if(arry[i]===value)
                    return true;
      }
      return false;
}

//
//bitwise conversion of rgb color to a hex value
function rgb2hex(r, g, b) {
    return(r<<16 | g<<8 | b);
}
//bitwise conversion of a hex color into rgb values
function hex2rgb (hex){
    var red = hex>>16;
    var greenBlue = hex-(red<<16)
    var green = greenBlue>>8;
    var blue = greenBlue - (green << 8);
  //trace("r: " + red + " g: " + green + " b: " + blue);
    return({r:red, g:green, b:blue});
}
