// =====  hg nov2006 because of UTF-8
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}
// ==================================

function isEmpty(aTextField) {
	if ((aTextField.value.length==0) || (aTextField.value==null)) {
		return true;
	} else {
		return false;
	}
}

function makeArray(IntarrSize) {

	for (var n = 0; n < IntarrSize; n++)
		this[n] = "";
	
	return this;

}

function customSplit(strvalue, separator, arrayName) {
	var n = 0;
	
	if (separator.length != 0) {
		while (strvalue.indexOf(separator) != -1) {
			eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
			strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
			strvalue.length+1);
			n++;
		}
		eval("arr" + n + " = strvalue;");
		arraySize = n+1;
	}
	else {
		for (var x = 0; x < strvalue.length; x++) {
			eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
			n++;
		}
		arraySize = n;
	}
	
	eval(arrayName + " = new makeArray(arraySize);");
	
	for (var i = 0; i < arraySize; i++)
		eval(arrayName + "[" + i + "] = arr" + i + ";");
	
	return arraySize;
}

function isEmail(el) {
	var argvalue = el.value;
	
	if (argvalue.indexOf(" ") != -1)
		return false;
	else if (argvalue.indexOf("@") == -1)
		return false;
	else if (argvalue.indexOf("@") == 0)
		return false;
	else if (argvalue.indexOf("@") == (argvalue.length-1))
		return false;
	
	// arrayString = argvalue.split("@"); (works only in netscape3 and above.)
	var retSize = customSplit(argvalue, "@", "arrayString");
	
	if (arrayString[1].indexOf(".") == -1)
		return false;
	else if (arrayString[1].indexOf(".") == 0)
		return false;
	else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
		return false;
	}
	
	return true;
}

function isEqualVal(el, val){
	return(el.value == val);
}

function isNumeric(sText){
	var ValidChars = "0123456789.";
	var isNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			isNumber = false;
		}
	}
	return isNumber;
}

function getSelectedOptionValues(el) {
	var arr = new Array(0);
	var idx = 0;
	
	for (var i = 0; i < el.options.length; i++) {
		if (el.options[i].selected) {
			arr[idx] = el.options[i].value;
			idx++;
		}
	}
	return(arr);
}

function getOptionValues(el) {
	var arr = new Array(0);
	var idx = 0;
	
	for (var i = 0; i < el.options.length; i++) {
		arr[idx] = el.options[i].value;
		idx++;
	}
	return(arr);
}

function displayMail(name, domain) {
//	var name = "cme";
//	var domain = "ehaweb.org";
	document.write('<a href=\"mailto:' + name + '@' + domain + '\">');
	document.write(name + '@' + domain + '</a>');
}
			
function displayMail2(name, domain, mail_subject) {
//	var name = "cme";
//	var domain = "ehaweb.org";
//	document.write(mail_subject);
	document.write('<a href=\"mailto:' + name + '@' + domain + '?subject=' + mail_subject  + '\">');
	document.write(name + '@' + domain + '</a>');
}
/* */
function toggleOthers(refID, listElement, otherElement) {
	var state;
	
	if (listElement.value == refID) {
		state = 'visible';
	}
	else {
		state = 'hidden';
	}
	otherElement.style.visibility = state
}
/* */
function toggleOtherCheckbox(checkbox, otherElement) {
	var state;
	
	if (checkbox.checked) {
		state = 'block';
	}
	else {
		state = 'none';
	}
	otherElement.style.display = state
}


function toggleOthers2(refID, listElement1, listElement2, otherElement) {
	var state;
	var inLE2 = false;
	var i;
	
	for (i = 0; i < listElement2.length; i++) {
		inLE2 |= (listElement2.options[i].value == refID);
	}
	
	var le1 = parseInt(listElement1.value);
	if ((le1 == refID) || inLE2) {
		state = 'visible';
	}
	else {
		state = 'hidden';
	}
	otherElement.style.visibility = state
}

function displayError(el, msg) {
	el.innerHTML = msg;
}

function MM_goToURL() { //v3.0 (taken from DreamWeaver
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function doPrintCheck(id) {
	var r = true;
	var pdf = parseInt(document.getElementById(id).value);
	if (pdf != 1) {
		r = confirm('Once you print your CME certificate the system will not allow you to make any adjustments to your evaluation consequently to the amount of credits you claimed for this meeting. Would you like to print your certificate?');
		if (r) {
			document.getElementById(id).value = 1;
		}
	}
	return r;
}