/*function optionCheck(option)
{
	var tmp=document.getElementById("optionHead");
	var nameChechedOld=tmp.getAttributeNode("checkedOption").nodeValue;
	var chekedOld=document.getElementById(nameChechedOld);
	
	document.getElementById(nameChechedOld+"_").style.backgroundColor="#E2EBED";
	tmp.getAttributeNode("checkedOption").nodeValue=option;

	document.getElementById(option+"_").style.backgroundColor="#FFF";
	chekedOld.style.display="none";
	document.getElementById(option).style.display="block";
	
}
*/
function selectDisable(com)
{
	var d=document;
	if(com=='yes')
	{
		d.getElementById('Country').setAttribute("disabled","yes");
		d.getElementById('Category').setAttribute("disabled","yes");
		d.getElementById('Title').setAttribute("disabled","yes");
	}
	else
	{
		d.getElementById('Country').removeAttribute("disabled");
		d.getElementById('Category').removeAttribute("disabled");
		d.getElementById('Title').removeAttribute("disabled");
	}
}

function getSelectedOpt(opt)
{
	var ObjSelected=opt.options[opt.options.selectedIndex]
	return (ObjSelected.getAttribute('rm')=='no')? '':ObjSelected.value;	
}

var ajaxObject;
function updateGetFeedStart(form)
{
	selectDisable("yes");
	ajaxObject = new sack();
//	showStatusBarMessage('Loading data...');
	var Country=(!form)? "":getSelectedOpt(form.Country);
	var Category=(!form)? "":getSelectedOpt(form.Category);
	var Title=(!form)? "":getSelectedOpt(form.Title);

	ajaxObject.requestFile = 'DB_files/updateGetFeed.php?Country='+Country+'&Category='+Category+'&Title='+Title+'&T3=&T4=&Url=';
//alert(ajaxObject.requestFile);
	ajaxObject.onCompletion = function(){updateGetFeedEnd();}
	ajaxObject.runAJAX();
}

function updateGetFeedEnd()
{
	var rssContentXml = ajaxObject.response;
//alert("YES"+rssContentXml);
	var selects=rssContentXml.split("\n");
	
	updateSelectTag(document.getElementById('Country'),selects[0].split('|'));
	updateSelectTag(document.getElementById('Category'),selects[1].split('|'));
	updateSelectTag(document.getElementById('Title'),selects[2].split('|'));
//	updateSelectTag(document.getElementById('T3'),selects[3].split('|'));
//	updateSelectTag(document.getElementById('T4'),selects[4].split('|'));
	document.getElementById('rssUrl').value=selects[3].split('|')[0];
	selectDisable("no");
}

function cleanSelect(sel)
{
	while (sel.options.length!=1)
	{
		
		if(sel.firstChild.getAttribute==null || sel.firstChild.getAttribute('rm')!='no')
			sel.removeChild(sel.firstChild);
		else sel.removeChild(sel.lastChild);
	}
}
function updateSelectTag(selectTag,options)
{
//	for(i=0;i<selectTag.childNodes.leight;i++)selectTag.removeChild(selectTag.firstChild);
	
	cleanSelect(selectTag);

	var elem;
	var attr;
	if(options[0]!='')
	{
		elem=document.createElement("option");
		//attr=document.createAttribute("value");
		//attr.value=options[i];
		elem.setAttribute("value",options[0]);
		elem.setAttribute("selected","yes");
		elem.innerHTML=options[0];
		selectTag.appendChild(elem);
	}
	for(var i=1;i<options.length;i++)
	{
		if(options[i]!='')
		{
			elem=document.createElement("option");
			//attr=document.createAttribute("value");
			//attr.value=options[i];
			elem.setAttribute("value",options[i]);
			elem.innerHTML=options[i];
			selectTag.appendChild(elem);
		}
	}
	
//		selectTag.innerHtml+='<option value="'+options[opt]+'">'+options[opt]+'</option>';
}

function printSearch(text)
{
	document.getElementById('searchContainerRes').innerHTML=text;
	document.getElementById('searchContainer').style.display="block";
}

function UTF8escape(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";
	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		} else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		} else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}

function GetSearch(form,page)
{
	var i;
	for(i=0;i<form.actions.length;i++)
		if(form.actions[i].checked) break;
	if (form.actions[i].value!='td_web') return true;
	ajax=new sack("search.php?from="+page+"&q="+UTF8escape(form.q.value));
	ajax.onCompletion=function(){printSearch(ajax.response)};
	ajax.runAJAX();
	return false;
}

function NextSearch(page)
{
	GetSearch(document.getElementById("form1"),page);
}
