/*Public variables*/
var in_request=0;
var flagOpa = 0;
var min_opacity=0;
var max_opacity=1;
var ResponseValue='';
var my_width  = 0;
var my_height = 0;
document.uploading = false;
/*----------------*/


/*Common_functions*/
function toggle_content(block_id){
	if ($(block_id + "_content").className == "invisible"){
		$(block_id + "_content").className = "block_content";
		$(block_id + "_pointer").src = "/images/point_down.gif";
	}else{
		$(block_id + "_content").className = "invisible";
		$(block_id + "_pointer").src = "/images/point_right.gif";
	};
}

function toggle_box(box_id){
	if ($(box_id).checked) {
		$(box_id + "_img").src = "/images/checkbox_em.png";
		$(box_id).checked = false;
	}else{
		$(box_id + "_img").src = "/images/checkbox_ch.png";
		$(box_id).checked = true;
	};
}


function toggle_search_box(box_id){
	if (!$(box_id).checked) {
		for (i in Boxes) {
			if ($(Boxes[i]).checked && Boxes[i] != box_id) {
				$(Boxes[i] + "_img").src = "/images/checkbox_em.png";
				$(Boxes[i]).checked = false;
			}
		}
		$(box_id + "_img").src = "/images/checkbox_ch.png";
		$(box_id).checked = true;
	};
}

function toggle_list(field) {
	$(field).className = $(field).className=='invisible' ? '' : 'invisible';
	$(field + '_full').className = $(field + '_full').className=='invisible' ? '' : 'invisible';
}


function check_srch() {
	if($("srch_q").value=="") {
		alert("Введите запрос!");
		return false;
	}
	if($("srch_q").value.length<3) {
		alert("Вы ввели слишком короткий запрос!");
		return false;
	}
	return true;
}

function MyTip(value){Tip(value, SHADOW, true,FONTCOLOR, '#465B6B',BGCOLOR,'#E9F1F5', BORDERCOLOR, '#A3D5CB', LEFT, false, FADEIN, 200, FADEOUT, 50);}
function MyTipBalloon(value, width) {
	if(!width) width=300;
	Tip(value, BALLOON, true,ABOVE, true, FADEIN, 200, FADEOUT, 50, WIDTH, width);
}
/*-----------------------------*/

/*Ajax request*/
function Request(Type, Method, Id_form, Id_recepient, Id_loading, LoadingHTML, Module, Action, Params, FuncCallBack) {
	if(Id_recepient.length > 0 || Id_loading.length > 0) {
		if(LoadingHTML.length==0) LoadingHTML = '<div style="color:#555555;font-size: 11px; text-align:center; position: relative; padding: 60px 0px;"><b>Загрузка...</b><br><br><img src="/images/loading.gif"/></div>';
		$(Id_loading.length > 0 ? Id_loading : Id_recepient).innerHTML = LoadingHTML;
	}
	var Url = '/index.php?dyn_type&module=' + Module + '&action=' + Action;
	var Parameters = "";
	if (Id_form.length > 0) Parameters += $(Id_form).serialize() + "&";
	if (Params.length > 0) Parameters += Params;
	//if(!FuncCallBack) FuncCallBack = returnResponse;
	
	if(Type=='Updater') new Ajax.Updater(Id_recepient,Url,{method: Method.toLowerCase(), parameters: Parameters, evalScripts: true, onComplete: FuncCallBack, onFailure: requestError});
	else new Ajax.Request(Url,{method: Method.toLowerCase(), parameters: Parameters, evalScripts: true, onComplete: FuncCallBack, onFailure: requestError});
	
	return true;
}

function returnResponse(originalRequest) {
	ResponseValue = clearResponseText(originalRequest.responseText);
	return true;
}

function requestError() {
	//showMessage("An error occured while trying to connect to server<br>through Ajax. Please, reload page and try again.","fatal");
	alert("Во время подключения к серверу произошла ошибка.<br />Перезагрузите страницу и попробуйте ещё раз.","fatal");
	return false;
}

function clearResponseText(text){
 	text = text.replace(/^ */, '');
	text = text.replace(/ *$/, '');
	text = text.replace(/\n/, '');
	text = text.replace(/\r/, '');
	return text;
}
/*------------------------*/

function debugObj(obj,del){
	str = '';
	for(prop in obj)
		str += prop + del;
	return str;
}


