var asd = new Array();
function keyw(name,id){
	//alert(name);
	//alert(asd[id]);
	var delimeter='|';
	
	iid='#keyw'+id;
	$(iid).toggleClass("keyw_sel");
	current = document.getElementById('keywordsall').value;
	
	if(current==''){
		current=delimeter;
	}
	if(asd[id]==1){
		// remove item
		asd[id]=0;
		current = current.replace(delimeter+name+delimeter,delimeter);
	}else{
		//alert(asd[id]);
		asd[id]=1;
		current = current + name + delimeter; 
	}
	
	document.getElementById('keywordsall').value = current;
	
}
function sel_img(id){
	document.getElementById('image_id').value = id;
	document.getElementById('img_select').submit();
	//alert(id);
}
// function to send ajax when creating poster
function pupd(){
	var postvars = 'act=1&postar_idea='+encodeURIComponent($('#postar_idea').val())+'&postar_desc='+encodeURIComponent($('#postar_desc').val());
	//alert(postvars);
	$.post('ajax.php',postvars, function(data){
		//alert(data);
		img_upd(1);
	});

}
function pupd_clean(){
	$('#postar_idea').val('');
	$('#postar_desc').val('');
	pupd();
}
var ttt = 1;
function img_upd(type){
	
	ttt++;
	if(type==1){
		document.getElementById('postar').src='i_postar.php?p=postar&k='+ttt;
		//document.getElementById('postar').src='img/dot.gif';
	}else{
		document.getElementById('pikcha').src='i_pikcha.php?p=postar&k='+ttt;
	}

}
function upper(){
	var str = $('#postar_idea').val();
	$('#postar_idea').val(str.toUpperCase());
}
function publish(id){
	if(id==1){
		$('#create_final_id').val('postar');
	}else{
		$('#create_final_id').val('pikcha');
	}
	if(confirm('Is everything ok? Press "OK" to publich then!')){
		$('#create_final').submit();
	}
}
function pik_ch(color){
//alert(color);
	if(color){
		$('#ep_color').val(color);
	}

	var size = $('#ep_size').val();

	$('#ep_text').css("font-size",size+'pt');
	$('#ep_text').css("font-family",$('#ep_font').val());
	$('#ep_text').css("color",$('#ep_color').val());


}


function pik_edit(){


	var postvars = 'text='+encodeURIComponent($('#ep_text').val())+'&font='+encodeURIComponent($('#ep_font').val())
	+'&color='+encodeURIComponent($('#ep_color').val())+'&fontsize='+encodeURIComponent($('#ep_size').val())+'&pos_top='+encodeURIComponent($('#pos_top').val())
	+'&pos_left='+encodeURIComponent($('#pos_left').val())+'&act=pikcha';
	
	$.post('ajax.php',postvars, function(data){
		img_upd(2);
		get_panel();
		move_drag();
	});

}


var drag_pos = $('#draggable').offset();


function move_drag(){
    $(document).ready(function() {
        $("#draggable").animate({ 
			'left': drag_pos.left+'px', 'top': drag_pos.top+'px'
		}, 'normal');

     });
}

function drag_stop(){
	var pos1 = $('#draggable').offset(); // position = { left: 42, top: 567 }
	var pos0 = $('#pikcha').offset();
	//var pos_txt = ' Left:'+(pos1.left-pos0.left) + ' Top:' + (pos1.top-pos0.top);
	$('#pos_top').val(pos1.top-pos0.top+34);
	$('#pos_left').val(pos1.left-pos0.left+4);
}

function del_txt(id){
	var postvars = 'ep_id='+id+'&ep_act=del_txt&act=pikcha';
	$.post('ajax.php',postvars, function(data){
		img_upd(2);
		get_panel();
	});
}

function pik_clr(){
	if(confirm('Are you sure?')){
		var postvars = 'act=pikcha_del_all';
		$.post('ajax.php',postvars, function(data){
			img_upd(2);
			get_panel();
		});
	}
}

function get_panel(){
	var postvars = 'act=panel';
	$.post('ajax.php',postvars, function(data){
		//img_upd(2);
		//alert(data);
		$('#remove_text').html(data);
	});
}
function rate(num,pikcha_id){
	//alert(num);
	var kkk = num + 2;
	var postvars = 'pikcha_id='+pikcha_id+'&num='+num+'&act=rate';
	$.post('ajax.php',postvars, function(data){
		//alert(data);
	});
	$('#rateme').toggleClass("def");
	var clss = 'rate'+kkk;
	$('#rateme').toggleClass(clss);
	$('#rateme').html('');
}
function sel_img2(id,action){
	frm = document.getElementById('mod_pikcha_select');
	frm.image_id.value = id;
	frm.action.value = action;
	frm.submit();
}
function del_comm(id){
	if(confirm('Delete id['+id+'] RU Sure?')){
		var postvars = 'act=del_comm&id='+id;
		$.post('ajax.php',postvars, function(data){
			//alert(data);
			$('#comment_'+id).html('removed');
		});
	}
}
function mod_approve(act){
	
	if(act==1){
		if(confirm('OK, RU Sure?')){
			frm = document.getElementById('mod_one_pikcha');
			frm.action.value=1;
		}
	}else if(act==2){
		if(confirm('NOT OK, RU Sure?')){
			frm = document.getElementById('mod_one_pikcha');
			frm.action.value=2;
		}
	}else if(act==3){
		if(confirm('OK, RU Sure?')){
			frm = document.getElementById('mod_keywords');
			frm.action.value=1;
		}
	}else if(act==4){
		if(confirm('NOT OK, RU Sure?')){
			frm = document.getElementById('mod_keywords');
			frm.action.value=2;
		}
	}
	
	frm.submit();
}

function bookmarks() {  

     var title = document.title; var url = location.href;  
     if (window.sidebar) // Firefox  
         window.sidebar.addPanel(title, url, 'AAA');  
     else if(window.opera && window.print) // Opera  
     {  
         var elem = document.createElement('a');  
         elem.setAttribute('href',url);  
         elem.setAttribute('title',title);  
         elem.setAttribute('rel','sidebar'); // required to work in opera 7+  
         elem.click();  
     }   
     else if($.browser.msie == true)  { // IE 
		//alert(window.external.AddFavorite('asd','qwe'));
		if($.browser.version>6 && $.browser.version<8){
			window.external.AddFavorite(url, title);
		}else{
			alert('Please use CTRL + D to bookmark this website.');
		}
    }
}




