<script language="JavaScript" type="text/JavaScript">

var items = document.getElementsByTagName("*");
var myItems=[];var nn=-1;
var myItemType=[];

 for (var i = 0; i < items.length; ++i) {
 	 if(items[i].tagName == 'TEXTAREA' || items[i].tagName == 'INPUT') {	 
        nn=nn+1;
 	    myItems[nn]= items[i].name;
		myItemType[nn]= items[i].tagName;
  }
 }
 
 document.onkeydown = processKey;
 
function processKey(e) {
if (null == e) { e = window.event; } 
if (e.keyCode == 13) { e.keyCode=9;
      var myFocused=document.activeElement;
		for (var i = 0; i < myItems.length; ++i) {
			 if(myFocused.name==myItems[i] ){
				 e.keyCode=0;
				 document.getElementById(myItems[i+1]).focus();
				 if (myItemType[i+1] != 'TEXTAREA'){
				  document.getElementById(myItems[i+1]).select();
				 }else {
					//	document.getElementById(myItems[i+1]).focus();  
				  	  e.keyCode=0;
						var length = document.getElementById(myItems[i+1]).value.length;  
						document.getElementById(myItems[i+1]).setSelectionRange(length, length); 
				 }
				  break;
				 }
		    }
	} else if(e.keyCode==38) { e.keyCode =0;
     var myFocused=document.activeElement;
		for (var i = 0; i < myItems.length; ++i) {
			 if(myFocused.name==myItems[i] ){document.getElementById(myItems[i-1]).focus();
			 document.getElementById(myItems[i-1]).select(); break;}
		    }			
	} else if(e.keyCode==27) {confirmExit();} 
}
 
document.getElementById('<?php echo $FocusField;?>').focus();
 
if(screen.width<500){//get the screen width
   //get element form document
//   bloc1.style.display == 'none'; //toggle visibility
}
 
function submit(cmd,IDc){
   
// alert(cmd+" " +IDc);
$rq_value=document.getElementById("<?php echo $RequiredField;?>").value;
if(cmd=='sv' && $rq_value==''){
	 document.getElementById("<?php echo $RequiredField;?>").style.borderColor = "red";
	 return;
}

   if(cmd=='sv'){
		 if($rq_value!==''){
			 document.<?php echo $MyFormName;?>.action='_rs.php';
			 document.getElementById("<?php echo $MyFormName;?>").submit(); 
		 }
	}else if(cmd=='new'){
	document.cookie = '<?php echo $IDcField;?>=' + IDc;
	document.<?php echo $MyFormName;?>.action='_ad.php';
	document.getElementById("<?php echo $MyFormName;?>").submit(); 
	}else if(cmd=='dl'){
		if(IDc!==0){		
		  document.<?php echo $MyFormName;?>.action='_dl.php';
		  document.getElementById("<?php echo $MyFormName;?>").submit(); 
		}		  
	}
 }
 
function chkUpd(element){
	var chk=document.getElementById(element).value;
	if(chk==-1){chk=0;}else{chk=-1;}
	document.getElementById(element).value=chk;	
 } 
 

	
 window.onunload = refreshParent;
 function refreshParent() {
       // window.opener.location.reload();
 }
 
</script>