﻿function get_dropdown(obj, number){
	
	var obj1 = document.getElementById('searchBy1');
	var obj2 = document.getElementById('searchBy2');
	var obj3 = document.getElementById('searchBy3');
	
	var val1 = obj1.options[obj1.selectedIndex].value;
	var val2 = obj1.options[obj2.selectedIndex].value;
	var val3 = obj1.options[obj3.selectedIndex].value;
	
	var cobj1 = document.getElementById('SearchCriteria1');
	var cobj2 = document.getElementById('SearchCriteria2');
	var cobj3 = document.getElementById('SearchCriteria3');
	
	var cval1 = cobj1.options[cobj1.selectedIndex].value;
	var cval2 = cobj2.options[cobj2.selectedIndex].value;
	var cval3 = cobj3.options[cobj3.selectedIndex].value;

	var fobj1 = document.getElementById('filter1');
	var fobj2 = document.getElementById('filter2');
	
	var filter1 = fobj1.options[fobj1.selectedIndex].value;
	var filter2 = fobj2.options[fobj2.selectedIndex].value;
	
	//alert("S1 "+cval1+" S2 "+cval2+" S3"+cval3);
	
	var params = "action=dropdown_fill&field1="+val1+"&field2="+val2+"&field3="+val3+"&obj_number="+number+"&value1="+cval1+"&value2="+cval2+"&value3="+cval3+"&filter1="+filter1+"&filter2="+filter2;
	ajax_request(params);
	
}

function search_request(number){
	
	var obj1 = document.getElementById('searchBy1');
	var obj2 = document.getElementById('searchBy2');
	var obj3 = document.getElementById('searchBy3');
	
	var val1 = obj1.options[obj1.selectedIndex].value;
	var val2 = obj1.options[obj2.selectedIndex].value;
	var val3 = obj1.options[obj3.selectedIndex].value;
	
	var cobj1 = document.getElementById('SearchCriteria1');
	var cobj2 = document.getElementById('SearchCriteria2');
	var cobj3 = document.getElementById('SearchCriteria3');
	
	var cval1 = cobj1.options[cobj1.selectedIndex].value;
	var cval2 = cobj2.options[cobj2.selectedIndex].value;
	var cval3 = cobj3.options[cobj3.selectedIndex].value;

	var fobj1 = document.getElementById('filter1');
	var fobj2 = document.getElementById('filter2');
	
	var filter1 = fobj1.options[fobj1.selectedIndex].value;
	var filter2 = fobj2.options[fobj2.selectedIndex].value;
	
	
	var params = "action=search&field1="+val1+"&field2="+val2+"&field3="+val3+"&obj_number="+number+"&value1="+cval1+"&value2="+cval2+"&value3="+cval3+"&filter1="+filter1+"&filter2="+filter2;
	ajax_request(params);
	
}
function update_search_cr(obj_id){
	var y1 = document.getElementById('year_s1');
	var y2 = document.getElementById('year_s2');

	var update_obj = document.getElementById(obj_id);
	
	var val1 = y1.options[y1.selectedIndex].value;
	var val2 = y2.options[y2.selectedIndex].value;
	
	update_obj.options[update_obj.selectedIndex].value = val1+"-"+val2;
	//alert(update_obj.options[update_obj.selectedIndex].value);
}

function ajax_request(params){
	var xmlHttp;
	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;
			}
		}
	}
	xmlHttp.open("POST",'./dropdown_search_actions.php',true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			var txt = xmlHttp.responseText;
			//alert(txt);
			txt = txt.replace(/\n/g, '');
			txt = txt.replace(/\r/g, '');
			txt = txt.replace(/\t/g, '');

			eval(txt);
		}
	}
	xmlHttp.send(params);
}