//GlobalCalls to all Forms

function getHTTPObject() {
  //-----------------------------
  /*  Create ajax object   */
  //-----------------------------
 var xmlhttp;

	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		microsoft= true;
	} catch (e1) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			microsoft= true;
		} catch (e2) {
			xmlhttp = null;
			microsoft= false;
		}
	}

	if (! xmlhttp) {
		if (typeof XMLHttpRequest != "undefined") {
			xmlhttp = new XMLHttpRequest();
			//if (xmlhttp.overrideMimeType) {
			//	xmlhttp.overrideMimeType('text/xml');				
			//{
			microsoft= false;	
		} else {
			xmlhttp = false;
			microsoft= false;
		}
	}
	
  return xmlhttp;
}

var http = getHTTPObject();   //Create AJAX Object

function doUpper(crtl){
 //-----------------------------
 /*  Select text to uppercase */
 //-----------------------------
crtl.value = crtl.value.toUpperCase();

return;
}

function delRow(currObj){
 //-------------------------------------------
 /*  Delete selected row and re-number gird   */
 //-------------------------------------------
 var current = window.event.srcElement;
 var i = 0;
 var id = 0;	
 var QString;
 var Valn = new Array;
 var QStr;
 
	  while( (currObj.tagName != "TR") && (currObj.tagName != null) ){
		currObj = currObj.parentElement;
	  }

	  var rowObj    = currObj;
	  //var cellCount = rowObj.cells.length;
	 // var tdObj     = rowObj.firstChild;
	 // var colValues = new Array( cellCount );            

	 for( i = 0; i < 1; i++ ) { //cellCount
				id = parseInt(rowObj.cells[i].childNodes[0].data); //cells[i].innerText);
	 }
	 //alert(id);
				
	//here we will delete the line
	while ( (current = current.parentElement)  && current.tagName !="TR"){
		//delete the entire row
		//current.parentElement.removeChild(current);
		currObj.parentElement.removeChild(currObj);
	}	 

	//Reduce counter for next item to grid
	counter = counter - 1;
	
	//Prepape to update Quantity String
	Qty=document.getElementById("hDetail").value;
	Valn = Qty.split("|");
	QStr="";
	
	for (i=0; i < Valn.length-1; i++) {
		 if (i==(id-1)){
		 	//remove deleted value from Quantity String
			Valn[i]="";
		} else {
		   //recreate value -Quantity String
		   QStr = QStr + Valn[i] + "|"; 
		}
	}
	
	//Renumber Grid
	 gdObj = document.getElementById("Grid");
	 
	 RenumberGrid(gdObj);
	
	 document.getElementById("hDetail").value = QStr;	
	
	 return;
 }


function RenumberGrid(gdObj){
//---------------------------------------
//Renumber grid positions after deletes
//---------------------------------------  
 p=1;

 for (i=1; i < gdObj.rows.length; i++) {
 	//Get current row
    myrow = gdObj.getElementsByTagName("tr")[i];
	
	if (p==1){ //odd numbers
		//Set the Odd background color of this row
		myrow.bgColor="#E9F0F5";
		p = 0;	
	} else {  //even numbers 
		//Set the Even background color of this row
		myrow.bgColor="#FDFBDB";
		p = 1;
	}
	
	for (j=0; j <  myrow.cells.length; j++) { 
		//Get current cell
		if (j == 0){
			mycel = myrow.cells[j];
			mycel.childNodes[0].data = i;
			continue;
		}	
	}
 }
 
 document.getElementById("LastCounter").value = i;
 //Clear the Items Field for new Lines
 ClearFields();
 return;
}