/***************************************************************************
%name: TabScriptUtil.js %
%version: 1 %
%date modified: 10/19/2001%

File Name:     PWCScriptUtil.js

Copyright 2001 Novell, All Rights Reserved.

****************************************************************************/

var agent = navigator.userAgent.toLowerCase();
var agent_isIE = (agent.indexOf('msie') >= 0)

var ie = (navigator.appName.indexOf('Microsoft') != -1) ? true : false;
var ie4 = (ie && document.all && !document.getElementById) ? true : false;
var ie5 = (ie && document.getElementById && navigator.appVersion.indexOf('MSIE 6.0') == -1) ? true : false;
var ie6 = (ie && document.getElementById && navigator.appVersion.indexOf('MSIE 6.0') != -1) ? true : false;
var ie4Min = (ie && (document.all || document.getElementById)) ? true : false;
var ie5Min = (ie && document.getElementById) ? true : false;
var ie6Min = (ie && document.getElementById) ? true : false;

var ns = (navigator.appName.indexOf('Netscape') != -1) ? true : false;
var ns4 = (ns && document.layers) ? true : false;
var ns6 = (ns && document.getElementById) ? true : false;
var ns4Min = (ns && (document.layers || document.getElementById)) ? true : false;
var ns6Min = (ns && document.getElementById) ? true : false;
var fieldFocused = false;
var formName;


/*
* Functions for Item Properties management: used to determine if a field is in focus or not, 
*  and to determine if the "Enter" key was pressed in that field.
*/

function blurField()
{
   fieldFocused = false;
}

function focusField(ref)
{
   fieldFocused = true;
   formName = ref;
}

function onKeyPress(e)
{
   var keycode;
   if (window.event)
       keycode = window.event.keyCode;
   else if (e)
       keycode = e.which;
   else
       return true;

   if (keycode == 13)
   {
       if (fieldFocused == true)
       {
          formName.FINISH.value='SAVE';
          formName.submit();
          return false
       }
   }
   return true
}


/*
* Function used to select the current form and set the action to the one sent in
*/
function changeSelection(currentSelection,action)
{
	//
	// First get the right form
	// 
	currentForm = currentSelection.form;
	currentForm.NPAction.value = action;
	currentForm.submit();

}


function CCL(CB){

if (CB.checked)
highlight(CB);
else
unHighlight(CB);

}


function highlight(E){
if (agent_isIE)
{
while (E.tagName!="TR")
{E=E.parentElement;}
}
else
{
while (E.tagName!="TR")
{E=E.parentNode;}
}
E.className = "pwcHighlight";
}


function unHighlight(E){
if (agent_isIE)
{
while (E.tagName!="TR")
{E=E.parentElement;}
}
else
{
while (E.tagName!="TR")
{E=E.parentNode;}
}
E.className = "pwcsmalltext";
}




//Check all radio/check buttons script- by javascriptkit.com
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use  

function checkall(formname,checkname,currentCheck){

var continueLoop = true;
var count = 1;

thestate = currentCheck.checked;


	while(continueLoop)
	{
	
		var item = checkname + count;
		var el_collection=eval("document.forms."+formname+"."+item);
		
		if(el_collection != null)
		{
			el_collection.checked= thestate;
			CCL(el_collection);
		}
		else
		{
			continueLoop = false;
		}
		
		count ++;
	}
}

	function doLaunchPWC(href,height,width,useValues,setFocus,target)
	{
   	var features = "resizable=yes,height=500,width=700";
		
		if(useValues)
		{
			features = "resizable=yes,height=" + height + ",width=" + width;
		}
		
		if(target)
			newWindow = window.open(href,target,features);
		else
			newWindow = window.open(href,"_blank",features);


		if(setFocus)
			window.focus();
	}


function getDocHeight() {
	
	if (ie4Min) return (document.body.scrollHeight > document.body.clientHeight) ? document.body.scrollHeight : document.body.clientHeight;
   else if (ns4Min) return (document.height > window.innerHeight) ? document.height : window.innerHeight;
   }

function getDocWidth() {
   if (ie4Min) return (document.body.scrollWidth > document.body.clientWidth) ? document.body.scrollWidth : document.body.clientWidth;
   else if (ns4Min) return (document.width > window.innerWidth) ? document.width : window.innerWidth;
   }

function getDocScrollLeft() {
   if (ie4Min) return document.body.scrollLeft;
   else if (ns4Min) return window.pageXOffset;
   }

function getDocScrollTop() {
   if (ie4Min) return document.body.scrollTop;
   else if (ns4Min) return window.pageYOffset;
   }

function getLeftPosition(imagename, offset) {
	var objImg
		objImg = document.images[imagename]
	
	if (!offset) offset = 0
	if (ns4){
		return eval(objImg).x
	} else {
		xPos = eval(objImg).offsetLeft;
		tempEl = eval(objImg).offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
	   
		var result = xPos + offset;
		if(result == 0)
	 		result = 600;
		return result;
	}
}

function getTopPosition(imagename, offset) {
	var objImg
	objImg = document.images[imagename]
	if (!offset) offset = 0
	if (ns4){
		return eval(objImg).y + offset
	} else {
		yPos = eval(objImg).offsetTop;
		
		imgElemHeight = eval(objImg).height
		tempEl = eval(objImg).offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		
		var result = yPos + imgElemHeight + offset;
		if(result == 0)
			result = 700;
		return result;

		return result;
	}
}


function noScrollIE(){
	document.body.scroll="auto"
}
function scrollIE(){
	document.body.scroll="yes"
}
function noScrollNS(){
	document.width=	window.innerWidth
	document.height=window.innerHeight
}
function scrollNS(){
	document.width=1000
	document.height=1000
}


function disableScroll()
{
	if(ns4)
		noScrollNS();
	else
		noScrollIE();
}

function resizeWindowDirect() {
	resizeWindow(getLeftPosition("LOCATER")+35,getTopPosition("LOCATER")+60);
	//center();
	window.focus();
}

function center()
{
	centerWindow(window);
}

function centerWindow(currentWindow)
{
   if (currentWindow.document.all) { w = currentWindow.document.body.clientWidth; h = currentWindow.document.body.clientHeight; }
	else if (currentWindow.document.layers) { w = currentWindow.innerWidth; h = currentWindow.innerHeight; }
	
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;

	
	newWidth = sWidth -w - 20;
	newHeight=sHeight - h - 20;
	
	if (currentWindow.moveTo) currentWindow.moveTo(newWidth/2,newHeight/2);
}


function resizeWindow(width,height) {
	
	disableScroll();
	window.resizeTo(width,height);
	//center();
	window.focus();
}


//
// Functions for a popout
//

		function makeItVisible(id,event)
        { 
	    	  leftOffset = document.body.scrollLeft + event.clientX;
			  leftOffset = leftOffset - 150;
			  
			  document.all[id].style.pixelLeft = leftOffset;
			  document.all[id].style.pixelTop = (document.body.scrollTop + event.clientY) + 10;
			  document.all[id].style.visibility="visible";
        }
        function hideHelp(id)
        {
        document.all[id].style.visibility="hidden";
        }




//
// Functions for document management
//

	  function checkOut(coURL, ciURL, docID, filepath, filename, user, controller)
	  {

	     var user = "<User dt='pwcUser'><DN>" + user + "</DN></User>";
			//alert("open: \ncheckoutURL=" + coURL + "\ncheckinURL=" + ciURL + "\nDocID=" + libraryID + ":" + docNum + "\npath=" + filepath + "\nfilename=" + filename);
	     
		  controller.GetContent(coURL, ciURL, "http://127.0.0.1:5080/XisRPC/v2", filepath, "", "flags", "token", docID, "", user, document.cookie);
	  }


	  function importDoc(ciURL, libraryID, path, filename, controller)
	  {
		  //libraryID = g_LibraryId;
		  controller.ImportDocument(ciURL, "c:\\temp", "cascade server url", filename, "flags", "token", libraryID, "objXML", "parmsXML", document.cookie);
	  }


	  function openDoc(docHandlerUrl,filePath,fileName,itemID,user,controller)
	  {
		  var hostPath = window.location.protocol	+ "//" +  window.location.host;
	     var coURL = hostPath + docHandlerUrl + "&FilePath=" + escape(filePath) + "&FileName=" + escape(fileName) + "&id=" + escape(itemID) + "&RequestType=CHECKOUT";
		  var ciURL = hostPath + docHandlerUrl + "&FilePath=" + escape(filePath) + "&FileName=" + escape(fileName) + "&id=" + escape(itemID) + "&RequestType=CHECKIN";
		  var docID = itemID;
		  var filePath = filePath;
		  var fileName = fileName;



		  //if(false)
		  if (agent_isIE && controller != null)
		  {
			  coURL = coURL + "&ActiveX=Y";   
			  ciURL = ciURL + "&ActiveX=Y";   

			  checkOut(coURL, ciURL, docID, filePath, fileName,user,controller);

			  //window.opener.focus();
			  //window.close();
		  }
		  else
		  {
			  coURL = coURL;   
			  ciURL = ciURL;   

			  doLaunchPWC(coURL,500,600,true);
			  //window.location.replace(coURL);


		  }

	  }




