
function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
  return obj_window;
}

function help(pagename) {
	newWindow (pagename, 'help', 500, 300, 1, 0, 0, 0, 0, 0, 0);
}

function EnableDisable(id) {
     body=document.getElementById(id);
     if (body) {
       if (body.style.display == 'none') {
         try {
           body.style.display='table-row';
         } catch(e) {
           body.style.display = 'block';
         }
       }
       else {
         body.style.display = 'none';
       }
     }
}

function SetText (id, text) {
	body=document.getElementById(id);
	if (body) {
		body.innerHTML  = text;
	}
}



function Disable(id) {
	body=document.getElementById(id);
     if (body) {
     	body.style.display = 'none';
     }
}

function Enable(id) {
     body=document.getElementById(id);
     if (body) {
         try {
           body.style.display='table-row';
         } catch(e) {
           body.style.display = 'block';
         }
     }
}

function formCheck(formobj){
	// name of mandatory fields
	fieldRequired = formobj.RequiredString.value.split (",");
	fieldDescription = formobj.RequiredStringDescription.value.split (",");
	
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].text == "----" || obj.value== "----" || obj.value == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "file":
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				else {
					if (obj.id == 1) {
						// -- Then this is an e-mail field.
						// -- Check the e-mail
						var Check = 0;
						Check = obj.value;;
					 	if ((Check.indexOf ('@',0) == -1) || (Check.indexOf ('.',0) == -1)) {
							 alertMsg += " - " + fieldDescription[i] + " is invalid." + "\n";
					    }
					}
				}
				break;
			case "password":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
				
			default:
			}
			
			if (obj.type == undefined){
				// then it must be a checkbox or radio
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					//var obj = formobj.elements[Options[k]];
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
	
	
	if (alertMsg.length == l_Msg){
		//return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function storeCaret (textEl) {
	if (textEl.createTextRange)
	 textEl.caretPos = document.selection.createRange().duplicate();
	}
	function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
	 var caretPos = textEl.caretPos;
	 caretPos.text =
		caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text + ' ' : text;
	}
	else
	 textEl.value = text;
	}

 function onKeyDown(textE2)
 {
	 var e = window.event;
	 if (e.keyCode == 9) // tab
	 {
		insertAtCaret(textE2, "\t")
		 return false;
	 }
	 return true;
 }
 
 function redirect(URL){
 	window.location.assign(URL);
 }

function rhino_tell () {
	var tellurl = 'modules/friend/';
	newWindow(tellurl, 'Print', '400', '300', 0, 0, 0, 0, 0, 0, 0);
}

function getXMLHTTP() 
	{ //fuction to return the xml http object
		var xmlhttp=false;
			
		try{xmlhttp=new XMLHttpRequest();}
		catch(e)	
		{		
			try{xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e)
			{
				try{req = new ActiveXObject("Msxml2.XMLHTTP");}
				catch(e1){xmlhttp=false;}
			}
		}
		 	
		return xmlhttp;
	}
