
function bindFuncAjaxGet(bindObjects, bindEvent, hrefField, resultFunction, question)
{
	$(bindObjects).bind(bindEvent, function(){
		var href ;
		var protocol = hrefField.substr(0,7);
		if (protocol=='http://') {
			href = hrefField;
		}
		else {
			href = $(this).attr(hrefField);
		}
		if ((question==undefined) || (confirm(question))) {
			$.get(href, {}, resultFunction);
		}
		return false;
	});
}

function bindConfirmedAjaxGet(bindObjects, bindEvent, hrefField, resultObjects, question)
{
	return bindFuncAjaxGet(bindObjects, bindEvent, hrefField, function(data){
			$(resultObjects).html(data);
	}, question);
}

function bindAjaxGet(bindObjects, bindEvent, hrefField, resultObjects)
{
	return bindFuncAjaxGet(bindObjects, bindEvent, hrefField, function(data){
			$(resultObjects).html(data);
	});
}

function bindAjaxPost(bindObjects, bindEvent, hrefField, dataObjects, resultObjects, question)
{
	return bindAjaxPostForm(bindObjects, bindEvent, hrefField, dataObjects, resultObjects, question, 'post');
}

function bindAjaxGetForm(bindObjects, bindEvent, hrefField, dataObjects, resultObjects, question)
{
	return bindAjaxPostForm(bindObjects, bindEvent, hrefField, dataObjects, resultObjects, question, 'get');
}


function bindAjaxPostForm(bindObjects, bindEvent, hrefField, dataObjects, resultObjects, question, method)
{
	$(bindObjects).bind(bindEvent, function(){

		var dataValues = {};

		$(bindObjects+' input[type=submit]').attr('disabled', '1');

		$(dataObjects).each(function(i){
			var fieldName;
			var fieldObject;
			var fieldValue;
			var t;
			if (typeof(dataObjects) == 'string') {
				fieldName = this.name;
				fieldObject = $(this);
			}
			else {
				fieldName = this;
				fieldObject = $("[name="+this+"]");
			}
			if ((fieldObject.val() == '')
				&& ((fieldObject.attr('type')=='') || (fieldObject.attr('type')=='hidden'))) {
				if (typeof(window.FCKeditorAPI) != 'undefined') {
					fieldValue = FCKeditorAPI.GetInstance(fieldName).GetHTML();
				}
				else {
					if (typeof(dataObjects) != 'string') {
						t = $("#"+this);
						if ((t.val()!='') && (t.val()!='undefined')) {
							fieldValue = t.val();
						}
						else {
							fieldValue = '';
						}
					}
					else {
						fieldValue = '';
					}
				}
			}
			else {
				fieldValue = fieldObject.val();
			}

			if (
				((fieldObject.attr('type')!='checkbox')&&(fieldObject.attr('type')!='radio'))
				||
				(fieldObject.attr('checked'))
			   ) {
					dataValues[fieldName] = fieldValue;
			}
		});
		var href;
		if (hrefField.substr(7)=='http://') {
			href = hrefField;
		}
		else {
			href = $(this).attr(hrefField);
		}
		if ((question==undefined) || (confirm(question))) {
			if (method == 'post') {
				$.post(href, dataValues, function(data){
					$(resultObjects).html(data);
				});
			}
			else {
				$.get(href, dataValues, function(data){
					$(resultObjects).html(data);
				});
			}
		}
		return false;
	});
}


function drawAjaxWindow(windowObj, windowWidth, windowHeight, posH, posV)
{

	if (windowWidth==undefined) {
		windowWidth = parseInt($(windowObj).attr('dialogWidth'));
	}
	if (windowHeight==undefined) {
		windowHeight = parseInt($(windowObj).attr('dialogHeight'));
	}

	if (posV == undefined) {
		posV = parseInt(getBrowserHeight() / 2 - windowHeight / 2);
    }
	if (posH == undefined) {
		posH = parseInt(getBrowserWidth() / 2 - windowWidth / 2);
	}

	$(windowObj).modal({sizes: [windowHeight, windowWidth], position: [posV, posH]});

}

function bindAjaxWindow(bindObj, bindEvent, hrefField, windowObj, windowWidth, windowHeight, posH, posV)
{
	bindFuncAjaxGet(bindObj, bindEvent, hrefField, function(data){

		$(windowObj).html(data);

		drawAjaxWindow(windowObj, windowWidth, windowHeight, posH, posV);

	});
}

function getFlashObject(movieName)
{
  if (window.document[movieName])
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}


function getFlashCurrentFrame(movieName)
{
	var flash = getFlashObject(movieName);
	var frame;
	if (flash) {
		frame = flash.TGetProperty("/", 4);
		return frame;
	}
	else {
		return false;
	}
}

function setFlashCurrentFrame(movieName, frame)
{
	var flash = getFlashObject(movieName);
	frame = parseInt(frame) - 1;
	if (flash) {
		flash.GotoFrame(frame);
	}
	else {
		alert('unable to find flash object!'+ movieName);
		alert(flash);
	}
}


function getBrowserWidth()
{
    var width;
    if ($.browser.msie) {
        width = document.body.clientWidth;
    }
    else {
        width = window.innerWidth;
    }
    return width;
}

function getBrowserHeight()
{
    var height;
    if ($.browser.msie) {
        height = document.documentElement.clientHeight;
    }
    else {
        height = window.innerHeight;
    }
    return height;
}


function drawFlash(width, height, flash_id, src, fvars, salign, scale, movieSuffix) {
    if (movieSuffix == undefined) {
    	movieSuffix = '_movie';
    }
    if (salign == undefined) {
    	salign = 'lt';
    }
    if (scale == undefined) {
    	scale = 'showall';
    }
    var flash_name = flash_id.substr(1) + movieSuffix;
    $(flash_id).flash(
        {
            'src': src,
            'width': width,
            'height': height,
            'wmode': 'opaque',
            'name': flash_name,
            'id': flash_name,
            'menu': false,
            'salign': salign,
            'scale': scale, // 'showall' 'exactfit' 'noscale'
            'quality': 'high',
            'flashvars':fvars
        }
    );
    $(flash_id).show();
}



function drawSWFObject(width, height, flash_id, src, fvars, salign, scale, movieSuffix) {
    if (movieSuffix == undefined) {
    	movieSuffix = '_movie';
    }
    var flash_name = flash_id.substr(1) + movieSuffix;
	var so = new SWFObject("http://flashki.ru/games/uploads/swfPlayer.swf?gamePath="+src+"&flashvars="+fvars, "swfPlayer", width, height, "10", "#FFFFFF");
	so.useExpressInstall('http://www.metah.ch/expressinstall.swf');
	so.write(flash_name);
}

