//BACKUPS INFORMATION IN DESCENDING ORDER
/*
28-11-2006
*/

var DayNames= new Array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");

function isEmail(entry){	
	/*var invalidChar = "`~!#$%^&*()+=/\\\"'?<>{}[]| ";	
	for(y = 0 ; y < invalidChar.length ; y++)
	{
		if(entry.indexOf(invalidChar.charAt(y)) >= 0)
			return false;
	}
	var emailReg = "^[\\w]\.*[\\w]\@[\\w]\.+[\\w]+[\\w]$"; 	
	var emailReg = new RegExp(emailReg);	*/
	var emailReg = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
    return emailReg.test(entry);
}
function ValidateEmail(S)
{
	var R=false;
	if (typeof(S) != "undefined")
	{
		if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(S))
			R=S;
	}
	return R;
}

function isDate(y,m,d){
	if((m<1) || (m>12)) return false;
	if((m==4 || m==6 || m==9 || m==11) && (d > 30)) return false;
	if((m==2) && (d > 29)) return false;
	var isVYear = (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0));
	if(m == 2 && !isVYear && d>28) return false;
	return true;
}

var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=500,width=750,toolbar=no,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}


function isphone(phone) {
	// Pattern matches 9999999999, 999-999-9999, or (999) 999-9999
	var rex = /^(\d{11}|\d{3}-\d{3}-\d{4}|\(\d{3}\) \d{3}-\d{4})$/;
	return rex.test(phone);
}


function isColor(color){
	var rex = /^((\#([a-fA-F0-9]{6}))|([a-zA-Z]{1,100})){1}$/
//	var rex = /^(\#([a-fA-F0-9]{6}))|([a-zA-Z]{1,100})$/
	return rex.test(color);
}

function toDays(y, m, d){
	return y * 1000 + m * 50 + d;
}

function checkNumber(number){
	//check numbers in 123,123,122.23 or 123123123.123 or 123,123,123 or 123123123 format
	var rex = /^((\d{1,3},)?(\d{3},)?(\d{3})|(\d{1,}))((\.(\d{1,}))?)$/;
	return rex.test(number);
}

function isInt(number){
	var rex = /^(\d{1,})$/;
	return rex.test(number);
}

function isText(txt){
	var rex = /.{0,}((\w{1,})|(\d{1,})|([\~\!\@\#\$\%\^\&\*\(\)\_\+\`\-\=\{\}\[\]\:\;\"\'\<\>\,\.\?\/\\\|]{1,2})).{0,}/;
	return rex.test(txt);
}

function isurl (url) {
  var rex = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;  
  return rex.test(url);
}


function normalizeNumber(number){
	var s = number;
	var ss = "";
	var c = "";
	var rex = /^(\d{1})|(\.{1})$/;
	for(i=0; i < s.length; i++){
		c = s.charAt(i);
		if(rex.test(c)){
			ss = ss + c;
		}
	}
	return parseFloat(ss);
}

function hideBlockDiv(menu_id){
	document.getElementById('block_' + menu_id).style.display = "none";
	document.getElementById('menuimg_' + menu_id).src = site_skin_images + "/menu_tree_arrow_right.gif";
}

function showBlockDiv(menu_id){
	document.getElementById('block_' + menu_id).style.display = "block";
	document.getElementById('menuimg_' + menu_id).src = site_skin_images + "/menu_tree_arrow_down.gif";
}
	
function showHideBlock(menu_id){
	return false;
	alert(document.getElementById('block_' + menu_id));
	if(document.getElementById('block_' + menu_id).style.display == "block") {
   		hideBlockDiv(menu_id);
    }
   	else{
       	showBlockDiv(menu_id);
    }
}

function validate(field) {
	var valid = ".0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only numbers are accepted!");
		field.focus();
		field.select();
		return false;
	}
	return true
}

function ignorecommas(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}

function checkMaxLength (textarea, evt, maxLength) {
  if (textarea.selected && evt.shiftKey) 
    // ignore shift click for select
    return true;
  var allowKey = false;
  if (textarea.selected && textarea.selectedLength > 0)
    allowKey = true;
  else {
    var keyCode = 
      document.layers ? evt.which : evt.keyCode;
    if (keyCode < 32 && keyCode != 13)
      allowKey = true;
    else           
      allowKey = textarea.value.length < maxLength;
  }
  textarea.selected = false;
  return allowKey;
}

function storeSelection (field) {
  if (document.all) {
    field.selected = true;
    field.selectedLength = 
      field.createTextRange ?
        document.selection.createRange().text.length : 1;
  }
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function taCount(textarea, maxChars, counter) {
	// if there's more than allowed, chop off the end 
	if (textarea.value.length > maxChars) { 
       textarea.value = textarea.value.substring(0, maxChars);
 	}
 	
	// change the number in the counter element
	if(document.getElementById) { 
		if (document.getElementById(counter)) {
			document.getElementById(counter).innerHTML = maxChars - textarea.value.length;
		}
	}
}

function initCounter(textarea, counter, maxChars) {

   if(document.getElementById && document.getElementById(counter) && textarea) {
      document.getElementById(counter).innerHTML = maxChars - textarea.value.length;
   }
}

function refreshParent() {
  window.opener.location.href = window.opener.location.href;
  if (window.opener.progressWindow) 
    window.opener.progressWindow.close();
  window.close();
}

var arrOldValues;
	
function SelectAllList(CONTROL){
for(var i = 0;i < CONTROL.length;i++){
CONTROL.options[i].selected = true;
}
}

function DeselectAllList(CONTROL){
for(var i = 0;i < CONTROL.length;i++){
CONTROL.options[i].selected = false;
}
}


function FillListValues(CONTROL){
var arrNewValues;
var intNewPos;
var strTemp = GetSelectValues(CONTROL);
arrNewValues = strTemp.split(",");
for(var i=0;i<arrNewValues.length-1;i++){
if(arrNewValues[i]==1){
intNewPos = i;
}
}

for(var i=0;i<arrOldValues.length-1;i++){
if(arrOldValues[i]==1 && i != intNewPos){
CONTROL.options[i].selected= true;
}
else if(arrOldValues[i]==0 && i != intNewPos){
CONTROL.options[i].selected= false;
}

if(arrOldValues[intNewPos]== 1){
CONTROL.options[intNewPos].selected = false;
}
else{
CONTROL.options[intNewPos].selected = true;
}
}
}


function GetSelectValues(CONTROL){
var strTemp = "";
for(var i = 0;i < CONTROL.length;i++){
if(CONTROL.options[i].selected == true){
strTemp += "1,";
}
else{
strTemp += "0,";
}
}
return strTemp;
}

function GetCurrentListValues(CONTROL){
var strValues = "";
strValues = GetSelectValues(CONTROL);
arrOldValues = strValues.split(",")
}
function ValidateValues(control){
	if(control.selectedIndex == 0)
	{
		for(i==0 ; i<control.length ; i++)
			control.options[i].selected = false;
		
		control.options[0].selected = true;
	}
	else
	{
		control.options[0].selected = false;
	}
}
incrementalVal = 10
function NewWindow(mypage, myname, w, h, otherProps) {
	if(otherProps)
	{
		if(otherProps.toLowerCase().indexOf("modal=yes") > -1)
		{
			return startWizard(mypage, myname, w, h)
		}
	}
	var xPos = (screen.width - w) / 2;
	var yPos = ((screen.height - h) / 2)-(15+incrementalVal);		
	if(otherProps)
		otherProps = ","+otherProps
	else
		otherProps = "";
	winprops = 'height='+h+',width='+w+',top='+yPos+',left='+xPos+otherProps
	win = window.open(mypage,myname,winprops)		
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return win;
}
function reminderWindow(mypage, myname, w, h, x,y) {
	var xPos = x;
	var yPos = y;
	
	winprops = 'height='+h+',width='+w+',top='+yPos+',left='+xPos
	win = window.open(mypage,myname,winprops)		
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return win;
}
function resizeWindow(windowCtrl,w,h){
	var xPos = (screen.width - w) / 2;
	var yPos = (screen.height - h) / 2;
	windowCtrl.resizeTo(w,h);
	
	windowCtrl.moveTo(xPos+5,yPos-incrementalVal);
	windowCtrl.focus();
}
function startWizard(url, parent, w, h, otherProps){
	if(otherProps)
		otherProps = ","+otherProps
	else
		otherProps = "";
	
	dialogProps = "dialogWidth:"+w+"px;dialogHeight:"+h+"px;help:no;status:no;scroll:no;resizable:no;";
	var ewin = window.showModalDialog(url, parent, dialogProps);
	
	if(ewin){
		obj.value = ewin;		
		obj.focus();
	}
}

function selectFromList(form,cmbfield,itemValue,isText,isMultiple,matchCase){
	exactField = form.elements[cmbfield];	
	if(matchCase)
	{		
		if(isMultiple);
		else{
			//return if already selected
			if(isText){
				if(exactField.options[exactField.selectedIndex].text == itemValue){
					return false;
				}
			}
			else{
				if(exactField.options[exactField.selectedIndex].value == itemValue){
					return false;
				}
			}
			//////////////////////////
			
			for(x=0 ; x<exactField.length ; x++)
			{
				exactField.options[x].selected = false;
			}
		}
		
		for(i=0;i<exactField.length;i++)
		{
			if(isText){
				if(exactField.options[i].text == itemValue){
					exactField.options[i].selected = true;
					return false;
				}
			}
			else{
				if(exactField.options[i].value == itemValue){
					exactField.options[i].selected = true;
					return false;
				}
			}
		}
	}
	else
	{
		if(isMultiple);
		else{
			//return if already selected
			if(isText){
				if(exactField.options[exactField.selectedIndex].text.toString().toLowerCase() == itemValue.toString().toLowerCase()){
					return false;
				}
			}
			else{
				if(exactField.options[exactField.selectedIndex].value.toString().toLowerCase() == itemValue.toString().toLowerCase()){
					return false;
				}
			}
			///////////////////////////
			
			for(x=0 ; x<exactField.length ; x++)
			{
				exactField.options[x].selected = false;
			}
		}
		for(i=0;i<exactField.length;i++)
		{
			if(isText){
				if(exactField.options[i].text.toString().toLowerCase() == itemValue.toString().toLowerCase()){
					exactField.options[i].selected = true;
					return false;
				}
			}
			else{				
				if(exactField.options[i].value.toString().toLowerCase() == itemValue.toString().toLowerCase()){
					exactField.options[i].selected = true;					
					return false;
				}
			}
		}
	}
}
function selectFromListLIKE(form,cmbfield,itemValue,isText,isMultiple,matchCase){
	exactField = form.elements[cmbfield];	
	if(matchCase)
	{		
		if(isMultiple);
		else{
			//return if already selected
			if(isText){
				if(exactField.options[exactField.selectedIndex].text.indexOf(itemValue) > -1){
					return false;
				}
			}
			else{
				if(exactField.options[exactField.selectedIndex].value.indexOf(itemValue) > -1){
					return false;
				}
			}
			//////////////////////////
			
			for(x=0 ; x<exactField.length ; x++)
			{
				exactField.options[x].selected = false;
			}
		}
		
		for(i=0;i<exactField.length;i++)
		{
			if(isText){
				if(exactField.options[i].text.indexOf(itemValue) > -1){
					exactField.options[i].selected = true;
					return false;
				}
			}
			else{
				if(exactField.options[i].value.indexOf(itemValue) > -1){
					exactField.options[i].selected = true;
					return false;
				}
			}
		}
	}
	else
	{
		if(isMultiple);
		else{
			//return if already selected
			if(isText){
				if(exactField.options[exactField.selectedIndex].text.toString().toLowerCase().indexOf(itemValue.toString().toLowerCase()) > -1){
					return false;
				}
			}
			else{
				if(exactField.options[exactField.selectedIndex].value.toString().toLowerCase().indexOf(itemValue.toString().toLowerCase()) > -1){
					return false;
				}
			}
			///////////////////////////
			
			for(x=0 ; x<exactField.length ; x++)
			{
				exactField.options[x].selected = false;
			}
		}
		for(i=0;i<exactField.length;i++)
		{
			if(isText){
				if(exactField.options[i].text.toString().toLowerCase().indexOf(itemValue.toString().toLowerCase()) > -1){
					exactField.options[i].selected = true;
					return false;
				}
			}
			else{				
				if(exactField.options[i].value.toString().toLowerCase().indexOf(itemValue.toString().toLowerCase()) > -1){
					exactField.options[i].selected = true;					
					return false;
				}
			}
		}
	}
}
function validateFile(form,title,fileField,fileFieldId,extensionArr){
	fileCtrl = form.elements[fileField+fileFieldId];
	if(fileCtrl.value.length > 0){
		filePath = fileCtrl.value.toLowerCase();	
		for(i=0;i<extensionArr.length;i++)
		{
			ext = "." + extensionArr[i].toLowerCase();
			index = filePath.lastIndexOf(ext);
			
			if(index >= 0)
			{
				if((filePath.length - index) == ext.length)
					return true;
			}
		}
		
	}
	var allowedFormats  = ""
	for(i=0;i<extensionArr.length;i++)
	{
		allowedFormats += "'"+extensionArr[i].toLowerCase()+"'";
		if(i != extensionArr.length-1)
			allowedFormats += ", "
	}
	alert("Invalid file selected in "+title+" "+fileFieldId+". Only following format(s) are allowed to upload.\n["+allowedFormats+"]");
	return false;
}
function setParentValues(form,field,val){
	cmbField = eval("form."+field);
	cmbValue= val.substr(0,val.indexOf("_"));
	cmbText = val.substr(val.indexOf("_")+1,val.length);			
	found = isValueExists(form,field,cmbValue);
	if(found == -1)
	{
		cmbField.options[cmbField.length] = new Option(cmbText,cmbValue);
		cmbField.options[cmbField.length-1].selected = true;
	}
	else
	{
		cmbField.options[found] = new Option(cmbText,cmbValue);
		cmbField.options[found].selected = true;
	}	
}
function isValueExists(form,cmbfield,itemValue,isText){
	for(i=0;i<form.elements[cmbfield].length;i++)
	{
		if(isText){
			if(form.elements[cmbfield].options[i].text == itemValue){
				return i;
			}
		}
		else{
			if(form.elements[cmbfield].options[i].value == itemValue){
				return i;
			}
		}
	}
	return -1;
}
function doCancel(wind){
	if(wind)
		win = wind;
	else
		win = window;
		
	if(confirm('Are you sure, you want to cancel')){
		win.close();
	}
	return false;
}
function doConfirm(){
	if(confirm('Are you sure, you want to delete')){
		return true;
	}
	return false;
}

function getHtmlCode(taName){
	taFrame = taName+"___Frame";
	tempVal = eval(taFrame).FCK.EditorDocument.body.innerHTML;
	for(i=0 ; i<100 ; i++)
	{
		str = ' _fckxhtmljob="'+i+'"';
		while(tempVal.indexOf(str) >= 0)
			tempVal = tempVal.replace(str,"");
	}
	str = ' class=" FCK__ShowTableBorders"';
	while(tempVal.indexOf(str) >= 0)
		tempVal = tempVal.replace(str,"");

	return tempVal;
}
function getPureHtml(code){
	tempVal = code;
	str = ' class=" FCK__ShowTableBorders"';
	while(tempVal.indexOf(str) >= 0)
		tempVal = tempVal.replace(str,"");

	chancedStr = "<p>&nbsp;</p>";
	if(tempVal.toLowerCase() == chancedStr)
		tempVal = "";
		
	return tempVal;
}
//IeSpell Checker
//this function will invoke ieSpell on the specified node. The rest of the document is 
//not touched
function checkSpell(node) {
  try {
    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
	if(node)
	    tmpis.CheckDocumentNode(node);
	else
		tmpis.CheckAllLinkedDocuments(document);
		
  } catch(exception) {
		if(confirm("You do not have spell check plug-in installed on your machine.\nYou must download and install it now. Click OK to do so, or you can cancel."))
	    	window.open("documents/spellcheck/spellcheck.exe");
		else
			return false;
  }
}
function checkSpellWholePage() {	
	
	if(document.getElementById("documentText") == null)	
		document.body.insertAdjacentHTML('afterBegin', '<textarea style="display:none;" id="documentText"></textarea>');
	else 
		document.getElementById("documentText").value = '';
	
	text = document.getElementById("documentText").value = document.body.innerText;	
	for(i=1 ; i<=3 ; i++) //repeats 3 times because it is the maximum chance that the countries list can occur in the same page.
	{
		s = text.toLowerCase().indexOf("afghanistan");
		e = text.toLowerCase().indexOf("zimbabwe");
		
		ex = text.toLowerCase().indexOf("hccpandemic - hcc");
		
		if(s > -1 && e > -1)
		{
			textB4 = text.substring(0,s);
			if(ex > -1)
				textAF = text.substring(e+8,ex);
			else
				textAF = text.substring(e+8,text.length);
		}
		else if(ex > -1)
		{
			textB4 = text.substring(0,ex);
			textAF = "";
		}
		else
		{
			textB4 = text;
			textAF = "";
		}
			
		//alert(text);
		//alert(textB4);
		//alert(textAF);
		text = textB4 + ' ' + textAF;
	}
	
	document.getElementById("documentText").value = text;
	checkSpell(document.getElementById("documentText"));
}

//this function uses the more advanced node spell check method that does not
//prompts the user with the "Spell Check Completed" message as well as returning a
//FALSE if the user cancels the spell check.
function checkSpellAdv(node) {
  try {
    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
	if(node)
	    return tmpis.CheckDocumentNode2(node, true);
	else
		return tmpis.CheckAllLinkedDocuments2(document, true);
		
  } catch(exception) {
      window.open("http://www.iespell.com/rel/ieSpellSetup211325.exe");   
  }
}

/////////////////
//////////////////////////////////BLINKER////////////////////////////////////
/*
var alerts = 0;
var blinker = 0
function alertError(backgroundId,count){	
	alert(1);
	bgId = document.getElementById(backgroundId+count);
	alerts = 6;
	blinker = setInterval("blinkError(bgId)",200);
}
function blinkError(bgId){
	if (alerts > 0)
	{
		if((alerts%2)==0)
			bgId.style.background="##FF0000"
		else
			bgId.style.background="##FFFFFF"
			
		alerts--;
	}
	else{
		clearInterval(blinker);
	}
}*/
//////////////////////////////////////////////////////////////////////////////

function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER 
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
function openDialog(OLECMDID, PROMPT, FOCUSSEDWINDOW){
	/* OLECMDID values:
	* 6 - print
	* 7 - print preview
	* 1 - open window
	* 4 - Save As
	*/
	// PROMPT = 1 PROMPTUSER
	// PROMPT = 2 DONTPROMPTUSER 
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	if(FOCUSSEDWINDOW)
	{
		FOCUSSEDWINDOW.document.body.insertAdjacentHTML('afterBegin', WebBrowser); 		
		FOCUSSEDWINDOW.WebBrowser1.ExecWB(OLECMDID, PROMPT,1,0);
		FOCUSSEDWINDOW.WebBrowser1.outerHTML = "";
	}
	else
	{
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 		
		WebBrowser1.ExecWB(OLECMDID, PROMPT);
		WebBrowser1.outerHTML = "";
	}
}
function removeIeCtrl(Browser){
	Browser.outerHTML = "";
}
function capitalLetter (string) {
  var match;
  var r = '';
  if (document.all) {
    var re = /\b\w/g;
    while ((match = re.exec(string))) {
      re = /(.|\n)\b\w/g;
      r += string.substring(0, match.index) + match[0].toUpperCase();
      string = string.substring(match.index + match[0].length);
    }
    r += string;
  }
  else {
    var re = /\b\w/g;
    var ind = 0;
    while ((match = re.exec(string))) {
      r += string.substring(ind, match.index) + match[0].toUpperCase();
      ind = re.lastIndex;
    }
    r += string.substring(ind)
  }
  return r;
}
var alertsCount = 0;
var blinkerObject = null
function adminAlert(id,count,speed){	
	idCtrl = document.getElementById(id);
	alertsCount = count * 2;
	return blinkerObject = setInterval("blinkIt(idCtrl)",speed);	
}
function blinkIt(idCtrl){
	if (alertsCount > 0)
	{
		if((alertsCount%2)==0)
			idCtrl.style.visibility="hidden"
		else
			idCtrl.style.visibility="visible"
			
		alertsCount--;
	}
	else{				
		clearInterval(blinkerObject);
	}
}

function dateDiff(date1,date2,datepart){
	var date1 = new Date(date1);
	var date2 = new Date(date2);
	
	var difference = date1-date2;
	
	datepart = datepart.toLowerCase();
	if(datepart == 'ms')
		formatdifference = Math.round(difference);
	else if(datepart == 's')
		formatdifference = Math.round(difference/1000);
	else if(datepart == 'm')
		formatdifference = Math.round(difference/1000/60);
	else if(datepart == 'h')
		formatdifference = Math.round(difference/1000/60/60);
	else if(datepart == 'd')
		formatdifference = Math.round(difference/1000/60/60/24);
	
	
	return formatdifference;
}
function isPureNumber(number) {
	var valid = "0123456789"
	var temp;
	for (var i=0; i<number.length; i++) {
		temp = number.substring(i, i+1);		
		if (valid.indexOf(temp) == -1) 
			return false;
	}
	return true
}

function trimString(inputString) {
	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); 
	}
	return retValue;
}
function AddToTheList(frm,sourceList,destList) 
{
	var NonSelected = true;
	var DidAdd = false;
	var AddSelected = true;
	
	if(typeof frm.emailAddr != "undefined")
	{
		if (frm.emailAddr.value.length>0)
		{
			if (!isEmail(frm.emailAddr.value))
			{
				alert("Invalid Email Address.");
				return false;
			}
			else
			{	
				var SrcEmail = frm.emailAddr.value;
				if (!IsIDAdded(SrcEmail,destList,1))
				{
					var DestRow = destList.insertRow();
					var DestCell = DestRow.insertCell();
					DestRow.UID = SrcEmail;
					DestRow.email = SrcEmail;
					DestRow.text = SrcEmail;				
					DestRow.className='row';
					
					DestCell.innerText=SrcEmail;				
					DestCell.className='rowBorder';
					DestCell.onmouseover=DoHL;
					DestCell.onmouseout=DoLL;
					DestCell.onclick=DoSL;								
					DidAdd=true;
				}
				frm.emailAddr.value="";
			}
			AddSelected = false;
		}
		else
		{
			AddSelected = true;
		}
	}
	if(AddSelected)
	{
		for (var i=0;i<sourceList.rows.length;i++)
		{
			if (sourceList.rows[i].className=='rowOnClicked')
			{
				var SrcID = sourceList.rows[i].UID;				
				var SrcEmail = IsDefined(sourceList.rows[i].email) ? sourceList.rows[i].email : '';
				var SrcText = IsDefined(sourceList.rows[i].text) ? sourceList.rows[i].text : sourceList.rows[i].innerText;

				if (!IsIDAdded(SrcID,destList))
				{					
					var DestRow = destList.insertRow();
					var DestCell = DestRow.insertCell();
					DestRow.UID = SrcID;
					if(IsDefined(sourceList.rows[i].email))
						DestRow.email = SrcEmail;
					if(IsDefined(sourceList.rows[i].text))
						DestRow.text = SrcText;				
					
					DestRow.className='row';
					
					DestCell.className='rowBorder';
					DestCell.innerText=SrcText; //ViewAble
					DestCell.onmouseover=DoHL;
					DestCell.onmouseout=DoLL;
					DestCell.onclick=sourceList.rows[i].cells[0].onclick;
					
					DidAdd=true;
				}
				NonSelected = false;
				sourceList.rows[i].className='row';			
			}
		}
		if (NonSelected)
		{
			alert("Please select a contact to add.");
			return false;
		}
	}	
}

function RemoveFromTheList(frm,sourceList,destList)
{
	var NonSelected = true;
	for (var i=0;i<destList.rows.length;i++)
	{
		if (destList.rows[i].className=='rowOnClicked')
		{
			destList.deleteRow(i); i--;
			NonSelected = false;
		}
	}
	if (NonSelected)
		alert("Please select a contact to remove.");
	
}
function ClearList(destList)
{
	for (var i=0;i<destList.rows.length;i++)
	{
		destList.deleteRow(i); i--;
	}
}
function TestListData(sourceField){
	data = ""
	for (var i=0;i<sourceField.rows.length;i++)
	{
		data += "["+sourceField.rows[i].UID+"]";
		
		if(IsDefined(sourceField.rows[i].email))
			data += "["+sourceField.rows[i].email+"]";
			
		if(IsDefined(sourceField.rows[i].text))
			data += "["+sourceField.rows[i].text+"]";
		
		data += "\n";
	}
	alert(data);
}
function TableDataToList(tableId,field,colDel,rowDel){
	field.value = "";
	for (var i=0;i<tableId.rows.length;i++)
	{
		data = tableId.rows[i].UID;
		if(IsDefined(tableId.rows[i].email))
			data += colDel + tableId.rows[i].email;
			
		if(IsDefined(tableId.rows[i].text))
			data += colDel + tableId.rows[i].text;
			
		if( i < tableId.rows.length-1 )
			field.value += data + rowDel;
		else
			field.value += data;
			
	}
}
function InsertDataToList(array,destList){
	var DestRow = destList.insertRow();
	var DestCell = DestRow.insertCell();
	DestRow.UID = array[2];
	if(trimString(array[4].toString()) != "")
		DestRow.email = array[4];
		
	if(trimString(array[4].toString()) != "")
		DestRow.text = array[3];				
		
	DestRow.className='row';
	
	DestCell.className='rowBorder';
	DestCell.innerText=array[3]; //ViewAble
	DestCell.onmouseover=DoHL;
	DestCell.onmouseout=DoLL;
	DestCell.onclick=DoSL;
}
function DoHL()
{
	var e=window.event.srcElement;
	while (e.tagName.toUpperCase()!="TR")
		e=e.parentElement;
	
	if (e.className=='row') 
		e.className='rowOnOver';
}
function DoLL()
{
	var e=window.event.srcElement;
	while (e.tagName.toUpperCase()!="TR")
		e=e.parentElement;

	if (e.className=='rowOnOver')	
		e.className='row';
}
function DoSL()
{
	var TB=e=window.event.srcElement;
	while (TB.tagName.toUpperCase()!="TABLE")
		TB=TB.parentElement;

	for (var i=0;i<TB.rows.length;i++)
		TB.rows[i].className='row';

	while (e.tagName.toUpperCase()!="TR")
		e=e.parentElement;

	e.className='rowOnClicked';
}
function IsIDAdded(Val,destList,isEmail)
{
	var ret=false;
	for (var i=0;i<destList.rows.length;i++)
	{
		if(isEmail){
			if (Val==destList.rows[i].email)
				ret=true;
		}
		else{
			if (Val==destList.rows[i].UID)
				ret=true;
		}
	}
	return ret;
}
function colorPicker(colorInit)
{
	var sColor = null
	if (!Client.Browser.IsIE())
		alert("This is only supported by IE");
	else
	{
		var dlg = document.getElementById("DlgHelper");
		if (!dlg)
		{
			document.body.insertAdjacentHTML("beforeEnd",
											 "<OBJECT id='DlgHelper' CLASSID='clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b' width='0px' height='0px'></OBJECT>")
			dlg = document.getElementById("DlgHelper");
		}
		if (dlg)
		{
			sColor = dlg.ChooseColorDlg(colorInit);
			sColor = sColor.toString(16);
			if (sColor.length < 6) {
				var sTempString = "000000".substring(0,6-sColor.length);
				sColor = sTempString.concat(sColor);
			}
			sColor = "#" + sColor;
		}
		return sColor;
	}
}
RegisterNamespaces("Client.Browser");
if(!Client.Browser.IsMozilla)
{
    Client.Browser.IsMozilla=function()
    {
        return false;
    };
}
nav = navigator.userAgent;
//alert(nav);
Client.Browser._IsNetscape	=	(nav.indexOf("Netscape") > -1) ? true : false;
Client.Browser._IsOpera		=	(nav.indexOf("Opera") > -1) ? true : false;
Client.Browser._IsFireFox	=	(nav.indexOf("Firefox") > -1) ? true : false;
Client.Browser._IsIE		=	!Client.Browser._IsNetscape && !Client.Browser._IsOpera && !Client.Browser._IsFireFox;

Client.Browser.IsNetscape = function()
{
    return Client.Browser._IsNetscape;
};
Client.Browser.IsOpera = function()
{
    return Client.Browser._IsOpera;
};
Client.Browser.IsFireFox = function()
{
    return Client.Browser._IsFireFox;
};
Client.Browser.IsIE = function()
{
    return Client.Browser._IsIE;
};

function RegisterNamespaces()
{
    for(var i=0;
    i<arguments.length;i++)
    {
        var astrParts=arguments[i].split(".");
        var root=window;
        for(var j=0;
        j<astrParts.length;j++)
        {
            if(!root[astrParts[j]])
                root[astrParts[j]]=new Object();
            root=root[astrParts[j]];
        }
    }
}
function IsDefined(param){
	if(param == null)
		return false;
	else
		return (typeof param != "undefined");
}
function getBeforeCh(str,c){
	res = null;
	
	index = str.indexOf(c);
	res = str.substring(0,index);	
	
	return res;
}
function getAfterCh(str,c){
	res = null;
	
	index = str.indexOf(c);
	res = str.substring(index+1);	
	
	return res;
}
function doCancelOnEscape(){
	document.body.onkeypress = function(){		
		if(event.keyCode == 27)
			doCancel();
	}
}
function setTitle(title){
	document.title = title;
}
function pickDate(tField,trig,lang){
	Zapatec.Calendar.setup({
		firstDay          : 1,
		weekNumbers       : false,
		inputField        : tField,
		button            : trig,
		ifFormat          : "%d-%b-%Y",
		daFormat          : "%Y/%m/%d",
		align             : "Bl"
	});
	//updateCalenderLang(lang);
}
function updateCalenderLang(lang){	
	Zapatec.Calendar._TT = Zapatec.Calendar["_TT_" + lang];
	Zapatec.Calendar._initSDN();
	flat_calendar.refresh();
	initFactoryFormats();
}

function multiSelFunc(frm,field){	
	
	if(field.options[0].selected == true){
		for(j=1 ; j < field.length; j++ ){
			if(field.options[j].selected == true){
				field.options[j].selected	=	false;
			} // end if
		} // end for
	}// end if

	if(field.value == '')
		field.options[0].selected = true;
		
}// end func

function copyText(theSel) {
   //if (!document.all) return; // IE only
   theForm = theSel.form;
   //theForm.copyArea.value=theSel.options[theSel.selectedIndex].value;
   var r = document.getElementById('dumpText').createTextRange();
   r.select();
   r.execCommand('copy');
}
/*
function copyText(theSel) {
   //if (!document.all) return; // IE only
   theForm = theSel.form;
   theForm.copyArea.value=theSel.options[theSel.selectedIndex].value;
   var r = document.getElementById('copyArea').createTextRange();
   r.select();
   r.execCommand('copy');
}
*/
function setCaretToEnd (control) {
	if (control.createTextRange) {
		var range = control.createTextRange();
		range.collapse(false);
		range.select();
		range.execCommand('copy');
	}
	else if (control.setSelectionRange) {
		control.focus();
		var length = control.value.length;
		control.setSelectionRange(0, length);
		control.execCommand('copy');
	}
}

function copy_clip(meintext)
{
 if (window.clipboardData) 
   {
   
   // the IE-manier
   window.clipboardData.setData("Text", meintext);
   
   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   
   // dit is belangrijk maar staat nergens duidelijk vermeld:
   // you have to sign the code to enable this, or see notes below 
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');
   
   // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
   // nodig om het in op te slaan
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   alert("Following info was copied to your clipboard:\n\n" + meintext);
   return false;
}
//Tackles three combo boxes having name with the same prefixes and the postfixes "_day","_month","_year"
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function checkDateCombo(frm,name)
{
	var x = frm.elements;
	var day = parseInt(x[name+"_day"].options[x[name+"_day"].selectedIndex].value);
	var month = parseInt(x[name+"_month"].selectedIndex);
	var year = parseInt(x[name+"_year"].options[x[name+"_year"].selectedIndex].value);
	
	if (!day || !month || !year)
	{
		return false;
	}
	if (year%4 == 0)
		monthLength[1] = 29;

	if (day > monthLength[month-1])
	{
		return false;
	}	
	return true;
}
function disableNavigationHistory(){
	history.forward();//Disables back button on page	
}
//////////////////
function isValidDate(d,convert) {
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intDay;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	strDate = d;
	if (strDate.length < 1) {
		return false;
	}
	if (strDate.toLowerCase()=="today" || strDate.toLowerCase()=="now"){return true;}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];

				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}

	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
		else
			return false;
	}
	
	// verify year part	2 or 4 digits
	if (strYear.length != 2 && strYear.length != 4) {return false;}
	if (isNaN(strYear)){return false;}
	// US style (swap month and day)
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	// verify 1 or 2 digit integer day
	if (strDay.length<1 || strDay.length>2) {return false;}
	if (isNaN(strDay)){return false;}
	
	// month may be digits of characters, hence following check
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}

	intDay=parseInt(strDay,10);
	intYear = parseInt(strYear, 10);
	
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	
	// day in month check
	if (intDay < 1 || intDay > 31){return false;}
		
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30)) {
		return false;
	}
	
	if (intMonth == 2) {
		if (LeapYear(intYear)) {
			if (intDay > 29) {return false;}
		}
		else 
		{
			if (intDay > 28) {return false;}
		}
	}
	
	if (!convert)
		return true;
	else
	{
		if (intYear<=99){intYear=intYear+2000;}
		return intDay+"/"+intMonth+"/"+intYear;
	}
}

function ConvertToJscriptDate(mydate)
{
	if (!isValidDate(mydate)){return "";}
	var vdate=isValidDate(mydate,true);
	var dparts= vdate.split("/");
	var JDate = new Date(dparts[2]+"/"+dparts[1]+"/"+dparts[0]);
	return JDate;
}

// check a composite date/time field
// assume date is everything up to first space
// and time is everything after first space

function isValidDateTime(strDateTime)
{
	var dt = TrimString(strDateTime);
	var intMatch;
	var intDateOnly = false;

	if (strDateTime.toLowerCase()=="today" || strDateTime.toLowerCase()=="now"){return true;}
	
	intMatch=dt.indexOf(":");
	if (intMatch < 0)
	{
		intDateOnly = true;
		intMatch=dt.length;
	}
	else
	{
		intMatch=dt.indexOf(" ");
	}
	if (intMatch < 0) {return false;}
	
	// check date
	if (!isValidDate(dt.substr(0,intMatch))){return false;}
	
	// check time
	if (!intDateOnly) {
		if (!isValidTime(dt.substr(intMatch+1,dt.length-intMatch))){return false;}
	}
	
	return true;
}


function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function isEarlierOrEqual(start,end)
{
	// convert dates to dd/mm/yyyy
	var myStart = isValidDate(start,true);
	var myEnd = isValidDate(end,true);
	if (myStart=="" || myEnd=="") return false;
	
	var startparts= myStart.split("/");
	var endparts=myEnd.split("/");
	
	if (Date.UTC(startparts[2],startparts[1],startparts[0]) <= Date.UTC(endparts[2],endparts[1],endparts[0]))
		return true;
	else
		return false;
}

function isTimeEarlierOrEqual(start,end)
{
	// convert times to UTC dates
	if (start=="" || end=="") return false;
	
	var startparts= start.split(":");
	var endparts=end.split(":");
	
	if (Date.UTC(2000,1,1,startparts[0],startparts[1]) <= Date.UTC(2000,1,1,endparts[0],endparts[1]))
		return true;
	else
		return false;
}
function validateDate(obj)
{
	if(ConvertToJscriptDate(obj.value) == "")
	{			
		return false;		
	}	
	return true;
}
function getXMLHttpHandler() {
	xObj = null;
	if(window.ActiveXObject){
		xObj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xObj = new XMLHttpRequest();
	}	
	return xObj;
}
function loadXmlDoc(strXML,sync){
	/*e = strXML.indexOf("?>");
	strXML = strXML.substring(e+2,strXML.length);
	strXML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + strXML;
	*/
	var tryO = 0;
	try{
		tryO = 1;
		xDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
		tryO = 2;
		xDoc.async = (sync) ? false : true;
		tryO = 3;
		xDoc.validateOnParse = true;
		tryO = 4;
		if (!xDoc.loadXML(strXML)) 
		{
			tryO = 5;
			alert(xDoc.parseError.reason + "\n" + xDoc.parseError.srcText);
			return false;
		}
		else {			
			return xDoc;
		}
	}catch(e){
		alert("ERROR:" + tryO + "\n" + e.message);
		return false;
	}
	
}
function getValueByTag(tag,doc){
	var sTag = "<" + tag.toLowerCase() + ">";
	var eTag = "</" + tag.toLowerCase() + ">";
	foundS = doc.indexOf(sTag);
	foundE = doc.indexOf(eTag);
	sLen = sTag.length;
	value = doc.substring(foundS+sLen,foundE);
	return value
}
function hideDocElement(id,display){
	obj = document.getElementById(id);
	if(typeof display == 'undefined')
		obj.style.visibility = "hidden";
	else
		obj.style.display = "none";
}
function unHideDocElement(id,display){
	obj = document.getElementById(id);
	if(typeof display == 'undefined')
		obj.style.visibility = "visible";
	else
		obj.style.display = "";
}
function printDoc(win,exc,display){
	if(exc){
		toHideArr = exc.split(",");	
		for(i=0 ; i< toHideArr.length ; i++){
			if(toHideArr[i])
				hideDocElement(toHideArr[i],display);
		}
	}
	
	win.focus();
	win.print();
	
	if(exc){
		for(i=0 ; i < toHideArr.length ; i++){
			if(toHideArr[i])
				unHideDocElement(toHideArr[i],display);
		}
	}
}
function bindCheckBoxes(box,boxes){
	 if(boxes){
	 	if(boxes.length){
			for(i=0;i<boxes.length;i++)
				boxes[i].checked = box.checked;
		}
		else{
			boxes.checked = box.checked;
		}
	 }	
}
function confirmSelection(frm,chkBoxName){
	retVal = 0;
	checkBoxes = frm.elements[chkBoxName];
	if(checkBoxes){
		if(checkBoxes.length){
			for(i=0;i<checkBoxes.length;i++){
				if(checkBoxes[i].checked)
					retVal++;
			}
		}
		else{
			if(checkBoxes.checked)
				retVal++;
		}
	}
	else{
		retVal = -1
	}
	
	return retVal;
	/*
	-1				If no check box exists in the document form
	0				If one more check boxes exist but no one is checked in the document form
	+ve integer		Total no of check boxes checked
	*/
	
}
function getTagData(StringWhole,tag){
	StringFrom = "<" + tag + ">"
	StringTo = "</" + tag + ">"
	
	NewString = StringWhole;
	RetString = "";
	
	fromVal = NewString.indexOf(StringFrom);
	startAt =  fromVal + StringFrom.length;
	toVal = NewString.indexOf(StringTo);
	
	pickLen = toVal - startAt;
	
	RetString =  NewString.substr(startAt,pickLen);
	
	return RetString;
}
function validateString(s,inValids){
	//t = "~,`,!,@,$,%,^,*,|,>,<,?,£,&";	
	t = "@,%,£,$,?,&,|";
	if(inValids)
		iV = inValids;
	else
		iV = t;
	
	iV = iV.split(",");
	
	for(i=0 ; i<iV.length; i++){
		if(s.indexOf(iV[i]) >= 0)
			return false;
	}
	return true;
}
function confirmPremier(val){
	startWizard("confirm_message.cfm",this.window,"400","350")
}
function proceedSubmit(hBtn,sBtn){
	document.getElementById(hBtn).style.display = 'none';
	document.getElementById(sBtn).style.display = '';
	return true;
}
function cancelSubmit(hBtn,sBtn){
	document.getElementById(hBtn).style.display = 'none';
	document.getElementById(sBtn).style.display = '';
	return true;
}
function confirmDiv(Msg,divHnd,msgHnd){
	mainCtrl = document.getElementById("outerDiv"); 

	if(mainCtrl){
		mainCtrl.style.top = 0;
		mainCtrl.style.left = 0;
		mainCtrl.style.width = '100%';
		mainCtrl.style.height = '100%';
		mainCtrl.style.display = '';
	}
	
	divCtrl = document.getElementById(divHnd);
	msgCtrl = document.getElementById(msgHnd);
	
	var xPos = ((screen.width - parseInt(divCtrl.style.width)) / 2) - (1 + incrementalVal);
	var yPos = ((screen.height - parseInt(divCtrl.style.height)) / 2) - (50 + incrementalVal);
	
	divCtrl.style.top = yPos;
	divCtrl.style.left = xPos;
	
	toggleWCs(0);
	
	msgCtrl.innerHTML = Msg;
	divCtrl.style.display = "";
	document.getElementById("confirmOk").focus();
}
function closeConfirm(divHnd){
	mainCtrl = document.getElementById("outerDiv"); 
	document.getElementById(divHnd).style.display = "none";
	toggleWCs(1);
	if(mainCtrl){
		mainCtrl.style.display = 'none';
	}
}
function toggleWCs(flag){
	if(!Client.Browser.IsIE())
		return;
		
	selects = document.getElementsByTagName("SELECT");
	for (i=0; i<selects.length; i++){
		elem = selects[i];
		if(flag == 0){
			elem.style.visibility = 'hidden';
		}
		else{
			elem.style.visibility = 'visible';
		}
	}
}