var editImageControllerPath="/plugins/edit_photo/index.php";
var editControllerPath="/plugins/edit_photo/close.php";

var agt = navigator.userAgent.toLowerCase ();
var is_major = parseInt (navigator.appVersion);
var is_minor = parseFloat (navigator.appVersion);
var is_nav  = ((agt.indexOf ('mozilla') != -1) && (agt.indexOf ('spoofer') == -1) && (agt.indexOf ('compatible') == -1) && (agt.indexOf ('opera') == -1) && (agt.indexOf ('webtv') == -1) && (agt.indexOf ('hotjava') == -1) && (agt.indexOf ('safari') == -1));
var is_nav6 = (is_nav && (is_major == 5) && (agt.indexOf ("netscape") != -1) && (agt.indexOf ("netscape/7") == -1));
var is_nav6up = ((is_nav && (is_major >= 5)) || (is_nav && (agt.indexOf ('netscape/7') != -1)));
var is_ie      = ((agt.indexOf ("msie") != -1) && (agt.indexOf ("opera") == -1) && (agt.indexOf ("safari") == -1));
var is_ie3     = (is_ie && (is_major < 4));
var is_ie4     = (is_ie && (is_major == 4) && (agt.indexOf ("msie 4")!=-1));
var is_ie4up   = (is_ie && (is_major >= 4));
var is_ie5     = (is_ie && (is_major == 4) && (agt.indexOf ("msie 5.0") != -1));
var is_ie5_5   = (is_ie && (is_major == 4) && (agt.indexOf ("msie 5.5") != -1));
var is_ie5up   = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6     = (is_ie && (is_major == 4) && (agt.indexOf ("msie 6.") != -1));
var is_firefox = ((agt.indexOf ("firefox") != -1) && (agt.indexOf ("opera") == -1) && (agt.indexOf ("safari") == -1));
var is_opera = (agt.indexOf ("opera") != -1);
var is_nn = ((is_nav6 || is_nav6up) ? true : false);

function MouseOver( element, buttonColor ) {
	g_PopupColor = buttonColor;
	element.onmousemove=MouseMove;
	element.onmouseout=MouseOut;
	g_element_on = element;
	if( element.title ) {
		document.getElementById( 'popup_center_' + g_PopupColor ).innerHTML = element.title;
		g_title = element.title;
		element.title = '';
	}
}


function MouseMove(e){

	if ( g_PopupColor == '' ) {
		return;

	}
	var popup=document.getElementById( 'popup_' + g_PopupColor );
	if(window.event){
		popup.style.visibility="visible";

		oCanvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];

		x = event.clientX + 10 + oCanvas.scrollLeft;
		y = event.clientY + 10 + oCanvas.scrollTop;

		popup.style.top = y;

		if ( x < (document.documentElement.clientWidth) - popup.offsetWidth )
		{
			popup.style.left = x;
		}
		else if ( x > (((document.documentElement.clientWidth / 2)) + popup.offsetWidth/2) )
		{
			popup.style.left = x - popup.offsetWidth - 13;
		}
		else
		{
			popup.style.top = y+9;
			popup.style.left = x - (popup.offsetWidth/3 + 5);
		}

	}else{
		popup.style.visibility="visible";

		x = e.pageX + 10;
		y = e.pageY + 10;

		popup.style.top=y+'px';

		if ( x < (document.documentElement.clientWidth) - popup.offsetWidth )
		{
			popup.style.left = x + 'px';
		}
		else if ( x > (((document.documentElement.clientWidth / 2)) + popup.offsetWidth/2) )
		{
			popup.style.left = x - popup.offsetWidth - 13 + 'px';
		}
		else
		{
			popup.style.top = y + 9 + 'px';
			popup.style.left = x - (popup.offsetWidth/3  + 5) + 'px';
		}
	}
}

function MouseOut( ) {
	try{
		var popup=document.getElementById( 'popup_' + g_PopupColor );
		g_element_on.title = g_title;
		document.getElementById( 'popup_center_' + g_PopupColor ).innerHTML = '';
		if(window.event){
			popup.style.visibility="hidden";
		}else{
			popup.style.visibility="hidden";
		}
		g_PopupColor = '';
	} catch(e) {;}
}
function $(id){
	return document.getElementById(id);
}

function applyEditPicture(action){
    if (cropMode){ switchCrop(); }
    if (textMode){ switchText(); }

    $('btnCancel').style.visibility = (action == 'return')
        ? 'hidden' : 'visible';

	showBlockedAlert();
	$("picture").src=editImageControllerPath+"?uid="+pic_UID+"&aid="+pic_AID+"&pid="+pic_PID+"&action="+action+"&random="+Math.random();
}

function applyEdit(action){
	document.location=editControllerPath+"?uid="+pic_UID+"&aid="+pic_AID+"&pid="+pic_PID+"&action="+action+"&random="+Math.random();
}

function applyEditEnd(){
	applyEdit('end');
}

function fKeyPress(ev,el){
	if (!is_ie && !is_opera) {
		event=ev;
		if ((event.charCode>47 && event.charCode<58) || event.charCode==0 || event.charCode==46 || event.charCode==44){
			return event;
		} else return false;
	} else {
		if ((event.keyCode>47 && event.keyCode<58) || event.keyCode==46 || event.keyCode==44){
			return event;
		} else return false;
	}
}

//Вычисление смещения y координаты объета
function calcTop(x_ele){
//	if (!document.all) return (x_ele.offsetTop);
	var x_ret=0;
	var oParent = x_ele.offsetParent;
	if (oParent == null) return 0
		else x_ret=x_ele.offsetTop + calcTop(oParent);
	return x_ret;
}

//Вычисление смещения x координаты объета
function calcLeft(x_ele){
//	if (!document.all) return (x_ele.offsetLeft);
	var x_ret=0;
	var oParent = x_ele.offsetParent;
	if (oParent == null) return 0
		else x_ret=x_ele.offsetLeft + calcLeft(oParent);
	return x_ret;
}

function showBlockedAlert(){
	showBlockAlert("Подождите, идет генерация картинки...");
}

function hideBlockedAlert(){
	hideAlert();
}

function setStatusView1 ( o ) {
	document.getElementById ( 'status_message_0' ).style.display = 'none';
	document.getElementById ( 'status_message_1' ).style.display = 'none';
	document.getElementById ( 'status_message_2' ).style.display = 'none';
	document.getElementById ( 'status_message_'+o ).style.display = '';
	if ( o == 1 )
		document.getElementById ( 'tr_show_dr' ).style.display = '';
	else
		document.getElementById ( 'tr_show_dr' ).style.display = 'none';
}

var curentFriendsCount1 = 0;
function addAlbomFriend1 ( ) {
	curentFriendsCount1++;

	var span = document.createElement ( 'span' );
	span.setAttribute ( 'id', 'friendsRow'+curentFriendsCount1 );

	var html = 'E-mail: <input type="text" id="open_user_email_'+curentFriendsCount1+'" name="open_user_email['+curentFriendsCount1+']" style="width:200px"><br />';
	span.innerHTML = html;

	document.getElementById ( 'friendsContainer' ).appendChild ( span );
}

function delAlbomFriend1 ( ) {
	if ( curentFriendsCount1 > 0 ) {
		document.getElementById ( 'friendsContainer' ).removeChild ( document.getElementById('friendsRow'+curentFriendsCount1) );
		curentFriendsCount1--;
	}
}
