// JavaScript Document

function copyToList(from,to) {
	
	fromList = eval('document.forms[0].' + from);
	toList = eval('document.forms[0].' + to);
	
	if (toList.options.length > 0 && toList.options[0].value == 'temp') {
		
		toList.options.length = 0;
	}
	var sel = false;
	
	for (i=0; i<fromList.options.length; i++) {
		
		var current = fromList.options[i];
		
		if (current.selected) {
			
			sel = true;
			
			if (current.value == 'temp') {
				
				alert ('You cannot move this text!');
				return;
			}
			txt = current.text;
			val = current.value;
			toList.options[toList.length] = new Option(txt,val);
			fromList.options[i] = null;
			i--;
		}
	}
	if (!sel) alert ('You haven\'t selected any options!');
}

function getRandomNum(lbound, ubound) {
	
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar() {
	
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	charSet = numberChars + lowerChars + upperChars;
	
	return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length, start, end) { 

	var rc = "";
	
	if (length >= start && length <= end) {
		
		for (var idx = 1; idx <= length; idx++) {
			
			rc = rc + getRandomChar();
		}
		
	} else {
		
		alert("Password must be " + start + "-" + end + " characters.");
	}
	return rc;
}

function getformCheckValues(pcheckbox) {

	var xID="";

	if (pcheckbox) {

		if (pcheckbox.length == undefined) {
	
			if (pcheckbox.checked == true) { 
				xID = pcheckbox.value;
			}	
	
		} else {
	
			var nbox = pcheckbox.length; 
	
			for (var j=0; j < nbox; j++)  {
				
				if (pcheckbox[j].checked == true) {
					
					if (xID == "") {	
						xID = pcheckbox[j].value; 
					} else {	
						xID = xID + "," + pcheckbox[j].value;
					}	
				} 
			} 
		} 
	} 
	return xID;
}

function dataAction(checkbox, preURL, nameStr, noSelectedMsg) {

	var redirectURL = "";
	var xValue = "";

	xValue = getformCheckValues(checkbox);
	//alert(xValue); 

	if (xValue == "") {
		
		alert(noSelectedMsg);
		
	} else {

		if (preURL.indexOf("?") == -1) {

		 	redirectURL = preURL + "?" + nameStr + "=" + xValue; 

		} else {

		 	redirectURL = preURL + "&" + nameStr + "=" + xValue; 
		} 
		window.location = redirectURL;	 
	}	
}

function checkAll (pcheckbox, pchecked) {

 if (pcheckbox) {

 	var nbox=pcheckbox.length;

	if (nbox == undefined) { 
		pcheckbox.checked = pchecked
		
	} else {
	    for (var j = 0; j < nbox; j++)  {
			pcheckbox[j].checked = pchecked;
		}
	 }	
  }
}

function checkClick(pcheckall, pcheckbox, pchecked) {   

    if (pchecked.checked == false) { 
		pcheckall.checked = pchecked.checked; 
	
	} else {
	    var ibox = pcheckbox.length;

		for (var j=0; j < ibox; j++) {

			if (pcheckbox[j].checked != pchecked.checked) {	
				return; 
			}
		}
		pcheckall.checked = pchecked.checked;
	 }	 
}

function IsEmail(emailStr) {

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	//var filter=/^(.+)@(.+)$/

	if (emailStr.match(filter) == null)
		return false;
	else 
		return true;
}

function IsAlphaNumeric(str) {

	str = str.toLowerCase();

	for (var i=0; i < str.length; i++) {

		if (!((str.charAt(i) >= 'a' && str.charAt(i) <= 'z') || (str.charAt(i) >= '0' && str.charAt(i) <= '9') || (str.charAt(i) == '_')))
		
			return false;
	}
	return true;
}

function highlight(h) {
	
	event.srcElement.className = h;
}

