
/*
 *
 * Copyright (c) 2002 NetXposure, Inc. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of 
 * NetXposure, Inc.  You shall not disclose such Confidential Information 
 * and shall use it only in accordance with the terms of the license 
 * agreement you entered into with NetXposure.
 *
 */

var mediaServer = '/';

appVer = parseInt(navigator.appVersion);
	
isIE = (navigator.appName.indexOf("Explorer") > -1) ? 1 : 0;
isNS = (navigator.appName.indexOf("Netscape") > -1) ? 1 : 0;
isMac = (navigator.userAgent.indexOf("Mac") > -1) ? 1 : 0;
isWin = (navigator.userAgent.indexOf("Win") > -1) ? 1 : 0;
isUnix = (navigator.userAgent.indexOf("Sun") > -1) ? 1 : 0;
isLinux = (navigator.userAgent.indexOf("Linux") > -1) ? 1 : 0;
isIE5Mac = (isMac && isIE && (navigator.appVersion.indexOf('MSIE 5')> -1)) ? 1 : 0;
isNS6 = (isNS && (appVer >= 5));
isDOM1 = document.getElementById;

function printStyleSheet() {	
	var fontSizeArr = new Array('xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large');
	var baseFont = 0;
	var fontFam = 'sans-serif';
	var leading = 150;
	//Set Font Family per platform
	if (isWin) fontFam = 'Verdana,Arial,sans-serif';
	if (isMac) fontFam = 'Verdana,Helvetica,sans-serif';
	if (isUnix) fontFam = 'Geneva,Verdana,Arial,Helvetica,sans-serif';
	//Set base font for browser
	//Do not change order
	if (isIE) baseFont = 0; //Win IE && Mac IE5 Sun IE
	if (isMac && isIE && (!isIE5Mac)) baseFont = 1; //Mac IE4x
	if ((isMac && isNS)) baseFont = 2; //Mac NS4
	if ((isWin && isNS) || (isMac && isNS6)) baseFont = 1; //Mac NS6 & Win NS4 & NS6
	if (isUnix && isNS) baseFont = 3;
	if (isLinux && isNS) baseFont = 3;
	//Set Text Leading
	if (isMac || (isWin && isNS) || (isLinux && isNS)) leading = 140;
	if (isWin && isNS6) leading = 154;
	if (isUnix && isNS) leading = 110;
	
	var smallFont = fontSizeArr[baseFont];
	var mediumFont = fontSizeArr[baseFont + 1];
	var largeFont = fontSizeArr[baseFont + 2];
	var xLargeFont = fontSizeArr[baseFont + 3];
	if (isNS && (!isNS6)) xLargeFont = fontSizeArr[baseFont + 2];
	
	var str = '';
	
	str += '<style type="text/css">\n';
	str += 'A { color: #2E2E58; }\n';
	str += 'A:HOVER {color:#2E2E58}\n';
	str += 'A:VISITED { color: #2E2E58; }\n';
	str += 'A:LINK { color: #2E2E58; }\n';	
	str += '.genericPageBkg { background:#f5f5f5 url(' + mediaServer + 'images/nav_bkg.gif) repeat-x }\n';
	str += '.navText { color:#ffffff; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.bodytext { color:#000000; line-height:' + leading + '%; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.smallbody { color:#000000; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.smallbodywhite { color:#ffffff; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.footerTextGray { color:#666666; font-size:' + smallFont + '; font-family:' + fontFam + '; line-height:' + leading + '%; }\n';
	str += '.crumbs { font-size:' + smallFont + '; font-weight:bold; font-family:' + fontFam + '; color:#8B96FC; }\n';
	str += '.error  { color:#cc0033; font-size:' + mediumFont + '; font-family:' + fontFam + '; }\n';
	str += '.label { color:#000000; font-weight: bold; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.data { color:#000000; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.asterick { color:#000000; font-size:' + mediumFont + '; }\n';
	str += '.spacer { font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.Title { color:#2E2E58; font-weight: bold; font-size:' + largeFont + '; font-family:' + fontFam + '; }\n';
	str += '.whiteTitle { color:#FFFFFF; font-weight: bold; font-size:' + largeFont + '; font-family:' + fontFam + '; }\n';
	str += '.command { color:#8B96FC; font-weight: bold; font-size:' + mediumFont + '; font-family:' + fontFam + '; }\n';
	str += '.commandSmall { color:#8B96FC; font-weight: bold; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.plainCommand { color:#8B96FC; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.subTitle { color:#0000; font-weight: bold; font-size:' + mediumFont + '; font-family:' + fontFam + '; }\n';
	str += '.columnCommand { color:#666666; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.formControlStyleXSmall { width:40px; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.formControlStyleSmall { width:75px; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.formControlStyleMedium { width:150px; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.formControlStyleLarge { width:300px; font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '.formControlStyleContainer { font-size:' + smallFont + '; font-family:' + fontFam + '; }\n';
	str += '</style>\n';



	
	//print in style sheet
	document.write(str);
	//Empty to release memory
	str = '';
}

function NCSSFix() {
   if (document.NeedsFix.NCSSFix.initWindowWidth != window.innerWidth 
|| document.NeedsFix.NCSSFix.initWindowHeight != window.innerHeight) {
     document.location = document.location;
   }
}

function NCSSFixItNow() {
   if ((isNS) && (parseInt(navigator.appVersion) == 4)) {
     if (typeof document.NeedsFix == 'undefined'){
       document.NeedsFix = new Object;
     }
     if (typeof document.NeedsFix.scaleFont == 'undefined') {
       document.NeedsFix.NCSSFix = new Object;
       document.NeedsFix.NCSSFix.initWindowWidth = window.innerWidth;
       document.NeedsFix.NCSSFix.initWindowHeight = window.innerHeight;
     }
     window.onresize = NCSSFix;
   }
}

NCSSFixItNow()

function IEBlur(obj) {
	if(isIE)
		obj.blur();	
}

function setFormValue(formName, elementName, value)
{
	var theForm = document[formName];
	
	var obj = theForm.elements[elementName];
	if (obj)
	{
		switch(obj.type)
		{
			case "select-one":
			case "select-multiple":
				for (var i=0; i<obj.options.length; i++)
				{
					if (obj.options[i].value == value)
						obj.options[i].selected = true;
				}
			break;
			
			case "checkbox":
				obj.checked = (value == "true") ? true : false;
			default:
				obj.value = value;
		}
		
	}
}

function getFormValue(formName, elementName)
{
	var theForm = document[formName];
	var obj = theForm.elements[elementName]
	if (obj)
	{
		switch(obj.type)
		{
			case "select-one":
				return obj.options[obj.selectedIndex].value;
			
			case "checkbox":
				return obj.checked ? "true" : "false";
			
			default:
				return obj.value;
		}
	}
	else
	{
//		alert("element: " + name + " not found!");
		return null;
	}

}

function setAction(formName, theAction)
{
	var theForm = document[formName];
	theForm.action = theAction;
}

function submitFormToTarget(formName, theTarget)
{
	var theForm = document[formName];
	theForm.target = theTarget;
	theForm.submit();
}

function getTimeStamp()
{
	var aDate = new Date();
 	var stamp = aDate.getTime();
  	
  	return stamp;
}

function goToURL(url) {

	var stampedURL = url 
				+ ((url.indexOf("?") > -1) ? "&" : "?") 
				+ "ts=" + getTimeStamp();
				
	location.href = stampedURL;
}

function submitFormValues(formName, elementName, elementValue)
{
	var theForm = document[formName];
	var lastArg = submitFormValues.arguments.length
	for (var i=1; i<lastArg-1; i+=2) 
	{
		setFormValue(submitFormValues.arguments[0], submitFormValues.arguments[i], submitFormValues.arguments[i+1]);
	}

	theForm.submit();
}

function getObject(id)
{
	var obj;
	
	if (isDOM1)
	{
		//alert('here');
		obj = document.getElementById(id);		
	}
	else if (isIE)
	{
		obj = document.all[id];
	}
	else if (isNS)
	{
		obj = document[id];
	}
	//alert(obj);
	return obj;
}


function setFrameSrc(frameName, newSrc)
{
	var obj = getObject(frameName);
	//alert(obj.document.location);
	obj.src = newSrc;	
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function popupHelp(server, id)
{
	
	var top = 138;
	var left = screen.availWidth - 592;
	var height = 401;
	var width = 570;
	
	if(isIE)
	{
		height -= 27;
		width += 2;
		
		if(isMac)
		{
			top += 42;
			left += 10;
			height += 13;
			width -= 18;
		}
	}
	
	if(isNS)
	{
		if(isWin)
		{
			height += 8;
		}
	}
	
	var decorations = "menubar=yes,";
	decorations += "scrollbars=auto,";
	decorations += "resizable=yes,";
	//decorations += "toolbar=no,";
	decorations += "top=" + top + ",";
	decorations += "left=" + left + ",";
	decorations += "height=" + height + ",";
	decorations += "width=" + width + ",";

	helpWin = window.open(server + "/docs/html/index.html", 'AdobeAlterCastHelpWindow', decorations);
	
	if((isIE) && (isMac))
	helpWin.moveTo(left,top);
}


/** ***************************************************************************
 * 	Form Validation 
 */
 
 function validateTextReplacementForm() {
 	return true;
 }


/** ***************************************************************************
 * 	Auto task
 */


var smallMultiplier = 2.5;
	var medMultiplier   = 2.5;


	var isNS = false;
	var isIE = false;

	if (navigator.appName == "Netscape") {
		isNS = true;
	}
	else {
		isIE = true;
	}

	
	var isNS6OrAbove = false;

	if (isNS && parseInt(navigator.appVersion) >= 5) {
		isNS6OrAbove = true;
	}
	
	function deleteTask(id) {
	
		if (confirm("This will permanently remove the script '" + taskNameArray[id] + "' and it's settings.  Are you sure?")) {
			var escapedLocation = escape(location);
			goToURL("delete.jsp?id=" + id + "&backUrl=" + escapedLocation);
		}
	}
	
	function gotoMainPage() {
		navigator.location = "index.html";
	}


	function saveSelections() {
		document.forms[0].saveSelections.value = "";
		
		var checkboxNamePrefix = "enable_checkbox-";
		
		for (i = 0; i < document.forms[0].length; i++) {
			var currItem = document.forms[0][i];
			if (currItem.name.indexOf(checkboxNamePrefix) == 0) {	
				var id = currItem.name.substring(checkboxNamePrefix.length, currItem.name.length);
				if (document.forms[0].saveSelections.value != "") {
					document.forms[0].saveSelections.value += "|||";
				}
				document.forms[0].saveSelections.value += id + ":" + document.forms[0][i].checked;
			}
		}
		document.forms[0].submit();
	}
	
	function editTask(id) {
		goToURL("edit.jsp?id=" + id);
	}
	
	function doTask(id) {
		goToURL("go.jsp?id=" + id);
	}
	
	function newRendition() {
		goToURL("rendition.jsp");
	}
	
	function newReplacement() {
		goToURL("replacement.jsp");
	}

	function copyTask(id) {
		goToURL("copy.jsp?id=" + id);
	}
	
	function selectAll() {
		for (i=0; i < document.forms[0].length; i++) {
			
			var ctrl = document.forms[0][i];
			if (ctrl.type == "checkbox") {
				ctrl.checked = true;
			}
		}
	}
	
	function deSelectAll() {
		for (i=0; i < document.forms[0].length; i++) {
			
			var ctrl = document.forms[0][i];
			if (ctrl.type == "checkbox") {
				ctrl.checked = false;
			}
		}
	}
	
	
	function runSelected() {
		
		document.forms[0].selectedList.value = "";
		document.forms[0].action = "go.jsp";
		
		var checkboxNamePrefix = "enable_checkbox-";
		
		var afterFirst = false;
		var numTasks = 0;
		
		for (i = 0; i < document.forms[0].length; i++) {
			var currItem = document.forms[0][i];
			if (currItem.name.indexOf(checkboxNamePrefix) == 0) {
				numTasks++;
				if (currItem.checked == true) {	
					var id = currItem.name.substring(checkboxNamePrefix.length, currItem.name.length);
					if (afterFirst) {
						document.forms[0].selectedList.value += ",";
					} else {
						afterFirst = true;
					}
					document.forms[0].selectedList.value += id;
				}
			}
		}
		
		if (numTasks == 0) {
			alert("Please add tasks to run.");	
		} else if (document.forms[0].selectedList.value == "") {
			alert("Please check tasks to run.");
		} else {
			document.forms[0].submit();
		}
	}
/** ***************************************************************************
 * 	
 */

