var main_cat=0;
var sub_cat=0;
//var cart_count;
//var cart_summ;
function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}


function show_div(id)
{
   d =  document.getElementById(id);

   if(d.style.display == 'none' || d.style.display == '') d.style.display = 'block';
   else d.style.display = 'none';
}

function get_content(url, to_div)
{
set_get();

document.body.scrollTop=225;
   var req = get_req();
  //  alert(url);
   document.getElementById(to_div).innerHTML = loading;
   loadData(req, url, to_div);

}

function select_cat(id, url, show)
{



page=0;
   document.getElementById('cat_' + id).style.fontWeight = "bold";

  


   if(show)
   {
      if(main_cat && main_cat != id)
      {

         document.getElementById('cat_' + main_cat).style.fontWeight = "normal";
         if(sub_cat)document.getElementById('cat_' + sub_cat).style.fontWeight = "normal";
         sub_cat = null;
         document.getElementById('div_cat_' + main_cat).style.display="none";

      }
   }
   else if(sub_cat && sub_cat != id) document.getElementById('cat_' + sub_cat).style.fontWeight = "normal";



	//alert(main_cat);
   if(show) document.getElementById('div_cat_' + id).style.display="block";
	else if(main_cat&&(
	document.getElementById('div_cat_' + main_cat).style.display=="none"||document.getElementById('div_cat_' + main_cat).style.display)
	) {document.getElementById('div_cat_' + main_cat).style.display="block";document.getElementById('cat_' + main_cat).style.fontWeight = "bold";}

     if((show && main_cat != id) || (show && sub_cat) ||  (!show && sub_cat != id)) {

	
	var cc=document.getElementById('cont');
	
	
	if(main_cat)m=document.getElementById("cat_"+main_cat);
	if(sub_cat)s=document.getElementById("cat_"+sub_cat);
	
	
	if(show)	text=document.getElementById("cat_"+id).innerHTML;
 	else 		text=m.innerHTML+" >> "+document.getElementById("cat_"+id).innerHTML;
	
	
	cc.innerHTML="<div class=cont-header>"+text+"</div><div id=cont1></div>";
	
}
//alert(url);
	get_content(url, 'cont1');

 if(show){main_cat = id; 
  	 if(sub_cat){
 				  document.getElementById('cat_' + sub_cat).style.fontWeight = "normal";
 		  			sub_cat=null;
		  		}
 		}
   else sub_cat = id;



if(sub_cat)document.title=lang['title']+" :: "+document.getElementById('cat_' + main_cat).innerHTML+" >> "+document.getElementById('cat_' + sub_cat).innerHTML;
else if(main_cat)document.title=lang['title']+" :: "+document.getElementById('cat_' + main_cat).innerHTML;

}

function get_return_key(e){

if(e){
   var keynum;

   if(window.event) // IE
   {
      keynum = e.keyCode;
   }
   else if(e.which) // Netscape / Firefox / Opera
   {
      keynum = e.which;
   }
   if(keynum == 13)  return true; 
return false;
}
}

function select_topic(s){

url = 'ajax_index.php?mode=topic&full_page=1&cat='+s.options[s.selectedIndex].value;
//alert();
select_cat(s.options[s.selectedIndex].value,url,1);
//get_content(url,'cont');
}

function clear_div(id){
document.getElementById(id).innerHTML="";
}

function load_image(id,type,flags,add_id){
var img=[];

   img[id] = document.createElement("img");
   img[id].style.cursor="pointer";
   img[id].onload = function()
{

l=document.getElementById('loading_img_'+id+add_id);
if(l)l.parentNode.removeChild(l);
document.getElementById('img_'+id+add_id).insertBefore(img[id], document.getElementById('hid_'+id+add_id));
z=document.getElementById("zoom_foto_"+id);
if(z)z.style.display="block";
//alert(button.value);
}

img[id].src = "copyr.php?type="+type+"&id="+id+"&flags="+flags;


}

function change_title(t){

document.title=lang['title']+" :: "+t.innerHTML;
}

function region_select(s,ids){
id=s.options[s.selectedIndex].value;
//if(id!='1')document.getElementById('adr_tr').style.display='block'
//else document.getElementById('adr_tr').style.display='none'
//alert('city'+ids);

url="ajax_req.php?region="+id;
document.getElementById('city'+ids).innerHTML=loading_small;

loadData(get_req(),url,'city'+ids);
}

function city_select(s){
//id=s.options[s.selectedIndex].value;

//if(id!='1')document.getElementById('adr_tr').style.display='block'
//else document.getElementById('adr_tr').style.display='none'
}

function contact(){
//alert('');
email = document.quick_contact.email.value;
text = document.quick_contact.text.value;

id = document.quick_contact.id.value;

if (!email) {document.quick_contact.email.focus();alert(lang['enter_all_fields']);return;}
if (!text) {document.quick_contact.text.focus();alert(lang['enter_all_fields']);return;}

data = "email="+email;
data += "&text="+text;
data += "&id="+id;
data += "&contact=1";
//alert(data);
document.getElementById("content").innerHTML=loading;

postData(get_req(),"ajax_post.php",'content',data);	

}

function news_show(id){

d = document.getElementById("new_"+id);
show_div("new_"+id);

	if(!d.innerHTML){
		d.innerHTML=loading;
		url="ajax_req.php?get_new_text="+id;
		loadData(get_req(),url,"new_"+id);
	}
}
   
   
 f_img=0;
function admin_add_file(id){
f_img++;

f = document.createElement("div");
f.id="div_file_"+id+"_"+f_img;
t="<input type=file name='add_img_"+f_img+"' onchange=\"admin_add_file("+id+")\">";
t+="<img border=0 class=pointer src=template/images/x.png onclick=delete_file("+id+","+f_img+")>";
f.innerHTML=t;

d = document.getElementById("div_add_img_"+id);
h = document.getElementById("img_hid_"+id);

d.insertBefore(f,h);



}
function delete_file(id,i){

d = document.getElementById("div_file_"+id+"_"+i);
d.parentNode.removeChild(d);

}

function del_add_req(id){
if(!confirm("Delete?"))return;
url="ajax_admin.php?del_add="+id;
send_req(get_req(),url);
im = document.getElementById("add_"+id);
im.parentNode.removeChild(im);

}   
   