function newHttpRequest(){
  var http_request;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
  }
//  http_request.overrideMimeType('text/xml');
  return http_request;
}

function del_comment(comm_id)
{
    	var req = newHttpRequest();
    	req.onreadystatechange = function(){
    		if (req.readyState == 4) {
   			var resp = req.responseText;
        		if (req.status == 200)
        		{
        		//alert(resp);
                window.location.href=window.location.href;
        		}
        		else
        		{
        		alert('request error');
        		}
     								 }
    										}
  		var request = '/process.php?action=del_comment&comm_id='+comm_id;
    	req.open('GET', request, true);
    	req.send(null);
}


function del_comment(comm_id)
{
    var req = newHttpRequest();
    req.onreadystatechange = function(){
    	if (req.readyState == 4) {
    	var resp = req.responseText;
    		if (req.status == 200)
    		{
    		//alert(resp);
            window.location.href=window.location.href;
    		}
    		else
    		{
    		alert('request error');
    		}
    							 }
    									}
    var request = '/process.php?action=del_comment&comm_id='+comm_id;
    req.open('GET', request, true);
    req.send(null);
}

function changestate_comment(comm_id, to_state)
{
    	var req = newHttpRequest();
    	req.onreadystatechange = function(){
    		if (req.readyState == 4) {
   			var resp = req.responseText;
        		if (req.status == 200)
        		{
                window.location.href=window.location.href;
        		}
        		else
        		{
        		alert('request error');
        		}
     								 }
    										}
  		var request = '/process.php?action=changestate_comment&comm_id='+comm_id+'&to_state='+to_state;
    	req.open('GET', request, true);
    	req.send(null);
}

function $(name)
{
return document.getElementById(name);
}

function setreg()
{
    var inst=document.main;
    if (inst.id_regtype.selectedIndex==0)
    {
    document.getElementById("free_reg").style.display='block';
    document.getElementById("paying_reg").style.display='none';
    document.getElementById("ind_reg").style.display='none';
    document.getElementById("main_reg").style.display='block';
    document.getElementById("add_reg").style.display='none';
    document.getElementById("end_reg").style.display='block';
    }
    if (inst.id_regtype.selectedIndex==1)
    {
    document.getElementById("free_reg").style.display='none';
    document.getElementById("paying_reg").style.display='block';
    document.getElementById("ind_reg").style.display='none';
    document.getElementById("main_reg").style.display='block';
    document.getElementById("add_reg").style.display='block';
    document.getElementById("end_reg").style.display='block';
    }
    if (inst.id_regtype.selectedIndex==2)
    {
    document.getElementById("free_reg").style.display='none';
    document.getElementById("paying_reg").style.display='none';
    document.getElementById("ind_reg").style.display='block';
    document.getElementById("main_reg").style.display='none';
    document.getElementById("add_reg").style.display='none';
    document.getElementById("end_reg").style.display='block';
    }
}

function add_key()
{
    var flag_1=1;
    var flag=0;

    while(flag_1==1)
    {
    flag_1=0;
        var inst=document.main;
        for (var i=0; i< inst.all_key.options.length; i++)
        {
            if (inst.all_key.options[i].selected)
            {
                flag=1;
                flag_1=1;
                var ln=inst.sel_key.options.length;
                inst.sel_key.options[ln] = new Option(inst.all_key.options[i].value, inst.all_key.options[i].text);
                inst.all_key.options[i]=null;
            }
        }
    }
    if (flag==0) alert ("Выберите поле");
}

function add_all_keys()
{
    var flag=0;
    var inst=document.main;
    //добавляем всех
    var len= inst.all_key.options.length;
    for (var i=0; i< len; i++)
    {
        var ln=inst.sel_key.options.length;
        inst.sel_key.options[ln] = new Option(inst.all_key.options[0].value, inst.all_key.options[0].text);
        inst.all_key.options[0] = null;
    }
}

function del_key()
{
    var flag_1=1;
    var flag=0;

    while(flag_1==1)
    {
        flag_1=0;
        var inst=document.main;
        for (var i=0; i< inst.sel_key.options.length; i++)
        {
            if (inst.sel_key.options[i].selected)
            {
                flag=1;
                flag_1=1;
                var ln=inst.all_key.options.length;
                inst.all_key.options[ln] = new Option(inst.sel_key.options[i].value, inst.sel_key.options[i].text);
                inst.sel_key.options[i]=null;
            }
        }
    }
    if (flag==0) alert ("Выберите поле");
}

function del_all_keys()
{
    var inst=document.main;
    var len= inst.sel_key.options.length;
    for (var i=0; i< len; i++)
    {
        var ln=inst.all_key.options.length;
        inst.all_key.options[ln] = new Option(inst.sel_key.options[0].value, inst.sel_key.options[0].text);
        inst.sel_key.options[0]=null;
    }
}

function add_cat()
{
    var flag_1=1;
    var flag=0;

    while(flag_1==1)
    {
        flag_1=0;
        var inst=document.main;
        for (var i=0; i< inst.all_cat.options.length; i++)
        {
            if (inst.all_cat.options[i].selected)
            {
                flag=1;
                flag_1=1;
                var ln=inst.sel_cat.options.length;
                inst.sel_cat.options[ln] = new Option(inst.all_cat.options[i].text, inst.all_cat.options[i].value);
                inst.all_cat.options[i]=null;
            }
        }
    }
    if (flag==0) alert ("Выберите поле");
}

function add_all_cats()
{
    var flag=0;
    var inst=document.main;
    //добавляем всех
    var len= inst.all_cat.options.length;
    for (var i=0; i< len; i++)
    {
        var ln=inst.sel_cat.options.length;
        inst.sel_cat.options[ln] = new Option(inst.all_cat.options[0].text, inst.all_cat.options[0].value);
        inst.all_cat.options[0] = null;
    }
}

function del_cat()
{
    var flag_1=1;
    var flag=0;

    while(flag_1==1)
    {
        flag_1=0;
        var inst=document.main;
        for (var i=0; i< inst.sel_cat.options.length; i++)
        {
            if (inst.sel_cat.options[i].selected)
            {
                flag=1;
                flag_1=1;
                var ln=inst.all_cat.options.length;
                inst.all_cat.options[ln] = new Option(inst.sel_cat.options[i].text, inst.sel_cat.options[i].value);
                inst.sel_cat.options[i]=null;
            }
        }
    }
    if (flag==0) alert ("Выберите поле");
}

function del_all_cats()
{
    var inst=document.main;
    var len= inst.sel_cat.options.length;
    for (var i=0; i< len; i++)
    {
        var ln=inst.all_cat.options.length;
        inst.all_cat.options[ln] = new Option(inst.sel_cat.options[0].text, inst.sel_cat.options[0].value);
        inst.sel_cat.options[0]=null;
    }
}

function send1()
{
    var inst=document.main;
    //keywords
    inst.categories.value="";
    for (var i=0; i< inst.sel_cat.options.length; i++)
    {
    inst.categories.value=inst.categories.value+inst.sel_cat.options[i].text+";";
    }
    inst.keywords.value="";
    for (var i=0; i< inst.sel_key.options.length; i++)
    {
    inst.keywords.value=inst.keywords.value+inst.sel_key.options[i].text+";";
    }
    inst.keywords.value=inst.keywords.value+inst.other_key.value+";"
}

/*ads*/
function ads_delete(ads_id)
{
    if (!confirm('Удалить объявление?')) {
    return 0;
    }
    var req = newHttpRequest();
    req.onreadystatechange = function(){
    	if (req.readyState == 4) {
    	var resp = req.responseText;
    		if (req.status == 200){
        		alert('Объявление удалено');
                window.location.href='/ads/cats/';
    		}else{
        		alert('request error');
    		}
    							 }
    									}
    var request = '/process.php?action=ads_delete&ads_id='+ads_id;
    req.open('GET', request, true);
    req.send(null);
}

function setExprDate(add_date, ads_id, period)
{
	var req = newHttpRequest();
    req.onreadystatechange = function(){
    	if (req.readyState == 4) {
    	var resp = req.responseText;
    		if (req.status == 200){
        		document.getElementById('date_expired_format').value=resp;
    		}else{
        		alert('request error');
    		}
    							 }
    									}
    var request = '/process.php?action=ads_getexprdate&ads_id='+ads_id+'&add_date='+encodeURI(add_date)+'&period='+period;
	req.open('GET', request, true);
    req.send(null);
}
/*ads end*/


function echoContact(email, descr){
    var addr1="mailto:";
    var addr2=email;
    document.write('<a href="'+addr1+addr2+'@xrem.com.ua">');
    document.write(descr+'</a>');
}



function initTinyMCE(selector, width, height){
if(width>0 && height>0){
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	plugins : "myimage, myflash",
	editor_selector : selector,
	theme_advanced_toolbar_location : "top",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
    + "justifyleft,justifycenter,justifyright,justifyfull,"
    + "bullist,numlist,"
    + "link,unlink,separator,"
    +"undo,redo,cleanup,code,separator,sub,sup,charmap, myimage, myflash",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    width:width+"px",
    height: height+"px",
    language : "ru",
    inline_styles : true,
    remove_trailing_nbsp : true,
    remove_script_host : false,
    relative_urls : false,
    element_format : "html",
    valid_elements : "*[*]"
});
}else{
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	plugins : "myimage, myflash",
	editor_selector : selector,
	theme_advanced_toolbar_location : "top",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
    + "justifyleft,justifycenter,justifyright,justifyfull,"
    + "bullist,numlist,"
    + "link,unlink,separator,"
    +"undo,redo,cleanup,code,separator,sub,sup,charmap, myimage, myflash",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    language : "ru",
    inline_styles : true,
    remove_trailing_nbsp : true,
    remove_script_host : false,
    relative_urls : false,
    element_format : "html",
    valid_elements : "*[*]"
});
}
}

