function validateForm() {
	var from;
	var to;
	var flag = 1;
	var expression = /^[0-9.]*$/;
	if(from = document.getElementById("from")) {
		if(from.value.length == 0) {
			flag = 2;
		}
		if(!expression.test(from.value)) {
			alert("Please put a number in From field");
			from.value = "";
			flag = 0;
		}
	}
	if(to = document.getElementById("to")) {
		if(!expression.test(to.value)) {
			alert("Please put a number in To field");
			to.value = "";
			flag = 0;
		}
		if(flag == 2) {
			if(to.value.length != 0)
				from.value = 0;
			flag = 1;
		}				
	}
	if(flag == 1)
		document.form1.submit();
}

function buy(url) {
	location = url;
}

function other(name) {
	var sel;
	var other;
	if(sel = document.getElementById("categs")) {
		if(sel.options[sel.selectedIndex].value == -1) {
			if(other = document.getElementById("o_categs")) {
				other.disabled=false;
			}
		}
		else {
			if(other = document.getElementById("o_categs")) {
				other.value = "";
				other.disabled=true;
				default_url(sel.options[sel.selectedIndex].value, "");
			}
		}
	}
}

function getIMG(aff){
	setQueryString(aff);
	var url="./images_left.php";
	httpRequest("POST",url,true, 1);
}

function setQueryString(aff){
	queryString = "aff="+encodeURIComponent(aff);
}

function default_url(c_id, c_name) {
	var p_name = document.getElementById('new_name').value;
	setQueryString1(p_name, c_id, c_name);
	var url="./default_url.php";
	httpRequest("POST",url,true, 2);	
}

function setQueryString1(p_name, c_id, c_name) {
	queryString = "product_name="+encodeURIComponent(p_name)+"&cat_id="+encodeURIComponent(c_id)+"&cat_name="+encodeURIComponent(c_name);
}

function httpRequest(reqType,url,asynch,option){
	//Mozilla-based browsers
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest(  );
	} 
	else if (window.ActiveXObject){
		request=new ActiveXObject("Msxml2.XMLHTTP");
		if (! request){
			request=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	//the request could still be null if neither ActiveXObject
	//initialization succeeded
	if(request){
		initReq(reqType,url,asynch,option);
	} 
	else {
		alert("Your browser does not permit the use of all of this application's features!");
	}
}

function initReq(reqType,url,isAsynch,option){
	/* Specify the function that will handle the HTTP response */
	if(option == 1)
		request.onreadystatechange=handleResponse;
	else if(option == 2)
		request.onreadystatechange=handleURL;
	request.open(reqType,url,isAsynch);
	/* Set the Content-Type header for a POST request */
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	request.send(queryString);
}

//event handler for XMLHttpRequest
function handleResponse(  ){
	if(request.readyState == 4){
		if(request.status == 200){
			document.getElementById('progr').innerHTML = request.responseText;
		} 
		else {
			alert("A problem occurred with communicating between the XMLHttpRequest object and the server program.");
		}
	}//end outer if
}

function handleURL(  ){
	if(request.readyState == 4){
		if(request.status == 200){
			document.getElementById('def_url').value = request.responseText;
		} 
		else {
			alert("A problem occurred with communicating between the XMLHttpRequest object and the server program.");
		}
	}//end outer if
}