//////// hight light table row ////////////////////////////////////
var maxIndustry = 3; // So luong nganh nghe toi da duoc chon khi search
var industry_count = 0; // So luong nganh nghe da chon
///////////////////////////////////////////////////////////////////

function displayContent(id, total){
	var i;
	for(i = 1; i <= total; i++){
		if(i == id){
			//$('#div'+i).fadeIn('slow');
			$('#div'+i).show();
		}else{
			$('#div'+i).hide();
		}
	}
}

function change_text(obj, str){
	if(obj.value == str){
		obj.value = '';
		obj.style.color = '#000000';
	}
}

function change_text_again(obj, str){
	if(!obj.value){
		obj.value = str;
		obj.style.color = '#989a97';
	}
}

function maxLength(obj,len){
	if(obj.value.length>len){
		obj.value= obj.value.substr(0,len);
	}
}

function showSalary(value) {
	if (value == 'usd') { // USD
		$('#salaryFrom_VN').hide();
		$('#salaryTo_VN').hide();
		$('#salaryFrom_USD').show();
		$('#salaryTo_USD').show();
	}else if (value == 'vnd') { // VND
		$('#salaryFrom_VN').show();
		$('#salaryTo_VN').show();
		$('#salaryFrom_USD').hide();
		$('#salaryTo_USD').hide();
	}else {
		$('#salaryFrom_VN').hide();
		$('#salaryTo_VN').hide();
		$('#salaryFrom_USD').hide();
		$('#salaryTo_USD').hide();
	}
}

function showHideCombo(value) {
	if (value == 1){
		$('#jsavesearch_receivetime').show();
	}else if (value == 2){
		$('#jsavesearch_receivetime').hide();
	}
}

function addIndustry() {
	var lst1 = document.getElementById('industry');
	var lst2 = document.getElementById('industry_selected');
	var i;
	for(i = 0; i < lst1.length; i ++) {
		if (lst1.options[i].selected) {
			if (industry_count == 3) {
				alert('Ban chi duoc chon toi da 3 nganh nghe');
			} else {
				if (GetItemIndex(lst2, lst1.options[i].value) == -1) {
					AddItem(lst2, lst1.options[i].text, lst1.options[i].value);
					industry_count ++;
				}
			}
		}
	}
}

function removeIndustry() {
	var lst1 = document.getElementById('industry');
	var lst2 = document.getElementById('industry_selected');
	var i = 0;
	while ( i < lst2.length ) {
		if (lst2.options[i].selected) {
			RemoveItem(lst2, lst2.options[i].value);
		}else
			i ++;
	}
	industry_count --;
}

function AddItem(objListBox, strText, strId)
{
  var n = objListBox.options.length;
  objListBox.options[n] = new Option(strText, strId);
}

function RemoveItem(objListBox, strId)
{
  var intIndex = GetItemIndex(objListBox, strId);
  if (intIndex != -1)
    objListBox.remove(intIndex);
}

function GetItemIndex(objListBox, strId)
{
  for (var i = 0; i < objListBox.length; i++)
  {
    var strCurrentValueId = objListBox.options[i].value;
    if (strId == strCurrentValueId)
    {
      return i;
    }
  }
  return -1;
}

function showHideId(id1, id2, value){
	if($('#'+value).val() == 1)
	{
		$('#'+ id1).show();
		$('#'+ id2).hide();
	}
	else
	{
		$('#'+ id1).hide();
		$('#'+ id2).show();
	}
}

function maxLength(oText, len) {
	if (oText.value.length>len) oText.value = oText.value.substr(0,len);
}

function limitLen(t,l){
	 var mlength=t.getAttribute? parseInt(t.getAttribute("maxlength")):"";
	 tmp=trim(t.value);
	 if(tmp.length > mlength) {
	 //alert('vuot qua');
		 t.value=tmp.substr(0,mlength)
		 t.focus();
	 }
	 l.value=mlength-t.value.length;
	 //alert(mlength-t.value.length);
}

function trim(val){
	return val.replace(/^\s+|\s+$/g,"");
}

function reloadLocation(path, parentId, targetID, width_option) {
	var url = path + '/modules/getlst_location.php?id=' + parentId + '&width=' + width_option;
	$.ajax({
	    url: url,
	    type: 'GET',
	    dataType: 'text/xml',
	    timeout: 10000,
	    error: function(){
	        //
	    },
	    success: function(stringdata){
	        $('#'+targetID).html(stringdata);
	    }
	});
}

function OpenWindow(windowUri, windowName, windowWidth, windowHeight, property )
{
	var centerWidth = (window.screen.width - windowWidth) / 2;
	var centerHeight = (window.screen.height - windowHeight - 60) / 2;

	newWindow = window.open(windowUri, windowName, 'width=' + windowWidth +
	',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight+ ',' + property);

	newWindow.focus();
	 //return newWindow.name;
}

function updateSelect(cal) {
	var date = cal.date;
	var selectMonth = document.getElementById("selectMonth");
	selectMonth.selectedIndex = date.getMonth();
	var selectDay = document.getElementById("selectDay");
	selectDay.selectedIndex = (date.getDate() - 1);
	var selectYear = document.getElementById("selectYear");
	var d = new Date();
	var curr_year = d.getFullYear();
	if(min_year == null) min_year = curr_year;
	selectYear.selectedIndex = (date.getFullYear() - min_year);
}