// JavaScript Document

var forms = new Array();
var dsForms = new Array();
function displayCommentField(n){
	var obj = document.getElementById('comments_'+n);
	if (obj.style.visibility == "hidden"){
		obj.style.visibility = "visible";
		obj.style.height="100px";
		forms.push(n);
	}
}

function addToProcessList(n, which){
	if (which ==1){
		dsForms.push(escape(n));
	}else{
		forms.push(escape(n));
	}
}

function submitForm(i){
	PageSectionIDs="";
	dsFieldNames="";
	
	// the sectionsids concatinated in one variable
	for (i=0; i<forms.length; i++){
		if (i == forms.length-1){
			PageSectionIDs+= forms[i];
		}else{
			PageSectionIDs+= forms[i]+",";
		}
	}
	// the datasheet fields names to be edited
	for (i=0; i<dsForms.length; i++){
		if (i == dsForms.length-1){
			dsFieldNames+= dsForms[i];
		}else{
			dsFieldNames+= dsForms[i]+",";
		}
	}
	document.commentForm.sectionIDs.value=PageSectionIDs;
	document.commentForm.FieldNames.value=dsFieldNames;
	document.commentForm.whatToDo.value='1';

	document.commentForm.submit();
}

function rejectForm(i){
	PageSectionIDs="";
	dsFieldNames="";
	
	// the sectionsids concatinated in one variable
	for (i=0; i<forms.length; i++){
		if (i == forms.length-1){
			PageSectionIDs+= forms[i];
		}else{
			PageSectionIDs+= forms[i]+",";
		}
	}
	// the datasheet fields names to be edited
	for (i=0; i<dsForms.length; i++){
		if (i == dsForms.length-1){
			dsFieldNames+= dsForms[i];
		}else{
			dsFieldNames+= dsForms[i]+",";
		}
	}
	document.commentForm.sectionIDs.value=PageSectionIDs;
	document.commentForm.FieldNames.value=dsFieldNames;

	document.commentForm.whatToDo.value='2';
	document.commentForm.submit();
}

function saveForm(i){
	PageSectionIDs="";
	dsFieldNames="";
	
	// the sectionsids concatinated in one variable
	for (i=0; i<forms.length; i++){
		if (i == forms.length-1){
			PageSectionIDs+= forms[i];
		}else{
			PageSectionIDs+= forms[i]+",";
		}
	}
	// the datasheet fields names to be edited
	for (i=0; i<dsForms.length; i++){
		if (i == dsForms.length-1){
			dsFieldNames+= dsForms[i];
		}else{
			dsFieldNames+= dsForms[i]+",";
		}
	}
	document.commentForm.sectionIDs.value=PageSectionIDs;
	document.commentForm.FieldNames.value=dsFieldNames;
	
	document.commentForm.whatToDo.value='3';
	document.commentForm.submit();
}

function saveFormThenEdit(i,url){
	PageSectionIDs="";
	dsFieldNames="";
	
	// the sectionsids concatinated in one variable
	for (i=0; i<forms.length; i++){
		if (i == forms.length-1){
			PageSectionIDs+= forms[i];
		}else{
			PageSectionIDs+= forms[i]+",";
		}
	}
	// the datasheet fields names to be edited
	for (i=0; i<dsForms.length; i++){
		if (i == dsForms.length-1){
			dsFieldNames+= dsForms[i];
		}else{
			dsFieldNames+= dsForms[i]+",";
		}
	}
	document.commentForm.sectionIDs.value=PageSectionIDs;
	document.commentForm.FieldNames.value=dsFieldNames;
	
	document.commentForm.whatToDo.value='4';
	document.commentForm.destination.value=url;
	document.commentForm.submit();
}

function editContent(name,content, col, rows, which){
	var obj = document.getElementById(name);
	addToProcessList(name,which);
	if (which ==1){
		obj.innerHTML='<textarea name="'+name+'" cols="'+col+'" rows="'+rows+'">'+content+'</textarea>';
	}else{
		obj.innerHTML='<textarea name="sectionComment_'+name+'" cols="'+col+'" rows="'+rows+'">'+content+'</textarea>';
	}
}

function alertBeforePublish(linkToPublish){

	var answer = confirm("WARNING\nPublishing does not automatically save your last changes. \nAre you sure you want to publish?")
	if (answer){
		window.location = linkToPublish;
	}

}

function alertBeforeDelete(num,linkToPublish){
	if (num==0){
		var answer = confirm("WARNING\nThis action will remove any references to this section from this page. \nThis action will not delete the section from other pages\nAre you sure you want to delete?")
		
	}else if (num==1){
		var answer = confirm("WARNING\nThis action will Permanently delete all instances of this section in all pages \nAre you sure you want to delete?")
	}
	if (answer){
		window.location = linkToPublish;
	}

}

function alertBeforePerformAction(linkToPublish){

	var answer = confirm("WARNING\nChanges made to the description, comments, and title will not be saved automatically. \nDo you still want to perform this action and lose any unsaved changes?")
	if (answer){
		window.open(linkToPublish);
	}

}

// JavaScript Document
var url2 = "getDatasheetInfos.php?id="; // The server-side script
var whichElement=''
var thisHeight;
 

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}


function showDatasheetContent(elementID,id,dsid,currCatID,secID,showPub){

		document.getElementById(elementID).style.visibility='visible';
		 document.getElementById(elementID).innerHTML = "Loading ...";
		whichElement=	elementID;
		  http.open("GET", url2+id+'&dsid='+dsid+'&currCatID='+currCatID+'&sectionID='+secID+'&showPub='+showPub , true);
		  http.onreadystatechange = handleHttpResponse;

		  http.send(null);
		  

}
function handleHttpResponse(elementID) {
  if (http.readyState == 4) {
  	
     document.getElementById(whichElement).innerHTML = http.responseText;
	
  }
}
var http = getHTTPObject(); 
