﻿function ConfirmDelete(what){
	if(confirm("Моля, потвърдете желанието си да изтриете "+what+"!")){
		return true;
	}else{
		return false;
	}
}

function addStateId(url, state_id){
	if(state_id > 0){
		window.location.href=url+'state_id/'+state_id+'/';
	}
}

function venLocationSelect(f, divid){
	
	if(divid == 'f1'){
		document.getElementById('locations_area').innerHTML = '';
	}
	
	if(f.selectedIndex == 0){
		document.getElementById('locations_area').innerHTML = '';
	}else{

		var url = '/ajax/locationSelect/location_id/'+f.value+'/';

		var params = '';
		var ajax = new Ajax.Updater(
			
			{success: 'locations_area'},
			url,
			{method: 'get', parameters: params, insertion: Insertion.Bottom , onFailure: reportError});
	}
}

function venCategorySelect(f, divid){
	
	if(divid == 'f1'){
		document.getElementById('categories_area').innerHTML = '';
	}
	
	if(f.selectedIndex == 0){
		document.getElementById('categories_area').innerHTML = '';
		
		document.getElementById('category_id').value = '1';
	}else{

		var url = '/ajax/categorySelect/category_id/'+f.value+'/';

		var params = '';
		var ajax = new Ajax.Updater(
			{success: 'categories_area'},
			url,
			{method: 'get', parameters: params, insertion: Insertion.Bottom , onFailure: reportError});
			
	}
}

	function reportError(request) {
		alert("Error"+request);
	}
	
function roll_image(img_name, img_src, w, h) {
	
	document[img_name].src = img_src;
	document[img_name].width = w;
	document[img_name].height = h;
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function showImage(file_name, width, height, item_id) {
	window.open('/show/index/name/'+file_name+'/area/custom/item_id/'+item_id+'/', 'image_win', 'width=800,height=600,resizable=0,scrollbars=0');	
}

function instCountSymbols(element){

	var symbols = $(element).value.length;

	if(symbols > 0){
		var rest = 100000 - symbols;
		
		if(rest > 0){
			$('inst_counts').innerHTML = rest;
		}else{
			$(element).value = $(element).value.slice(0,100000);
			$('inst_counts').innerHTML = 0;
		}
		
		$('inst_counts_container').show();
		
	}else{
		$('inst_counts_container').hide();
	}
}


function instCheckPrice(){
	//get the number of symbols
	var symbols = $('item_text').value;
	
	new Ajax.Request('/inst/check/index/text/'+symbols,
								{
									method: "get",

									onSuccess: function(transport){
										alert(transport.responseText);
									}
								}		
		);	 
}
