function SwapImage(sImageID, sSource, iTimeout){
	self.setTimeout("document.images['" + sImageID + "'].src = '" + sSource + "';", iTimeout);
}

function ReturnFromPreview(objForm){
	window.location.href = objForm.site_renderer.value + '?sectionpath=' + objForm.sectionpath.value + '&action=previewreturn&editmode=admin&id=' + objForm.id.value;
}
function todaysDate(fmt){
	var sRetVal = "";
	var dtDate = new Date();
	
	switch(fmt){
		case 1:
			sRetVal = dtDate.getMonth()+1 + "/" + dtDate.getDate() + "/" + dtDate.getYear()
			break;
		
		case 2:
			sRetVal = GetMonth(dtDate.getMonth()) + " " + dtDate.getDate() + ", " + dtDate.getFullYear();
			break;
		
		case 3:
			sRetVal = dtDate.getMonth()+1 + "/" + dtDate.getDate() + "/" + dtDate.getFullYear()
			break;
				
		default:
			sRetVal = dtDate.toString();
	}
	return sRetVal;
}

function GetMonth(iIndex){
	var  sRetVal = "";
	switch(iIndex){
		case 0:
			sRetVal = "January";
			break;
		
		case 1:
			sRetVal = "February";
			break;
		
		case 2:
			sRetVal = "March";
			break;
			
		case 3:
			sRetVal = "April";
			break;
			
		case 4:
			sRetVal = "May";
			break;
			
		case 5:
			sRetVal = "June";
			break;
			
		case 6:
			sRetVal = "July";
			break;
			
		case 7:
			sRetVal = "August";
			break;
			
		case 8:
			sRetVal = "September";
			break;
			
		case 9:
			sRetVal = "October";
			break;
			
		case 10:
			sRetVal = "November";
			break;
			
		case 11:
			sRetVal = "December";
			break;
	}
	return sRetVal;
}

function trim(sValue){
	return(sValue.replace(" ", ""));
}

function defaultDateField(oField){
	if(trim(oField.value) == ''){
		oField.value = todaysDate(1).toString();
	}
}

function validateDate(oField){
	if(!IsDate(oField.value)){
		alert("Invalid Format.\nDefault date set.");
		oField.value = todaysDate(1).toString();
		oField.focus();
		return false;
	}else{
		return true;
	}
}

function IsDate(sVal){
	if(isNaN(sVal.replace(/[\/-]/g, "", 0))) return false;
	return true;
}

function validateEmail(oField){
	if(!IsEmail(oField.value)){
		alert('Please enter a valid e-mail address.');
		oField.focus();
		return false;
	}else{
		return true;
	}
}

function IsEmail(sVal){
	
}

function GetRandomNumber(){
	var axel = Math.random() + "";
	var ord = axel * 100000000;
	
	return ord;
}

function ShowProgress(oForm, oFormField)
{
  strAppVersion = navigator.appVersion;
  if (oFormField.value != "")
  {
    if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
    {
    
      winstyle = "dialogWidth=375px; dialogHeight:130px; center:yes";
      window.showModelessDialog('/core/framework/scripts/FRAMEBAR.ASP?pid=' + document.dummy.random_num.value + '&to=10&b=IE',null,winstyle);
    }
    else
    {
      window.open('/core/framework/scripts/FRAMEBAR.ASP?pid=' + document.dummy.random_num.value + '&to=10&b=NN','','width=370,height=115', true);
    }
  }
  return true;
}


function checkRequiredFields(oForm, arFields, arTitles){
	var sMessage = "Please fill in the following required fields:\n";
	for(var i = 0;i<arFields.length;i++){
		if(oForm[arFields[i]].value == ""){
			sMessage += "\n" + arTitles[i];
		}
	}
	
	if(sMessage != "Please fill in the following required fields:\n"){
		alert(sMessage);
		return false;
	}else return true;
}

//copied from CSScriptLib.js:

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
mustInitImg = true;
function initImgID() {di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}
function findElement(n,ly) {
	d = document;
	if (browserVers < 4)		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}
function changeImages() {
	d = document;
	if (d.images) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (d.layers) {img = findElement(changeImages.arguments[i],0);}
			else {img = d.images[changeImages.arguments[i]];}
			if (img) {img.src = changeImages.arguments[i+1];}
		}
	}
}

function openWindow(URL, windowTitle, windowWidth, windowHeight)
{
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (windowWidth / 2));
	var yCoordinate = ((high / 2) - (windowHeight / 2));
	var w = window.open(URL,windowTitle,"width=" + windowWidth + ",height=" + windowHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=no,status=no,menubar=no,scrollbars=auto,innerheight=" + windowHeight + ",innerwidth=" + windowWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
}

function openContactWindow(URL, windowTitle)
{
	var sWidth;
	var sHeight;
	
	sWidth = 420;
	sHeight = 555;

	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (sWidth / 2));
	var yCoordinate = ((high / 2) - (sHeight / 2));
	var w = window.open(URL,windowTitle,"width=" + sWidth + ",height=" + sHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=no,status=no,menubar=no,scrollbars=auto,innerheight=" + sHeight + ",innerwidth=" + sWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
}
function openScrollingWindow(URL, windowTitle, windowWidth, windowHeight)
{
	var wide = screen.width;
	var high = screen.height;
	var xCoordinate = ((wide / 2) - (windowWidth / 2));
	var yCoordinate = ((high / 2) - (windowHeight / 2));
	var w = window.open(URL,windowTitle,"width=" + windowWidth + ",height=" + windowHeight + ",left=" + xCoordinate + ",top=" + yCoordinate + ",resizable=yes,status=yes,menubar=no,scrollbars=yes,innerheight=" + windowHeight + ",innerwidth=" + windowWidth + ",screenx=" + xCoordinate + ",screeny=" + yCoordinate + ",toolbar=no");
	w.focus();
	w.opener = window;
	w.resizeTo (windowWidth, windowHeight);
	
}
function browseStreams(sectionpath, kbactionid, kbcontentid, div_name, form_name){
	var sStreamIDs = '';
	if(document.forms[1].streamid){
		for(var i=0;i<document.forms[1].streamid.length;i++){
			sStreamIDs += "&selectedstreamid=" + document.forms[1].streamid[i].value;
		}
	}
	openScrollingWindow("?sectionpath=" + sectionpath + "&processor=asp&asp_processor=streams&action=loadstreamtree&div_name=" + div_name + "&kbactionid=" + kbactionid + "&kbcontentid=" + kbcontentid + sStreamIDs, "StreamManager", 736, 320);
}

function addStreams(div_name, form_name){
	var streamid = '';
	opener.document.all[div_name].innerHTML = '';
	for(var i=0;i<document.forms[form_name].selectedstreamid.length;i++){
		if(document.forms[form_name].selectedstreamid[i].checked){
			streamid = document.forms[form_name].selectedstreamid[i].value;
			opener.document.all[div_name].innerHTML = opener.document.all[div_name].innerHTML + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=streamid_" + streamid + " value=" + document.forms[form_name]["streamid_" + streamid].value + "><input type=hidden name=streamid value=" + streamid + ">" + document.forms[form_name]["streamid_" + streamid].value + "</td><td align=right><a href=# onClick=javascript:removeTopic('" + div_name + "','documentedit','" + streamid + "')>Remove</a></td></tr></table>";
		}
	}
}

function removeStream(div_name, form_name, streamid){
	var curtopicid = '';
	var sRetVal = '';
	var sNameKey = '';
	if(document.forms[form_name].streamid){
	
		for(var i=0;i<document.forms[form_name].streamid.length;i++){
			if(document.forms[form_name].streamid[i].value != streamid){
				curstreamid = document.forms[form_name].streamid[i].value;
				sRetVal = sRetVal + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=streamid_" + curstreamid + " value=" + document.forms[form_name]["streamid_" + curstreamid].value + "><input type=hidden name=streamid value=" + curstreamid + ">" + document.forms[form_name]["streamid_" + curstreamid].value + "</td><td align=right><a href=# onClick=javascript:removeStream('" + div_name + "','" + form_name + "','" + curstreamid + "')>Remove</a></td></tr></table>";
			}
		}
		document.all[div_name].innerHTML = sRetVal;
	}
}

function browseTopics(sectionpath, kbactionid, kbcontentid, div_name, form_name){
	var sTopicIDs = '';
	
	if(document.forms[form_name].topicid){
		for(var i=0;i<document.forms[form_name].topicid.length;i++){
			sTopicIDs += "&selectedtopicid=" + document.forms[form_name].topicid[i].value;
		}
	}
	openScrollingWindow("?sectionpath=" + sectionpath + "&processor=asp&asp_processor=topics&action=loadtopictree&div_name=" + div_name + "&kbactionid=" + kbactionid + "&kbcontentid=" + kbcontentid + sTopicIDs, "TopicManager", 736, 320);
}

function addTopics(div_name, form_name){
	var topicid = '';
	opener.document.all[div_name].innerHTML = '';
	for(var i=0;i<document.forms[form_name].selectedtopicid.length;i++){
		if(document.forms[form_name].selectedtopicid[i].checked){
			topicid = document.forms[form_name].selectedtopicid[i].value;
			opener.document.all[div_name].innerHTML = opener.document.all[div_name].innerHTML + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=topicid_" + topicid + " value=" + document.forms[form_name]["topicid_" + topicid].value + "><input type=hidden name=topicid value=" + topicid + ">" + document.forms[form_name]["topicid_" + topicid].value + "</td><td align=right><a href=# onClick=javascript:removeTopic('" + div_name + "','documentedit','" + topicid + "')>Remove</a></td></tr></table>";
		}
	}
}

function removeTopic(div_name, form_name, topicid){
	var curtopicid = '';
	var sRetVal = '';
	var sNameKey = '';
	if(document.forms[form_name].topicid){
	
		for(var i=0;i<document.forms[form_name].topicid.length;i++){
			if(document.forms[form_name].topicid[i].value != topicid){
				curtopicid = document.forms[form_name].topicid[i].value;
				sRetVal = sRetVal + "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><input type=hidden name=topicid_" + curtopicid + " value=" + document.forms[form_name]["topicid_" + curtopicid].value + "><input type=hidden name=topicid value=" + curtopicid + ">" + document.forms[form_name]["topicid_" + curtopicid].value + "</td><td align=right><a href=# onClick=javascript:removeTopic('" + div_name + "','" + form_name + "','" + curtopicid + "')>Remove</a></td></tr></table>";
			}
		}
		document.all[div_name].innerHTML = sRetVal;
	}
}

var arImages = new Array();
var preloadFlag = false;
function preloadImages(arImages) {
	preloadFlag = false;
	if (document.images) {
		var img;
		
		for (var i=0;i<arImages.length;i++) {
			img = newImage(arImages[i]);		
		}
		preloadFlag = true;
	}
}

function setFormFocus(sFormName){
	
	var sFieldName;
	
	if (sFormName != ""){
		if (document.forms[sFormName]){
			if (document.forms[sFormName].taborder && !document.all['elementeditor']){
				sFieldName = document.forms[sFormName].taborder.value;
				if (sFieldName != ""){
					document.forms[sFormName][sFieldName].focus();
				}
			}
		}
	}
}

function resizeImageWidth(form, imagename, imageasppath){
	if(form.width.value != ''){
		if(form.source.value.indexOf('.jpg') != -1){
			document.images[imagename].style.width=form.width.value;
			document.images[imagename].style.height=form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		}else{
			document.images[imagename].style.width=form.width.value;
		}
	}else{
		if(form.source.value.indexOf('.jpg') != -1){
			document.images[imagename].style.width=form.width.value;
			document.images[imagename].style.height=form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		}else{
			if(document.images[imagename].style.width != ''){
				document.images[imagename].style.width='auto';
			}
		}
	}
}

function resizeImageHeight(form, imagename, imageasppath){
	if(form.height.value != ''){
		if(form.source.value.indexOf('.jpg') != -1){
			document.images[imagename].style.width=form.width.value;
			document.images[imagename].style.height=form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		}else{
			document.images[imagename].style.height=form.height.value;
		}
	}else{
		if(form.source.value.indexOf('.jpg') != -1){
			document.images[imagename].style.width=form.width.value;
			document.images[imagename].style.height=form.height.value;
			document.images[imagename].src = aspResizeImage(imageasppath, form.source.value, form.height.value, form.width.value);
		}else{
			if(document.images[imagename].style.height != ''){
				document.images[imagename].style.height='auto';
			}
		}
	}
}

function aspResizeImage(sResizer, sPath, iHeight, iWidth){
	return sResizer + "?path=" + escape(sPath) + "&height=" + iHeight + "&width=" + iWidth;
}

//copied from helppane.js:

function DoHelp(help_url){

var W;
var H;
var sWD;
var sc=screen.width;
var agent = navigator.userAgent.toLowerCase();
var app = navigator.appName.toLowerCase();

//If screen width is 800 or less and this is not a mac, set width to 180, otherwise set to 230
W=(sc<= 800 && agent.indexOf("mac")==-1)?230:336;

// If using AOL then height = available height - 22 from top, Otherwise height = available height 
H=(agent.indexOf("windows")>0 && agent.indexOf("aol")>0) ? screen.availHeight-window.screenTop-22:screen.availHeight

//sWD="toolbar=0,status=0,menubar=0,width="+W+",height="+H+",left="+(sc-W)+",top=0,resizable=1";
sWD="toolbar=0,status=0,scrollbars=1,location=0,menubar=0,left="+(sc-W)+",top=0,resizable=1";


h_win=window.open(help_url,'help',sWD);
h_win.focus();
h_win.resizeTo(W,H);

//if not using a mac and not using netscape
if (h_win && agent.indexOf("mac")<0 && app.indexOf("netscape")<0) h_win.opener=self//*IE5+PC
//h_win.opener.focus();
h_win.opener.resizeTo((sc-W),H);
h_win.opener.moveTo(0,0);

}

function populateFields(chkThis, frmThis, arFieldsFrom, arFieldsTo){
	var i;
	
	if (chkThis.checked){
		for (i=0; i < arFieldsFrom.length; i++){
			if(frmThis[arFieldsTo[i]])
				frmThis[arFieldsTo[i]].value = frmThis[arFieldsFrom[i]].value;
		}
	}else{
		for (i=0; i < arFieldsFrom.length; i++){
			if(frmThis[arFieldsTo[i]])
				frmThis[arFieldsTo[i]].value = '';
		}
	}
}
				
// EOF

