
function browerGroups(country){
   
   showCountryFlag(country);
   var _curregion = $j("#brower_country").val();
   var param = "region="+_curregion+"&categoryId="+curCategoryId;
   if(key != '') param += "&key=" + key;
   var url = urlPath+"/g/search_init.do?"+param;
   window.location.href = url;
}


function showCountryFlag(country){
   try{
		var flag = "http://static.groups.im/group/msngroup/enp4/imagesq/contries/flagblank.gif";
		if (country != "") {
			flag = "http://static.groups.im/group/msngroup/enp4/imagesq/contries/" + country + ".gif";
		}
		$j("#contryFlag").attr({ src:flag}); 
	}catch(e){}
}


function changeCls(obj,cls){
	$j("#"+obj).removeClass();
	$j("#"+obj).addClass(cls);
 }
 
 
var browerCategoryId = -1;

var ty = "";
function showSearchType(type){
    ty = type;
	if(type){
	    if(searchKey == "" || searchKey == inputKey)
	      searchKey = $j("#search_key1").attr("value");
		$j("#normalSearch").hide();
		$j("#advancedSearch").show();
		
		$j("#search_country").val(region);
		$j("#search_category").val(ca);
	}else{
	    if(searchKey == "" || searchKey == inputKey){
          searchKey = $j("#search_key2").attr("value");
        }
		$j("#advancedSearch").hide();
		$j("#normalSearch").show();
	}
	if(searchKey != ""){
		$j("input[name='key']").val(searchKey);
	}
}

function inputKeyClear(){	
	if($j("input[name='key']").val() ==  inputKey){
		$j("input[name='key']").val("");
	}
	searchKey = "";
}

function cloneKey(){
    var sk = "";
    if(ty){
      sk = $j("#search_key2").attr("value");
    }else{
      sk = $j("#search_key1").attr("value");
    }
    searchKey = $j.trim(sk);
}


function search(type){
    if(ty == "")
      searchKey = $j("input[name='key']").attr("value");
    if(searchKey ==  inputKey){
		searchKey = '';
	}
	curRegion = region;
	curCategoryId = -1;
	if(ca != '-1'){
	  curCategoryId = ca;
	}
	if(type){
		curRegion = $j("#search_country").val();
		curCategoryId = $j("#search_category").val();
	}
	
    var param = "region="+curRegion+"&categoryId="+curCategoryId;
    if(searchKey != ""){
      param += "&key="+$j.trim(searchKey);
   	}
	var url = urlPath + '/g/search_init.do?'+param;
	window.location.href = url;
}

/*
function resetKey(key){
	if(key == ""){
		$j("input[name='key']").val(inputKey);
		searchKey = "";
	}
}
*/

function goCreateGroup(){
	$j("#gn").val(searchKey);
	$j("#goCGForm").submit();
}

function setPassportAdd(gid,mp){
	//if(navigator.appName == "Microsoft Internet Explorer"){
		//window.location.href="msnim:add?contact="+gp;
	//}else{
		_commJs.quickJoin(gid,mp);
	//}
}


function setCountry()
{
 if(region != '' || ca != '-1'){
  if(totalCount == 0){
    showSearchType(true);
  }
  showCountryFlag(region);
  var country = document.getElementById('brower_country');
  country.value = region;
  
  setCategory();
  }
  if(key != ''){
    $j("input[name='key']").val(key);
  }
  
}

function setCategory()
{
    if(ca != browerCategoryId){
		changeCls("category_"+browerCategoryId,"");
		//$j("#"+"category_"+browerCategoryId).css({"background-repeat": "no-repeat","background-position":"0 -1000px"});
	}
	changeCls("category_"+ca,"sel2");
	$j("#"+"category_"+ca).css({"background-position":"2px 5px"});
	curCategoryId = ca;
	browerCategoryId = ca;
}


