/*
 * Copyright 2006 Servelots Infotech Pvt. Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at:
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
function addRemarkCheck()
{
  if (document.RemarkForm.subject.value.length == 0)
    {
      alert("Title of the Remark Should not be Empty");
    }
  else if (tinyMCE.getContent()=="")
    {
      alert("Enter Remark");
    }
  else
    {
      document.RemarkForm.submit();
    }
}			      
     
function showDescription()
{
  var originalText = document.RemarkForm.remark.value;
  document.RemarkForm.quoteOriginal.disabled=true;
  var entireText = originalText + "\n\n"+document.RemarkForm.replySubject.value;
  //document.RemarkForm.remark.value = desc;
  tinyMCE.setContent(entireText);
}

function showSubject(subject)
{
  document.RemarkForm.useParentSubject.disabled=true;
  subject = "RE:"+subject;
  document.RemarkForm.subject.value=subject;
}

function resetFields()
{
  if(confirm("Are you sure you want to clear all contents?"))
    {
  document.RemarkForm.remark.value="";
  document.RemarkForm.subject.value="";
  document.RemarkForm.useParentSubject.disabled=false;
  document.RemarkForm.quoteOriginal.disabled=false;
    }
}

function manipulateScreen(div_id,visibility)
{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
    {
      changeObjectVisibility(div_id,visibility);
    }
  else 
    {
      alert("sorry, this only works in browsers that do Dynamic HTML");
    }
}

function closeButton(div_id,visibility)
{
   manipulateScreen(div_id,visibility);
   document.RemarkForm.remark.value="";
   document.RemarkForm.subject.value="";
   document.RemarkForm.useParentSubject.disabled=false;
   document.RemarkForm.quoteOriginal.disabled=false;
}

						     
function changeObjectVisibility(objectId, newVisibility) 
{
  // first get a reference to the cross-browser style object 
  // and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) 
    {
      //styleObject.visibility = newVisibility;
      styleObject.display = newVisibility;
      return true;
    }
  else
    {
      // we couldn't find the object, so we can't change its visibility
      return false;
    }
}

// function getStyleObject(string) -> returns style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.
//
function getStyleObject(objectId)
{
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId))
    {
      return document.getElementById(objectId).style;
    }
  else if (document.all && document.all(objectId))
    {  
      return document.all(objectId).style;
    } 
  else if (document.layers && document.layers[objectId])
    { 
      return document.layers[objectId];
    }
  else
    {
      return false;
    }
}

function deleteSelected()
{
  var flag=0;
  var submit=0;
  var formElements=document.RemarkThread.elements;
  for(var cnt=0;cnt<formElements.length;cnt++){
    if(formElements[cnt].type=='checkbox'){
      if(formElements[cnt].checked){
	flag++;
	isParent=formElements[cnt].name;
	var parent = isParent.substring(0,4);
	  if(parent=="REMP")
	    {
	      if(confirm("All the responses to this remark will be deleted.Do you want to delete it?"))
		{
		  submit++;
		}
	      else
		{
		  formElements[cnt].checked=false;
		}
	    }
	  else
	    {
	      submit++;
	    }
      }
    }
  }

  if(submit!=0)
    {
      document.RemarkThread.req.value = 602;
      document.RemarkThread.submit();
    }

  if(flag==0)
    {
      alert("Please select a remark to delete.");
    }

}

//When the persona clicks on 'Add a response', toggle the response screen.
function toggleRes()
{
 var addrmkid = getStyleObject("addrmk");
 addrmkid.display = "block";
 var styleObject2 = getStyleObject("notifyinaddrmk");
 styleObject2.display = "none";
 tinyMCE.execCommand('mceResetDesignMode');
}																		

