// JavaScript Document
var xmlHttp;

function getXMLHttpRequest(){
	var xmlHttp=null;
	try{// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}catch(e){
		try{ // Internet Explorer
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
   		 }catch(e){
   			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   		 }
	}
	return xmlHttp;
}

function BN(obj){
	return document.getElementById(obj);
	}
function getCombo(obj){
	var w=document.getElementById(obj).selectedIndex;
	return document.getElementById(obj).options[w].text;
	//alert(DAB("hdd").value);
	
}	
function emptyText(obj){
		if(document.getElementById(obj).value==""){
			document.getElementById(obj).style.background = 'Yellow';
			return 1;
			}
			else{
					return 0;
				}
		}
		
//add application			
function startadd(){
	
xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
if(emptyText("txtapp")){
		alert("Enter an application name");
		return 1;
		}
		
		if(emptyText("txtdes")){
		alert("Application descripion is required");
		return 1;
		}
		
if(emptyText("txtappurl")){
	alert("Supply a URL");
	return 1;
	}	

	var dx=document.getElementById("datex1").value;
	var de=document.getElementById("datex2").value;
	
	
	app=document.getElementById("txtapp").value;
	des=document.getElementById("txtdes").value;
	txtappurl=document.getElementById("txtappurl").value;
	
	url="save_app.php?" + "app=" + app + "&des=" + des + "&dx=" + dx + "&de=" + de + "&appid=" + app+"&txtappurl="+txtappurl;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			alert(xx);
			//document.getElementById("txtapp").value="";
			window.location="application.php";
			document.getElementById("txtapp").value="";
	document.getElementById("txtdes").value="";
	document.getElementById("datex1").value="";
	document.getElementById("datex2").value="";
	

		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	
}

//add menu
function add_menu(){
	
xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
if(emptyText("txtmenu")){
		alert("Enter an menu name");
		return 1;
		}

if(emptyText("txturl")){
	alert("Enter a module url");
	return 1;
	}
	menu=document.getElementById("txtmenu").value;
	appid=document.getElementById("cboapp").value;
	txtdes=document.getElementById("txtdes").value;
	txturl=document.getElementById("txturl").value;
	url="save_menu.php?" + "menu=" + menu + "&appid=" + appid + "&txtdes=" + txtdes+"&txturl="+txturl;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			alert(xx);
			//document.getElementById("txtapp").value="";
			window.location="applicationmodule.php";
			document.getElementById("txtdes").value="";
	document.getElementById("menu").value="";
	
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	
}

//edit menu

function edit_menu(){
	
xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
if(emptyText("txtmenu")){
		alert("Enter an menu name");
		return 1;
		}

	if(emptyText("txturl")){
		alert("Enter a module URL");
		return 1;
		}
	menu=document.getElementById("txtmenu").value;
	appid=document.getElementById("cboapp").value;
	txtdes=document.getElementById("txtdes").value;
	txturl=document.getElementById("txturl").value;
	url="edit_menu.php?" + "menu=" + menu + "&appid=" + appid + "&txtdes=" + txtdes+"&txturl="+txturl;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			alert(xx);
			//document.getElementById("txtapp").value="";
			window.location="applicationmodule.php";
			document.getElementById("txtdes").value="";
	document.getElementById("menu").value="";
	
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	
}

function startedit(){	
xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
if(emptyText("txtapp")){
		alert("Enter an application name");
		return 1;
		}
		
		if(emptyText("txtdes")){
		alert("Application descripion is required");
		return 1;
		}
	
	
var dx=document.getElementById("datex1").value;
		var de=document.getElementById("datex2").value;
	
	
	app=document.getElementById("txtapp").value;
	des=document.getElementById("txtdes").value;
	txtappurl=document.getElementById("txtappurl").value;
	url="edit_app.php?" + "app=" + app + "&des=" + des + "&dx=" + dx + "&de=" + de + "&appid=" + app+"&txtappurl="+txtappurl;
		xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			alert(xx);
			window.location="application.php";
			document.getElementById("txtapp").value="";
	document.getElementById("txtdes").value="";
	document.getElementById("date1").value="";
	document.getElementById("date2").value="";
	
	
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);	
}
//Delete app
function deleapp(){
	
	txtapp=document.getElementById("txtapp").value;
	if(txtapp==""){
			alert("Supply application you wish to delete");
			return 1;
		}
		var d=confirm("Do you really want to delete application");
	if(!d){
		return 1;
		}
		
	qry="delete from tbl_Application where Application="+ "'" + txtapp + "'";
	xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
	url="func.php?" + "qry=" + qry;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			
			alert(xx);
			window.location="index.php";
		document.getElementById("txtapp").value="";
		document.getElementById("txtdes").value="";
		
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	}
//Delete menu
function delemenu(){
	txtmenu=document.getElementById("txtmenu").value;
	appid=document.getElementById("cboapp").value;
	if(txtmenu==""){
		alert("Supply the menu you wish to delete");
		return 1;
		}
		var d=confirm("Do you really want to delete menu");
		if(!d){
			return 1;
		}
	qry="delete from tbl_applicationModule where ModuleName="+ "'" + txtmenu + "'"+ " and ApplicationModuleID="+"'"+appid+"'";
	xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
	url="func.php?" + "qry=" + qry;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			
			alert(xx);
			//loadgrid();
		document.getElementById("txtmenu").value="";
		document.getElementById("txtdes").value="";
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	}


//load data 2 function
function loaddata2(){
	
	cboapp=document.getElementById("cboapp").value;
	txtmenu=document.getElementById("txtmenu").value;
	xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
	url="getdetail2.php?" + "cboapp=" + cboapp+"&txtmenu="+txtmenu;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			
			document.getElementById("txtdes").value=xx;
		
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	}

//load data function

function loaddata(){
	
	app=document.getElementById("txtapp").value;
	xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser does not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
url="getdetail.php?" + "app=" + app;
	

	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;
			//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			
			document.getElementById("txtdes").value=xx;
		
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
	}
//get combo
function getC(sql,fld,id,cbo,param){
	xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	//alert(sql);
clearcb(cbo);
addToCombo(param + "_0",cbo);

	url="lista.php?" + "qry=" + sql + "&fld=" + fld+"&id="+id;
		xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			
			if(xx==""){
				return 1;
				}
			var sp=xx.split(",");
			v=sp.length;
			var i;
			
			for(i=0;i<=v;i++){
				
				if(!sp[i]==""){
					addToCombo(sp[i],cbo);
							}
						}
					}		
				}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);	
	
	}
	
	function dogetC(){		
		var app=document.getElementById("cboapp").value;
		var qry="select * from tbl_applicationmodule where application_id='" + app + "'";
		getC(qry,"module_name","application_module_id","cbomenu","Select Module");
		}
	function dogetCk(){
			var qry="select * from tbl_applicationmodule where application_id=" + "'1'";
			document.getElementById("cbomenu").style.width="100px";
			getC(qry,"module_name","application_module_id","cbomenu","Select Module");
			}
		
function addToCombo(str,cbo)
	{
		var sp=str.split("_");
		
	  var elOptNew = document.createElement('option');
	  elOptNew.text = sp[0];
	  elOptNew.value = sp[1];
	  if(elOptNew.text==""){
		  return 1;
		  }
	  var elSel = document.getElementById(cbo);
	
	  try {
		elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	  }
	  catch(ex) {
		elSel.add(elOptNew); // IE only
	  }
	}
//Clear combo box
function clearcb(cb){
	var myList = document.getElementById(cb);

/* Initialize the mySelect list box */
for(var count = myList.options.length - 1; count >= 0; count--)
    {
        myList.options[count] = null;
    }
	}
	
function startedits(){	
	
xmlHttp=getXMLHttpRequest();
	if(xmlHttp==null){
		alert("Your browser dose not support Ajax \n Try viewing this page with Internet Explorer \n or browsers with Ajax functionality");
		return;
	}
	
if(emptyText("txtapp")){
		alert("Enter an application name");
		return 1;
		}
		
		if(emptyText("txtdes")){
		alert("Application descripion is required");
		return 1;
		}
	
	
var dx=document.getElementById("datex1").value;
		var de=document.getElementById("datex2").value;
	
	
	app=document.getElementById("txtapp").value;
	des=document.getElementById("txtdes").value;
	txtappurl=document.getElementById("txtappurl").value;
	txtid=document.getElementById("txtid").value;
	url="edit_app.php?" + "app=" + app + "&des=" + des + "&dx=" + dx + "&de=" + de + "&appid=" + app+"&txtappurl="+txtappurl+"&txtid="+txtid;
		xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==4){ 
			var xx=xmlHttp.responseText;//get id txtBrand to change inner HTML
			//document.getElementById("txtfee").value=xx;
			alert(xx);
	window.location="index.php";
		}		
	}
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);	
}
