// Java Document
// SEND EMAILS
function php( p_script_url ) {
      script = document.createElement( 'script' );
      script.src = p_script_url;
      document.getElementsByTagName( 'head' )[0].appendChild( script );}
function check_chislo(obj) {
	var t=obj.value;
	var l=obj.value.length;
	l--;
	if (t != Number(t)) obj.value=obj.value.substr(0,l);
		//document.getElementById().length
		}
function check_email(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
   }
function check_form(form,action,msg) {
	var f=0;
	if (action == 'racers' || action == 'breeders' || action == 'sale') {
		var name=document.getElementById('ring');
		name.className='';
		if (!name.value) {name.className='red_border'; f=1;name.focus();}
	}
	if (action == 'links') {
		var name=form.title;
		name.className='';
		if (!name.value) {name.className='red_border'; f=1;name.focus();}
	}
	if (action == 'system') {
		var email=form.email;
		email.className='';
		if (!check_email(email.value)) {email.className='red_border'; f=1;email.focus();}

	}
	
	if (action == 'users') {
		var username=form.username;
		var password=form.password;
		var password2=form.password2;
		username.className='';
		password2.className='';
		password.className='';
		if (!password.value) {password.className='red_border'; f=1;password.focus();}
		if (!password2.value) {password2.className='red_border'; f=1;password2.focus();}
		if (!username.value) {username.className='red_border'; f=1;username.focus();}

	}
	if (action == 'users2') {
		var username=form.username;
		var password=form.password;
		var password2=form.password2;
		var old=form.old;
		username.className='';
		password2.className='';
		password.className='';
		old.className='';
		if (!username.value) {username.className='red_border'; f=1;username.focus();}
		if (password.value || password2.value || old.value) {
		if (!password.value) {password.className='red_border'; f=1;password.focus();}
		if (!password2.value) {password2.className='red_border'; f=1;password2.focus();}
		if (!old.value) {old.className='red_border'; f=1;old.focus();}
			
			
		}
	}
	
	if (f==0) 	{		
		form.submit();
	} else alert (msg);}
	
function url(url,txt) {
	var a=confirm(txt);
	if (a) window.location=url; else return false;};

////////////////////////////////////////////////////////////
function save_NEW_field(form) {
		var name=$('#name').val();	
		if (!name) {$('#name').addClass('border_red'); return false;} else $('#name').removeClass('border_red');
		form.submit();
	}
function SaveShowOrder() {
				$('#ids').val('');
				obj=$('#sortable');
				obj=$(obj).find('li');
				//obj=$(obj).find('img');
				var i=0; var id=0;
				while (obj[i]) {
					id=obj[i]["id"];
					$('#ids').val($('#ids').val()+id+',');
				i++;
				}
				php (CONFIG_HOST+'/js.php?action=save_arange_fields&ids='+$('#ids').val());
				
			}
	
function delete_fg(n,id,type) {
	var name=$('#name_'+n).val();
	var del=confirm ('Delete '+name+'?');
	if (del) {
		document.getElementById(id).innerHTML=LOAD_BAR;	
	php (CONFIG_HOST+'/js.php?action=delete_'+type+'&id='+id);}}	
  function SaveShowOrder_all(obj,what,table) {
			var ids='';
			obj=$('#'+obj);
			obj=$(obj).find(what);
			var i=0; var id;
			while (obj[i]) {
				id=obj[i]["id"];
				ids+=id+',';
			i++;
			}
			php (CONFIG_HOST+'/js.php?action=save_sort&ids='+ids+'&table='+table);
			
		}
  function save_photo_description(obj,flag,type) {
			var id=obj.pic_id.value; 
			var f=0;
			var en='';
			var nl='';
			var ch='';
			$('#list').find("#"+id).find('#buttons').hide();
			$('#list').find("#"+id).find('#loader').html(LOAD_BAR);
			if (flag=='save') {
			 en=obj.name_en; 
			 nl=obj.name_nl; 
			 ch=obj.name_ch; 
			$(en).removeClass('red_border');
			$(nl).removeClass('red_border');
			$(ch).removeClass('red_border');
			
			if (!$(en).val()) en=''; else en=$(en).val();
			if (!$(nl).val()) nl=''; else nl=$(nl).val();
			if (!$(ch).val()) ch=''; else ch=$(ch).val();
			}
			
			if (f==0) {
			  $.ajax({type: "POST",
        url: CONFIG_HOST+"/ajax.php",
        data: {action: 'save_photo_description',id: id, en: en, nl: nl, ch: ch, flag: flag, type: type},
        dataType: "json",
        success: function(data){
			var flag=data.flag;
			var id=data.id;
			if (flag=='delete') {
				$('#list').find("#"+id).hide('slow');
			}
			if (flag=='save') {
				if (id=='-1') {
					window.location=CONFIG_HOST+'/master/page/photogallery/edit/'+data.id2; 
				} 
				if (id=='-2') {
					window.location=CONFIG_HOST+'/admin.php?page=groups&pigeon='+data.type;
				} 	else {
			$('#list').find("#"+id).find('#loader').html('');
			$('#list').find("#"+id).find('#buttons').show();
				}
				}
			if (flag=='as_main') {
				
				$('#list').find("#"+id).find('#loader').html('');
				$('#list').find("#"+id).find('#buttons').show();	
				$('#list').find("li").attr("style","background-color:#fff");
				$('#list').find("#"+id).attr("style","background-color:#dbe8ef");
				
				
				}
					}
			
    });
			} else {
				$('#list').find("#"+id).find('#loader').html('');
				$('#list').find("#"+id).find('#buttons').show();
			}

		 }
// JavaScript Document
 function show_system_message () {
  $("#system_messanger").animate({  top: "0px"  }, 1500 );
  $("#system_messanger").click(function()  {$("#system_messanger").animate({  top: "-170px"  }, 1500 );});
  var t=setTimeout("$('#system_messanger').animate({  top: '-170px'  }, 1500 );",3000);}
 function alert_error(title,msg) {
	 document.getElementById('system_title').innerHTML=title;
	 document.getElementById('system_msg').innerHTML=msg;
	 document.getElementById('system_img').src=CONFIG_HOST+'/images/error.png';
	 document.getElementById('system_messanger').className='system_error';
	 show_system_message();
 }
 function alert_result(title,msg) {
	 document.getElementById('system_title').innerHTML=title;
	 document.getElementById('system_msg').innerHTML=msg;
	 document.getElementById('system_img').src=CONFIG_HOST+'/images/result.png';
	 document.getElementById('system_messanger').className='system_result';
	 show_system_message();
 }

