/*********************************************************
	
	* DO NOT REMOVE *

	Project: PHP Weby directory software version 1.2
	Url: http://phpweby.com
	Copyright: (C) 2009 Blagoj Janevski - bl@blagoj.com
	Project Manager: Blagoj Janevski

	For help, comments, feedback, discussion ... please join our
	Webmaster forums - http://forums.phpweby.com
	
	License------------------------------------------------:
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    End License----------------------------------------------
    

	
*********************************************************/
function fetch_categ_info()
{

var id=document.getElementById("catid").innerHTML;
if(id!="")
xajax_fetch_categ_info(id);

}
function fixcategs()
{
if((confirm("Use this only if you have non-existen categories, categories are not loading or other simular problems.\nWARNING: In the process of fixing categories some categories may get deleted!\nAlso the category cache will be recreated.\nAre you sure you want continue?")))
xajax_fixcategs();

}
function rewriteurl(id)
{
	document.getElementById("url2_"+id).href="http://"+document.getElementById("url_"+id).value.trim().replace(/^http:[\/]*/g,'');
}
function deleteallcontacts()
{
	clearinfoajax();
	if((confirm("Are you sure you want delete ALL CONTACTS?")))
	xajax_deleteallcontacts();
}
function del_contact(id)
{
	clearinfoajax();
	if((confirm("Are you sure you want delete contact id " + id)))
	xajax_del_contact(id);
}
function get_link_information(id)
{
	var odg=new Array();
	odg['contactname']=document.getElementById("contactname_"+id).value.trim();
	odg['pagerank']=document.getElementById("pagerank_"+id).value.trim();
	odg['contactemail']=document.getElementById("contactemail_"+id).value.trim();
	odg['sitedesc']=document.getElementById("sitedesc_"+id).value.trim();
	odg['categoryid']=document.getElementById("c_"+id)[document.getElementById("c_"+id).selectedIndex].value;
	odg['caption']=document.getElementById("caption_"+id).value.trim();
	odg['url']=document.getElementById("url_"+id).value.trim();
	return odg;
}
function save_ap_link(id)
{
	clearinfoajax();
	if((confirm("Are you sure you want to save changes and approve link? Link id " +id)))
	{
		var num=document.getElementById("numberlinks").innerHTML;
		var linkinfo=new Array();
		linkinfo=get_link_information(id);
		document.getElementById("infoajax_"+id).innerHTML="<img src='tpl/images/s.gif' alt='' />";
		xajax_save_ap_link(id,linkinfo,num);		
	}
}
function save_link(id)
{
	clearinfoajax();
	if((confirm("Are you sure you want to save changes? Link id " +id)))
	{
		var linkinfo=new Array();
		linkinfo=get_link_information(id);
		document.getElementById("infoajax_"+id).innerHTML="<img src='tpl/images/s.gif' alt='' />";
		xajax_save_link(id,linkinfo);
	}
}
function ap_link(id)
{
	clearinfoajax();
	if((confirm("Are you sure that you want to approve " + id)))
	{
		var num=document.getElementById("numberlinks").innerHTML;
		document.getElementById("infoajax_"+id).innerHTML="<img src='tpl/images/s.gif' alt='' />";
		xajax_do_act("approve",id,num);
	}
}
function del_link(id,val)
{
	clearinfoajax();
	if((confirm("Are you sure that you want to delete link " + id)))
	{
		var num=document.getElementById("numberlinks").innerHTML;
		document.getElementById("infoajax_"+id).innerHTML="<img src='tpl/images/s.gif' alt=''/>";
		xajax_del_link(id,num,val);
	}
}
function clearinfoajax()
{
	var em=document.getElementsByName("infoajax");

	for(var i=0;i<em.length;i++)
	em[i].innerHTML='';
}
function refreshlinks()
{
	window.location=location.href;
}

function writecat(obj)
{
	var t=obj;
	if(!obj)
	t=document.getElementById("c");
	
	var catpath=t.options[t.selectedIndex].text;
	var ca=new Array();
	ca=catpath.split("\xAB");
	var catname=ca[ca.length-1];
	document.getElementById("catid").innerHTML=t.options[t.selectedIndex].value;
	document.getElementById("cat").innerHTML=catpath.trim();
	document.getElementById("catname").innerHTML=catname.trim();
	document.getElementById("catname1").value=catname.trim();
	document.getElementById("c1").options[0].selected=true;
	fetch_categ_info();
}
function newmaincat()
{
	var v=document.getElementById("cats").value;
	if((v!=""))
	{

		if(confirm("Are you sure that you create new main category\n" +v))
		xajax_do_add_maincat(v.replace(/\n/g,';'));
		else
		{
			document.getElementById("cats").focus();
			return;
		}
	}
	else
	alert("Write the name(s) of the new main categories, separate with ;");

	document.getElementById("cats").value="";
	document.getElementById("cats").focus();
}
function addcats()
{
	var c=document.getElementById("cats");
	var cats=c.value;
	var catid=document.getElementById("catid").innerHTML;
	var catname=document.getElementById("cat").innerHTML;

	if(cats!="" && catid!="")
	{
		if((confirm("Are you sure that you want to add these categories to database:\n" + cats + "\n with parrent category " + catname + " with id " + catid)))
		xajax_addcats(cats.replace(/\n/g,';'),catid);
		else
		{
			c.focus();
			return;
		}
	}
	else
	{
		if(catid=='')
		{
			alert('Please select parent category!');
			return;
		}
		if(cats=='')
		alert('Write the names of the new subcategory(ies), separate with ;');
		c.focus();
		return;
	}
	c.value="";
	c.focus();
}
function del_cat()
{
	var id=document.getElementById("catid").innerHTML;
	if(id!='')
	{
		if((confirm('Are you sure that you want to delete this category \nCategory Name: '+document.getElementById("catname").innerHTML+'\nCategory Path: '+document.getElementById("cat").innerHTML +'\n ALL SUBCATEGORIES AND LINKS WILL BE AUTOMATICALLY DELETED!')))
		xajax_del_cat(id);
	}
	else
	alert("Select a category from the select box!");
}
function make_premium(id)
{
	if((confirm("Are you sure that you want to make link " + id +" premium link?")))
	xajax_make_premium(id);
}
function ordinary(id,url)
{
	//xajax_check_da_link(url);

	if((confirm("Are you sure that you want to make link " + id +" normal link?")))
	xajax_make_ordinary(id);
}

function clear(obj)
{
	obj.value='';
	obj.innerHTML='';
}
function editmailtemplate()
{
	location.href='mail_admin.php?r=templates&act=edit&tplid=' + document.getElementsByName('TEMPLATE')[0][document.getElementsByName('TEMPLATE')[0].selectedIndex].value;
}
function deletemailtemplate()
{
	if((confirm('Are you sure that you want to delete the selected template?')))location.href='mail_admin.php?r=templates&act=del&tplid=' + document.getElementsByName('TEMPLATE')[0][document.getElementsByName('TEMPLATE')[0].selectedIndex].value;
}
function del_m_template(id)
{
	if((confirm('Are you sure that you want to delete this template?')))
	location.href='mail_admin.php?r=templates&act=del&tplid='+id;
}
function editcateg()
{
	if(document.getElementById("catid").innerHTML!="")
	{
		var el=document.getElementById("editcat");
		if(el.style.display=='block')
		{
			el.style.display='none';
		}
		else
		{
			el.style.display='block';
		}
	}
}
function updatecateg()
{
	if(document.getElementById("catname1").value!="" && document.getElementById("catid").innerHTML!="")
	{
		var t=document.getElementById("c1");
		if(t.options[t.selectedIndex].value!=document.getElementById("catid").innerHTML)
		{
			var catinfo=new Array();
			catinfo['catid']=document.getElementById("catid").innerHTML;
			catinfo['newcatname']=document.getElementById("catname1").value;
			catinfo['newparentcat']=t.options[t.selectedIndex].value;
			catinfo['desc']=document.getElementById("desc").value.trim();
			catinfo['meta_desc']=document.getElementById("meta_desc").value.trim();
			if((confirm('Are you sure that you want to continue?')))
			xajax_updatecateg(catinfo);
		}
		else
		alert("Please choose different parent category!");
	}
	else
	{
		alert("Choose category to edit or write a name!");
	}
}
function updatecategtomain()
{
	if(document.getElementById("catname1").value!="" && document.getElementById("catid").innerHTML!="")
	{
		if(document.getElementById("catname1").value!="info" && document.getElementById("catname1").value!="detail")
		{
			var catinfo=new Array();
			catinfo['catid']=document.getElementById("catid").innerHTML;
			catinfo['newcatname']=document.getElementById("catname1").value;
			catinfo['newparentcat']=-1;
			catinfo['desc']=document.getElementById("desc").value.trim();
			catinfo['meta_desc']=document.getElementById("meta_desc").value.trim();
			if((confirm('Are you sure that you want to continue?')))
			xajax_updatecateg(catinfo);
		}
		else
		alert("The words 'info','detail' are not allowed for main category!");
	}
	else
	{
		alert("Choose category to edit or write a name!");
	}
}
function openpage(caption, page, height, width)
{
return GB_showCenter(caption, page, height, width);
}

function getdivtext(id)
{
	return document.getElementById(id).innerHTML;
}
function getinputvalue(id)
{
	return document.getElementById(id).value;
}

function updatedivtext(id,txt)
{
	document.getElementById(id).innerHTML=txt;
}

function getselectedvalue(id)
{
	var t=document.getElementById(id);
	return t.options[t.selectedIndex].value;

}

function getselectedtext(id)
{
	var t=document.getElementById(id);
	return t.options[t.selectedIndex].text;
}

function setloadingimg(id)
{
	document.getElementById(id).innerHTML='<img src="tpl/images/s.gif" alt="" style="border:0" />';
}

function item_addcomment(id)
{
	var comment=new Array();
	comment['comment_name']=getinputvalue('comment_name');
	comment['comment_info']=getinputvalue('comment_info');
	comment['id']=id;
	xajax_ajax_addcomment(comment);
}
function item_approvecomment(id)
{
	if(confirm('Are you sure you want to approve this comment?'))
	xajax_ajax_approvecomment(id);
}

function item_deleteallcomments(id)
{
	if(confirm('Are you sure you want to delete all commments?'))
	xajax_ajax_deleteallcomments(id);
}

function item_deletecomment(id)
{
	if(confirm('Are you sure you want to delete the comment?'))
	xajax_ajax_deletecomment(id);
}
function js_addcomment(comment)
{
	setloadingimg('ajaxinfo_commentsubmit');
	var c=getdivtext('allcomments');
	c=c+ '<div id="comment_'+comment['id']+'"><div class="comment"><div class="name">'+ comment['comment_name'] +' <b>says:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:item_deletecomment('+ comment['id'] +');">Delete Comment</a></div><div class="com">'+ comment['comment_info'] +'</div><br /></div></div>';
	updatedivtext('allcomments',c);
}

function item_resetratings(id)
{
	if(confirm('Are you sure you want to reset the ratings?'))
	xajax_ajax_resetratings(id);
}

function item_upgrade(id,type)
{
	if(confirm('Are you sure you want to upgrade to ' + type + ' link?'))
	{
		xajax_ajax_item_upgrade(id,type);
	}
}
function ban_ip(ip)
{
if(confirm('Are you sure you want to ban ' + ip + '?'))
	{
		xajax_ajax_ban_ip(ip);
	}
}