

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//-- InstanceEndEditable ----------------------------


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//------------------------------------------------------------------------



function user_dialog_visible_4()
{
	$('#user_dialog_4').css('visibility', 'visible');
	$('#user_dialog_4').modal({
	     opacity:80,
	     overlayCss: {backgroundColor:"#000"}
	});
	$('#test6').focus();
}

function user_dialog_hide_4()
{
	$.modal.close();
  $('#user_dialog_4').css('visibility', 'hidden');
  
}

function user_dialog_visible_6()
{
  $('#user_dialog_6').css('visibility', 'visible');
  $('#user_dialog_6').modal({
	     opacity:80,
	     overlayCss: {backgroundColor:"#000"}
	});
}

function user_dialog_hide_6()
{
	$.modal.close();
  $('#user_dialog_6').css('visibility', 'hidden');
}



function user_login(value)
{
	remember = 0;
	if (value)
	{
		email = $('#email').val();
		passwd = $('#password').val();
		if ($('#remember_s').is(':checked'))
		{
			remember = 1;
		}
	}
	$.post(
			base_url + '/json/user_login',
			{
				email: email,
				passwd: passwd,
				remember: remember,
				swf: GetSwfVer()
			},
			function(data)
			{
				if (data.status)
				{
					window.location = base_url;
				}
				else
				{
					user_dialog_visible_4();
				}
			},
			"json"
		);
}

function forgot_password_question_hide()
{
  forgot_email_question_hide();
  forgot_register_question_hide();
  $.modal.close();
	$('#delete_dialog').css('visibility', 'hidden');
}

function user_reset()
{
	$.post(
			base_url + '/json/user_reset',
			{
				email: $('#reset').val()
			},
			function(data)
			{
			 if(!data.staus)
			 {
			   if(data.message == 1)
			   {
			     forgot_password_question_hide();
			     forgot_email_question();
			     
         }
         if(data.message == 2)
         {
          forgot_password_question_hide();
          forgot_register_question();
         }
       }
        if(data.status)
        {
          $.modal.close();
          $('#delete_dialog').css('visibility', 'hidden');
        }
			},
			"json"
		);
}

function forgot_password_question()
{
	$('#delete_dialog').modal({
	     opacity:80,
	     overlayCss: {backgroundColor:"#000"}
	});
	$('#delete_dialog').css('visibility', 'visible');
	document.getElementById('reset').focus();
}

function forgot_email_question()
{
	$('#delete_dialog_email').modal({
	     opacity:80,
	     overlayCss: {backgroundColor:"#000"}
	});
  $('#delete_dialog_email').css('visibility', 'visible');
  document.getElementById('test1').focus();
}

function forgot_register_question()
{
	$('#delete_dialog_register').modal({
	     opacity:80,
	     overlayCss: {backgroundColor:"#000"}
	});
  $('#delete_dialog_register').css('visibility', 'visible');
  document.getElementById('test2').focus();
}



function forgot_email_question_hide()
{
	$.modal.close();
	$('#delete_dialog_email').css('visibility', 'hidden');
}

function forgot_register_question_hide()
{
	$.modal.close();
	$('#delete_dialog_register').css('visibility', 'hidden');
	//document.getElementById('test2').focus();
}








/*$(document).ready(function(){
	var item_number = document.getElementById('gallery_key_');
	var gkey = item_number.value;
	gallery_upload_swf('uploader_button_',314,61,base_url + '/designes/2dbin/images_home/upload_photos_btn_all.PNG',gkey);
});
*/

/*$(document).ready(function()
 {
 alert(auth);
  if(auth)
  {
    $('#user_panel').css('visibility', 'visible');
  }
  else
  {
    $('#user_panel').css('visibility', 'hidden');
  }
 });

*/


function user_exit()
{
	$.getJSON(
			base_url + '/json/user_exit',
			{
			},
			function(data)
			{
				window.location = base_url;
			}
	);
}


function automatically_processed_(key)
{
  	$.post(
			base_url + '/json/start_scenario_task_auto_anon',
			{
				'mark': -1,
				'key': key
			},
			function(data)
			{
				var t_key = data.status;
				if (t_key!='none')
				{
					window.location = base_url + '/Autoprocess' + '/' + t_key;
				}
				return;
			},
			"json"
		);
}

function gallery_upload_swf(value_name, width, height, img, key)
{ 
	$('#' + value_name).swfupload({
		upload_url: base_url + '/Galleryupload/' + session_id + '/11/1/' + key ,
		file_size_limit : "1000 MB",
		file_types : "*.jpg;*.jpeg;*.png;*.gif;*.bmp",
		file_types_description : "Images",
		file_upload_limit : "0",
		flash_url : base_url + '/' + design_current + '/swf/swfupload.swf',
		button_image_url : img,
		button_width : width,
		button_height : height,
		button_placeholder : $('#' + value_name)[0],
		debug: false,
		button_window_mode: 'transparent',
		button_cursor: SWFUpload.CURSOR.HAND
	})
	.bind('fileQueued', function(event, file){
		$('#property_upload_progress').modal();
		$(this).swfupload('startUpload');
		/*$('#property_upload_progress_can').bind('click', function(){//alert(value_name);
			var swfu = $.swfupload.getInstance('#' + value_name);
			swfu.stopUpload();
			swfu.cancelUpload();
		});*/
	})
	.bind('fileQueueError', function(event, file, errorCode, message){
		$.post(
				base_url + '/json/property_swfupload_warning',
				{
					message: message
				},
				function(data)
				{
					popup(1, data.message, 369, 200);
				},
				"json"
			);
	})
	.bind('uploadStart', function(event, file){
	})
	.bind('uploadProgress', function(event, file, bytesLoaded, bytesAll){
		value = parseInt(bytesLoaded*100/bytesAll, 10);
		$('#property_upload_progress_n').css('width', value + '%');
		$('#property_upload_progress_p').html(value + '%');
	})
	.bind('uploadSuccess', function(event, file, serverData){
		//$.modal.close();
		//alert('asdf');
		automatically_processed_(key);
	});
}


$('#auth_form').keydown(function(event){
  
  document.getElementById('auth_submit').focus();
  if(event.keyCode == 13) 
  {
    //alert('qwe');
    user_login(true);
    return false;
  }
});



$(document).ready()
{
  Height = document.documentElement.clientHeight;
  Width = document.documentElement.clientWidth;
  //alert(Height);
  //alert(Width);

  $('#user_dialog_4').css('top', Height/9-40);
  $('#user_dialog_4').css('left', Width/9-180);
  $('#user_dialog_6').css('top', Height/9-40);
  $('#user_dialog_6').css('left', Width/9-180);
  $('#delete_dialog_register').css('top', Height/9-40);
  $('#delete_dialog_register').css('left', Width/9-180);
  $('#delete_dialog_email').css('top', Height/9-40);
  $('#delete_dialog_email').css('left', Width/9-180);
  $('#delete_dialog').css('top', Height/9-40);
  $('#delete_dialog').css('left', Width/9-180);
};



