var AJAX_PATH;
if(IS_BACKEND){ AJAX_PATH = "../ajax/"; IMAGE_PATH = "../images/";}
else{ AJAX_PATH = "ajax/"; IMAGE_PATH = "images/";}
function addAreaOfStudy(){
	
		area = document.getElementById("salary_place");		
		val = document.getElementById("addareaofstudy").value;		
		
		
		xmlHttp_addareaofstudy = getHttpRequest();
		loading = document.getElementById("loading_area");
		loading.innerHTML = ' &nbsp;Please Wait...<img src = "../images/indicator.gif" width="15">';
		xmlHttp_addareaofstudy.onreadystatechange = function(){
				if(xmlHttp_addareaofstudy.readyState == 4){
						msg = xmlHttp_addareaofstudy.responseText;
						if(msg == 'Already exists') alert(msg)
						else area.innerHTML = msg;
						loading.innerHTML = '';
				}
		}		
		
		
		xmlHttp_addareaofstudy.open("GET",AJAX_PATH+"addareaofstudy.php?parent="+0+"&area="+val,true);
		xmlHttp_addareaofstudy.send(null);
}
function addSubAreaOfStudy(){
		
		area_ = document.getElementById("salary_place");		
		val_ = document.getElementById("salary").options[document.getElementById("salary").selectedIndex].value;
		area = document.getElementById("openings_place");		
		val = document.getElementById("addsubareaofstudy").value;
		if(val == ""){alert("Input Sub Area of Study"); return false;}
		xmlHttp_addsubareaofstudy = getHttpRequest();
		
		loading = document.getElementById("loading_subarea");
		loading.innerHTML = ' &nbsp;Please Wait...<img src = "../images/indicator.gif" width="15"> ';
		xmlHttp_addsubareaofstudy.onreadystatechange = function(){
				if(xmlHttp_addsubareaofstudy.readyState == 4){
						msg = xmlHttp_addsubareaofstudy.responseText;
						loading.innerHTML = '';
						if(msg == 'Already exists') alert(msg)
						else area.innerHTML = msg;
						
				}
		}
		
		
		xmlHttp_addsubareaofstudy.open("GET",AJAX_PATH+"addsubareaofstudy.php?parent="+val_+"&area="+val,true);
		xmlHttp_addsubareaofstudy.send(null);
}
function selectAreaOfStudy(f,def){
	var b=0;
		xmlHttp_areaofstudy = getHttpRequest();
		subarea = document.getElementById("openings_place");
		loading = document.getElementById("loading_area");
		xmlHttp_areaofstudy.onreadystatechange = function(){
				if(xmlHttp_areaofstudy.readyState == 4){
						msg = xmlHttp_areaofstudy.responseText;	
						document.getElementById("openings").readonly = false;
						subarea.innerHTML = msg;
						
						loading.innerHTML = '';
				}
		}
		val = f.options[f.selectedIndex].value;
		if(IS_BACKEND) b = 1;
		document.getElementById("openings").readonly = true;
		loading.innerHTML = ' &nbsp;Please Wait...<img src = "'+IMAGE_PATH+'indicator.gif" width="15"> ';
		
		xmlHttp_areaofstudy.open("GET",AJAX_PATH+"areaofstudy.php?area="+val+"&def="+def+"&backend="+b,true);
		xmlHttp_areaofstudy.send(null);
}
function login(button,jobid){
		if(username = prompt("Username")){
				if(password = prompt("Password")){
						xmlHttp_login = getHttpRequest();
						xmlHttp_login.onreadystatechange = function(){
								if(xmlHttp_login.readyState == 4){
										msg = xmlHttp_login.responseText;
										if(msg == "success"){
												button.onclick = applyJob(button,jobid);
												button.value = "Apply For The Job";
										}else{
												alert("Invalid Login Attempt");
										}
								}
						}
						xmlHttp_login.open("GET",AJAX_PATH+"login.php?username="+username+"&password="+password,true);
						xmlHttp_login.send(null);
				}
		}
}
function removeFromBasket(button,jobid,tbl){
		if(confirm("Are you sure want to remove this item from your basket?")){
			button.innerHTML = "Removing From Your Basket......";			
			xmlHttp_removeFromBasket = getHttpRequest();
			xmlHttp_removeFromBasket.onreadystatechange = function(){
					if(xmlHttp_removeFromBasket.readyState == 4){
							button.onclick = "";
							button.innerHTML = xmlHttp_removeFromBasket.responseText;
					}
			}
			xmlHttp_removeFromBasket.open("GET",AJAX_PATH+"removeFromBasket.php?id="+jobid+"&tbl="+tbl,true);
			xmlHttp_removeFromBasket.send(null);	 
	}
}
function addToBasket(button,jobid,tbl){
		if(confirm("Are you sure want to add this item in your basket?")){
			button.innerHTML = "Adding To Your Basket......";			
			xmlHttp_addToBasket = getHttpRequest();
			xmlHttp_addToBasket.onreadystatechange = function(){
					if(xmlHttp_addToBasket.readyState == 4){
							button.onclick = "";
							button.innerHTML = xmlHttp_addToBasket.responseText;
							
					}
			}
			xmlHttp_addToBasket.open("GET",AJAX_PATH+"addToBasket.php?id="+jobid+"&tbl="+tbl,true);
			xmlHttp_addToBasket.send(null);	 
	}
}
function showJobs(f){
		id = f.options[f.selectedIndex].value;
		window.location.href = "index.php?page=jobs&category="+id;
}
function findSimilarJobs(cat){
	
		form = document.getElementById("quick_search");
		form.qs_category.value = cat;
		
		form.qs_keyword.value = "";
		form.what.value = "job";	
		
		redirectSearchPage(form);
}
function applyJob(button,jobid){
	if(confirm("Are you sure want to apply for this job?")){
			button.value = "Applying......";
			button.disabled = true;
			xmlHttp_applyJob = getHttpRequest();
			xmlHttp_applyJob.onreadystatechange = function(){
					if(xmlHttp_applyJob.readyState == 4){
							button.value = xmlHttp_applyJob.responseText;
							button.disabled = false;
							button.onclick = "";
					}
			}
			xmlHttp_applyJob.open("GET",AJAX_PATH+"applyJob.php?jobid="+jobid,true);
			xmlHttp_applyJob.send(null);	 
	}
}
function checkUserIdAvailability(type){
		userid = document.getElementById('userid').value;
		if(userid == ""){ alert("Input Desired UserID"); return false;}
		document.getElementById('useridavailable').innerHTML  = "<img src=\""+IMAGE_PATH+"/indicator.gif\" width=15> Please Wait..";
		xmlHttp_checkuserid = getHttpRequest();
		xmlHttp_checkuserid.onreadystatechange = function(){
				if(xmlHttp_checkuserid.readyState == 4){
						document.getElementById('useridavailable').innerHTML = xmlHttp_checkuserid.responseText;
				}
		}
		xmlHttp_checkuserid.open("GET",AJAX_PATH+"checkUserAvailable.php?type="+type+"&userid="+userid,true);
		xmlHttp_checkuserid.send(null);	 
}
function confirmDelete(act){
		if(confirm("Are you sure want to delete this item?"))
		window.location.href = act;
}
function _addDepartment(company){
		if(val = prompt("Add Department\nPlease Input Department Name")){
				window.location.href = "act_edit_department.php?company="+company+"&val="+val+"&act=add";
		}
}
function editDepartment(depart,company){
		if(val = prompt("Edit Department\nPlease Input The New Name For Department")){
				window.location.href = "act_edit_department.php?depart="+depart+"&company="+company+"&val="+val+"&act=edit";
		}
}
function addCategory(){
	list = false;
	if(addCategory.arguments[1] != null){
		catid = addCategory.arguments[1];
		list = true;
	}else{
		catid = document.getElementById("category").options[document.getElementById("category").selectedIndex].value;
	}
	if(addCategory.arguments[0] == "remove"){
			if(confirm("Warning !!\nAre you sure want to remove this category/subcategory\nAll the subcategories within this category will be removed, if exists")){	
					xmlHttp_addcat = getHttpRequest();
					xmlHttp_addcat.onreadystatechange = function(){
							if(xmlHttp_addcat.readyState == 4){
									
									if(list){
										listCategories();
									}else{
										loadCategory(catid);
									}
									alert(xmlHttp_addcat.responseText);
							}
					}
					xmlHttp_addcat.open("GET",AJAX_PATH+"addCategory.php?type="+addCategory.arguments[0]+"&parent="+catid,true);
					xmlHttp_addcat.send(null);	   
			}				
	}
	else if(addCategory.arguments[0] == "edit"){
		if(confirm("Are you sure want to edit "+addCategory.arguments[0]+" category?")){
			if(category = prompt("Please input the new category name")){
			
				xmlHttp_addcat = getHttpRequest();
				xmlHttp_addcat.onreadystatechange = function(){
						if(xmlHttp_addcat.readyState == 4){			
								
								if(list){
										listCategories();									
								}else{
									loadCategory(catid);
								}
								alert(xmlHttp_addcat.responseText);
						}
				}
				xmlHttp_addcat.open("GET",AJAX_PATH+"addCategory.php?type="+addCategory.arguments[0]+"&val="+category+"&parent="+catid,true);
				xmlHttp_addcat.send(null);
			}
		}
	}
	else if(confirm("Are you sure want to add "+addCategory.arguments[0]+" category?")){
			if(category = prompt("Please input the category name")){
			
				xmlHttp_addcat = getHttpRequest();
				xmlHttp_addcat.onreadystatechange = function(){
						if(xmlHttp_addcat.readyState == 4){			
								
								if(list){
										listCategories();									
								}else{
									loadCategory(catid);
								}
								alert(xmlHttp_addcat.responseText);
						}
				}
				xmlHttp_addcat.open("GET",AJAX_PATH+"addCategory.php?type="+addCategory.arguments[0]+"&val="+category+"&parent="+catid,true);
				xmlHttp_addcat.send(null);
			}
	}
}
function loadCategory(catid){
		xmlHttp_loadcat = getHttpRequest();
		xmlHttp_loadcat.onreadystatechange = function(){
				if(xmlHttp_loadcat.readyState == 4){
						
						document.getElementById("dropdowncategory").innerHTML = xmlHttp_loadcat.responseText;
				}
		}
		xmlHttp_loadcat.open("GET",AJAX_PATH+"loadCategory.php?catid="+catid,true);
		xmlHttp_loadcat.send(null);
}
function listCategories(){
		xmlHttp_listcat = getHttpRequest();
		xmlHttp_listcat.onreadystatechange = function(){
				if(xmlHttp_listcat.readyState == 4){	
					
						document.getElementById("listCategory").innerHTML = xmlHttp_listcat.responseText;
				}
		}
		xmlHttp_listcat.open("GET",AJAX_PATH+"listCategory.php",true);
		xmlHttp_listcat.send(null);
}
function addDepartment(c,id){
		company = c;
		
		cf = document.getElementById("selectCompany");
		company = cf.options[cf.selectedIndex].value;
		if(company == "" || c == ""){ alert("Please Select Company First"); return false;}

		department = document.getElementById(c).value;
		if(department == ""){
			alert("Input Department Name");
			return false;
		}
		xmlHttp_depart = getHttpRequest();
		xmlHttp_depart.onreadystatechange = function(){
				if(xmlHttp_depart.readyState == 4){
						loadDepartments(company,id);
						alert(xmlHttp_depart.responseText);
				}
		}
		xmlHttp_depart.open("GET",AJAX_PATH+"addDepartment.php?company="+company+"&depart="+department,true);
		xmlHttp_depart.send(null);
}
function getHttpRequest(){
	
	try{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}catch (e){
	  	// Internet Explorer
  		try{
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}catch (e){
    		try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}catch (e){
			      alert("Your browser does not support AJAX!");
      			  return false;
      		}
    	}
  	}
	return xmlHttp;
	
}
function loadDepartments(c,id){	
	company = c;
	
	
		xmlHttp = getHttpRequest();
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4){			
				msgs=xmlHttp.responseText;
				document.getElementById("depart").innerHTML = msgs;
			}
		}
		xmlHttp.open("GET",AJAX_PATH+"loadDepartments.php?company="+company+"&sel="+id,true);
		xmlHttp.send(null);
	
}

function changeOnclick(f,val){
	if(f.value == val)
	f.value = "";
}
function changeBlur(f,val){
	if(f.value == "") f.value = val;
}
function advancedSearch(){
	document.getElementById("quickSearch").style.display = "none";
	document.getElementById("advancedSearch").style.display = "block";
}
function quickSearch(){
	document.getElementById("quickSearch").style.display = "block";
	document.getElementById("advancedSearch").style.display = "none";
}
function search_date(s){
		if(s.value != ""){
				document.getElementById("demo1").disabled = true;
				document.getElementById("demo2").disabled = true;
		}else{
				document.getElementById("demo1").disabled = false;
				document.getElementById("demo2").disabled = false;
		}
}
function setMax(m){
	max_ = document.getElementById("as_max_salary");
	min_ = document.getElementById("as_min_salary");
	max_.options.length = 0;
	max_.options[0] = new Option("No Limit","");
	var k = 1;
	i = parseInt(min_.value);
	for(;i<=1000000;i+=5000){		
		max_.options[k] = new Option(i,i);
		k++;		
	}
	if(min_.value != "" && min_.value != "less 5000" && min_.value != "greater 1000000")
	max_.options[k] = new Option("1000000 <","greater 1000000");
}
function redirectSearchPage(f){
	var page;
	
	page = "programs";
	f.action = "index.php?page="+page+"&q_search";
	f.submit();
	
}
function closeSearchBox(){
		document.getElementById("quickSearch").style.display = "none";
	document.getElementById("advancedSearch").style.display = "none";
}
