var hw;
var hw2;
var hw3;
var info;
var out;


function changepop() {	var pop=$('#pop').val();
	//alert(pop);
	setuserdata('pop',pop);
    window.location='http://www.andboson.net/?items='+pop;}

function changesort() {
    var sortby=$('#sort').val();	setuserdata('sortby',sortby);
	//alert(sortby);
    window.location='http://www.andboson.net/?sortby='+sortby;}

function setuserdata(type,value) {
	//alert(type+'='+value);
	setCookie(type,value);
}


function setCookie(name, value) {	var d=new Date();	d.setMonth(d.getMonth()+1);
	var dat=d.toGMTString();
    var curCookie = name + "=" + escape(value) +"; expires=" + dat+"; domain=.andboson.net";
    document.cookie = curCookie;
}


//var id;

function votes(){	alert('ak');
	return;}

function vote(id,type) { $.ajax({
   type: "GET",
   url: "server.php",
   data: "type=voteit&picforvote="+id+"&rate="+type,
   success: function(msg){    if(msg!='already voted') {    	$("#ratebox"+id).html(msg);
           setTimeout(
                  function()
                        {
								$.ajax({
								   type: "GET",
								   url: "server.php",
								   data: "type=getrate&id="+id,
								   success: function(msg){
								       		 $("#ratebox"+id).html(msg);
								    	  }
								});
                        },
                        600);
	}
  }
 });}


function flagit(id) {
 $.ajax({
   type: "GET",
   url: "server.php",
   data: "type=flagit&id="+id,
   success: function(msg){
    if(msg!='already flagged') {
    	$("#flagbox"+id).html('flagged!');
	}
  }
 });
}


function showtagger(id) {
	$("#tagger"+id).slideDown("normal");
  $(document).ready(function(){
      var data = "server.php";
      $("#tagstext"+id).focus();
	  $("#tagstext"+id).autocomplete(data, {
						multiple: true,
						extraParams: { type: 'suggest' }
						});
  });}


function disclaimer(){
	var w=$(window).width(); //screen.width;
	var h=$(window).height(); //screen.height;
	var off=$(document).scrollTop();
	var top=off+h/2-75;
	var left=w/2-325;
	//alert(off);
     $.dimScreen(100, 0.7, 0);
   	$("#disclaimer").css("zIndex",1000);
	$("#disclaimer").css("top",top);
	$("#disclaimer").css("left",left);    $("#disclaimer").slideDown('normal');
}


function adult(show){	if (!show) {
 var agent=navigator.userAgent;
 var url = ['Googlebot','msnbot','Yahoo','Alexa','Yandex','YaDirectBot','ia_archiver','iPhone','alexa', 'Msnbot'];
 for (var count = 0 ; count < url.length ; count++){
  	if (agent.indexOf(url[count])!=-1) {
  	var start=agent.indexOf(url[count]);
  	var len=url[count].length;
  	   var agent=agent.substr(start,len);
    return;
    }
}
var allcookies = document.cookie;
var pos = allcookies.indexOf("adult=");
	if (pos != -1) {
    var start = pos + 6;                       // Start of cookie value
    var end = allcookies.indexOf(";", start);  // End of cookie value
    if (end == -1) end = allcookies.length;
    var value = allcookies.substring(start, end);  // Extract the value
    value = decodeURIComponent(value);
   // alert(value);             // Decode it
    if (value == 'agree') return;
	}
}
	var w=$(window).width(); //screen.width;
	var h=$(window).height(); //screen.height;
	var off=$(document).scrollTop();
	var top=off+h/2-200;
	var left=w/2-325;

    //  $.dimScreen(100, 0.7, 0);
	$("#adult").css("top",top);
	$("#adult").css("left",left);
    $("#adult").slideDown('normal');
   	$("#adult").css("zIndex",1000);
}


function closewin(win){   $(win).slideUp('fast');
   $.dimScreenStop();
  if (win=='#uplbox'){
	     var img=$("#realpic").val();	  	 //$('#div_id').html('Upload');
	  	   $.ajax({
		   type: "GET",
		   url: "server.php",
		   data: "type=removeup&img="+img
		    });
  	 }
   if (win=='#adult') {   	 setCookie('adult','agree');   }
}


 $(document).ready(function(){
     $("#myForm").submit(function() {        if (checkform()) {
	      		savecomment();
	      		return true;
	        } else  return false;
    });
});


function savecomment(){
 	var commentname = $("#commentname").val(),
		commentemail = $("#commentemail").val(),
		picid=$("#picid").val(),
		cap=$("#cap").val(),
		commenttext = $("#commenttext").html();
    $.ajax({
   type: "POST",
   url: "comment.php",
   data: "pic="+picid+"&name="+commentname+"&email="+commentemail+"&txt="+commenttext+"&captcha="+cap,
   success: function(msg){
	  		if (msg=='Passed!') {
			$("#commentform").hide('slow');
			getnewcomment(picid);
			return true;
			} else {
			updateTips('you are a human?');
			    $("#ajax-fc-task").effect("pulsate", { times:2 }, 1000);
	    $("#ajax-fc-content").effect("highlight",{},2000);
			return false;
			}
		}
	});}

function getnewcomment(id){
 $.ajax({
   type: "GET",
   url: "server.php",
   data: "type=getlastcomment&id="+id,
   success: function(msg){
	  $("#new").after(msg);
	  $(".newcomm").show('slow');
	  return true;
  	}
 });
}


function updateTips(t) {	$("#validateTips").html(t);
	$("#validateTips").effect("highlight",{},2000);
}

function updateTips2(t) {
	$("#fvalidateTips").html(t);
	$("#fvalidateTips").effect("highlight",{},2000);
}

function checkLength(o,n,min,max) {
	if ( o.val().length > max || o.val().length < min ) {
	    o.effect("pulsate", { times:2 }, 1000);
		updateTips("Length of " + n + " must be between "+min+" and "+max+".");
		return false;
	} else {
		return true;
	}
}

function checkLength3(o,n,min,max) {
	if ( o.val().length > max || o.val().length < min ) {
	    o.effect("pulsate", { times:2 }, 1000);
		updateTips2("Length of " + n + " must be between "+min+" and "+max+".");
		return false;
	} else {
		return true;
	}
}

function checkLength2(o,n,min,max) {
	if ( o.html().length > max || o.html().length < min ) {
	    $("#commenttext_tbl").effect("pulsate", { times:2 }, 2000);
		updateTips("Length of " + n + " must be between "+min+" and "+max+".");
		return false;
	} else {
		return true;
	}
}

function checkRegexp(o,regexp,n) {	if ( !( regexp.test( o.val() ) ) ) {
	    o.effect("pulsate", { times:2 }, 2000);
		updateTips(n);
		return false;
	} else {
		return true;
	}
}

function checkRegexp2(o,regexp,n) {
	if ( !( regexp.test( o.val() ) ) ) {
	    o.effect("pulsate", { times:2 }, 2000);
		updateTips2(n);
		return false;
	} else {
		return true;
	}
}

function checkform() {	var commentname = $("#commentname"),
		commentemail = $("#commentemail"),
		tips = $("#validateTips"),
		commenttext = $("#commenttext");
			//allFields = $([]).add(name).add(email).add(password),
 	var bValid = true;
	bValid = bValid && checkLength(commentname,"username",3,20);
	bValid = bValid && checkRegexp(commentname,/^[a-zа-яА-Я]([а-яА-Я0-9a-z_])+$/i,"Username may consist of alphabet, 0-9, underscores, begin with a letter.");
	bValid = bValid && checkLength(commentemail,"email",6,80);
	// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
	bValid = bValid && checkRegexp(commentemail,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"email incorrect");
	bValid = bValid && checkLength2(commenttext,"comment text",3,500);
	if (bValid) return true;}


function progress(d){	if (d=="show") {	var w=$(window).width(); //screen.width;
	var h=$(window).height(); //screen.height;
	var off=$(document).scrollTop();
	var top=off+h/2-200;
	var left=w/2-400;
    // $.dimScreen(100, 0.2, 0);
   	$("#uprogress").css("zIndex",100);
	$("#uprogress").css("top",top);
	$("#uprogress").css("left",left);
	$("#uprogress").show();	}

	if (d=="hide") {			$("#uprogress").hide();
			//$.dimScreenStop();		}
 return;}

function freload(){
  	$(document).ready(function() {
		window.location.reload ( true );
	});
	return;}


function grad(id,endcolor){
		    var startcolor='9E9E9E';
			var st=$(id).html();
	        var l=st.length;
            var min=l-6;
            var o=st.substr(0,min);
            var end=st.substr(min,5);
            o = o+"<span class='end'>"+end+"</span>";
            $(id).html(o);
               $(".end").each(function(){
        	gradientText.set(this,startcolor,endcolor);
      		});
}

function profile(resp) {	var w=$(window).width(); //screen.width;
	var h=$(window).height(); //screen.height;
	var off=$(document).scrollTop();
	var top=off+h/2-235;
	var left=w/2-255;
   	$.dimScreen(100, 0.2, 0);
   	$("#userinfo").css("zIndex",1000);
	$("#userinfo").css("top",top);
	$("#userinfo").css("left",left);
    var allcookies = document.cookie;
	var pos = allcookies.indexOf("user=");
	if (pos != -1) {
    var start = pos + 5;                       // Start of cookie value
    var end = allcookies.indexOf(";", start);  // End of cookie value
    if (end == -1) end = allcookies.length;
    var user = allcookies.substring(start, end);
    user=jQuery.trim(user);
     // Extract the value
    user=decodeURIComponent(user);
	pos = allcookies.indexOf("pwd=");
	start = pos+4;
    end = allcookies.indexOf(";", start);
    if (end == -1) end = allcookies.length;
    var pass = allcookies.substring(start, end);
    pass=jQuery.trim(pass)
    pass = decodeURIComponent(pass);
     }
     var posterinfo=getauthor(user,pass);
   // alert(user+pass);
             $("#fpostername").val(user);
             $("#fpassword").val(pass);
             $("#fmail").val(posterinfo.email);
             $("#fimclient").val(posterinfo.imclient);
             $("#fsite").val(posterinfo.site);
             if (posterinfo.comment) {
             tinyMCE.execCommand('mceSetContent',false,html_entity_decode(posterinfo.comment));
             $("#fnotes").val(html_entity_decode(posterinfo.comment));
             }  else   {             	tinyMCE.execCommand('mceSetContent',false,'');
             $("#fnotes").val('');             }
$("#userinfo").slideDown('normal');
			$(function() {
		$("#userinfo").draggable();
	});}

function show_upl_dial(resp) {
    var w=$(window).width(); //screen.width;
	var h=$(window).height(); //screen.height;
	var off=$(document).scrollTop();
	var top=off+h/2-285;
	var left=w/2-325;

	   hw3 = $("#uplboxcontent").html();

	$.dimScreen(100, 0.2, 0);
   	$("#uplbox").css("zIndex",1000);
	$("#uplbox").css("top",top);
	$("#uplbox").css("left",left);
	try
	{
	var resp = jQuery.parseJSON(resp);
	var status= resp.status;
	var img=resp.src;
	var imgh=resp.height;
	var imgw=resp.width;
	if (resp.realpic){
	    var realpic=resp.realpic;
	    var name=realpic.substr(realpic,realpic.indexOf('.'));
	    }
	}
	catch(e)
	{
		$("#uplboxcontent").html('<br><br><center><h1>Image too big<br>We accept images 2M size and 400x400px min dimensions</h1></center>');
	    $("#uplbox").slideDown('normal');
	     $("#uplbox").fadeOut(4000);
         $(document).ready(function() {
         $.dimScreenStop();
        window.setTimeout(fvoid3,4100);
          //window.setTimeout(freload,2000);
          });
		return;
	}
   $("#realpic").val(realpic);
   $("#addpicname").val(name);
   $("#imga").attr('href',img);
   $("#imgsrc").attr('src',img);
   $("#imgsrc").attr('width',imgw);
   $("#imgsrc").attr('height',imgh);
  // alert('!');
  // alert(status);
    if(!status) alert('no status!');
	if (status!='ok') {		$("#uplboxcontent").html('<br><br><br><center><h1>'+status+'</h1></center>');
         // window.setTimeout(freload,2000);
          $("#uplbox").slideDown('normal');
         $("#uplbox").fadeOut(2300);
         $(document).ready(function() {
         $.dimScreenStop();
        window.setTimeout(fvoid3,2300);
    $(function() {
		$("#uplbox").draggable();
	});
        return;
        });
	} else {		$("#uplbox").slideDown('normal');
			$(function() {
		$("#uplbox").draggable();
	});
		return;	}
}



function fvoid3(){
		$("#uplboxcontent").html(hw3);
			 var data = "server.php";
			 $(document).ready(function() {
	  $("#addtagstext").autocomplete(data, {
						multiple: true,
						extraParams: { type: 'suggest' }
						});
			});
	return;}

//dimScreen()
//by Brandon Goldman
jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;

        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }

        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
        opacity = (opacity > 0) ? opacity : 0.5;
        return jQuery('<div></div>').attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000'
            ,height: $(document).height()
            ,left: '0px'
            ,opacity: 0
            ,position: 'absolute'
            ,top: '0px'
            ,width: '100%'
            ,zIndex: 999
        }).appendTo(document.body).fadeTo(speed, opacity, callback);
    },

    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = $('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(speed, function() {
            x.remove();
            if(typeof callback == 'function') callback();
        });
    }
});


function show(that){	$(that).toggle();}

Shadowbox.init({
    handleOversize:     "resize",
    displayNav:         true,
    handleUnsupported:  "remove",
    autoplayMovies:     true,
    autoDimensions:	true,
    continuous:	true,
    resizeDuration:	0.1
});


function logout(){
	var d=new Date();
	d.setMonth(d.getMonth()-1);
	var dat=d.toGMTString();
    var curCookie = "user=" + escape("") +"; expires=" + dat+"; domain=.andboson.net";
    document.cookie = curCookie;
    var curCookie = "pwd=" + escape("") +"; expires=" + dat+"; domain=.andboson.net";
    document.cookie = curCookie;
    login();
    hw=$("#loginboxcontent").html();
       $("#loginboxcontent").html('<br><h1><center>logged out</center></h1>');
   $.dimScreenStop();
          $("#liloginlog").css("display","block");
         $("#liprofile").css("display","none");
         $("#lilogout").css("display","none");
 $("#loginbox").fadeOut(2000);
       window.setTimeout(fvoid,1900);
       $("#reminder").css('display','none');
    return;
}



function login(){
		var w=$(window).width(); //screen.width;
	var h=$(window).height(); //screen.height;
	var off=$(document).scrollTop();
	var top=off+h/2-235;
	var left=w/2-255;
   	$.dimScreen(100, 0.2, 0);
   	$("#loginbox").css("zIndex",1000);
	$("#loginbox").css("top",top);
	$("#loginbox").css("left",left);
$("#loginbox").slideDown('normal');
	$(function() {
		$("#loginbox").draggable();
	});

}


function lupdateTips(t){
	$("#lvalidateTips").html(t);
	$("#lvalidateTips").effect("highlight",{},2000);
}
function loginin(){   	var lpostername = $("#lpostername"),
		lpassword = $("#lpassword"),
		ltips = $("#lvalidateTips");

  	if ( lpostername.val().length > 250 || lpostername.val().length < 3 ) {
	    lpostername.effect("pulsate", { times:2 }, 2000);
		lupdateTips("Length of name must be between 3 and 250.");
		return;
    }

    if ( lpassword.val().length > 250 || lpassword.val().length < 3 ) {
	    lpostername.effect("pulsate", { times:2 }, 2000);
		lupdateTips("Length of password must be between 3 and 250.");
		return;
    }
   var  regexp=/^([а-яА-Я0-9a-z_\+])+$/i;
	if ( !( regexp.test( lpostername.val() ) ) ) {
	    lpostername.effect("pulsate", { times:2 }, 2000);
		lupdateTips('Name may consist of alphabet, 0-9, underscores.');
		return;
		}

	if ( !( regexp.test( lpassword.val() ) ) ) {
	    lpassword.effect("pulsate", { times:2 }, 2000);
		lupdateTips('Password may consist of alphabet, 0-9, underscores.');
		return;
		}
   var aid=checkauthor(lpostername.val(),lpassword.val());
   if(aid<0) {   	 alert('Invalid name and password combination or user not exist.\n Register with upload image!');
   	 return;
   	 }
   	    $("#liloginlog").css("display","none");
         $("#liprofile").css("display","block");
         $("#lilogout").css("display","block");
var posterinfo=getauthor(lpostername.val(),lpassword.val());
             $("#fpostername").val(lpostername.val());
             $("#fpassword").val(lpassword.val());
             $("#fmail").val(posterinfo.email);
             $("#fimclient").val(posterinfo.imclient);
             $("#fsite").val(posterinfo.site);
              if (posterinfo.comment) {
             tinyMCE.execCommand('mceSetContent',false,html_entity_decode(posterinfo.comment));
             $("#fnotes").val(html_entity_decode(posterinfo.comment));
             }  else   {
             	tinyMCE.execCommand('mceSetContent',false,'');
             $("#fnotes").val('');
             }
     //alert(posterinfo.name);

   hw=$("#loginboxcontent").html();
   $("#loginboxcontent").html('<br><h1><center>logged in</center></h1>');
   $.dimScreenStop();
   $("#loginbox").fadeOut(2000);
     	$(document).ready(function() {
	   window.setTimeout(fvoid,1900);
	   if (!posterinfo.email) reminder();
	});

}

function fvoid(){	$("#loginboxcontent").html(hw);
	return;}


function getauthor(a,p){
   $.ajax({
   type: "GET",
   async:false,
   url: "server.php",
   data: "type=getauthor&a="+a+"&p="+p,
   success: function(msg){
   			   try
   			   			{
						msg = jQuery.parseJSON(msg);
						}
						catch(e)
						{
							alert(e)
							info=false;
							return;
						}
     		info=msg;
     		return;
			}
	 });
return info;}


function checkauthor(poster,addposterpass) {
	$.ajax({
   type: "GET",
   async:false,
   url: "server.php",
   data: "type=checkauthor&poster="+poster+"&addposterpass="+addposterpass,
   success: function(msg0){
                	try
						{
						msg = jQuery.parseJSON(msg0);
						}
						catch(e)
						{
							alert(e)
							out=false;
							return;
						}
        	    if (msg.status=='exists') {
        	    	     alert('Poster with same name already exists \n try another name\\pass or log in');
        	    	     out=-99;
        	    	     return -99;
        	    	     }
        	    if (msg.status=='loginok') { //pass and name ok
        	             setuserdata('user',poster);
        	             setuserdata('pwd',addposterpass);
        	            // $("#addposter").attr('id','sads');
        	            // $("#addposterpass").attr('id','dsadasd');
        	            // $("#tohide").css('display','none');
        	             out=msg.aid;
        	    	     return msg.aid;
        	    	     }
        	    if (msg.status=='no') {     //if login not exists send flag for insert author
    		              out=-1;
	        	    	} else {
	        	    		alert(msg.status); /// if some errors
	    					return false;
	        	     	}
			}
	 });
 return out;
}


function checkprofileform() {
	var fpostername = $("#fpostername"),
		fpassword = $("#fpassword"),
		fmail = $("#fmail"),
		fimclient = $("#fimclient"),
		fnotes = $("#fnotes"),
		fsite = $("#fsite"),
		tips = $("#fvalidateTips");
 	var bValid = true;
	bValid = bValid && checkLength3(fpostername,"Poster name",3,250);
	bValid = bValid && checkLength3(fpassword,"Password",2,250);
	bValid = bValid && checkRegexp2(fpostername,/^([а-яА-Я0-9a-z_\+])+$/i,"Poster name may consist of alphabet, 0-9, underscores.");
	if (fimclient.val().length>0) bValid = bValid && checkRegexp2(fimclient,/^([а-яА-Я0-9a-z_\+-:])+$/i,"IM client id may consist of alphabet, 0-9, underscores.");
	bValid = bValid && checkRegexp2(fpassword,/^([а-яА-Я0-9a-z_\+])+$/i,"Password may consist of alphabet, 0-9, underscores");
	if (fsite.val().length>0) bValid = bValid && checkRegexp2(fsite, /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/,"site url incorrect");
		// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
	bValid = bValid && checkRegexp2(fmail,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"email incorrect");
	if (bValid) return true;
}


function saveprofile(){	if(!checkprofileform())return;

	var fpostername = $("#fpostername").val(),
		fpassword = $("#fpassword").val(),
		fmail = $("#fmail").val(),
		fimclient = $("#fimclient").val(),
		fsite = $("#fsite").val(),
		fnotes = $("#fnotes").val();

 $.ajax({
   type: "GET",
   url: "server.php",
   data: "type=saveprofile&fpostername="+fpostername+"&fpassword="+fpassword+"&fmail="+fmail+"&fimclient="+fimclient+"&fnotes="+fnotes+"&fsite="+fsite,
   success: function(msg0){
                	try
						{
						var msg = jQuery.parseJSON(msg0);
						}
						catch(e)
						{
							$("#userinfocontent").html(e);
							return;
						}
        	    if (msg.status=='ok') {
        	     hw2 = $("#userinfocontent").html();
        	        setuserdata('user',fpostername);
					setuserdata('pwd',fpassword);
        	       		$("#userinfocontent").html('<br><br><br><br><center><h1>Profile was udated</h1></center>');
			              $("#userinfo").fadeOut(2000);
			              $.dimScreenStop();
			              window.setTimeout(fvoid2,2100);
			              if (fmail) $("#reminder").css('display','none');
        	    		} else  {
							$("#userinfocontent").html(msg.status);
							window.setTimeout(fvoid2,2100);
							return;
        	    	}
			}
	 });}

function fvoid2(){
	$("#userinfocontent").html(hw2);
	return;
}

function reminder(){
  $("#reminder").show("drop", { direction: "down" }, 1000);
  $("#reminder").effect("bounce", { times:3}, 400);

	//$("#reminder").show("fold", {}, 1000);
}


function checkpictureform() {
	var name = $("#addpicname"),
		poster = $("#addposter"),
		pass = $("#addposterpass"),
		tips = $("#validateTips"),
		tags = $("#addtagstext");
 	var bValid = true;
	bValid = bValid && checkLength(name,"picname",3,250);
	bValid = bValid && checkRegexp(name,/[^\\&-=\'\"`~]/gi,"Picture name may consist of alphabet, 0-9, underscores.");
	bValid = bValid && checkLength(poster,"poster",3,100);
	bValid = bValid && checkRegexp(poster,/[^\\&-=\'\"`~]/gi,"Poster may consist of alphabet, 0-9, underscores");
	bValid = bValid && checkRegexp(pass,/^([а-яА-Я0-9a-z_\+])+$/i,"Password may consist of alphabet, 0-9, underscores");
	if (tags.val().length>0) bValid = bValid && checkRegexp(tags,/[^0123456\\789&-=\'\"`~]/gi,"Tags may consist of alphabet, comma, underscores, begin with a letter.");
	// bValid = bValid && checkRegexp(tags,/[^0123456\\789&-=\'\"`~]/gi,"Tags may consist of alphabet, 0-9, comma, underscores, begin with a letter.");
	if (bValid) return true;
}

function uploadimage(){
   if (!checkpictureform()) return;
   hw3 = $("#uplboxcontent").html();
 	var poster=$("#addposter").val();
 	var addposterpass=$("#addposterpass").val();
 var aid=checkauthor(poster,addposterpass);
 	if (aid==-99) return;
	var tags=$("#addtagstext").val();
	var name=$("#addpicname").val();
	//var poster=$("#addposter").val();
	var posterid=aid;
	var realpic=$("#realpic").val();
	//var addposterpass=$("#addposterpass").val();
 $.ajax({
   type: "GET",
   url: "server.php",
   data: "type=addpicture&picturename="+name+"&tags="+tags+"&poster="+poster+"&realpic="+realpic+"&addposterpass="+addposterpass+"&posterid="+posterid,
   success: function(msg0){
                	try
						{
						var msg = jQuery.parseJSON(msg0);
						}
						catch(e)
						{
							$("#uplboxcontent").html(e);
							return;
						}
        	    if (msg.status=='ok') {
        	       		$("#uplboxcontent").html('<br><br><center><h1>Image was uploaded</h1></center><br><br><center><a href="http://www.andboson.net/?pic='+msg.id+'">Link to image</a></center>');			              $.dimScreenStop();
			              $("#uplbox").fadeOut(6000);
		         $(document).ready(function() {
			        window.setTimeout(fvoid3,6100);
			        return;
				  });
			                  // window.setTimeout(freload,3000);
			                  return;
        	    		} else  {
        	    			$("#uplboxcontent").html(msg.status);
        	    	$.dimScreenStop();
			        $("#uplbox").fadeOut(6000);
				         $(document).ready(function() {
					        window.setTimeout(fvoid3,6100);
			    		    return;
						  });
							return;        	    	}
			}
	 });


}


function addtags(id){
	var tags=$("#tagstext"+id).val();
	var reg=/[0123456\\789&='\"`~]/gi;
	 if (reg.test(tags)) {
	 alert('Wrong tags!\n Only letters allowed!');
	 return false;
	 }

 $.ajax({
   type: "GET",
   url: "server.php",
   data: "type=addtags&id="+id+"&tags="+tags,
   success: function(msg){
     		$("#tagcloud"+id).html(msg);
        	setTimeout(
                  function()
                        {
                      	$("#tagger"+id).slideUp("fast");
                        $("#tagstext"+id).val('');
                        },
                  600);
			}
	 });
}

function html_entity_decode(texte) {
texte = texte.replace(/&quot;/g,'"'); // 34 22
texte = texte.replace(/&amp;/g,'&'); // 38 26
texte = texte.replace(/'/g,"'"); // 39 27
texte = texte.replace(/&lt;/g,'<'); // 60 3C
texte = texte.replace(/&gt;/g,'>'); // 62 3E
texte = texte.replace(/&circ;/g,'^'); // 94 5E
texte = texte.replace(/&lsquo;/g,'‘'); // 145 91
texte = texte.replace(/&rsquo;/g,'’'); // 146 92
texte = texte.replace(/&ldquo;/g,'“'); // 147 93
texte = texte.replace(/&rdquo;/g,'”'); // 148 94
texte = texte.replace(/&bull;/g,'•'); // 149 95
texte = texte.replace(/&ndash;/g,'–'); // 150 96
texte = texte.replace(/&mdash;/g,'—'); // 151 97
texte = texte.replace(/&tilde;/g,'˜'); // 152 98
texte = texte.replace(/&trade;/g,'™'); // 153 99
texte = texte.replace(/&scaron;/g,'š'); // 154 9A
texte = texte.replace(/&rsaquo;/g,'›'); // 155 9B
texte = texte.replace(/&oelig;/g,'œ'); // 156 9C
texte = texte.replace(/ť/g,' '); // 157 9D
texte = texte.replace(/ž/g,'ž'); // 158 9E
texte = texte.replace(/&Yuml;/g,'Ÿ'); // 159 9F
texte = texte.replace(/&nbsp;/g,' '); // 160 A0
texte = texte.replace(/&iexcl;/g,'¡'); // 161 A1
texte = texte.replace(/&cent;/g,'¢'); // 162 A2
texte = texte.replace(/&pound;/g,'£'); // 163 A3
texte = texte.replace(/&curren;/g,' '); // 164 A4
texte = texte.replace(/&yen;/g,'¥'); // 165 A5
texte = texte.replace(/&brvbar;/g,'¦'); // 166 A6
texte = texte.replace(/&sect;/g,'§'); // 167 A7
texte = texte.replace(/&uml;/g,'¨'); // 168 A8
texte = texte.replace(/&copy;/g,'©'); // 169 A9
texte = texte.replace(/&ordf;/g,'ª'); // 170 AA
texte = texte.replace(/&laquo;/g,'«'); // 171 AB
texte = texte.replace(/&not;/g,'¬'); // 172 AC
texte = texte.replace(/&shy;/g,'­'); // 173 AD
texte = texte.replace(/&reg;/g,'®'); // 174 AE
texte = texte.replace(/&macr;/g,'¯'); // 175 AF
texte = texte.replace(/&deg;/g,'°'); // 176 B0
texte = texte.replace(/&plusmn;/g,'±'); // 177 B1
texte = texte.replace(/&sup2;/g,'²'); // 178 B2
texte = texte.replace(/&sup3;/g,'³'); // 179 B3
texte = texte.replace(/&acute;/g,'´'); // 180 B4
texte = texte.replace(/&micro;/g,'µ'); // 181 B5
texte = texte.replace(/&para/g,'¶'); // 182 B6
texte = texte.replace(/&middot;/g,'·'); // 183 B7
texte = texte.replace(/&cedil;/g,'¸'); // 184 B8
texte = texte.replace(/&sup1;/g,'¹'); // 185 B9
texte = texte.replace(/&ordm;/g,'º'); // 186 BA
texte = texte.replace(/&raquo;/g,'»'); // 187 BB
texte = texte.replace(/&frac14;/g,'¼'); // 188 BC
texte = texte.replace(/&frac12;/g,'½'); // 189 BD
texte = texte.replace(/&frac34;/g,'¾'); // 190 BE
texte = texte.replace(/&iquest;/g,'¿'); // 191 BF
texte = texte.replace(/&Agrave;/g,'À'); // 192 C0
texte = texte.replace(/&Aacute;/g,'Á'); // 193 C1
texte = texte.replace(/&Acirc;/g,'Â'); // 194 C2
texte = texte.replace(/&Atilde;/g,'Ã'); // 195 C3
texte = texte.replace(/&Auml;/g,'Ä'); // 196 C4
texte = texte.replace(/&Aring;/g,'Å'); // 197 C5
texte = texte.replace(/&AElig;/g,'Æ'); // 198 C6
texte = texte.replace(/&Ccedil;/g,'Ç'); // 199 C7
texte = texte.replace(/&Egrave;/g,'È'); // 200 C8
texte = texte.replace(/&Eacute;/g,'É'); // 201 C9
texte = texte.replace(/&Ecirc;/g,'Ê'); // 202 CA
texte = texte.replace(/&Euml;/g,'Ë'); // 203 CB
texte = texte.replace(/&Igrave;/g,'Ì'); // 204 CC
texte = texte.replace(/&Iacute;/g,'Í'); // 205 CD
texte = texte.replace(/&Icirc;/g,'Î'); // 206 CE
texte = texte.replace(/&Iuml;/g,'Ï'); // 207 CF
texte = texte.replace(/&ETH;/g,'Ð'); // 208 D0
texte = texte.replace(/&Ntilde;/g,'Ñ'); // 209 D1
texte = texte.replace(/&Ograve;/g,'Ò'); // 210 D2
texte = texte.replace(/&Oacute;/g,'Ó'); // 211 D3
texte = texte.replace(/&Ocirc;/g,'Ô'); // 212 D4
texte = texte.replace(/&Otilde;/g,'Õ'); // 213 D5
texte = texte.replace(/&Ouml;/g,'Ö'); // 214 D6
texte = texte.replace(/&times;/g,'×'); // 215 D7
texte = texte.replace(/&Oslash;/g,'Ø'); // 216 D8
texte = texte.replace(/&Ugrave;/g,'Ù'); // 217 D9
texte = texte.replace(/&Uacute;/g,'Ú'); // 218 DA
texte = texte.replace(/&Ucirc;/g,'Û'); // 219 DB
texte = texte.replace(/&Uuml;/g,'Ü'); // 220 DC
texte = texte.replace(/&Yacute;/g,'Ý'); // 221 DD
texte = texte.replace(/&THORN;/g,'Þ'); // 222 DE
texte = texte.replace(/&szlig;/g,'ß'); // 223 DF
texte = texte.replace(/&agrave;/g,'à'); // 224 E0
texte = texte.replace(/&aacute;/g,'á'); // 225 E1
texte = texte.replace(/&acirc;/g,'â'); // 226 E2
texte = texte.replace(/&atilde;/g,'ã'); // 227 E3
texte = texte.replace(/&auml;/g,'ä'); // 228 E4
texte = texte.replace(/&aring;/g,'å'); // 229 E5
texte = texte.replace(/&aelig;/g,'æ'); // 230 E6
texte = texte.replace(/&ccedil;/g,'ç'); // 231 E7
texte = texte.replace(/&egrave;/g,'è'); // 232 E8
texte = texte.replace(/&eacute;/g,'é'); // 233 E9
texte = texte.replace(/&ecirc;/g,'ê'); // 234 EA
texte = texte.replace(/&euml;/g,'ë'); // 235 EB
texte = texte.replace(/&igrave;/g,'ì'); // 236 EC
texte = texte.replace(/&iacute;/g,'í'); // 237 ED
texte = texte.replace(/&icirc;/g,'î'); // 238 EE
texte = texte.replace(/&iuml;/g,'ï'); // 239 EF
texte = texte.replace(/&eth;/g,'ð'); // 240 F0
texte = texte.replace(/&ntilde;/g,'ñ'); // 241 F1
texte = texte.replace(/&ograve;/g,'ò'); // 242 F2
texte = texte.replace(/&oacute;/g,'ó'); // 243 F3
texte = texte.replace(/&ocirc;/g,'ô'); // 244 F4
texte = texte.replace(/&otilde;/g,'õ'); // 245 F5
texte = texte.replace(/&ouml;/g,'ö'); // 246 F6
texte = texte.replace(/&divide;/g,'÷'); // 247 F7
texte = texte.replace(/&oslash;/g,'ø'); // 248 F8
texte = texte.replace(/&ugrave;/g,'ù'); // 249 F9
texte = texte.replace(/&uacute;/g,'ú'); // 250 FA
texte = texte.replace(/&ucirc;/g,'û'); // 251 FB
texte = texte.replace(/&uuml;/g,'ü'); // 252 FC
texte = texte.replace(/&yacute;/g,'ý'); // 253 FD
texte = texte.replace(/&thorn;/g,'þ'); // 254 FE
texte = texte.replace(/&yuml;/g,'ÿ'); // 255 FF
return texte;
}
