// JavaScript Document
var AjaxFile= SiteAdminPath+"ajax/ajax.php";
var loader_img = "<p align='center'><img src=\"images/ajax-loader.gif\"></p>";
var xmlhttp;
function showCategory(val) {
	if(document.getElementById("content_CategoryId").innerHTML!='')
	document.getElementById("content_CategoryId").innerHTML='';
	 
	if(document.getElementById("content_SectionId").value=='')
	AddItem('','- - Select - -');
	
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=SiteAdminPath+"/ajax/ajax.php?v="+val+"&PageAction=GetCategory&sid="+Math.random();
	xmlhttp.onreadystatechange=getstate;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function getstate() {
	if(xmlhttp.readyState==4) {
		var str = xmlhttp.responseText;
		var srtArray = new Array();
		var strfinalArray;
		var final='';
		
		srtArray = str.split("|");
		
		var j=(srtArray.length)-1;
		var i=0;
		while(j!=0) {
			final = srtArray[i];
			strfinalArray=final.split(",");
			AddItem(strfinalArray[0],strfinalArray[1]);
			i++;
			j--;
		}
	}
}	

function viewForm(id){
	document.getElementById("Reason").style.display="block";
 	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=SiteAdminPath+"/ajax/ajax.php?ID="+id+"&PageAction=GetReason&sid="+Math.random();
	xmlhttp.onreadystatechange=getReasonState;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}

function getReasonState() {
	if(xmlhttp.readyState==4) {
		var str = xmlhttp.responseText;
		var EmpArray = new Array();
		EmpArray = str.split("|");
		document.getElementById("EmployeeID").value = EmpArray [0];
		document.getElementById("reason-txt").value = EmpArray [1];
		document.getElementById("empname").value = EmpArray [2];
	}
}

function AddTempEmpOfMonth(EmpId) {
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=AjaxFile+"?Id="+EmpId+"&PageAction=AddTempEmpOfMonth";
	xmlhttp.onreadystatechange=getstate1;
	alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function RemoveTempEmpOfMonth(EmpId) {
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=AjaxFile+"?Id="+EmpId+"&PageAction=RemoveTempEmpOfMonth";
	xmlhttp.onreadystatechange=getstate1;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function RemoveAllEmpOfMonth() {
	document.getElementById('content').innerHTML=loader_img; 
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=AjaxFile+"?PageAction=RemoveAllEmpOfMonth";
	xmlhttp.onreadystatechange=getstate1;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function AddAllEmpOfMonth(EmpIds){
	document.getElementById('content').innerHTML=loader_img; 
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=AjaxFile+"?&EmpIds="+EmpIds+"&PageAction=AddAllEmpOfMonth";
	xmlhttp.onreadystatechange=getstate1;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function getstate1() {
	document.getElementById('main-content-box').style.display="none";
	document.getElementById('content').innerHTML="";
	document.getElementById('content').innerHTML=xmlhttp.responseText;
	if(xmlhttp.readyState==4) {
		var str = xmlhttp.responseText;
	}
}
function UpdateReason(id,position,value){
	var range=document.getElementById('count').value;
	for(i=0;i<range;i++){
	 var  sucid="status"+i;
	 document.getElementById(sucid).innerHTML=''; 
    }
	var txtid='reason'+position;
	var txtclass='class'+position;
	var Reason='';
	Reason=value;
	if(document.getElementById(txtid).value!=""){
	  if(txtclass=="none")	{
		document.getElementById(txtid).className='reason-exist-txt';
	  }else{
		document.getElementById(txtid).className='reason-exist-alt';   
	  }
	}
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=AjaxFile+"?Id="+id+"&PageAction=AddReason&reason="+Reason+"&pos="+position;
	var status='status'+position;
	xmlhttp.onreadystatechange=getstate2;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function getstate2() {
   var status = 'status'+xmlhttp.responseText;
   var Tarea  = xmlhttp.responseText;
   if(document.getElementById('reason'+Tarea).value!='')
   document.getElementById(status).innerHTML='<img src="'+SiteAdminPath+'images/tick.png" align="middle">';
}
function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
  // code for IE7+, Firefox, Chrome, Opera, Safari
	return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
  // code for IE6, IE5
	return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function AddItem(Value,Text) {
	// Create an Option object        
	var opt = document.createElement("option");
	// Add an Option object to Drop Down/List Box
	document.getElementById("content_CategoryId").options.add(opt);
	// Assign text and value to Option object
	opt.text = Text;
	opt.value = Value;
}

function showEventByDate(date,month,year){
	var X = (document.body.clientWidth)/2;
	var Y = (document.body.clientHeight)/4;
	
	X = X + document.documentElement.scrollLeft;
	Y = Y + document.documentElement.scrollTop;
	
	document.getElementById("background").style.display="block";
	document.getElementById("eventdiv").style.left = (X-250)+"px";
	document.getElementById("eventdiv").style.top = (Y+100)+"px";
	document.getElementById("eventdiv").style.display="block";
	
    document.getElementById('eventdiv').innerHTML=loader_img;
	var date=year+"-"+month+"-"+date;
	xmlhttp=GetXmlHttpObject();
	if(xmlhttp!=null) {
	var url=AjaxFile+"?PageAction=GetEvent&date="+date;
	xmlhttp.onreadystatechange=showEventByDateComplete;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	} else {
	alert("Your browser doesn't support xmlhttp");
	return;
	}
}
function showEventByDateComplete(){
	document.getElementById('eventdiv').innerHTML=xmlhttp.responseText;
}
function hideDiv(divid){
  document.getElementById("background").style.display="none";
  document.getElementById(divid).style.display="none";
}

