function populateParentWindow(vMessage) {
     window.opener.document.getElementById("messageDiv").innerHTML += vMessage;
     return false; // you'll need this to ensure that you don't actually have a clickthrough to your child window link.
}

function left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }
     	
function right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

function len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
        {  return String(str).length;  }

function inStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                      
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < len(strSearch); i++)
	{
	    if (charSearchFor == mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}


function mid(str, start, theLen)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || theLen < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + theLen > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + theLen;

                return String(str).substring(start,iEnd);
        }  

function rightBack(sourceStr, keyStr){
arr = sourceStr.split(keyStr);
return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : arr.pop()
}

function leftBack(sourceStr, keyStr){
arr = sourceStr.split(keyStr)
arr.pop();
return (keyStr==null | keyStr=='') ? '' : arr.join(keyStr)
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "_","#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function returnProcessing(vReturnField)
{
// dummy function for returning from Name Pick function
}


function getFieldValue(f,vFieldName)
	{

	var vValue=''

	if(typeof f[vFieldName]=='undefined')
		{
		vValue=''
		return vValue		
		}

	var vFieldLength=f[vFieldName].length;

	if(typeof vFieldLength!='number')
		{
		if(f[vFieldName].checked==true)
			{// Removed + ";" from end of next line - Doug
	//		vValue=f[vFieldName].value
			vValue=f[vFieldName][i].text + ";"
			}
		else
			{vValue=""}
		return vValue
		};

	if(f[vFieldName].type=='select-one')
		{for (var i=0; i<vFieldLength; i++)
			{if (f[vFieldName][i].selected)
				{vValue=f[vFieldName][i].text + ";"}
			}
		}
		else	if(f[vFieldName].type=='select-multiple')
		{vValue=''
		for (var i=0; i<vFieldLength; i++)
			{if (f[vFieldName][i].selected)
				{vValue+=vValue=f[vFieldName][i].text + ";"}
			}
		}
		else
			{
			for (var i=0; i<vFieldLength; i++)
			//alert(.theGraphicDialogFlag[0].checked)
				if(f[vFieldName][i].checked==true)
					{
					vValue+=f[vFieldName][i].value + ";"
					}
			}



if(len(vValue)>0)
	{return left(vValue,(len(vValue)-1))}
else
	{return vValue}
	}
function submitForm(vForm,vSize,vGraphicName)	
{//var f=document.forms['snipshot'];
	{
//var vSize=getFieldValue(vForm,"SnipshotSize")

	
//vForm.snipshot_output.value = vForm.snipshot_output.value + "&name=" + vGraphicName + "&file"
//alert(vForm.snipshot_output.value)
//vForm.snipshot_output_options.value="{'size': {  'max': {'width': 200,'height': 200}}}"
if (vSize=="Small")
	{vForm.snipshot_output_options.value="{'size': {  'max': {'width': 150}}}"}
else if (vSize=="Medium")
	{vForm.snipshot_output_options.value="{'size': {  'max': {'width': 300}}}"}	
else if (vSize=="Large")
	{vForm.snipshot_output_options.value="{'size': {  'max': {'width': 500}}}"}	
else
	{vForm.snipshot_output_options.value=""}		
	
//alert(vForm.snipshot_output_options.value)	
	
	 vForm.submit();}

	 }

function searchContent()
{vSearchValue=document.forms["siteSearch"].Query.value;
//var vSearchValue=getFieldValue(vForm,"")
if (vSearchValue=="" || vSearchValue=="Enter keywords")
	{
	alert("Please enter search value.")
	}
else
	{	
	var vAddress="theSearchResults.xsp?SearchValue=" +vSearchValue	
	location.href=vAddress;
	}
}

function gup( name ){
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null )
	return "";
else
	return results[1];
}

function showDialog(vAddress,vName,vWidth,vHeight)
{
if (typeof vWidth=="undefined")
	{vWidth="900"}

if (typeof vHeight=="undefined")
	{vHeight="600"}
var vParameters ="width=" + vWidth + ",height=" + vHeight + ",left=80,top=80,scrollbars=yes,resizable=yes,titlebar=0"
window.open(vAddress,vName,vParameters)
} 

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function moveImage(vImage,vImageAddress){

	var vImageHtml="<img src='" + vImageAddress + "'>";
	document.getElementById('mainGraphic').innerHTML = "";
	document.getElementById('mainGraphic').innerHTML = vImageHtml;
	
	document.getElementById('graphicName').value = vImage
	document.getElementById('graphicAddress').value = vImageAddress
	var vObj = document.getElementById('mainGraphic') ;
	//document.getElementById('AttachWizard:_id1:username').value =vObj.offsetWidth;
	var vImageMessage="Name: " + vImage + "    Height: " + vObj.offsetHeight+ "   Width: " + vObj.offsetWidth;
	document.getElementById('messageGraphic').innerHTML = vImageMessage;
}

function moveImageCkEditor(vImage,vImageAddress){

	var vImageHtml="<img src='" + vImageAddress + "'>";
	document.getElementById('mainGraphicCkEditor').innerHTML = "";
	document.getElementById('mainGraphicCkEditor').innerHTML = vImageHtml;
	
	document.getElementById('graphicName').value = vImage
	document.getElementById('graphicAddress').value = vImageAddress
	//document.getElementById('graphicAddress').value = "get/Image-Default-LCD+2011/$file/wall mount.jpg"
	var vObj = document.getElementById('mainGraphicCkEditor') ;
	//document.getElementById('AttachWizard:_id1:username').value =vObj.offsetWidth;
	var vImageMessage="Name: " + vImage + "    Height: " + vObj.offsetHeight+ "   Width: " + vObj.offsetWidth;
	document.getElementById('messageGraphicCkEditor').innerHTML = vImageMessage;
}

function getUrlParam(paramName)
{
  var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
  var match = window.location.search.match(reParam) ;
 
  return (match && match.length > 1) ? match[1] : '' ;
}

function Init_CKEditor(ClientId) {
    // Perform the replace on the given client id
    var Editor = CKEDITOR.replace(ClientId);
   
    
    // Add a function used by our custom plugins
    Editor.loadXMLDoc = function(path) {
        var xhttp=new XMLHttpRequest();
        xhttp.open("GET", path, false);
        xhttp.send();
       
        return xhttp.responseXML;
    }
    
    // The data used by the plugins
     
    Editor.StaffData = 'http://localhost/theTemplate.nsf/Personnel.xml'; 
   
}

function InsertHTML(vHtml)        
{
var myinstances = [];
var oEditor
//this is the foreach loop
for(var i in CKEDITOR.instances) {
oEditor =CKEDITOR.instances[i]
   /* this  returns each instance as object try it with alert(CKEDITOR.instances[i]) */
  //  CKEDITOR.instances[i]; 
   
    /* this returns the names of the textareas/id of the instances. */
  //  CKEDITOR.instances[i].name;

    /* returns the initial value of the textarea */
  //  CKEDITOR.instances[i].value;  

   /* this updates the value of the textarea from the CK instances.. */
 //  CKEDITOR.instances[i].updateElement();

   /* this retrieve the data of each instances and store it into an associative array with
       the names of the textareas as keys... */
 //  myinstances[CKEDITOR.instances[i].name] = CKEDITOR.instances[i].getData(); 




// Check the active editing mode.
if ( oEditor.mode == 'wysiwyg' )
{// Insert the desired HTML.
oEditor.insertHtml( vHtml );

}
else
alert( 'You must be on WYSIWYG mode!' );
}
// Get the editor instance that we want to interact with.
//var oEditor = CKEDITOR.replaceClass ='view:_id1:_id2:_id7:tabPanel1:theEditor'


//var oEditor =CKEDITOR.instances.['view:_id1:_id2:_id7:tabPanel1:theEditor'];
//var oEditor = CKEDITOR.instances.page_content;

}
function getFirstElement(node,elementName) {
    
    child =  node.firstChild;
    while (  child != null ) {
        if (child.nodeType == 1) {
            if ( child.nodeName == elementName) {
                return child;
            }
        }    
        child = child.nextSibling;    
    }
    return null;    
}


function getLastElement(node,elementName) {
    
    child =  node.lastChild;
    while (  child != null ) {
        if (child.nodeType == 1) {
            if ( child.nodeName == elementName) {
                return child;
            }
        }    
        child = child.previousSibling;    
    }
    return null;    
}



function getNthElement(node, elementName, n) {
        
    foundCount = 0;
    child =  node.firstChild;    
    while (child != null)  {
        if (child.nodeType == 1) {
            if (child.nodeName == elementName) {
                foundCount = foundCount + 1;
                if (foundCount == n) {        
                    return child;        
                }
            }
        }
        child = child.nextSibling
    }
    
    return null;    
}

function getElementText(node) {
        
    if (node == null) {
        return("");
    }
    
    child =  node.firstChild;
    foundCDATA = false;
    foundPlainText = false;
    
    while (child != null) {    
        if (child.nodeType == 4) {            // CDATA node
            result = child.nodeValue;
            foundCDATA = true;
        }
        else {
            if (child.nodeType == 3) {        // Text node
                result = child.nodeValue;
                foundPlainText = true;
            }
        }
        if (foundCDATA == true) {
            return result
        }    
        child = child.nextSibling    
    }
    if (foundPlainText == false) {
        return("")
    }

    return result;
}


function newWindow(vUrl)
{
var ptr = window.open(vUrl,'xPopUp','width=300,height=200,resizable=yes,left=300,top=300,title=no,toolbar=no,directories=no,location=no,status=no,menubar=no');
//var ptr = window.open('proforma.asp?placement=12', 'myWin', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=670, height=800');
if(ptr) ptr.focus();
return false;
} 

// Copyright 2006-2007 javascript-array.com

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


function processEdit(vTab,vType,vDocumentType,vDocumentKey)
{
if (vType=="edit")
	{// The variable should probably be switch in the function calls
	var vAddress="GetEdit/" +vDocumentType + "?editDocument" + "&tab=" + vTab;
	}
else
	{
	var vAddress="theContentEdit.xsp?DocumentType=" +vDocumentType + "&DocumentKey=" + vDocumentKey + "&tab=" + vTab;	
	}
	
		
location.href=vAddress;
}


