function confirmSubmit(message, act,form,field) {
   if (!message)
	   var msgText = "You are about to delete?";
   else var msgText=message;
    		if (!act) act='delete';
   if (confirm(msgText)==true){
  	    if(form && field){
				field.value=act;
				form.submit();
		} else{
   			document.form1.take_action.value=act;
	   		document.form1.submit();			
		}
   }
}
function checkAll(d,message1,message2) {
 var counter=0;
 for (i = 0; i < d.elements.length; i++) {
   if (d.elements[i].type == "checkbox" && d.elements[i].checked == true ) {
		counter=counter+1;
   }
 }
 if (counter==0){
	 if (message1)
	 	alert(message1);
	 else
	    alert("Please select item to edit!");
 } else if (counter!=1){
	 if (message2)
	 	alert(message2);
  	 else
   	    alert("You can edit only one item at the time!");
 }else{
	 d.submit();
 }
}
function submitForm(theform) {
  var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ alert(req.responseText); }
    }
  );
  return status;
}
function open_dialog(get_id,count){
	for(i=1;i<=count;i++){
		document.getElementById("dialog_"+i).style.display='none'; 			
	}
	document.getElementById("dialog_"+get_id).style.display='block'; 				
}

function open_close(get_id){
	if (document.getElementById(get_id).style.display=='block') 
		document.getElementById(get_id).style.display='none'; 
	else 
		document.getElementById(get_id).style.display='block'; 
}
function setInnerHTML(div_id, value)
{
	var dstDiv = document.getElementById(div_id);
	dstDiv.innerHTML = value;
}
function postcomment_box(get_id,c,id){
	 open_close('postcomment_'+get_id);
	 open_close('reply_button_'+get_id);

		var innerHTMLContent = '\
		<form name="form2'+get_id+'" action="ajax.php" method="post" target="_blank" onSubmit="submitForm(this);return false;">\
			<input type="hidden" name="act" value="comments_post">\
			<input type="hidden" name="for" value="'+id+'">\
			<input type="hidden" name="type" value="'+c+'">\
			<input type="hidden" name="parent" value="'+get_id+'">\
			<textarea  name="html" style="width: 97%; height: 65px; display: block;"></textarea>\
			\
			<input align="right" type="submit" name="add_comment_button" value="Post Comment">\
			<input align="right" type="button" name="discard_comment_button"\
								value="Discard" '  + '\
								onclick="open_close(\'reply_button_'+get_id+'\'); open_close(\'postcomment_'+get_id+'\'); ">\
		</form>';

		setInnerHTML('postcomment_'+get_id, innerHTMLContent);
		

}
function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 9;
  h += 56;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=no, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
