// scripts

function checkAll(wen) {
      for(i=0;i<document.Message.length;i++) {
         nm=document.Message.elements[i].name;
         if(nm.match(/DEL_/)) {
            document.Message.elements[i].checked=!document.Message.elements[i].checked;
         }
      }
      if(wen=="CHECKALL2") {
               document.Message.CHECKALL.checked=!document.Message.CHECKALL.checked;
      }
      else {
         document.Message.CHECKALL2.checked=!document.Message.CHECKALL2.checked;
      }
}

function move_form_submit(){
    document.getElementById("verschieben").value="verschieben";
    document.getElementById("inboxform").submit();
}

function showkat_div(htmlid) {
   if ($(htmlid)) {
      $('img_'+htmlid).onclick=new Function("","hidekat_div('"+htmlid+"');return false;");
      $(htmlid).show();
      $('img_'+htmlid).src="../bilder/d5/bullet_toggle_minus.gif";
   }
}

function hidekat_div(htmlid) {
   if ($(htmlid)) {
      $('img_'+htmlid).onclick=new Function("","showkat_div('"+htmlid+"');return false;");
      $(htmlid).hide();
      $('img_'+htmlid).src="../bilder/d5/bullet_toggle_plus.gif";
   }
}

function show_div(htmlid) {
   if ($(htmlid)) {
      $('link_'+htmlid).onclick=new Function("","hide_div('"+htmlid+"');return false;");
      $(htmlid).show();
   }
}

function hide_div(htmlid) {
   if ($(htmlid)) {
      $('link_'+htmlid).onclick=new Function("","show_div('"+htmlid+"');return false;");
      $(htmlid).hide();
   }
}

function save_beitrag(formid) {
	 if (typeof(arguments[1]) != "undefined") {
		disable_bt_button(arguments[1]);
		window.setTimeout('enable_bt_button("'+arguments[1]+'")', 10000)
	 }
    data = $(formid).serialize();
    ajax_post('../dynamic/save_beitrag.php',data);
}

function disable_bt_button(htmlid) {
	document.getElementById(htmlid).disabled = true;
}

function enable_bt_button(htmlid) {
	document.getElementById(htmlid).disabled = false;
}

function save_image_stuff(formid,what) {
    data = $(formid).serialize();
    if (what == 'comment') {
       ajax_post('../dynamic/save_im_comment.php',data);
    } else {
       ajax_post('../dynamic/save_im_rating.php',data);
    }
}

function kill_friend(id, nickname) {
    var con = confirm("Bist du sicher, dass du deinen Freund "+nickname+" löschen willst?");
    if (con) {
       ajax_call('../dynamic/kill_friend.php?ID='+id);
    }
}

function kill_bild(id, bildname) {
    var con = confirm("Bist du sicher, dass du das Bild "+bildname+" löschen willst?");
    if (con) {
       ajax_call('../dynamic/kill_bild.php?ID='+id);
    }
}

function get_brands_to_pgid() {
      pgid = $F('PG_ID');
      ajax_call('../dynamic/get_brands_to_pgid.php?PG_ID='+pgid+'&SEL=BR_ID');
}

function add_option(sel,opt_show,opt_value) { 
       sel=$(sel);
       opt_show = unescape(opt_show);
       selected=arguments[3] || "";
       onclickfunc=arguments[4] || "";
       s_idx=sel.selectedIndex;
       if(s_idx < 0) s_idx=0;

       if(selected!="") {
         s_option = Builder.node('option',{'value':opt_value,selected:selected},opt_show);
       }
       else {
         s_option = Builder.node('option',{'value':opt_value},opt_show);
       }
       sel.appendChild(s_option);
       sel.selectedIndex=s_idx;
}

function add_option1(sel,opt_show,opt_value) {   
 
       selector = document.getElementById(sel);
       option = document.createElement('option');
       option.appendChild(document.createTextNode(unescape(opt_show)));
       option.setAttribute('value', opt_value);   
       selector.appendChild(option);
}

function clear_select(sel) {
       sel=$(sel);
       sel.innerHTML="";
}

function clear_select1(sel) {
    selector = document.getElementById(sel);
    laenge = selector.length;
    for (i = 0; i < laenge; i++) {
	 selector.options[selector.length-1] = null;
    }
}

function accept_reject_invitation(id,what) {
    if (id > 0) {
       ajax_call('../dynamic/accept_reject_inv.php?U_ID='+id+'&do='+what);
    } 
}

function getimage(idx,appends,doload) {
    if (doload == 0) {
         $('akt_img').src = "../bilder/d5/loading.gif";
    }
    ajax_call('../dynamic/bilder.php?idx='+idx+appends);
}

function getimage_comments(idx,appends) {
    ajax_call('../dynamic/image_comments.php?idx='+idx+appends);
}

function comments_allow(imid,dowhat,text) {
    $('com_allowed_link').innerHTML = text;
    $('com_allowed_link').onclick = new   Function("","ajax_call('../dynamic/comments_all.php?IM_ID="+imid+"&DO="+dowhat+"');return false;");
    if (dowhat == 'DEAKT') {
        $('RAT_COMMENTS_ALLOWED').show();
    }else 
    {
        $('RAT_COMMENTS_ALLOWED').hide();
    }

}

////////////////////////////////////////////////////
// Share
////////////////////////////////////////////////////

function show_share(w,h,id,what) {
    x = (screen.width-w)/2;
    y = (screen.height-h)/2;
    sharediv = document.createElement("div");
    sharediv.id = "share_div";
    sharediv.className = "share_div"; 
    sharediv.style.top = y+"px";
    sharediv.style.left = x+"px";
    body1 = document.getElementsByTagName("body").item(0);
    body1.appendChild(sharediv);
    ajax_call('../dynamic/share_it.php?id='+id+'&what='+what);
}

function close_share() {
    body1 = document.getElementsByTagName("body").item(0);
    body1.removeChild(document.getElementById("share_div"));
}

function submit_share(formid) {
   data = $(formid).serialize();
   ajax_post('../dynamic/save_share.php',data);
}


////////////////////////////////////////////////////
// multi box
////////////////////////////////////////////////////

function multi_box(w,h,htmlid,classname,call) {
    x = (screen.width-w)/2;
    y = (screen.height-h)/2;
    div = document.createElement("div");
    div.id = htmlid;
    div.className = "share_div";
    if (classname != "") {
       div.className = classname;
    } 
    div.style.top = y+"px";
    div.style.left = x+"px";
    body1 = document.getElementsByTagName("body").item(0);
    body1.appendChild(div);
    ajax_call('../dynamic/'+call);
}

function close_multi_box(htmlid) {
    body1 = document.getElementsByTagName("body").item(0);
    body1.removeChild(document.getElementById(htmlid));
}

function submit_multibox(formid,script) {
   data = $(formid).serialize();
   ajax_post('../dynamic/'+script,data);
}

////////////////////////////////////////////////////
// Smileys forum
////////////////////////////////////////////////////

function add_smiley(htmlid,key) {
    val = document.getElementById(htmlid);
    val.value = val.value+Smileys[key]; 
    val.focus();
}
