

function on_land(land_element,hover_image_src) {
	
	//var land_element = document.getElementById(land_id);
	land_element.src = hover_image_src;
	//land_element.style.borderLeft = "1px solid red";
	//land_element.style.borderRight = "1px solid red";
	//land_element.style.borderBottom = "1px solid red";
}

function out_land(land_element,image_src) {
	land_element.src = image_src;
	var landBox = document.getElementById("landBox");
	if (landBox != null) {
		//landBox.style.display="none";
	}
}

function hide_panel(obj_name) {
	try {
		var menu = document.getElementById(obj_name);
		if (menu.style.display == "") {
			menu.style.display = "none";
		} else {
			menu.style.display = "";
		}
	} catch (e) {
		
	}
	
}

function hide2panels(firstPanel,secondPanel) {
	hide_panel(firstPanel);
	hide_panel(secondPanel);
}

function view_message(el_id) {
	var el = document.getElementById(el_id);
	if (el.style.display == "") {
		el.style.display = "none";
	} else {
		el.style.display = "";
	}
}

function get_time(time_obj) {
	var obj = document.getElementById(time_obj);
	//alert(time_obj);
	var result = obj.innerHTML.split(":");
	//alert("r:" .result);
	return result;
}

function show_food_resource(production,max) {
	var current_value, prod;
		current_value = document.getElementById("food_resource").innerHTML;
		current_value = parseInt(current_value);
		
		if (current_value > max ) {
			current_value = max;
		}
		if (parseInt(current_value + production) < max) { 
		//	alert(current_value);
	//	alert(max);
		  prod = current_value + production;
		} else {
			prod = current_value;
		}
		//alert(prod);
		prod = parseInt(prod);
		
		document.getElementById("food_resource").innerHTML = prod;
		var interval = 1000 * 60;
		setTimeout("show_food_resource(" + production + "," + max + ")",interval );
		
}

function show_gold_resource(production,max) {
	var current_value, prod;
		current_value = document.getElementById("gold_resource").innerHTML;
		current_value = parseInt(current_value);
		
		if (current_value > max ) {
			current_value = max;
		}
		if (parseInt(current_value + production) < max) { 
			//alert(current_value + " " + max);
		//alert(max);
		
		  prod = current_value + production;
		} else {
			prod = current_value;
		}
		//alert(prod);
		prod = parseInt(prod);
		//
		document.getElementById("gold_resource").innerHTML = prod;
		var interval = 1000 * 60;
		setTimeout("show_gold_resource(" + production + "," + max + ")",interval );
		
}


function show_lumber_resource(production,max) {
	var current_value, prod;
		current_value = document.getElementById("lumber_resource").innerHTML;
		current_value = parseInt(current_value);
		
		if (current_value > max ) {
			current_value = max;
		}
		if (parseInt(current_value + production) < max) { 
			//alert(current_value + " " + max);
		//alert(max);
		
		  prod = current_value + production;
		} else {
			prod = current_value;
		}
		//alert(prod);
		prod = parseInt(prod);
		//
		document.getElementById("lumber_resource").innerHTML = prod;
		var interval = 1000 * 60;
		setTimeout("show_lumber_resource(" + production + "," + max + ")",interval );
		
}

function show_iron_resource(production,max) {
	var current_value, prod;
		current_value = document.getElementById("iron_resource").innerHTML;
		current_value = parseInt(current_value);
		
		if (current_value > max ) {
			current_value = max;
		}
		if (parseInt(current_value + production) < max) { 
			//alert(current_value + " " + max);
		//alert(max);
		
		  prod = current_value + production;
		} else {
			prod = current_value;
		}
		//alert(prod);
		prod = parseInt(prod);
		//
		document.getElementById("iron_resource").innerHTML = prod;
		var interval = 1000 * 60;
		setTimeout("show_iron_resource(" + production + "," + max + ")",interval );
		
}

function show_people_resource(production,max) {
	var current_value, prod;
		current_value = document.getElementById("people_resource").innerHTML;
		current_value = parseInt(current_value);
		
		if (current_value > max ) {
			current_value = max;
		}
		if (parseInt(current_value + production) < max) { 
			//alert(current_value + " " + max);
		//alert(max);
		
		  prod = current_value + production;
		} else {
			prod = current_value;
		}
		//alert(prod);
		prod = parseInt(prod);
		//
		document.getElementById("people_resource").innerHTML = prod;
		var interval = 1000 * 60;
		setTimeout("show_people_resource(" + production + "," + max + ")",interval );
		
}

function show_resource(res_object,production,max) {
	try {
		var current_value, prod;
		current_value = document.getElementById(res_object).innerHTML;
		current_value = parseFloat(current_value);
		if (current_value > max ) {
			current_value = max;
		}
		if (parseInt(current_value + production) < max) { 
		  prod = current_value + production;
		} else {
			prod = current_value;
		}
		prod = parseInt(prod);
		document.getElementById(res_object).innerHTML = prod;
		var interval = 1000;
		setTimeout("show_resource(\"" + res_object + "\"," + production + ")",interval );
	}  catch(e) {
          return false;
    }
    return true;
}


function show_time(time_obj,form_object,progress) {
      
   try {
      var txtTime,time,hours,minutes,seconds, time_result;
    //  time = new Date();
    	time_result = get_time(time_obj);
    	txtTime = timer_decrease(time_result,progress);
      
      //	alert(seconds);
      	
        
        document.getElementById(time_obj).innerHTML = txtTime;
            
        } catch(e) {
          return false;
        }
      //  alert(txtTime);
        if (txtTime == "0:0:0") {
        //	alert("time end");
      		document.getElementById(form_object).submit();
      	} else {
        	setTimeout("show_time(\"" + time_obj + "\",\"" + form_object + "\",\"" + progress + "\")",1000);
      	}
        return true; 
        
}
    
  
function timer_decrease(time_result,progress) {
	
	var hours   = time_result[0];	
    var minutes = time_result[1];
    var seconds = time_result[2];
   
  //  alert(Number.parse(seconds));
    if (seconds > 0) {
    	seconds = seconds - 1;
    } //else {
    //	alert("test seconds");
    //}
    
    if (seconds == 0) {
    	
    	if (minutes > 0) {
    		seconds = 59;
    		minutes = minutes - 1;
    		
    		
    		// set progress increase
    		var prvalue = $("#" + progress).progressbar('option', 'value');
			prvalue = prvalue + 1;
    		$("#" + progress).progressbar('option', 'value', prvalue);
    									
    	}
    	
    }
    
    if (minutes == 0) {
    	if (hours > 0) {
    		minutes = 59;
    		hours = hours - 1;
    	}
    	
    }
    
    if (hours == 0) {
    	hours = 0;
    }
    
   // if (seconds < 10) { seconds_txt = "0" + seconds; } else { seconds_txt = seconds; }
  //  if (minutes < 10) { minutes_txt = "0" + minutes; } else { minutes_txt = minutes; }
  //  if (hours < 10) { hours_txt = "0" + hours; } else { hours_txt = hours; }
    
    time_result[0] = seconds;
    time_result[1] = minutes;
    time_result[2] = hours;
    
    if (seconds == 0 && minutes == 0 && hours == 0) {
    	// submit form
    	
    }
    txtTime = hours + ":" + minutes + ":" + seconds;
    return txtTime;
}