function popup(url,name,win_height,win_width) {
	pos_horizon = ((screen.width/2)-(win_width/2)); 
	pos_vertical = ((screen.height/2)-(win_height/2)); 
	name = name.replace(' ' , '');
	hwnd = window.open(url,name,"width="+win_width+",scrollbars=yes,resizable=yes,height="+win_height+",top="+pos_vertical+",left="+pos_horizon); 
	hwnd.focus();
}

function toggleVisible(obj)	{
	if (obj.style.display=="none") {
		obj.style.display="block";
	} else {
		obj.style.display="none";
	}
	return false;
}

function textCounter(textarea,counter_div,max_length,suffix) {
	if (textarea.value.length > max_length){ // trimmer...
		textarea.value = textarea.value.substring(0, max_length);
	} else {
		counter_div.innerHTML = '<p>'+(max_length-textarea.value.length) + suffix+'</p>';
	}
}

function addTag(textarea,tag) {
	if(textarea.value.length > 0) {
		textarea.value += ', ' + tag;
	} else {
		textarea.value += tag;
	}
}

function showHide(id1,id2) {
	obj1 = document.getElementById(id1);
	obj2 = document.getElementById(id2);
	toggleVisible(obj1);
	toggleVisible(obj2);
}

function effectHideFade(obj){
	Effect.Fade(obj, { duration: .2 });
}

function effectShowFade(obj){
	Effect.Appear(obj, { duration: .2 });
}

function effectHideSlideFade(obj){
	new Effect.Parallel(
	    [ new Effect.SlideUp(obj, { sync: true }), 
	      new Effect.Fade(obj, { sync: true } ) ],
	    { duration: .8 }
	  );	
}

function effectShowSlideFade(obj){
	new Effect.Parallel(
	    [ new Effect.BlindDown(obj, { sync: true }), 
	      new Effect.Appear(obj, { sync: true } ) ],
	    { duration: .8 }
	  );
}


function destroy(obj, level){
	destroy_callback_variable = obj
	if(!level){
		new Effect.Parallel(
		    [ new Effect.BlindUp(obj, { sync: true }), 
		      new Effect.Fade(obj, { sync: true } ) ],
		    { duration: .8, afterFinish: function (effect){ destroy(obj, true); } }
		  );
	} else {
		for(var i = 0; i < obj.childNodes.length; i++){
			destroy(obj.childNodes[i], true);
		}
		obj.parentNode.removeChild(obj);
	}
}

function smartSubstring(string, length, smart, cutsymbol){
	if(!cutsymbol){
		cutsymbol = '...';
	}
	len = string.length;
	if(len > length){
		if(smart){
			cutlen = len - length;
			
			cutleft = Math.floor(cutlen / 2);
			cutright = Math.ceil(cutlen / 2);
			
			leftsplit = Math.floor(len / 2);
			rightsplit = Math.floor(len / 2);

			
			left = string.substring(0, leftsplit);
			left = left.substring(0, (left.length - cutleft));
			
			right = string.substring(rightsplit);
			right = right.substring(cutright);
			
			return left+cutsymbol+right;
		} else {
			return string.substring(0, length);
		}
	} else {
		return string;
	}
}

function in_array(needle, array){
	for(var ini = 0; ini < array.length; ini++){
		if(array[ini]){
			if(needle == array[ini]){
				return ini;
			}
		}
	}
	return false;
}
