/*********************************************************
	
	* DO NOT REMOVE *

	Project: PHPWeby directory software version 1.0
	Url: http://phpweby.com
	Copyright: (C) 2008 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----------------------------------------------
    
    Link to http://phpweby.com can not be removed from the software pages
	without permission of Blagoj Janevski <bl@blagoj.com>. 
	It is the only requirement for using this software.
	
*********************************************************/

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);
		if(navigator.appName=="Microsoft Internet Explorer")//fix ie bug
		document.getElementById("infoajax_"+id).innerHTML="Link with id "+ id +" approved.";
	}
}
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);
		if(navigator.appName=="Microsoft Internet Explorer") //fix ie bug
		document.getElementById("infoajax_"+id).innerHTML="Link with id "+ id +" saved.";
	}
}
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);
		if(navigator.appName=="Microsoft Internet Explorer")//fix ie bug
		document.getElementById("infoajax_"+id).innerHTML="Link with id "+ id +" approved.";
	}
}
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);
		if(navigator.appName=="Microsoft Internet Explorer")//fix ie bug
		document.getElementById("infoajax_"+id).innerHTML="Link with id "+ id +" deleted.";
	}
}
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()
{
	var br=navigator.appName;
	var t=document.getElementById("c");
	var catpath=t.options[t.selectedIndex].title;
	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;
}
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)
		{
			if((confirm('Are you sure that you want to continue?')))
			xajax_updatecateg(document.getElementById("catid").innerHTML,document.getElementById("catname1").value,t.options[t.selectedIndex].value);
		}
		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")
		{
			if((confirm('Are you sure that you want to continue?')))
			xajax_updatecateg(document.getElementById("catid").innerHTML,document.getElementById("catname1").value,-1);
		}
		else
		alert("The words 'info','detail' are not allowed for main category!");
	}
	else
	{
		alert("Choose category to edit or write a name!");
	}
}