//this function opens a new window
// when the url, width, height, and position of the window is provided
function OpenWindow(URL,w,h,px,py)
{
 mywindow = window.open(URL,"mywindow","resizable,location=1,status=1,scrollbars=1,width="+ w + ",height=" + h)
 mywindow.moveTo(px,py)
 } 
/* this function takes a text box as an argument
it varifies its value if empty generates an error message
if not ask to confirm if the user is sure to make the changes
*/

/*function that ties the next available button control to the textbox a user pressed enter key in*/
 function checkReturn(obj, windowEv, ev) {

     var workingEvent = null;

     if (windowEv != null) workingEvent = windowEv;
     else if (ev != null) workingEvent = ev;

     if (workingEvent.keyCode == 13 || workingEvent.which == 13) {
         var form = window.document.forms[0];
         var clicknext = false;
         var nextobj;
         for (var i = 0; i < form.elements.length; i++) {
             if (form.elements[i] == obj) clicknext = true;

             if (clicknext) {
                 nextobj = form.elements[i];

                 if (nextobj.type.toUpperCase() == "BUTTON" || nextobj.type.toUpperCase() == "SUBMIT") {
                     // for google search, move focus from the search input textbox to avoid page submit or url redirection by other code
                     if (obj.id == "searchText" && nextobj.id == "searchButton")
                         nextobj.focus();
                         
                     var ua = navigator.userAgent;
                     var isOpera = ua.indexOf("Opera") > -1;
                     var isIE = ua.indexOf("compatible") > -1 && ua.indexOf("MSIE") > -1 && !isOpera;
                     if (isIE || isOpera) { // IE or opera                     
                         nextobj.click();
                     }
                     else {    // other browsers that do not support calling click() directly
                         var newEvent = document.createEvent("MouseEvents");
                         newEvent.initEvent("click", true, true);
                         nextobj.dispatchEvent(newEvent);   // trigger click event on the button object
                         ev.preventDefault();  // avoid the default behaviour of the browsers
                     }
                     break;
                 }
             }
         }
         return false;
     }
     return true;
 }

function Form1_onsubmit(box) {
if(box.value=="")
	{ 
	alert("A required field found empty")
	box.focus()
	return (false)
	}
else {
	if(confirm("are you shure you want to make changes"))
		return(true)
	else 
		return(false)
	}
}
/*this functions takes a stirng  and checks if its value is numeric or not return value is 
boolean true or false
function IsNumeric(sText)
{
var ValidChars="0123456789"
var Char
var IsNumber=true
 if(sText.length==0)
	{
	return false
	}
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i) 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false
         }
      }
   return IsNumber
   }*/

/*this functions takes a controle checks its value and if null error
if not numeric error other wise disable it
function ValidateBox(box)
{
	if(box.text=="")
	{
		alert("Pleas enter number of headings")
		box.focus()
		return (false)
	}
	//else if(isNumeric(box.text))
	//	return (true)
	else
	{
		alert("Please enter a numeric value")
		box.focus()
		return (false)
	}
}
*/


