//alert(a);
/*
function includeJavascript(acJsFile) 
{
    document.write('<script src="' + acJsFile + '">' + '<\/script>');
}

includeJavascript("/v4/client/js/utils.js");
*/
function populateFieldList(aField, alDataList, alDispList, acDelimiter)
{
	dataList = alDataList.split(acDelimiter);
	displayList = alDispList.split(acDelimiter);
	dataValue = aField.value;
	bKeepOldValue = false;
	clearFieldList(aField);
	for (i = 0; i < dataList.length; i++)
	{
		newLine = aField.length;	
		aField.options[newLine] =new Option(displayList[i], dataList[i]);
		if (dataList[i] == dataValue)
			bKeepOldValue = true;
	}
	if (bKeepOldValue)
	{
		aField.value = dataValue;
	}
	else
	{
		if (dataList.length > 0)
			aField.value = dataList[0];
	}
}

function clearFieldList(aField)
{
	if (aField != null && aField.length > 0)
	{
		for (i = (aField.length - 1) ; i >= 0; i--)
			aField.options[i] = null;
	}
}

function getLocation(locations)
{
	rExp = /,/g;
	locations = locations.replace(rExp, "|");
	locationIDs = window.xShowModalDialog("/v3/popups/location.cfm?locations=" + locations, "",
																  "status:no;dialogWidth:640px;dialogHeight:500px;resizable:yes;scrollbars:no;center:yes");	
	return locationIDs;
}

function sort1(key)
{
	sort(key);
}

function sort1Action(key, cAction)
{	
	var iFrmOrder = oSiteManager.oUtils.getMainFormOrder();
	
	cActionFld = eval("document." + document.forms[iFrmOrder].name + ".cAction");
	cFrm = eval("document." + document.forms[iFrmOrder].name);

	if (cFrm != null)
	{
		cFrm.target = "";
		cFrm.action = "#";
	}
			
	if (cActionFld != null)
	{
		cActionFld.value = cAction;
	}

	sort(key);
}

function page1(no, cAction)
{
	if ((cAction != null) && (cAction != ""))
	{
		var iFrmOrder = oSiteManager.oUtils.getMainFormOrder();
		cActionFld = eval("document." + document.forms[iFrmOrder].name + ".cAction");
		if (cActionFld != null)
		{
			cActionFld.value = cAction;
		}
	}

	page(no);
}

function markChange()
{
	var iFrmOrder = oSiteManager.oUtils.getMainFormOrder();

	cModifiedFld = eval("document.forms[" + iFrmOrder + "].mgmt_sys_modified");
	//cModifiedFld = eval("document." + document.forms[iFrmOrder].name + ".mgmt_sys_modified");
	if (cModifiedFld != null)
	{
		cModifiedFld.value = 1;
	}
}


function submitForm(aForm, cAction)
{
	if (cAction != null)
	{
		aForm.cAction.value = cAction;
	}
	aForm.submit();
}

function gotoUrl(acUrl)
{
	location.href = acUrl;
}

function listFind(aList, aValueToFind, aSeparator)
{
	if (typeof(aList) != 'string')
		return false;
	arrListValues = aList.split(aSeparator);
	bFound = false;
	for (i = 0; i < arrListValues.length; i++)
	{
		if (arrListValues[i] == aValueToFind)
		{
			bFound = true;
			break;
		}
	}
	return bFound; 
}


function ShowHideSpan(displayValue,spanName,selectedValue)
{
	if (listFind(displayValue, selectedValue, "|"))
	{
		document.getElementById(spanName).style.visibility='visible';
	}
	else
	{
		document.getElementById(spanName).style.visibility='hidden';
	}
}

function ShowHideSpanBlocked(displayValue, spanName, selectedValue, blockValue, bExclusiveDisplay)
{
	var DisplayBlockValue = blockValue || 'block';
	var oSpanName = spanName.split(",");

	for (var i=0; i<oSpanName.length; i++)
	{
		if (bExclusiveDisplay != null && bExclusiveDisplay) 
			ShowHideSpan(displayValue, oSpanName[i], selectedValue);

		if (listFind(displayValue, selectedValue, "|"))
		{
			document.getElementById(oSpanName[i]).style.display=DisplayBlockValue;
		}
		else
		{
			document.getElementById(oSpanName[i]).style.display='none';
		}
	}
}



function countCheckedChkboxes(aCheckBox)
{
	var iCheckedChkBoxes = 0;

	if (aCheckBox != null)	
	{
		var bIsArray = aCheckBox.length != undefined;
	
		if (bIsArray)
		{
			for (var i=0; i <aCheckBox.length; i++)
			{
				if (aCheckBox[i].checked)
					iCheckedChkBoxes ++;
			}
		} else
		{
			if (aCheckBox.checked)
				iCheckedChkBoxes = 1;
		}
	}
	return iCheckedChkBoxes;
}


function getValuesCheckedChkboxes(aCheckBox) {
	var values = new Array();
	var strValues = new String();
	var valuesLength = 0;
	strValues = "";
	if (aCheckBox != null) {
		var bIsArray = aCheckBox.length != undefined;
		if (bIsArray) {
			for (i = 0; i < aCheckBox.length; i++) {
				if (aCheckBox[i].checked) {
					strValues = strValues + aCheckBox[i].value + ",";
				}
			}
			for (i = 0; i < values.length; i++) {
				strValues = strValues + values[i];
			}
			valuesLength = String(strValues).length;
			strValues = String(strValues).substring(0, valuesLength - 1);
		}
		else {
			if (aCheckBox.checked) {
				strValues = aCheckBox.value;
			}
		}
	}
	return strValues;
}


function num_format(x) { // format numbers with two digits
	sgn = (x < 0);
	x = Math.abs(x);
	x = Math.floor((x * 100) + .5);
	i = 3;
	y = "";
	while(((i--) > 0) || (x > 0)) {
		y = (x % 10) + y;
		x = Math.floor(x / 10);
		if(i == 1) {
			y = "." + y;
		}
	}
	if(sgn) {
		y = "-" + y;
	}
	return(y);
}

// makes sure an answer was checked before submitting a vote for a poll
function SubmitPoll(formName, pollID) {
	var sForm = "document." + formName + "_" + pollID; //form string
	var oForm = eval(sForm); //form object
	var oRadio = eval(sForm + ".poll_" + pollID); // get the whole set of radio buttons.
	var itemChecked = false;
	for (var j = 0 ; j < oRadio.length ; ++j) {
		if (oRadio[j].checked) {
			itemChecked = true;
			break;
		}
	}
	if (itemChecked) {
		oForm.submit();
	}
	else {
		alert("Please select an answer for this poll before you can vote!");
	}
}


//open a popup for viewing a 360 tour
function TourPopup(img,licd,picnum,mediaTp) 
{
	var ScreenWidth=window.screen.width;
	var ScreenHeight=window.screen.height;
	var movefromedge=0;
	placementx=(ScreenWidth/2)-((340)/2);
	placementy=(ScreenHeight/2)-((330+50)/2);
	var PopUpUrl = "/nqcontent.cfm?a_name=V3_360_popup&img=" + img+'&li_cd='+licd+'&picnum='+picnum + '&mediaTp=' + mediaTp;
	WinPop = window.open(PopUpUrl,"","width=520,height=550,toolbar=0,location=0,directories=0,status=0,scrollbars=1,menubar=0,resizable=1,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}



/*function newOpportunity(acOpportunityTpHiddenNm)
{
	var cSourceUrl = encodeURI(location.href);
	location.href ="/nqcontent.cfm?a_name=v3_opportunity_form&opp_tp=" + acOpportunityTpHiddenNm + "&sourceUrl=" + cSourceUrl;
}*/

function newOpportunity(acArticleNm, acAddlUrlParams)
{
	var cSourceUrl = encodeURIComponent(location.href);
	var cUrl = "/nqcontent.cfm?a_name=" + acArticleNm;
	if (acAddlUrlParams != null)
	 	cUrl +="&" + acAddlUrlParams;
	cUrl += "&sourceUrl=" + cSourceUrl;
	location.href =cUrl;
}

function selectLocation(acDataFieldId, acDispFieldId, abUseLongLocTitle)
{
	var oDispId = document.getElementById(acDataFieldId);
	var oValId = document.getElementById(acDispFieldId);
	var cBrowser = getBrowser();
	if ( cBrowser == 'IE')
	{
		var val = window.showModalDialog(
			"nqcontent.cfm?a_name=v3_location_popup&dispid=" + acDataFieldId + "&valid=" + acDispFieldId + "&uselong=" + abUseLongLocTitle, "",
			"dialogHeight: 640px; dialogWidth: 500px; center: yes; edge: Raised; resizable: Yes; status: No;");
		if (val != null)
		{
			var aSplit = val.split("|");
			oDispId.value=aSplit[0];
			oValId.value=aSplit[1];
		}
	}
	else
	{
		window.open(
			"nqcontent.cfm?a_name=v3_location_popup&dispid=" + acDataFieldId + "&valid=" + acDispFieldId + "&uselong=" + abUseLongLocTitle, 
			"", 
			"height=640,width=500,top=300,left=450,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
	}
}

// Open a listing in a new unnamed window
// unnamed = each click will result in a new window to pop up
function OpenLink(listing)
{
	var oPreview = window.open(listing, "_blank");
}

function CompareAndShow(expressions, exec_this, delimeter)
{
	if (ValidateExpressions(expressions,delimeter))
		eval(exec_this);
}

function ValidateExpressions(ExpressionList, delimeter)
{
	var bRetVal=true;
	if (delimeter==null) delimeter="|";
	var exoList = ExpressionList.split(delimeter);
	for (i = 0; i < exoList.length; i++)
	{	
		if (!eval(exoList[i]))
		{
			bRetVal=false;
			break;
		}
	}
	return bRetVal;
}

function ValidateNumbers(min_num, max_num, field)
{
	var bRetVal=true;
	if (parseInt(min_num) > parseInt(max_num))
	{
		bRetVal=false;
		alert("The maximum " + field + " cannot\nbe less than the minimum");
	}
	return bRetVal;
}

function checkUserLogin(userlogin) {
	if (getBrowser() == 'IE'){
		d_id = window.showModalDialog('/v3/popups/check_user.cfm?login=' + userlogin, '',
						'status:no;center:yes;dialogWidth:430px;dialogHeight:170px;resizable:no;scrollbars:no');
		return d_id;
	}
	else
	{
		window.open('/v3/popups/check_user.cfm?login=' + userlogin, '',
						'status=no,center=yes,width=430px,height=170px,resizable=no,scrollbars=no');
	}
}

function showHideDiv(elDiv) {
	var elCurrentState = document.getElementById(elDiv).style.display;
	if (elCurrentState == "block") {
		document.getElementById(elDiv).style.display = "none";
	}
	else {
		document.getElementById(elDiv).style.display = "block";
	}
}
/* Author Athos- Used to popup the picture view popup, Called from bs_listing_section_photo_office and bs_listing_section_media */
function openPhotoPopup(licd, picnum, mediaTp, showAll) 
{
	if (showAll == null) showAll = "0";
	window.open('/nqcontent.cfm?a_name=V3_photo_popup&li_cd='+licd+'&picnum='+picnum + '&mediaTp=' + mediaTp + '&showAll=' + showAll, null,"height=700,width=750,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}

function openSlideShowPopup(licd) 
{
	window.open('/nqcontent.cfm?a_name=V3_photo_popup&mediaTp=photo&slideshow=true&li_cd='+licd+'&picnum=1', null,"height=770,width=750,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}

function openVideoShowPopup(licd) 
{
	 window.open('/nqcontent.cfm?a_name=V3_video_popup&li_cd='+licd+'&mediaTp=flashvideo', null,"height=790,width=770,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}

//popup print window
function v3_Print(what)
{
	window.open('/v3_print.cfm' + what, 'newwindow', 'toolbar=no,status=no,scrollbars=yes,location=yes,menubar=no,directories=no,width=700,height=500');
}

//popup print window
function v3_PrintWithPrintTag(what, printTag)
{
	window.open('/v3_print.cfm' + what + "&printTag=" + printTag, 'newwindow', 'toolbar=no,status=no,scrollbars=yes,location=yes,menubar=no,directories=no,width=700,height=500');
}

function listAppend(list, value, delimiter)
{
	if (delimiter == null)
		delimiter = ",";
		
	if (list == "")
		list = value;
	else
		list = list + delimiter + value;
		
	return list;
}

/*
** Should be used only if one item with the removed value exists in the list
*/
function listRemove(list, value, delimiter)
{
	if (delimiter == null)
		delimiter = ",";
		
	list = listDeleteAt(list, listFind2(list, value, delimiter), delimiter);
	
	return list;
}

function listLen(list, delimiter)
{
	var aList = list.split(delimiter);
	return aList.length;
}

function listGetAt(list, position, delimiter)
{
	var aList = list.split(delimiter);
	var cRetVal = "";
	
	if (aList.length >= position)
		cRetVal = aList[position];

	return cRetVal;
}

/*
** Returns the index of the first occurance of a specific value in a list
** Will return -1 if not found!
*/
function listFind2(list, value, delimiter)
{
	if (delimiter == null)
		delimiter = ",";
		
	var iFound = -1;
	for(var i=0; i<listLen(list,delimiter); i++)
	{
		if (listGetAt(list,i,delimiter) == value)
		{
			iFound = i+1;
			break;
		}
	}
	return iFound;
}

function listDeleteAt(list, position, delimiter)
{
	if (delimiter == null)
		delimiter = ",";
		
	var aList = list.split(delimiter);
	var aNewList = new Array(1);
	
	for (var i=0; i<aList.length; i++)
	{
		if (i+1 != position)
			aNewList.push(aList[i]);
	}
	
	var newList = aNewList.toString(); //Returns the array as a comma-separated string
	newList = newList.replace(/,/, delimiter); //Replace comma with the delimiter
	
	return cleanList(newList, delimiter);
}

function cleanList(list, delimiter)
{
	if (delimiter == null)
		delimiter = ",";
		
	if (list.indexOf(delimiter) == 0)
		return cleanList(list.substr(1), delimiter);
	return list;
}

function imagePreviewInput(form,field)
{
  a=eval("document.forms[form]."+field);
  image_loc=a.value;  
 
  if (a.value!='')
  {
	  TopDistance = (screen.height/2)-200;
	  LeftDistance = (screen.width/2)-20;
	
	// All supported image formats for the img element in IE are: bmp,emf,gif,jpg,jpeg,png,wmf,xbm.
	// The complete list includes some movie formats: avi,bmp,emf,gif,jpg,jpeg,mov,mpg,mpeg,png,wmf,xbm 
	  if (image_loc.endsWith(".bmp") || image_loc.endsWith(".emf") || image_loc.endsWith(".gif")||
			image_loc.endsWith(".jpg") || image_loc.endsWith(".jpeg") || image_loc.endsWith(".png")||
			image_loc.endsWith(".wmf") || image_loc.endsWith(".xbm"))
	  {
		  HTML = "<html><style>body{margin:0px 0px 0px 0px}</style><body ><img src='"+image_loc +"' border=0 name=load_image onLoad='window.resizeTo(document.load_image.width+10,document.load_image.height+30)'></body></html>";
		  popupImage = window.open('','_blank','left='+LeftDistance+',top='+TopDistance+',width=0,height=0,toolbar=no,scrollbars=no');
		  popupImage.document.open();
		  popupImage.document.write(HTML);
		  popupImage.document.close();
	  }
	  else
	  {
		  if (image_loc.indexOf("C:") == 0)
		  {
			  alert('Preview is not available for non-image files');
		  }
		  else
			  popupImage = window.open(URLencode(image_loc),'_blank','left='+LeftDistance+',top='+TopDistance+',width=0,height=0,toolbar=no,scrollbars=no');
	  }
  }
  else
  {
  	
  	alert("Please select image.");
  }
}
function imagePreviewInputExtraValidation(form,field,cKey,cEntity,cTitle,cWidth,cHeight)
{
	var cUrl = "";
	var cFieldName = field+ "_encoded";
	a = eval("document.forms[form]."+cFieldName);
	image_loc=a.value;
	
	cUrl = '/mgmt_system/view_file.cfm?cFilePath='+image_loc+'&cKey='+cKey+'&cEntity='+cEntity+'&cTitle='+cTitle;
	
	if (a.value!=''){
		TopDistance = (screen.height/2)-200;
		LeftDistance = (screen.width/2)-20;
	
	// All supported image formats for the img element in IE are: bmp,emf,gif,jpg,jpeg,png,wmf,xbm.
	// The complete list includes some movie formats: avi,bmp,emf,gif,jpg,jpeg,mov,mpg,mpeg,png,wmf,xbm 
  	if (image_loc.endsWith(".bmp") || image_loc.endsWith(".emf") || image_loc.endsWith(".gif")||
		image_loc.endsWith(".jpg") || image_loc.endsWith(".jpeg") || image_loc.endsWith(".png")||
		image_loc.endsWith(".wmf") || image_loc.endsWith(".xbm"))
	 {
  		cUrl = cUrl + '&bPreview=true';
		popupImage = window.open(cUrl,'_blank','left='+LeftDistance+',top='+TopDistance+',toolbar=no,resizable=yes,width='+img.width+',height='+img.height);	
  	  }
  	else
	  {
		  if (image_loc.indexOf("C:") == 0)
	  		alert('Preview is not available for non-image files');
		  else
		  	popupImage = window.open(cUrl,'me','left='+LeftDistance+',top='+TopDistance+',width=0,height=0,toolbar=no,scrollbars=no');	
	  }
  }
  else
  {
  	alert("Please select image.");
  }
}
function openDocument(cFilePath,cKey,cEntity,cTitle,cWidth,cHeight)
{
	var cUrl = '/mgmt_system/view_file.cfm?cFilePath='+cFilePath+'&cKey='+cKey+'&cEntity='+cEntity+'&cTitle='+cTitle+ '&bPreview=true';
	doc = window.open(cUrl,"newwin","toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+cWidth+',height='+cHeight);	
}

function clearField(formOrigin,formName, dataFieldName)
{		
	if (formOrigin ==null || formOrigin =="")
		formOrigin="document"
	dataField = eval(formOrigin + "." + formName + "." + dataFieldName);
	if (dataField != null) 
		dataField.value = "";
	
	displayField = eval(formOrigin + "." + formName + ".disp_" + dataFieldName);			

	if (displayField != null)
		displayField.value = "";
}
if (!String.prototype.endsWith) {
  String.prototype.endsWith = function(suffix) {
    var startPos = this.length - suffix.length;
    if (startPos < 0) {
      return false;
    }
    return (this.lastIndexOf(suffix, startPos) == startPos);
  };
}
// copy from utils.js
function showHideFormField(acFieldName, acDispValue, acCurrentValue)
{
	if (document.getElementById(acFieldName))
		ShowHideSpanBlocked(acDispValue, acFieldName, acCurrentValue, "inline");
	if (document.getElementById("lbl_" + acFieldName))
		ShowHideSpanBlocked(acDispValue, "lbl_" + acFieldName, acCurrentValue, "inline");

	if (document.getElementById("tr_field_" + acFieldName)){
		var blockShow = 'table-row';
		if (window.ActiveXObject) //ie
		{
			 blockShow = 'inline';		
		}
		
		ShowHideSpanBlocked(acDispValue, "tr_field_" + acFieldName, acCurrentValue, blockShow);
	}	

	if (document.getElementById(acFieldName + "_icons"))
		ShowHideSpanBlocked(acDispValue, acFieldName + "_icons", acCurrentValue, "inline");

	if (document.getElementById("comments_" + acFieldName))
		ShowHideSpanBlocked(acDispValue, "comments_" + acFieldName, acCurrentValue, "inline");

	if (document.getElementById("readOnly_" + acFieldName))
		ShowHideSpanBlocked(acDispValue, "readOnly_" + acFieldName, acCurrentValue, "inline");

	if (document.getElementById("na_" + acFieldName))
		ShowHideSpanBlocked(acDispValue, "na_" + acFieldName, acCurrentValue, "inline");

	if (document.getElementById("span_view_file_" + acFieldName))
	{
		//Files
		ShowHideSpanBlocked(acDispValue, "span_view_file_" + acFieldName, acCurrentValue, "inline");
		if (acCurrentValue != acDispValue)
		{
			if (document.getElementById("span_edit_file_" + acFieldName))
				ShowHideSpanBlocked(acDispValue, "span_edit_file_" + acFieldName, acCurrentValue, "inline");
		}
	} else
	{
		if (document.getElementById("span_edit_file_" + acFieldName))
		{
			ShowHideSpanBlocked(acDispValue, "span_edit_file_" + acFieldName, acCurrentValue, "inline");
		}
	}
}
// copy from utils.js
function dateDiff(intervalflg,date1,date2)
{
	var yeaDiff = date2.getFullYear() - date1.getFullYear();
    var monDiff = (date2.getMonth() - date1.getMonth()) + (yeaDiff * 12);
   
	var msDiff = date2.getTime() - date1.getTime(); // Millisecs
	
    var secDiff = msDiff/1000;
	var minDiff = secDiff/60;
    var houDiff = minDiff/60;
	var dayDiff = houDiff/24;
    var weeDiff = dayDiff/7;
    var ret = 0;

switch(intervalflg) {
    case 'yyyy':
        ret = yeaDiff;
        break;
    case 'm':
        ret = monDiff;
        break;            
    case 'd':
    	ret = dayDiff;
    	break;
    case 'h':
        ret = houDiff;
        break;
    case 'min':
        ret = minDiff;
        break;
    case 's':
        ret = secDiff;
        break;
    case 'w':
        ret = weeDiff;
        break;
    default:
        // Do nothing
        break;        
	} 
    return parseInt(ret); // Return an integer

}
// copy from utils.js
function fldPopDateFromCombos(acFieldName)
{
	var fldDay = document.getElementById(acFieldName + "_day");
	var fldMonth = document.getElementById(acFieldName + "_month");
	var fldYear = document.getElementById(acFieldName + "_year");
	var fldDate = document.getElementById(acFieldName);

	if (fldDay && fldMonth && fldYear && fldDate)
	{
		var iDay = fldDay.value;
		var iMonth = fldMonth.value;
		var iYear = fldYear.value;

		if ((iDay > 0) && (iMonth > 0) && (iYear > 0))
		{
			fldDate.value = iYear + "/" + iMonth + "/" + iDay;
		}
	}
}