/**
** Document JavaScript
** Copyright ( c) Hamer, 2008 
**/
 function adrset(  name, user_id ) {
       $("#rem").html("<p>" + name + "</p>");
	   $("#a-id").attr('value', user_id );
	   showorhide('more_users', 'fast');
  }
function check( event )
  {

     var value = event.value;
	 var name  = event.name;
	 
	 if ( value == "" || value == " " || value == "  ")
	 {
	     var error = true;
	 }
	 else if ( value.length < 6 && name=='password')
	 {
	     var error = true;
	     var length_error = true;
	 } else if( name == 'rules' && event.checked == false ) {
		var error = true;
		 var rules_err = true;	 
	 } else if ( value ) {
		var error = false;
	 }
	 
	 switch( name ) {
	  
  	    case "name":
		var error_txt = "Заполните имя!";
		var div_id    = "n-info";
		break;
		
		case "email":
		var error_txt = "Введите E-mail!";
		var div_id    = "e-info";
		break;
		
		case "phone":
		var error_txt = "Введите телефон!";
		var div_id    = "phone-info";
		break;
		
		case "fio":
		var error_txt = "Введите Ф.И.О!";
		var div_id    = "fio-info";
		break;
		
		case "rules":
			if( rules_err ) {
				var error_txt = "Вы обязаны принять соглашения с правилами!";
				var div_id    = "rules-info";
			}
		break;
		
		case "capcha":
		var error_txt = "Введите код!";
		var div_id    = "capcha-info";
		break;
		
		case "password":
		if ( length_error )
		   var error_txt = "Пароль не может быть меньше 6ти символов";
		else
		   var error_txt = "Заполните пароль!";
		var div_id    = "p-info";
		break;
		
	 }
	 
	 if ( error  == true)  {	 
		$("#" + div_id ) . text (error_txt);	 
	 } else if ( error && rules_err == true ) {
		alert("rules");
		$("#" + div_id ) . text (error_txt);
	 } else if (! error ) {
		$("#" + div_id ) . text ("");
	 }
  }
  function check_password( event )
  {
      var value = event.value;
	  var pass  = $("#password").attr('value');
	  
	  if ( value != pass )
	  {
	    $("#rep-info").text("Пароли не совпадают!");
	  } else if ( value == "" || value == " " || value == "  ") {
	    $("#rep-info").text("Повторите пароль!");    
	  }
	  else $("#rep-info").text("");    
	}
 

/*---------------------------------------------------------------------------------------------/
\				AJAX LOADING					 	\
/*--------------------------------------------------------------------------------------------*/

function ajax_loading ( loading_layer, ShowOrHide )
{
  var img   = home_url + 'system/js/loading.gif';
  
  switch (ShowOrHide){
  case 0:$("#"  + loading_layer).html(""); break;
  case 1:$("#"  + loading_layer).html("<img src=\"" + img + "\" border=0>"); break;
  }
}




function showorhide( Object_id , typeofhide )
{
    if ( typeofhide == '')
	{
	    typeofhide = null;
	}
	var ob = $("#" + Object_id );
	if ( ob.css('display') == 'block')
	{
	  ob.hide(typeofhide);
	} else if ( ob.css('display') == 'none'){
	  ob.show(typeofhide);
	}
}	

function confirm_url ( cTEXT, cLocationURL )
{
    var agree_message;
	
	agree_message = confirm ( cTEXT );
	
	if ( agree_message )
	{
	    document.location =  cLocationURL;
	}
}

function loadrules() {	
	
	ajax_loading('rules_la', 1);
	
	$.post(home_url + 'system/ajax/rules.php', {id:4}, function( response )
	{
			$("#rules_la").html(response);
			//ajax_loading('rules_la', 0);
	});
	
	
}

function show_reuest(title, message, close) {
	if(close) {
		$("#show_reuest").animate({top:'-40%'}, 150).hide("slow");
		return false;
	}	
	$("#show_reuest").show().animate({top:'40%'}, 400);
	
	return false;
}

function login_open() {
	
	$('#login').dialog({
			autoOpen: true,
			show: 'fade',
			hide: 'fade',			
			width: 300,	
			buttons: {							
				"Закрыть" : function() {
					
					$(this).dialog("close");
				},
				"Войти" : function() {					
					$("#login_form").submit();
				}
			}
		});
	
}

function payconsult( sum ) {
	
	if(sum) $("#sum").val(sum);
	
	$('#payconsult').dialog({
			autoOpen: true,
			show: 'fade',
			hide: 'fade',			
			width: 400,
			buttons: {							
				"Отмена" : function() {					
					$(this).dialog("close");
				},
				"Оплатить" : function() {					
					$("#payconsultf").submit();
				}
			}
		});
	
}
function dwc_confirm(message, title, callback, callback_param){

	var b = {};

	b['Нет'] = function() { 
					$(this).dialog("close");
					$("#dwcpopup").remove();						
			    };

	b['Да'] = function() { 
					$(this).dialog("close");
					$("#dwcpopup").remove();
					if( callback ) callback(callback_param);					
				};

	$("#dwcpopup").remove();

	$("body").append("<div id='dwcpopup' title='" + title + "' style='display:none'><br />"+ message +"</div>");

	$('#dwcpopup').dialog({
		autoOpen: true,
		width: 470,
		buttons: b
	});
};
function dwc_info(message, title, callback, callback_param){

	var b = {};

	b['закрыть'] = function() { 
					$(this).dialog("close");
					if( callback ) callback( callback_param);					
					$("#dwcpopup").remove();						
			    };

	$("#dwcpopup").remove();

	$("body").append("<div id='dwcpopup' title='" + title + "' style='display:none'><br />"+ message +"</div>");

	$('#dwcpopup').dialog({
		autoOpen: true,
		width: 470,
		buttons: b
	});
};
function dwc_prompt(message, d, title, callback){

	var b = {};

	b['Закрыть'] = function() { 
					$(this).dialog("close");						
			    };

	b['Отправить'] = function() { 
					if ( $("#dwc-promt-text").val().length < 1) {
						 $("#dwc-promt-text").addClass('ui-state-error');
					} else {
						var response = $("#dwc-promt-text").val()
						$(this).dialog("close");
						$("#dwcpopup").remove();
						if( callback ) callback( response );
					}				
				};

	$("#dwcpopup").remove();

	$("body").append("<div id='dwcpopup' title='" + title + "' style='display:none'><br />"+ message +"<br /><br /><input type='text' name='dwc-promt-text' id='dwc-promt-text' class='ui-widget-content ui-corner-all' style='width:97%; padding: .4em;' value='" + d + "'/></div>");

	$('#dwcpopup').dialog({
		autoOpen: true,
		width: 470,
		show: 'blind',
		hide: 'blind',
		buttons: b
	});
};
