var xmlHttp

function showHint(str,act)
{
	if (str.length==0)
	{
		document.getElementById("txtHint").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="http://radiodream.ru/ajax/gethint.php";
	url=url+"?q="+str;
	url=url+"&act="+act;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function showimage(str,act)
{
	str="<img src="+str+" class=\"imagecache imagecache-product\" width=\"200\" />";
	document.getElementById(act).innerHTML=str;
}


function showmodels(str,act)
{
	if (str.length==0)
	{
		document.getElementById(act).innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="http://radiodream.ru/ajax/gethint.php";
	url=url+"?q="+str;
	url=url+"&act="+act;

	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4)
		{
			document.getElementById(act).innerHTML=xmlHttp.responseText;
		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function loadModel_ie(id,act)//id,source,act,withany, crc32values, cfg)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	//alert('There was a problem with the request.');
	
	var ind = document.getElementById(id).selectedIndex;
	if (ind>0) 
	{ 
		var str=document.getElementById(id).options[ind].value;
		var url="/catalog/"+document.getElementById(id).options[ind].value+"/"+document.getElementById(id).options[ind].text;
		//window.open(url,"_self");
	}
	
    var url="/ajax/gethint.php";
	url=url+"?q="+str;
	url=url+"&act="+act;
	var response='';

	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			response=xmlHttp.responseText;
			var text_test="linhduy@vuduylinh@giangtuy";
			myvar = response.split("@");
			//alert(response);
			//document.getElementById('producer1').innerHTML=response;
			//alert('There was a problem with the request.');

			var myselect = document.getElementById(act);
			myselect.innerHTML = '';
			el = document.createElement("OPTION");
			el.value='0';
			el.innerHTML ="Выбери Модель";
			myselect.appendChild(el);
			myOnChange = function()
			{
				var new_act=act.replace("mobile_model","detail");

				//alert(myselect.options[myselect.selectedIndex].value+"=="+new_act);
				showmodels_detail(myselect.options[myselect.selectedIndex].value,new_act);
			};//("firefox", "location.href=myselect.options[myselect.selectedIndex].value");


			for (var i = 0; i < myvar.length; i++)
			{
				myvalues = myvar[i].split("#");
				if(myvalues[0]!='')
				{
				el = document.createElement("OPTION");
				el.value=myvalues[0];
				el.innerHTML =myvalues[1];
				myselect.appendChild(el);
				}
			}
			myselect.onchange=myOnChange;

		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadModel(str,act)//id,source,act,withany, crc32values, cfg)
{

	if (str.length==0)
	{
		document.getElementById(act).innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="/ajax/gethint.php";
	url=url+"?q="+str;
	url=url+"&act="+act;
	var response='';
	//alert('There was a problem with the request.');



	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			response=xmlHttp.responseText;
			var text_test="linhduy@vuduylinh@giangtuy";
			myvar = response.split("@");
			//alert(response);
			//document.getElementById('producer1').innerHTML=response;
			//alert('There was a problem with the request.');

			var myselect = document.getElementById(act);
			myselect.innerHTML = '';
			el = document.createElement("OPTION");
			el.value='0';
			el.innerHTML ="Выбери Модель";
			myselect.appendChild(el);
			myOnChange = function()
			{
				var new_act=act.replace("mobile_model","detail");

				//alert(myselect.options[myselect.selectedIndex].value+"=="+new_act);
				showmodels_detail(myselect.options[myselect.selectedIndex].value,new_act);
			};//("firefox", "location.href=myselect.options[myselect.selectedIndex].value");


			for (var i = 0; i < myvar.length; i++)
			{
				myvalues = myvar[i].split("#");
				el = document.createElement("OPTION");
				el.value=myvalues[0];
				el.innerHTML =myvalues[1];
				myselect.appendChild(el);
			}
			myselect.onchange=myOnChange;

		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showmodels_detail(str,act)
{
	if (str.length==0)
	{
		document.getElementById(act).innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="/ajax/gethint.php";
	url=url+"?q="+str;
	url=url+"&act="+act;
	//alert ("Your "+url);
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var response=xmlHttp.responseText;
			arr=response.split("@VDL@");
			var new_act=act.replace("detail","photo");
			var img="<img src=/"+arr[0]+" class=\"imagecache imagecache-product\" />";
			document.getElementById(new_act).innerHTML=img;
			for (var i = 1; i < arr.length; i++)
			{
				var new_id=act+'_'+i;
				//alert(new_id);
			    document.getElementById(new_id).innerHTML=arr[i];
			}
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function loadModel_test(str,act)//id,source,act,withany, crc32values, cfg)
{
	if (str.length==0)
	{
		document.getElementById(act).innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="http://radiodream.ru/ajax/gethint.php";
	url=url+"?q="+str;
	url=url+"&act="+act;
	var response='';
	alert('There was a problem with the request.');
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			response=xmlHttp.responseText;
			alert('There was a problem with the request.');
			document.getElementById('producer1').innerHTML=response;
			alert('There was a problem with the request.');

			var select = document.getElementById('auto_model');

			alert('There was a '+i);
			var el = document.createElement('OPTION');
			alert('There was a '+i);
			el.value='tester'+i;
			el.innerHTML = 'tester'+i;
			select.appendChild(el);
			alert('There in a '+i);
		}
	};

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function makePOSTRequest(str, act)
{

	var url="http://radiodream.ru/ajax/gethint.php";

	http_request = false;
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	parameters="?q="+str+"&act="+act;
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}
function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
			document.getElementById('producer2').innerHTML = result;
		} else {
			alert('There was a problem with the request.');
		}
	}
}









function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


function loadModel_tmp(str,act)//id,source,act,withany, crc32values, cfg)
{

	/*var i='10';
	alert('There was a ');
	var myselect = document.getElementById('auto_model');

	//create an option
	alert('There in a ');

	theOption=document.createElement("OPTION");

	//make some text
	alert('There was a '+i);
	theText=document.createTextNode("Select A Page To Go");

	//add the text to the option
	alert('There was a '+i);
	theOption.appendChild(theText);

	//add the option to the select
	alert('There was a '+i);
	myselect.appendChild(theOption);
	alert('There was a '+i);
	*/
	myOnChange = function()
	{
		alert('ok');
	};//("firefox", "location.href=myselect.options[myselect.selectedIndex].value");
	var myselect = document.getElementById('auto_model');
	myselect.innerHTML = '';
	for (var i = 300; i < 310; i++)
	{
		alert('There was a '+i);
		el = document.createElement("OPTION");
		el.value='http://radiodream.ru/node/'+i;
		el.innerHTML = 'http://radiodream.ru/node/'+i;;
		myselect.appendChild(el);
	}
	myselect.onchange=myOnChange;

	//document.getElementById(act).innerHTML=xmlHttp.responseText;

}
