var SEARCH_LIMIT = 15;
var sel_index = 0;
UserLogin.cityLov({
	callback:function(str) {
	    var res = eval('['+str+']');
	    var arr = res[0].Rows;
	    var lov = document.getElementById('searchcity');var txt = document.getElementById("citytxt"); txt = (txt != null) ? txt.value : 0;	    
	    for (i=0; i< arr.length; i++) {
	    	var obj = arr[i];	    	
	    	var option = document.createElement("option");
	    	option.value = obj.city_id;	  
	    	option.appendChild(document.createTextNode(obj.city_name));
	    	if (parseInt(txt) == parseInt(obj.city_id)) {sel_index = (i + 1);option.setAttribute('selected','selected');}
	    	lov.appendChild(option);	    	
	    }
	    delete arr;
	    delete res;
	},
	failure:function(message) {
		alert(message)
	}
});
function indexSearch(val) {
	window.location = projPath+'/yelloSearch.do?function=getIndex&ind='+val;
}
function keydownSearch(e) {
	var evt=(e)?e:(window.event)?window.event:null;
	if(evt){
		var key=(evt.charCode)?evt.charCode:
			((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
		if(key=="13") {
			yelloSearch();
		}		
	}
}

function addEvent( obj, type, fn ) {
    if ( obj.attachEvent ) {
	    obj['e'+type+fn] = fn;
	    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
	    obj.attachEvent( 'on'+type, obj[type+fn] );
	} else
	    obj.addEventListener( type, fn, false );
}

function keydownnavi(e,obj) {
	var evt=(e)?e:(window.event)?window.event:null;
	if(evt){
		var key=(evt.charCode)?evt.charCode:((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));		
		if(key=="13") {
			var currvalue = parseInt(document.getElementById('currvalue').value);					
			if (obj.value == '' && currvalue == 1) yelloSearch(0);
			else if (obj.value == '' && currvalue > 1) yelloSearch(currvalue - 1);			
			else { 
				var bin = parseInt(obj.value);
				var last = parseInt(document.getElementById("lastvalue").value);
				if (bin > last) {yelloSearch(last-1);}
				else if (bin <=1) yelloSearch(0);
				else yelloSearch(bin -1)
			}
		}
		if (key ==8 || key == 37 || key == 39 || key == 46) return true;
		if (key <=47 || key >= 59) return false;
		return true;
	}
}

function yelloSearch(val) {
    var arr = document.getElementsByName('radio');    
    for (i=0; i<arr.length; i++) {if (arr[i].checked) {document.getElementById("passquery").value = arr[i].value;break;}}
    document.getElementById("keystring").value = document.getElementById('keytext').value;
    document.getElementById("start_val").value = (typeof val == 'undefined')? 0 : val;
    SEARCH_LIMIT = 15;
    document.getElementById("limit_val").value = SEARCH_LIMIT;
    document.getElementById("grp_id").value = 0;
    document.getElementById("status").value = 'normal';    
    document.searchform.submit();
}
function groupSearch(grpval,name) {//alert(grpval);alert(name)
	var arr = document.getElementsByName('radio');    
    for (i=0; i<arr.length; i++) {if (arr[i].checked) {document.getElementById("passquery").value = arr[i].value;break;}}
    document.getElementById("keystring").value = name;
    document.getElementById("start_val").value = (typeof val == 'undefined')? 0 : val;
    SEARCH_LIMIT = 10;
    document.getElementById("limit_val").value = SEARCH_LIMIT;
    document.getElementById("grp_id").value = grpval;
    document.getElementById("status").value = 'grp'
    document.searchform.submit();
}
function naviSearch(opt) {
	var currvalue = parseInt(document.getElementById("currvalue").value);
	var lastvalue = parseInt(document.getElementById("lastvalue").value);
	var arr = document.getElementsByName('radio');
	for (i=0; i<arr.length; i++) {if (arr[i].checked) {document.getElementById("passquery").value = arr[i].value;break;}}	
	document.getElementById("keystring").value = document.getElementById('searchtxt').value;
	document.getElementById("start_val").value = (opt == 'prev') ? currvalue -2 : (opt == 'first') ? 0 : (opt == 'last') ? (lastvalue - 1) : currvalue;
    document.getElementById("limit_val").value = SEARCH_LIMIT;
    document.getElementById("searchcity").selectedIndex = sel_index;
    document.getElementById("grp_id").value = document.getElementById("grouptxt").value;
    document.getElementById("status").value = document.getElementById("statustxt").value;
    document.searchform.submit();
}
var tiparr = {'both':'e.g. Builders, Tour Operators, YelloIndex, Hoobla etc.','company':'e.g.  YelloIndex, Hoobla, Centum etc.','classification':'e.g. Builders, Tour Operators, Banks, Architects etc.','brand':'e.g. Nokia, Sony, Suzuki, Mobile Phones, Automobiles etc.'};
var radio = document.getElementsByTagName('input');
for(i=0; i<radio.length; i++) {
	if (radio[i].type != 'radio') continue;	
	if (radio[i].checked && document.getElementById('tipradio') != null) document.getElementById('tipradio').innerHTML = tiparr[radio[i].value];
	addEvent(radio[i],'click',function() {
		document.getElementById('tipradio').innerHTML = tiparr[this.value];
	});
}

