// JavaScript Document

function toggle_content_input(id,type,hide)  {
	
	elem=id+'.'+type;
	vanish=id+'.'+hide;
	enter=id+'.submit';
    document.getElementById(vanish).style.display="none";
	document.getElementById(elem).style.display="block";
	document.getElementById(enter).style.display="block";
}

function toggle_wrappable(avail) {
	set_wrappable();
	document.getElementById(avail).disabled=false;
	if(document.getElementById(avail).checked==false)
	  reset_wrappable();
}

function deleted(url,desc)
{
  var answer = confirm("Are you sure that you want to completely remove this "+desc+"?")
	if (answer)
	  window.location = url;
	else return true;
}

function remove_block(url)
{
	window.location = url;
	return true; 
}

function set_wrappable() {
	var dynamic=0;
	for(y=0;y<document.forms['update_format'].elements.length;y++) {
	  if(document.getElementById('wrap_'+ dynamic)) {
	    document.getElementById('wrap_'+ dynamic).disabled=true;
		dynamic++;
	  }
	}
}

function reset_wrappable() {
	var dynamic=0;
	for(y=0;y<document.forms['update_format'].elements.length;y++) {
	  if(document.getElementById('wrap_'+ dynamic)) {
	    document.getElementById('wrap_'+ dynamic).disabled=false;
		dynamic++;
	  }
	}
}



function create_link() {
	the_title=document.getElementById('link_title').value;
	the_link=document.getElementById('link_page').value;
	document.getElementById('link_display').value='<a href="' + the_link + '" title="' + the_title + '">' + the_title + '</a>';
	document.getElementById('link_copy').style.visibility="visible";
}

function loadCategories(value) {
	current_href=location.href.split('&');
	if(current_href.length==1) args='&site=' + value;
	if(current_href.length>1)  { 
	  args = '&' + current_href[1] + '.' + value;
	  //else 
	}
	
	//alert(current_href[0] + args);
    window.location=current_href[0] + args;
 
}


function loadEditPage(value) {
	current_href=location.href.split('&');
	if(current_href.length==2) args='&' + current_href[1] + '&site=' + value;
	if(current_href.length>2)  { 
	  args = '&' + current_href[1] + '&' + current_href[2] + '.' + value;
	  //else 
	}
	window.location=current_href[0] + args;
	
	//alert(current_href[0] + args); 
}

//used in the main add task function to add message to new task
function loadSavedMsg(str) {
   if (str=="" || str==0) {
      document.getElementById("newtask_subject").value='';
      document.getElementById("newtask_content").innerHTML='';
      return;
   }
   if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
   } else {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   xmlhttp.onreadystatechange=function() {
      document.getElementById("newtask_msg_loading").innerHTML='<img src="../img/loading.gif">';
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//   alert(xmlhttp.responseText);
         data = xmlhttp.responseText.split('|||||');
         document.getElementById("newtask_msg_loading").innerHTML='';
         document.getElementById("newtask_subject").value=data[0];
         document.getElementById("newtask_content").innerHTML=data[1];
      }
   }
   xmlhttp.open("GET","ajax_update_task_msg.php?id=" + str);
   xmlhttp.send();

}
// used in the edit task function to add a message to existing task via ajax request
function showSavedMsg(str,tid) {
   if (str=="" || str==0) {
      document.getElementById("edit_saved_subject_" + tid).value='';
      document.getElementById("edit_saved_message_" + tid).innerHTML='';
      return;
   }
   if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
   } else {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   xmlhttp.onreadystatechange=function() {
      document.getElementById("add_msg_doc_loading_" + tid).innerHTML='<img src="../img/loading.gif">';
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//   alert(xmlhttp.responseText);
         data = xmlhttp.responseText.split('|||||');
         document.getElementById("add_msg_doc_loading_" + tid).innerHTML='';
         document.getElementById("edit_saved_subject_" + tid).value=data[0];
         document.getElementById("edit_saved_message_" + tid).innerHTML=data[1];
      }
   }
   xmlhttp.open("GET","ajax_update_task_msg.php?id=" + str);
   xmlhttp.send();
}


function deletePage(id) {
  var answer = confirm("Are you sure that you want to completely remove the page: "+id+"?")
	if (answer) {
	   document.getElementById('1').value=id;
	   document.forms[0].submit();
	}	 
}

function unassign_client(remove_id) {
  remove=document.getElementById('Remove_Secondary').value;
  if(remove!='') remove=remove+ '.' + remove_id;
  else remove=remove_id;
  document.getElementById('Remove_Secondary').value=remove;
  document.getElementById('link_' + remove_id).style.display='none';
  document.getElementById('pipe_' + remove_id).style.display='none';
}
