var loginFormParams = {container:'div-wlogin-container',
		  				 minHeight:0,
			  			 maxHeight:276
			 			};
function openLoginForm(){
	var login_form = document.getElementById(loginFormParams.container);
	if(login_form && !login_form.timerId){
		if(typeof(login_form.offsetHeight) == 'number' && login_form.offsetHeight>loginFormParams.minHeight){
			setDivHeight(login_form,loginFormParams.maxHeight,loginFormParams.minHeight);
			bindEnterKeyOnForm(login_form,false);
		}	
		else{
			setDivHeight(login_form,loginFormParams.minHeight,loginFormParams.maxHeight);
			bindEnterKeyOnForm(login_form,true);
		}	
	}
}

function bindEnterKeyOnForm(form,bind){
	if(form && form.getElementsByTagName('input').length){
		var cpt = 0;
		for(var i = 0; i<form.getElementsByTagName('input').length; i++){
			if(form.getElementsByTagName('input')[i].getAttribute('type') == 'text' || form.getElementsByTagName('input')[i].getAttribute('type') == 'password'){
				if(bind){
					if(cpt == 0)
						form.getElementsByTagName('input')[i].focus();
					ZEvent.addEventListener(form.getElementsByTagName('input')[i],'keydown',submitOnEnter,false);
					ZEvent.addEventListener(form.getElementsByTagName('input')[i],'keypress',cancelEnter,false);
					cpt++;
				}
				else{
					ZEvent.removeEventListener(form.getElementsByTagName('input')[i],'keydown',submitOnEnter,false);
					ZEvent.removeEventListener(form.getElementsByTagName('input')[i],'keypress',cancelEnter,false);
				}
			}
		}
	}
}

function setDivHeight(container,from,to,onCompleteCallback){
	var steps = 40, timelaps = 10, increment = 0;
	container.timerId = setInterval(	function(){
											increment++;
											var height = from;
											if(typeof(container.offsetHeight) == 'number')
												height = container.offsetHeight;
											
											if(height != to){
												height += 0.5*(1-Math.cos(Math.PI*increment/steps))*(to-from);
												if ((to-from)<0 && height < to) 
													height = to;
												else if ((to-from)>0 && height > to) 
													height = to;
												container.style.height = Math.floor(height)+'px';
											}
											else{
												clearInterval(container.timerId);
												container.timerId = null;
												if(onCompleteCallback)
													onCompleteCallback();
											}
										},timelaps
	);
}

function mousewheel_handler(e){
	var myEvent = new ZEvent(e);
	if(myEvent.source.id == "zoomBrowser"){
		myEvent.source.focus();
		myEvent.preventDefault();
	}	
	else{
		var flashObj = document.getElementById("zoomBrowser");
		if(flashObj){
			flashObj.blur();
			myEvent.stopPropagation();
		}
	}
}

function listenMouseWheelEvent(){
	if (window.addEventListener)
   		window.addEventListener("DOMMouseScroll", mousewheel_handler, false);
   window.onmousewheel = document.onmousewheel = mousewheel_handler;
}


function show_tab(num,id){
	var a = document.getElementById("zm-tab_"+num);
	if(a && a.getAttribute("class")!="zm-tab-active" && a.getAttribute("className")!="zm-tab-active"){
		if(id)
			var div_tabs = document.getElementById(id);
		else
			var div_tabs = document.getElementById("div-tabs");
			
		if(div_tabs){
			var tabs = div_tabs.getElementsByTagName("a");
			var active = 0,i = 0;
			while(!active && i < tabs.length){
				if(tabs[i].getAttribute("class")=="zm-tab-active" || tabs[i].getAttribute("className")=="zm-tab-active")
					active = i+1;
				i++;
			}
			if(active){
				document.getElementById("zm-tab_"+active).removeAttribute("class");
				document.getElementById("zm-tab_"+active).removeAttribute("className");
				document.getElementById("zm-tab-content_"+active).setAttribute("class","hidden");
				document.getElementById("zm-tab-content_"+active).setAttribute("className","hidden");
				a.setAttribute("class","zm-tab-active");
				a.setAttribute("className","zm-tab-active");
				document.getElementById("zm-tab-content_"+num).removeAttribute("class");
				document.getElementById("zm-tab-content_"+num).removeAttribute("className");
			}
		}
	}
}

function add_favorite(token,action){
	if(user_logged){
		var data = "token="+token+"&user="+user_logged;
		if(action)
			data += '&action='+action;
			
		var xhr = new ZHTTPRequest("POST","xml",true);
		xhr.setCompleteCallback(
				function(xml_doc){
					var success = false;
					var msg = "";
					if(xml_doc!=null){
						xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
						if(xml_doc.getElementsByTagName("success").length>0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue=="true")
							success = true;
						if(xml_doc.getElementsByTagName("message").length>0)
							var msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;

					}
					show_message_box(msg,success);
					//alert("Success : "+success+"\r\nMessage : \r\n"+msg);	
				}
		);
		xhr.setFailureCallback(
							function(){alert("Failed")}
		);
		xhr.query("../scripts/scp_fav.php",data);
	}
	else
		show_message_box(alerts.userNotLogged,false);
}

function bookmark_user(id,action){
	if(user_logged){
		var data = "id="+id+"&user="+user_logged;
		if(action)
			data += '&action='+action;
		else
			data += '&action=sav';
		var xhr = new ZHTTPRequest("POST","xml",true);
		xhr.setCompleteCallback(
				function(xml_doc){
					var success = false;
					var msg = "";
					if(xml_doc!=null){
						xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
						if(xml_doc.getElementsByTagName("success").length>0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue=="true")
							success = true;
						if(xml_doc.getElementsByTagName("message").length>0)
							var msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;

					}
					show_message_box(msg,success);
					//alert("Success : "+success+"\r\nMessage : \r\n"+msg);	
				}
		);
		xhr.setFailureCallback(
							function(){alert("Failed")}
		);
		xhr.query("../scripts/scp_favuser.php",data);
	}
	else
		show_message_box(alerts.userNotLogged,false);
}

function subscribe_to_user(id){
	var input = document.getElementById('txt-subscribe-email');
	if(input && id){
		var data = "id="+id+"&email="+input.value+"&user="+user_logged;
		var xhr = new ZHTTPRequest("POST","xml",true);
		xhr.setCompleteCallback(
				function(xml_doc){
					var success = false;
					var msg = "";
					if(xml_doc!=null){
						xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
						if(xml_doc.getElementsByTagName("success").length>0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue=="true")
							success = true;
						if(xml_doc.getElementsByTagName("message").length>0)
							var msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;

					}
					show_message_box(msg,success);
					//alert("Success : "+success+"\r\nMessage : \r\n"+msg);	
				}
		);
		xhr.setFailureCallback(
							function(){alert("Failed")}
		);
		xhr.query("../scripts/scp_subuser.php",data);
	}
	else
		show_message_box(alerts.userNotLogged,false);
}

function rate_zm(token,rating){
	var data = "token="+token+"&rating="+rating+"&user="+user_logged;
	var xhr = new ZHTTPRequest("POST","xml",true);
	xhr.setCompleteCallback(
			function(xml_doc){
				var success = false;
				var msg = "";
				if(xml_doc!=null){
					xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
					if(xml_doc.getElementsByTagName("success").length>0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue=="true")
						success = true;
					if(xml_doc.getElementsByTagName("message").length>0)
						var msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;
					if(xml_doc.getElementsByTagName("result").length>0){
						var result = parseInt(xml_doc.getElementsByTagName("result")[0].firstChild.nodeValue);
						var images = document.getElementById('p-fl-hl-info-rating').getElementsByTagName('img');
						if(images.length){
							for(var i=0;i<images.length;i++){
								if(result >= (i+1) && images[i].getAttribute('src').match(/_off.png$/))
									images[i].setAttribute('src',images[i].getAttribute('src').replace(/_off.png$/,'_on.png'));
								else if(result < (i+1) && images[i].getAttribute('src').match(/_on.png$/))
									images[i].setAttribute('src',images[i].getAttribute('src').replace(/_on.png$/,'_off.png'));
							}	
						}
					}

				}
				show_message_box(msg,success);
			}
	);
	xhr.setFailureCallback(
						function(){alert("Failed")}
	);
	xhr.query("../scripts/scp_zm_rating.php",data);
}

function display_infobulle(e){
	var myEvent = new ZEvent(e);
	var infobulle = document.getElementById('div-infobulle');
	if(myEvent.type == 'mouseover'){
		myEvent.source.style.cursor = 'pointer';
		myEvent.source.style.textDecoration='none';
	}
	else{
		myEvent.source.style.cursor = 'auto';
		myEvent.source.style.textDecoration='underline';
	}

	if(myEvent.type == 'mouseover' && infobulle.style.display!='block'){
		var coords = myEvent.getMouseCoords();
		infobulle.style.left = (coords.x-10)+'px';
		infobulle.style.top = coords.y+'px';
		ZEvent.addEventListener(infobulle,"mouseout",infobulle_event,false);
		infobulle.style.display='block';
	}
	else if(myEvent.type == 'mouseout' && infobulle.style.display!='none'){
		if(myEvent.relatedTarget.id!=infobulle.id && myEvent.relatedTarget.id != infobulle.firstChild.id){
			infobulle.style.display='none';
			ZEvent.removeEventListener(infobulle,"mouseout",infobulle_event,false);	
		}
	}
}

function infobulle_event(e){
	var myEvent = new ZEvent(e);
	var infobulle = document.getElementById('div-infobulle');
	var relatedTarget = myEvent.relatedTarget;
	while(relatedTarget != infobulle && relatedTarget.nodeName.toLowerCase() != 'body'){
		relatedTarget = relatedTarget.parentNode;
	}
	if(relatedTarget != infobulle){
		infobulle.style.display='none';
		ZEvent.removeEventListener(infobulle,"mouseout",infobulle_event,false);	
	}
}

function changeFilterChkState(elt){
	if(!elt.checked){
		alert(alerts.showExplicitContent);
		return false;
	} 
	else 
		return true;
}


function changeRdFilterChkState(){
	if(document.getElementById('adult_filter_off').checked){
		alert(alerts.showExplicitContent);
		document.getElementById('adult_filter_on').checked = true;
	} 
}

function display_owner_menu(id){
	if(id)
		var str_id = 'owner-menu_'+id;
	else
		var str_id = 'owner-menu';
		
	var a = document.getElementById('a-'+str_id);
	var menu = document.getElementById('ul-'+str_id);
	
	if(menu.style.display=='none' || a.text == '+'){
		
		menu.mouseOutEvent 	= 	function(e){
									hide_owner_menu(e,id);
								};
		menu.clickEvent 	= 	function(e){
									display_owner_menu(id);
						  		};		
								
		menu.mouseOverEvent = 	function(e){
									if(menu.timeout) 
										clearTimeout(menu.timeout);
								};		
		ZEvent.addEventListener(menu,'mouseout',menu.mouseOutEvent,false);
		ZEvent.addEventListener(a,'mouseout',menu.mouseOutEvent,false);
		var menu_items = menu.getElementsByTagName('a');
		if(menu_items.length){
			for(var i=0;i<menu_items.length;i++){
				ZEvent.addEventListener(menu_items[i],'click',menu.clickEvent,false);
			}
		}
		menu.style.display = 'block';
		a.firstChild.nodeValue = '-';
	}
	else{
		menu.style.display='none';
		var menu_items = menu.getElementsByTagName('a');
		if(menu_items.length){
			for(var i=0;i<menu_items.length;i++){
				ZEvent.removeEventListener(menu_items[i],'click',menu.clickEvent,false);
			}
		}
		ZEvent.removeEventListener(menu,'mouseout',menu.mouseOutEvent,false);
		ZEvent.removeEventListener(a,'mouseout',menu.mouseOutEvent,false);
		ZEvent.removeEventListener(menu,'mouseover',menu.mouseOverEvent,false);
		ZEvent.removeEventListener(a,'mouseover',menu.mouseOverEvent,false);
		a.firstChild.nodeValue = '+';
	}
}


function hide_owner_menu(e,id){
	if(id)
		var str_id = 'owner-menu_'+id;
	else
		var str_id = 'owner-menu';
	var myEvent = new ZEvent(e);
	var a = document.getElementById('a-'+str_id);
	var menu = document.getElementById('ul-'+str_id);
	
	var relatedTarget = myEvent.relatedTarget;
	while(relatedTarget.id != a.id && relatedTarget.id != menu.id && relatedTarget.nodeName.toLowerCase() != 'body'){
		relatedTarget = relatedTarget.parentNode;
	}

	if(relatedTarget.id != a.id && relatedTarget.id != menu.id){
		menu.timeout = setTimeout('display_owner_menu('+(id?id:'')+')',500);
		ZEvent.addEventListener(menu,'mouseover',menu.mouseOverEvent,false);
		ZEvent.addEventListener(a,'mouseover',menu.mouseOverEvent,false);
	}
}

function login(){
	var form = document.forms['zm-search-form'] || document.forms['zm-view-form'];
	var post_data = document.getElementById('post_data');
	post_data.value = '';
	if(form && form.elements.length){
		for(var i=0;i<form.elements.length;i++){
			if(post_data.value != '') post_data.value += '&';
			post_data.value += form.elements[i].name + '=' + encodeURIComponent(form.elements[i].value);
		}
	}
	document.getElementById('form-login').submit();
}

function zm_search_submit(){
	document.getElementById('zm-search-submit').value=1;
	document.getElementById('zm-search-form').submit();
}

function set_comment_form_visibility(visible,id){
	var form = document.getElementById(id+"-form");
	if (form && !form.timerId) {
		if (visible) {
			display_comment_form(true,id);
			setDivOpacity(form, 0, 100);
		}
		else 
			setDivOpacity(form, 100, 0, function(){display_comment_form(false,id);});
	}
}

function display_comment_form(display,id){
	if(display){
		document.getElementById(id+"-link").style.display='none';
		document.getElementById(id+"-form").style.display='block';
	}
	else{
		document.getElementById(id+"-form").style.display='none';
		document.getElementById(id+"-link").style.display='block';
		document.getElementById("id-comment").value = "";
		document.getElementById("txt-comment").value = "";
	}
}

function setDivOpacity(container,from,to,onCompleteCallback){
	var steps = 40, timelaps = 10, increment = 0;

	container.timerId = setInterval(function(){
										increment++;
										var opacity = from;
										if(typeof container.style.opacity == 'number' || container.style.opacity)
											opacity = container.style.opacity*100;
										else if(container.style.filter && container.style.filter.alpha && typeof container.style.filter.alpha.opacity == 'number')
											opacity = container.style.filter.alpha.opacity;
											
										if(opacity != to){
											opacity += 0.5*(1-Math.cos(Math.PI*increment/steps))*(to-from);
											if ((to-from)<0 && opacity < to) 
												opacity = to;
											else if ((to-from)>0 && opacity > to) 
												opacity = to;
											container.style.opacity = opacity/100;
											container.style.filter =  "alpha(opacity="+opacity+")";
										}
										else{
											clearInterval(container.timerId);
											container.timerId = null;
											if(onCompleteCallback)
												onCompleteCallback();
										}
									},timelaps
	);
}

function show_message_box(message,success,id){
	if(typeof id == 'string' && id != '' && document.getElementById(id))
		var div = document.getElementById(id);
	else
		var div = document.getElementById('div-action-result');
	if(div && div.getElementsByTagName('p').length){
		var p = div.getElementsByTagName('p')[0];
		p.innerHTML = message;
		if(success){
			p.removeAttribute('class');
			p.removeAttribute('className');
		}
		else{
			p.setAttribute('class','not_ok');
			p.setAttribute('className','not_ok');
		}
		div.style.display='block';
		setDivOpacity(div,0,100,function(){
									var timeout = setTimeout(
													function(){
														clearTimeout(timeout);
														setDivOpacity(div,100,0,
																		function(){
																			div.style.display='none';
																		}
																	 );
													},3000);
								}
					);
	}
}

function save_comment(script_url,data,zm_list_manager,form_id,msg_id){
	var xhr = new ZHTTPRequest("POST", "xml", true);
	xhr.setCompleteCallback(function(xml_doc){
		var success = false;
		var msg = "";
		if (xml_doc != null) {
			xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
			if (xml_doc.getElementsByTagName("success").length > 0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue == "true") 
				success = true;
			if (xml_doc.getElementsByTagName("message").length > 0) 
				var msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;
			
			if (xml_doc.getElementsByTagName("comment").length > 0 && typeof(zm_list_manager) == 'object') 
				zm_list_manager.addElement(xml_doc.getElementsByTagName("comment")[0]);
		}
		set_comment_form_visibility(false, form_id);
		if(msg_id)
			show_message_box(msg, success,msg_id);
		else
			show_message_box(msg, success);
	});
	xhr.setFailureCallback(function(){
		alert("Failed")
	});
	xhr.query(script_url, data);
}

function edit_comment(script_url,data,form_id,msg_id){
	var xhr = new ZHTTPRequest("POST","xml",true);
	xhr.setCompleteCallback(
			function(xml_doc){
				var success = false;
				var msg = "";
				if(xml_doc!=null){
					xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
					if(xml_doc.getElementsByTagName("success").length>0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue=="true")
						success = true;
					if(xml_doc.getElementsByTagName("message").length>0)
						 msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;
					
					if(success && xml_doc.getElementsByTagName("comment").length>0){
						var comment = xml_doc.getElementsByTagName("comment")[0];
						if(comment.getElementsByTagName("text").length);
							var text = comment.getElementsByTagName("text")[0];
						
						if(comment.getAttribute('id') && text){
							document.getElementById("id-comment").value = comment.getAttribute('id');
							document.getElementById("txt-comment").value = text.firstChild.nodeValue;
							set_comment_form_visibility(true,form_id);
						}
						else
							set_comment_form_visibility(false,form_id);
					}
				}
				if(!success){
					if(msg_id)
						show_message_box(msg, success,msg_id);
					else
						show_message_box(msg, success);
				}
			}
	);
	xhr.setFailureCallback(
		function(){alert("Failed")}
	);
	xhr.query(script_url,data);
}


function delete_comment(script_url,data,zm_list_manager,msg_id){
	var xhr = new ZHTTPRequest("POST","xml",true);
			
	xhr.setCompleteCallback(
			function(xml_doc){
				var success = false;
				var msg = "";
				if(xml_doc!=null){
					xml_doc = ZHTTPRequest.cleanXML(xml_doc.documentElement);
					if(xml_doc.getElementsByTagName("success").length>0 && xml_doc.getElementsByTagName("success")[0].firstChild.nodeValue=="true")
						success = true;
					if(xml_doc.getElementsByTagName("message").length>0)
						 msg = xml_doc.getElementsByTagName("message")[0].firstChild.nodeValue;
					
					if(success && xml_doc.getElementsByTagName("comment").length>0){
						var comment = xml_doc.getElementsByTagName("comment")[0];
						if(comment.getAttribute('id') && typeof(zm_list_manager) == 'object'){
							if(comment.getAttribute('token'))
								var div_id = 'div-zm-comment_' + comment.getAttribute('id');
							else if(comment.getAttribute('user'))
								var div_id = 'div-user-comment_' + comment.getAttribute('id');
							else
								var div_id = 'div-comment_' + comment.getAttribute('id');
							zm_list_manager.removeElement(div_id);
						}	
					}
				}
				if(msg_id)
					show_message_box(msg, success,msg_id);
				else
					show_message_box(msg, success);
			}
	);
	xhr.setFailureCallback(
		function(){alert("Failed")}
	);
	xhr.query(script_url,data);
}

function save_zmcomment(){
	if(user_logged){
		if(zm_token){
			var text = trim(document.getElementById('txt-comment').value);
			if(text != ''){
				var data = "action=sav&token="+zm_token+"&user="+user_logged+"&text="+text;
				if(document.getElementById('id-comment').value != '')
					data += "&id="+document.getElementById('id-comment').value;
				
				save_comment("../scripts/scp_comment.php",data,list_manager,'p-zm-add-comments');
			}
			else
				show_message_box(alerts.emptyText,false);
		}
	}
	else
		show_message_box(alerts.userNotLogged,false);
}
function edit_zmcomment(id){
	if(user_logged){
		if(zm_token && id){
			var data = "token="+zm_token+"&user="+user_logged+"&id="+id;	
			
			edit_comment("../scripts/scp_comment.php",data,'p-zm-add-comments');
		}
	}
	else
		show_message_box(alerts.userNotLogged,false);
}
function delete_zmcomment(id){
	if(user_logged){
		if(zm_token && id){
			var data = "action=del&token="+zm_token+"&user="+user_logged+"&id="+id;	
			delete_comment("../scripts/scp_comment.php",data,list_manager);
		}
	}
	else
		show_message_box(alerts.userNotLogged,false);
}

function save_ucomment(with_action){
	var msg_id =  'div-ucomments-save-result';
	if(user_logged){
		if(user_id){
			var text = trim(document.getElementById('txt-comment').value);
			if(text != ''){
				var data = "action=sav&user_id="+user_id+"&user="+user_logged+"&text="+text;
				if(with_action)
					data += '&wa=true';
				if(document.getElementById('id-comment').value != '')
					data += "&id="+document.getElementById('id-comment').value;
				
				save_comment("../scripts/scp_ucomment.php",data,comment_list_manager,'p-user-add-comments',msg_id);
			}
			else
				show_message_box(alerts.emptyText,false,msg_id);
		}
	}
	else
		show_message_box(alerts.userNotLogged,false,msg_id);
}
function edit_ucomment(id){
	if(user_logged){
		if(user_id && id){
			var data = "user_id="+user_id+"&user="+user_logged+"&id="+id;	
			
			edit_comment("../scripts/scp_ucomment.php",data,'p-user-add-comments');
		}
	}
	else
		show_message_box(alerts.userNotLogged,false);
}
function delete_ucomment(id){
	if(user_logged){
		if(user_id && id){
			var data = "action=del&user_id="+user_id+"&user="+user_logged+"&id="+id;	
			delete_comment("../scripts/scp_ucomment.php",data,comment_list_manager);
		}
	}
	else
		show_message_box(alerts.userNotLogged,false);
}

function create_content_dom_node(comment){
	var div = false;
	if (comment.getAttribute('id')) {
		if(comment.getElementsByTagName('labels').length)
			var labels = comment.getElementsByTagName('labels')[0];
			
		div = document.createElement('div');
		var node;
		if(comment.getAttribute('token')){
			div.id = 'div-zm-comment_' + comment.getAttribute('id');
			var edit_func = 'edit_zmcomment';
			var delete_func = 'delete_zmcomment';
		}
		else if(comment.getAttribute('user')){
			div.id = 'div-user-comment_' + comment.getAttribute('id');
			var edit_func = 'edit_ucomment';
			var delete_func = 'delete_ucomment';
		}
		else{
			div.id = 'div-comment_' + comment.getAttribute('id');
			var edit_func = 'edit_comment';
			var delete_func = 'delete_comment';
		}
			
		div.setAttribute('className', 'div-zm-comment');
		div.setAttribute('class', 'div-zm-comment');
		
		if (labels && labels.getElementsByTagName('title_label').length) {
			node = document.createElement('span');
			node.setAttribute('className', 'zm-comment-saved');
			node.setAttribute('class', 'zm-comment-saved');
			node.innerHTML = labels.getElementsByTagName('title_label')[0].firstChild.nodeValue;
			div.appendChild(node);
		}
		
		if (comment.getAttribute('editable') == 'true') {
			var action = comment.getElementsByTagName('action')[0];
			var a;
			node = document.createElement('span');
			node.setAttribute('className', 'zm-comment-actions');
			node.setAttribute('class', 'zm-comment-actions');
			
			if (labels && labels.getElementsByTagName('edit_label').length) {
				a = document.createElement('a');
				a.setAttribute('className', 'zm-link');
				a.setAttribute('class', 'zm-link');
				a.setAttribute('href', 'javascript:'+edit_func+'(' + comment.getAttribute('id') + ')');
				a.appendChild(document.createTextNode(labels.getElementsByTagName('edit_label')[0].firstChild.nodeValue));
				node.appendChild(a);
			}
			
			if (node.hasChildNodes()) 
				node.appendChild(document.createTextNode(' - '));
				
			if (labels && labels.getElementsByTagName('delete_label').length) {
				a = document.createElement('a');
				a.setAttribute('className', 'zm-link');
				a.setAttribute('class', 'zm-link');
				a.setAttribute('href', 'javascript:'+delete_func+'(' + comment.getAttribute('id') + ')');
				a.appendChild(document.createTextNode(labels.getElementsByTagName('delete_label')[0].firstChild.nodeValue));
				node.appendChild(a);
			}
			div.appendChild(node);
			delete a;
			delete action;
		}
		
		node = document.createElement('p');
		node.setAttribute('className', 'p-zm-comment');
		node.setAttribute('class', 'p-zm-comment');
		if (comment.getElementsByTagName('text').length) 
			node.innerHTML = nl2br(comment.getElementsByTagName('text')[0].firstChild.nodeValue);
		div.appendChild(node);
		
		if (labels && labels.getElementsByTagName('update_label').length) {
			node = document.createElement('span');
			node.setAttribute('className', 'zm-comment-updated');
			node.setAttribute('class', 'zm-comment-updated');
			node.appendChild(document.createTextNode(labels.getElementsByTagName('update_label')[0].firstChild.nodeValue));
			div.appendChild(node);
		}
		
		delete node;
	}

	return div;
}

function create_zmlist_dom_node(node){
	var div = document.createElement('div');
	div.setAttribute("className",'div-container-zmail');
	div.setAttribute("class",'div-container-zmail');
	var explicit_content = (node.getAttribute('explicit_content')=='true'?true:false);
	
	var childnode = node.getElementsByTagName('thumbnail');
	var container;
	if(childnode.length){
		var width = childnode[0].getAttribute('width');
		var height = childnode[0].getAttribute('height');
		var child;
		
		if (!explicit_content) {
			child = document.createElement('img');
			child.setAttribute('src', childnode[0].getAttribute('src'));
			child.setAttribute('width', width);
			child.setAttribute('height', height);
			child.setAttribute('alt', 'zr thumbnail');
			child.setAttribute("className", 'zm-thumb_' + width + 'x' + height);
			child.setAttribute("class", 'zm-thumb_' + width + 'x' + height);
		}
		else{
			child = document.createElement('span');
			child.appendChild(document.createTextNode(alerts.zmExplicitContent));	
		}
		
		if (node.getAttribute('url')) {
			var a = document.createElement('a');
			a.setAttribute('href', node.getAttribute('url'));
			//a.setAttribute('target', '_blank');
			a.setAttribute("className", 'no-outline');
			a.setAttribute("class", 'no-outline');
			a.appendChild(child);
			child = a;
			delete a;
		}

		container = document.createElement('p');
		container.setAttribute("className",'p-zm-thumb_'+width+'x'+height);
		container.setAttribute("class",'p-zm-thumb_'+width+'x'+height);
		container.appendChild(child);
		
		if (node.getAttribute('private') && node.getAttribute('private') == 'true') {
			if (node.getElementsByTagName('private_icon').length) {
				child = document.createElement('img');
				child.setAttribute('src',node.getElementsByTagName('private_icon')[0].getAttribute('url'));
				child.setAttribute('alt','zr private');
				child.setAttribute("className",'img-zm-priv');
				child.setAttribute("class",'img-zm-priv');
				container.appendChild(child);
			}
		}	
		div.appendChild(container);
		delete child;
	}
	
	container = document.createElement('div');
	container.setAttribute("className",'div-zm-attribute');
	container.setAttribute("class",'div-zm-attribute');
	
	var label,value;
	childnode = node.getElementsByTagName('title');
	if(childnode.length){
		var span = document.createElement('span');
		span.setAttribute("className",'span-container-zmail-title');
		span.setAttribute("class",'span-container-zmail-title');
		span.innerHTML = childnode[0].firstChild.nodeValue;
		container.appendChild(span);
		delete span;
	}
	childnode = node.getElementsByTagName('author');
	if(childnode.length){
		label = (childnode[0].getElementsByTagName('label')[0].firstChild.nodeValue || '');
		value = (childnode[0].getElementsByTagName('value')[0].firstChild.nodeValue || '');
		container.appendChild(document.createTextNode(label));
		if(value){
			value = document.createTextNode(value);
			if(childnode[0].getAttribute('url')){
				var a = document.createElement('a');
				a.setAttribute('href',childnode[0].getAttribute('url'));
				a.setAttribute("className",'zm-link');
				a.setAttribute("class",'zm-link');
				a.appendChild(value);
				value = a;
				delete a;
			}
			container.appendChild(value);
		}
		container.appendChild(document.createElement('br'));
	}
	childnode = node.getElementsByTagName('date');
	if(childnode.length){
		label = (childnode[0].getElementsByTagName('label')[0].firstChild.nodeValue || '');
		value = (childnode[0].getElementsByTagName('value')[0].firstChild.nodeValue || '');
		container.appendChild(document.createTextNode(label));
		container.appendChild(document.createTextNode(value));
		container.appendChild(document.createElement('br'));
	}	
	childnode = node.getElementsByTagName('views');
	if(childnode.length){
		label = (childnode[0].firstChild.nodeValue || '');
		container.appendChild(document.createTextNode(label));
		container.appendChild(document.createElement('br'));
	}	
	childnode = node.getElementsByTagName('rating');
	if(childnode.length){
		label = (childnode[0].getElementsByTagName('label')[0].firstChild.nodeValue || '');
		container.appendChild(document.createTextNode(label));
		var stars = childnode[0].getElementsByTagName('star');
		if(stars.length){
			var img;
			for(var i=0;i<stars.length;i++){
				img = document.createElement('img');
				img.setAttribute('src',stars[i].getAttribute('url'));
				img.setAttribute('alt','star');
				container.appendChild(img);
			}
			delete img;
		}
		delete stars;
	}
	div.appendChild(container);
	
	delete label;
	delete value;
	delete childnode;
	delete container;
	
	return div;
}

function create_bookmark_dom_node(node){
	var div = document.createElement('div');
	var css_class = node.getAttribute('cssclass')?' '+node.getAttribute('cssclass'):'';
	div.setAttribute("className",'div-main-box'+css_class);
	div.setAttribute("class",'div-main-box'+css_class);
	
	if(node.getElementsByTagName('pseudo').length)
		var pseudo = node.getElementsByTagName('pseudo')[0].firstChild.nodeValue;
	else
		var pseudo = '';
		
	if(node.getAttribute('img')){
		var img = document.createElement('img');
		img.setAttribute('src',node.getAttribute('img'));
		img.setAttribute('title',pseudo);
		img.setAttribute('alt',pseudo);
	}
	else
		var img = null;
		
	var a = document.createElement('a');
	a.setAttribute('title',pseudo);
	a.setAttribute('href',node.getAttribute('url'));
	
	if(img != null){
		a.setAttribute('class','no-outline');
		a.setAttribute('className','no-outline');
		a.appendChild(img);
	}
	else{
		a.setAttribute('class','a-no-avatar');
		a.setAttribute('className','a-no-avatar');
	}
	
	var p = document.createElement('p');
	p.setAttribute('class','p-img');
	p.setAttribute('className','p-img');
	p.appendChild(a);
	
	div.appendChild(p);
	
	if(node.getElementsByTagName('menu').length)
		div.appendChild(create_bookmark_menu(node.getElementsByTagName('menu')[0],node.getAttribute('id')));
	
	p = document.createElement('p');
	p.setAttribute('class','clear');
	p.setAttribute('className','clear');
	
	div.appendChild(p);
	
	a = document.createElement('a');
	a.setAttribute('class','zm-ulink');
	a.setAttribute('className','zm-ulink');
	a.setAttribute('href',node.getAttribute('url'));
	a.appendChild(document.createTextNode(pseudo));
	
	div.appendChild(a);
	
	delete pseudo;
	delete img;
	delete a;
	delete p;
	
	return div;
}

function create_bookmark_menu(menu,id){
	var items = menu.getElementsByTagName('item');
	var div = document.createElement('div');
	if(id) 
    	var str_id = 'owner-menu_'+id;
    else
    	var str_id = 'owner-menu';
	
	div.id = 'div-'+str_id;
	div.setAttribute('class','div-owner-menu');
	div.setAttribute('className','div-owner-menu');

	if(items.length){
		var a = document.createElement('a');
		a.setAttribute('href','javascript:void(display_owner_menu('+(id?id:'')+'))');
		a.id = 'a-'+str_id;
		a.setAttribute('class','a-owner-menu');
		a.setAttribute('className','a-owner-menu');
		a.appendChild(document.createTextNode('+'));
		div.appendChild(a);
		var ul = document.createElement('ul');
		ul.id = 'ul-'+str_id;
		ul.setAttribute('class','ul-owner-menu');
		ul.setAttribute('className','ul-owner-menu');
		var li;
		for(var i=0;i<items.length;i++){
			li = document.createElement('li');
			a = document.createElement('a');
			a.setAttribute('href',items[i].getAttribute('action'));
			a.setAttribute('class','zm-wlink');
			a.setAttribute('className','zm-wlink');
			a.appendChild(document.createTextNode(items[i].firstChild.nodeValue));
			li.appendChild(a);
			ul.appendChild(li);
		}
		div.appendChild(ul);
		delete li;
		delete ul;
		delete a;
	}
	
	delete str_id;
	delete items;
	
	return div;
}

function frm_account_submit(){
	var form = document.getElementById('form_account');
	if(form){
		form['sub'].value = 1;
		form.submit();
	}
}
function initTextInput(inputs)
{
	if(inputs.length){
		for(var i=0;i<inputs.length;i++){
			if(inputs[i].className.match(/\bwith-default-value\b/)){
				if (inputs[i].value != ''){
					inputs[i].defaultText = inputs[i].value;
					ZEvent.addEventListener(inputs[i],'focus',
								function(e){
									var myEvent = new ZEvent(e);
									if(myEvent.source.defaultText && myEvent.source.defaultText == myEvent.source.value)
										myEvent.source.value = '';
								},false);
					ZEvent.addEventListener(inputs[i],'blur',
								function(e){
									var myEvent = new ZEvent(e);
									if (myEvent.source.value == '' && myEvent.source.defaultText && myEvent.source.defaultText != '')
										myEvent.source.value = myEvent.source.defaultText;	
								},false);
				}
			}
		}
	}
}
function initTextFields()
{
	var inputs = document.getElementsByTagName('input');
	var textareas = document.getElementsByTagName('textarea');
	initTextInput(inputs);
	initTextInput(textareas)
}
initTextFields();