function GetXmlHttpObject()
	{
		var xmlHttp=null;	
		try
		 {
			 // Firefox, Opera 8.0+, Safari
			 xmlHttp=new XMLHttpRequest();			
		 }
		catch (e)
		 {
			 // Internet Explorer
			 try
			  {
				  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");				
			  }
			 catch (e)
			  {
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");			
			  }
		 }
		return xmlHttp;		
}

function new_inv(){

	xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert("Browser does not support HTTP Request");
        return;
    }
		document.getElementById('refno').value ='';
		document.getElementById('category').value ='';
		document.getElementById('msg_box').innerHTML = "";
	
  	var url = "group_mas_data.php";
    url = url + "?Command=" + "new_inv"; 
 
    

    xmlHttp.onreadystatechange = re_new_inv;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}


function re_new_inv() {

    var XMLAddress1;

    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

    	 

		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("id");
        document.getElementById('refno').value = XMLAddress1[0].childNodes[0].nodeValue;

        XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("uniq");
        document.getElementById('uniq').value = XMLAddress1[0].childNodes[0].nodeValue;

    }
}

function save_inv(){   
	
			
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			} 	

			document.getElementById('msg_box').innerHTML = "";

		    if (document.getElementById('category').value == "") {
		        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Please Enter Group Name</span></div>";
		        return false;
		    }
	
			var url="group_mas_data.php";			
			url=url+"?Command="+"save_inv";
			url=url+"&refno="+document.getElementById('refno').value;
			url=url+"&category="+document.getElementById('category').value;
			
			xmlHttp.onreadystatechange=re_save_inv;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		
		
}

function re_save_inv()
{
	var XMLAddress1;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

		if (xmlHttp.responseText == "Saved") {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-success' role='alert'><span class='center-block'>Saved</span></div>";

            setTimeout("location.reload(true);", 500);

        } else {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
        }
	}
}

function update_inv(){   
	
			
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 	

	document.getElementById('msg_box').innerHTML = "";

    if (document.getElementById('category').value == "") {
        document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Please Enter Group Name</span></div>";
        return false;
    }

	var url="group_mas_data.php";			
	url=url+"?Command="+"update_inv";
	url=url+"&refno="+document.getElementById('refno').value;
	url=url+"&category="+document.getElementById('category').value;
	
	xmlHttp.onreadystatechange=re_update_inv;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
		
		
}

function re_update_inv()
{
	var XMLAddress1;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

		if (xmlHttp.responseText == "Updated") {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-success' role='alert'><span class='center-block'>Updated</span></div>";

            setTimeout("location.reload(true);", 500);

        } else {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
        }
	}
}


function cancel_inv(){ 

	var msg = confirm("Do you want to CANCEL this ! ");
    if (msg == true) {  
			
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			} 		
		
	
			var url="group_mas_data.php";			
			url=url+"?Command="+"cancel_inv";
			url=url+"&refno="+document.getElementById('refno').value;
		

			xmlHttp.onreadystatechange=re_cancel_inv;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
	}
			
}

function re_cancel_inv()
{
	var XMLAddress1;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

		if (xmlHttp.responseText == "Canceled") {
            document.getElementById('msg_box').innerHTML = "<div class='alert alert-success' role='alert'><span class='center-block'>Cancelled</span></div>";
 	
			setTimeout("location.reload(true);", 500);
		} else {
		    document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
		}
		
	}
	
}



function stono(REFNO, NAME)
{    
			document.getElementById('refno').value =REFNO;
			document.getElementById('category').value =NAME;
			
			
		/*	xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			} 		
			
			
			var url="search_ord_data.php";			
			url=url+"?Command="+"pass_invno";
			url=url+"&invno="+invno;
			url=url+"&stname="+stname;
			//alert(url);
					
			xmlHttp.onreadystatechange=passinvresult;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);*/
			
			
		
	
}


