//Function to format text in the text box
vcolor = "";
tflag = null;
functionalityMsg = 'This functionality is not available under HTML Editor';
	
function FormatText(command, option) {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	if ((command == "forecolor") || (command == "backcolor")) {
		parent.command = command;
		buttonElement = document.getElementById(command);
		var mystyle = document.getElementById("colorpalette").style;
		mystyle.left = getOffsetLeft(buttonElement) + "px";	
		mystyle.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";

		if (mystyle.visibility == "hidden")
			mystyle.visibility="visible";
		else {
			mystyle.visibility="hidden";
		}
	}else {
		document.getElementById("edit").contentWindow.focus();
		document.getElementById("edit").contentWindow.document.execCommand(command, false, option);
		document.getElementById("edit").contentWindow.focus();
	}
}

function busy() {
		buttonElement = document.getElementById('msganchor');
		var mystyle = document.getElementById("busy").style;
		mystyle.left = getOffsetLeft(buttonElement) + "px";
		mystyle.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";

	
	//mystyle.left = "400px";
	//mystyle.top = "400px";

	if (mystyle.visibility == "hidden")
		mystyle.visibility="visible";
	else {
		mystyle.visibility="hidden";
	}	
}

function getTheColor( command, option ){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	getColor(command, option)
}

function getColor(command, option) {	
	if ((command == "hexcolor1") || (command == "hexcolor2") || (command == "hexcolor3") || (command == "hexcolor4")  || (command == "bgcolor") || (command == "link") || (command == "hover") || (command == "fontcolor")  || (command == "table1")  || (command == "table2")  || (command == "table3")  || (command == "table4") || (command == 'colorValue') || (command == 'colorValue1')) {
		parent.command = command;
		buttonElement = document.getElementById(command);
		var mystyle = document.getElementById("colorpalette2").style;
		mystyle.left = getOffsetLeft(buttonElement) + "px";
		mystyle.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";

		if (mystyle.visibility == "hidden")
			mystyle.visibility="visible";
		else {
			mystyle.visibility="hidden";
		}
	}	
}

function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	
	return mOffsetTop;
}

function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	
	return mOffsetLeft;
}

function Select(selectname){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	var cursel = document.getElementById(selectname).selectedIndex;

	// First one is always a label
	if (cursel != 0) {
		var selected = document.getElementById(selectname).options[cursel].value;
		document.getElementById('edit').contentWindow.document.execCommand(selectname, false, selected);
		document.getElementById(selectname).selectedIndex = 0;
	}
	document.getElementById("edit").contentWindow.focus();
}

//Function to set color
function setColor(color) {
	if((command == "colorValue") || (command == "colorValue1")){
		document.getElementById("colorpalette2").style.visibility="hidden";
		//to use this action, "colorValue, you must implement the processColorValue function
		processColorValue(color, command);
		return;
	}
	
	mywindow = document.getElementById('edit').contentWindow;
	document.getElementById("colorpalette").style.visibility="hidden";
	mywindow.focus();
	
	var range = mywindow.document.selection.createRange();
	if (parent.command == 'forecolor' || parent.command == 'backcolor') {
		mywindow.document.execCommand(parent.command, false, color);
	}else{		
		//return parent.command;
		if(parent.command == "hexcolor1"){		
			editdoc = parent.document;			
			if(editdoc.getElementById("bground1")){
				var imgobj = editdoc.getElementById("bground1");
				imgobj.style.backgroundColor = color;
				parent.document.forms[0].TitleBackGrourdColor.value = color;
			}	
		}else if(parent.command == "hexcolor2"){									
			//setEditWindowColor(color);			
			parent.document.forms[0].TextBackGrourdColor.value = color;
			setBGPropertiesVal();
		}else if(parent.command == "hexcolor3"){															
			parent.document.forms[0].TextBackGrourdColor.value = color;
			setTopPanelBGVal();									
		}else if(parent.command == "bgcolor"){					
			//setEditWindowColor(color);				
			/* Check if table object is selected */
			if (range.length == 1 && range(0).tagName.toLowerCase() == 'table'){
				vcolor = color;
				tflag = true;
			} else{					
				parent.document.forms[0].BackgroundColor.value = color;	
				parent.document.forms[0].TextBackGrourdColor.value = "";
			}			
			setBGPropertiesVal();						
		}else if(parent.command == "hexcolor4"){		
			editdoc = parent.document;			
			if(editdoc.getElementById("font")){
				var imgobj = editdoc.getElementById("font");
				imgobj.style.color = color;				
				parent.document.forms[0].FontTextColor.value = color;
			}
		}else if(parent.command == "link"){		
			setLinkColor(color);
		}else if(parent.command == "hover"){		
			setHoverColor(color);
		}else if(parent.command == "table1"){					
			var editdoc = document;
			setItemColorStyle(editdoc, color, "tableHeader")
			editdoc.forms[0].TableHeaderProperty.value = color;	
			setTableDispProp();
		}else if(parent.command == "table2"){		
			var editdoc = document;
			setItemColorStyle(editdoc, color, "tableBorder")
			editdoc.forms[0].TableBorderProperty.value = color;
			setTableDispProp();
		}else if(parent.command == "table3"){		
			var editdoc = document;
			setItemColorStyle(editdoc, color, "tableBG")
			editdoc.forms[0].TableBGProperty.value = color;	
			setTableDispProp();	
		}else if(parent.command == "table4"){		
			var editdoc = document;
			setItemColorStyle(editdoc, color, "tableSeparator")
			editdoc.forms[0].TableSeparatorProperty.value = color;	
			setTableDispProp();															
		}else if(parent.command == "fontcolor"){
			var myframe = window.frames['editArea']; 	
			if (myframe && myframe.document){						
				var editdoc = myframe.document.getElementById("textcolor")
				if(color == ""){
					color = '#000000';
				}
				parent.document.forms[0].TextColor.value = color;
				editdoc.style.color = color; 							
			}							
		}		
	}	
}

function setItemColorStyle(editdoc, color, itemName){	
	if (editdoc){									
		if(editdoc.getElementById(itemName)){
			var itemobj = editdoc.getElementById(itemName);			
			itemobj.style.backgroundColor = color;								
		}		
	}		
}

function setLinkColor(color){
	var myframe = window.frames['editArea'];
	var parentdoc = parent.document;	 
	if (myframe && myframe.document){						
		editdoc = myframe.document;
		if((editdoc.getElementById("link1")) && (editdoc.getElementById("link2"))){
			var linkobj1 = editdoc.getElementById("link1");
			var linkobj2 = editdoc.getElementById("link2");
			linkobj1.style.color = color;
			linkobj2.style.color = color;						
			editdoc.forms[0].LinkersColor.value = color;
		}		

	}
		
	if(parentdoc.getElementById("linkdisp")){
		var imgobj = parentdoc.getElementById("linkdisp");
		imgobj.style.backgroundColor = color;
		parentdoc.forms[0].LinkColor.value = color;
	}	
}

function setHoverColor(color){
	var myframe = window.frames['editArea'];
	var parentdoc = parent.document;	 
	if (myframe && myframe.document){						
		editdoc = myframe.document;							
		editdoc.forms[0].HoversColor.value = color;		
	}
		
	if(parentdoc.getElementById("hoverdisp")){
		var imgobj = parentdoc.getElementById("hoverdisp");
		imgobj.style.backgroundColor = color;
		parentdoc.forms[0].HoverColor.value = color;
	}	
}


//sets the color of the edit box
function setEditWindowColor(color) {
	var myframe = window.frames['editArea']; 
	if (myframe && myframe.document && myframe.document.body){						
		myframe.document.body.style.backgroundColor = color; 				
	}			
} 

//sets the properties of the edit box
function setBackgroundProperties(repeat, position, attachment) {
	var myframe = window.frames['editArea']; 
	if (myframe && myframe.document && myframe.document.body){			
		myframe.document.body.style.backgroundRepeat = repeat;
		myframe.document.body.style.backgroundPosition = position;		
		myframe.document.body.style.backgroundAttachment = attachment;				
	}	
} 

//removes the background image of the edit box
function removeBackgroundImage() {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	var myframe = window.frames['editArea']; 
	if (myframe && myframe.document && myframe.document.body){		
		myframe.document.body.style.backgroundImage = "url('')";
		
		var editdoc = myframe.document.body.document;
		var range = editdoc.selection.createRange();		
		/* Check if one object is selected */
		if (range.length == 1 && range(0).tagName.toLowerCase() == 'table'){
			range(0).style.backgroundImage = "url('')";
			return;
		}
		
		parent.document.forms[0].BackgroundImage.value = "";					
		setBGPropertiesVal();
	}	
} 

var saveoriginal="";
var firstTimer='';
function setStartValue() { 
	firstTimer = parent.document.forms[0].JavaScriptPrompter.value;
	myframe = window.frames['editArea'];
			
  	if (myframe && myframe.document && myframe.document.body && parent.document.forms[0].PageContent && myframe.document.body.innerHTML=="")      { 
    	myedit = myframe.document.body; 
    	   
    	if (saveoriginal == "")	{      
    		tmpstring = parent.document.forms[0].PageContent.innerText;      	
    		var HTMLstring = parent.document.forms[0].PageContent.innerHTML;
    	
    		 if(HTMLstring == ""){
    	 		tmpstring = '<div>&nbsp;</div>';
    	 		parent.document.forms[0].PageContent.innerText = myedit.innerText;
    	 	}
        	
    	   	myedit.innerHTML = tmpstring;
     		saveoriginal = tmpstring;
      		
      
	  		if( firstTimer == ""){
    			alert('NOTE: You may resize your image in the content editor. To do so, click on it once and then resize as desired.\n\nClick OK to continue.');    	
	  		} 	             
    	}else {	       
      		myedit.innerHTML = saveoriginal;        	   	   
 	 	} 
 	 		
  		if (myframe && myframe.document && myframe.document.body) { 
    		myframe.document.designMode = "on";
			setBGPropertiesVal();
			resetAllObjects();		   		    		 	    	          
    	} 
  	}    
}

function setStartValue1() { 
	myframe = window.frames['editArea'];
			
  	if (myframe && myframe.document && myframe.document.body && parent.document.forms[0].PageContent && myframe.document.body.innerHTML=="")      { 
    		myedit = myframe.document.body;      
    		if (saveoriginal == "")	{      
    			tmpstring = parent.document.forms[0].PageContent.innerText;      	
    			var HTMLstring = parent.document.forms[0].PageContent.innerHTML;
    	
    			 if(HTMLstring == ""){
    	 			tmpstring = '<div>&nbsp;</div>';
    	 			parent.document.forms[0].PageContent.innerText = myedit.innerText;
    	 		}
        	
    	    myedit.innerHTML = tmpstring;
     		saveoriginal = tmpstring;
	             
    		}else {	        
      		myedit.innerHTML = saveoriginal;        	   	   
 	 	}  
  		if (myframe && myframe.document && myframe.document.body) { 
  	 	
    		myframe.document.designMode = "on";				   		    		 	    	          
    	} 
  	}    
}

function setBGPropertiesVal(){
	var img = "";
	var color = "";
	
	var pgSymbol = parent.document.forms[0].FdName.value.toLowerCase(); 
	if(pgSymbol == "logo"){	
		// do nothing
	}else{	
		
		var bgimagepage = parent.document.forms[0].BackgroundImage.value;
		//var bgcolorpage = document.forms[0].BackgroundColor.value;
		
		if(tflag){
			bgcolorpage = vcolor;
			tflag = null;		
		}else {
			bgcolorpage = document.forms[0].BackgroundColor.value;				
		}
		
		var bgimage = parent.document.forms[0].PropBGImage.value;
		var bgcolor = parent.document.forms[0].PropBGColor.value;
		var textcolor = parent.document.forms[0].PropBGTextColor.value;
		var pgcolor = parent.document.forms[0].TextBackGrourdColor.value;
		var repeat = parent.document.forms[0].PropBGRepeat.value;
		var position = parent.document.forms[0].PropBGPosition.value;
		var attachment = parent.document.forms[0].PropBGAttachment.value;
		var fn = parent.document.forms[0].FdName.value;	
	
		if(fn == "toppanel"){
			img = bgimagepage;
			
			if(trim(pgcolor, " ") != "") {		
				color = pgcolor;
			} else{
				color = bgcolorpage;
			}
							  		  							
			repeat = document.forms[0].TPanelRepeat.value;
			position = document.forms[0].TPanelPosition.value;	
			attachment = "";
			
		}else if(fn == "backgroundcolor"){		
			var dpObj = parent.document.forms[0];
			
			repeat = dpObj.Repeat.options[dpObj.Repeat.selectedIndex].value;
			position = dpObj.Position.options[dpObj.Position.selectedIndex].value;
			attachment = dpObj.Attachment.options[dpObj.Attachment.selectedIndex].value;
								
			if(trim(pgcolor, " ") != "") {		
				color = pgcolor;
			} else{
				color = bgcolorpage;
			}
			
			img = bgimagepage;
			color = bgcolorpage;
			textcolor = document.forms[0].TextColor.value;			
			repeat = repeat;
			position = position;
			attachment = attachment;
		} else if(trim(pgcolor, " ") != "") {
			img = bgimagepage;
			color = pgcolor;		
			repeat = "";
			position = "";
			attachment = "";
		} else if( (trim(bgimagepage, " ") != "") && (trim(bgcolorpage, " ") != "") ){
			img = bgimagepage;
			color = bgcolorpage;		
			repeat = "";
			position = "";
			attachment = "";		
		}else if( (trim(bgimagepage, " ") != "") && (trim(bgcolorpage, " ") == "") ){
			img = bgimagepage;
			color = "";		
			repeat = "";
			position = "";
			attachment = "";
		}else if( (trim(bgimagepage, " ") == "") && (trim(bgcolorpage, " ") != "") ) {
			img = "";
			color = bgcolorpage;		
			repeat = "";
			position = "";
			attachment = "";
		}else if( ( trim(bgcolor, " ") != "") && (trim(bgimage, " ") != "") ){
			img = bgimage;
			color = bgcolor;			
		}else if( (trim(bgcolor, " ") == "") && (trim(bgimage, " ") != "") ){
			img = bgimage;
			color = "";		
		}else if( (trim(bgcolor, " ") != "") && (trim(bgimage, " ") == "") ){
			img = "";
			color = bgcolor;
		}
				
		onLondEvent(img, textcolor, color, pgcolor, repeat, position, attachment, pgSymbol);		
	} 
}	

function setTopPanelBGVal(){
	var img = document.forms[0].BackgroundImage.value;
	var color = document.forms[0].TextBackGrourdColor.value;

	var myframe = window.frames['editArea'];		
  	if (myframe && myframe.document && myframe.document.body){ 
  		myedit = myframe.document.body;
  		
  		myedit.style.backgroundImage = "url('" + img + "')";		
		myedit.style.backgroundColor = color;
				
		var repeat = document.forms[0].TPanelRepeat.value;
		var position = document.forms[0].TPanelPosition.value;						
		
		myedit.style.backgroundRepeat = repeat;
		myedit.style.backgroundPosition = position;			
	}				
}				 		   		   

function onLondEvent(img, textcolor, color, pgcolor, repeat, position, attachment, pgSymbol){

	var myframe = window.frames['editArea'];	
  	if (myframe && myframe.document && myframe.document.body){  		
    	myedit = myframe.document.body;
   	
    	var editdoc = myframe.document.body.document;
		var range = editdoc.selection.createRange();		
		/* Check if one object is selected */
		if (range.length == 1 && range(0).tagName.toLowerCase() == 'table'){
			range(0).style.backgroundColor = color;
			return;
		}
				 
		myedit.style.backgroundImage = "url('" + img + "')";			
		myedit.style.backgroundColor = color;
		myedit.style.color = textcolor; 
		
		myedit.style.backgroundRepeat = repeat;
		myedit.style.backgroundPosition = position;
		myedit.style.backgroundAttachment = attachment;	
	}			
}				
				
//clears all the content entered and set the richtext area.
function clearFieldContent(){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	myframe = window.frames['editArea'];
  if (myframe && myframe.document && myframe.document.body && parent.document.forms[0].PageContent && myframe.document.body.innerHTML!=""){
	myedit = myframe.document.body;		  
	tmpstring = "<div></div>";
	myedit.innerHTML = tmpstring;		
	}
}

function contentUtility(selectname, option){	
	myframe = window.frames['editArea'];
	if (myframe && myframe.document && myframe.document.body){ 
		mywindow = document.getElementById('edit').contentWindow;
		mydoc = mywindow.document;
					
		var range = mydoc.selection.createRange();				
		var x = range.boundingHeight;	
		
		/* Check if one object is selected */
		if (range.length > 0 && range(0).tagName.toLowerCase() == 'img'){
			range(0).align = "";
		}
		
		mywindow.focus();
		mydoc.execCommand(selectname, false, "");
	}
}

function contentUtility2(selectname){	
	myframe = window.frames['editArea'];
	if (myframe && myframe.document && myframe.document.body){ 
		mywindow = document.getElementById('edit').contentWindow;
		mydoc = mywindow.document;
			
		mywindow.focus();
		mydoc.execCommand(selectname, false, "");
	}
}

//clears all the content entered and set the richtext area.
function UpdateWordFormat(){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	myframe = window.frames['editArea'];
  if (myframe && myframe.document && myframe.document.body && parent.document.forms[0].PageContent && myframe.document.body.innerHTML!=""){
	myedit = myframe.document.body;		  
	var tmpstring = myedit.innerHTML;
	
	tmpstring = tmpstring.replace(/<p\>/ig, "<div>");
    tmpstring = tmpstring.replace(/<\/p>/ig, "</div>");
    tmpstring = tmpstring.replace(/<p /ig, "<div ");
    tmpstring = tmpstring.replace(/<\/p \>/ig, "</div>");
    alert("Your content has been formated for easy editing. Click the help button for more help on formating your content.");   
	myedit.innerHTML = tmpstring;		
	}
}
 
function setInputValue(){
    myframe = window.frames['editArea'];
  if (myframe && myframe.document && myframe.document.body && parent.document.forms[0].PageContent){
    myedit = myframe.document.body;
    
	  resetAllObjects();               
      var tmpstring = myedit.innerHTML;  
      var strVal = myedit.innerText;         
      tmpstring = UtilityFormatAny(tmpstring, '&nbsp;&nbsp;', ' &nbsp; ' );      
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/dell', '' );
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www1.cyberinvader.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/dell', '' );     
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvader.com', '' );   
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvader.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvaders.net', '' );      
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvader.com', '' );   
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvader.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvaders.net', '' );  
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/process.cyberinvaders.net', '' );  
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvaders.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/process.cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvader.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvader.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/webdev.cyberinvader.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'eblank.gif', 'ecblank.gif' );                                
      tmpstring = tmpstring.replace(/<a href=\"http:/ig, '<a target="_blank" href="http:');
     
      var dName = document.jsvalue.DefWWWJ.value;
      w = UtilityFormatAny(dName, '\\/', '\\/' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
      w = UtilityFormatAny(w, 'http', 'https' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
	 
	  var dName = document.jsvalue.WWWJ.value;
      w = UtilityFormatAny(dName, '\\/', '\\/' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
      w = UtilityFormatAny(w, 'http', 'https' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
	      	       
	  parent.document.forms[0].PageContent.innerText = tmpstring;	 	 
	  var pgSymbol = parent.document.forms[0].FdName.innerText;
	  	  	  
	  if(pgSymbol.toLowerCase() == "journal"){	  
	  	var subj = parent.document.forms[0].Subject.value;
	  	if(trim(subj, " ") == ""){
	  		parent.document.forms[0].Subject.value = strVal.substring(0, 35) + " ...";
	  	}	  
	  	parent.document.forms[0].JournalContent.innerText = tmpstring;	  	
	  	parent.document.forms[0].JournalLength.innerText = tmpstring.length;		  
	  }	                  
  }
}

function AddMusicUrl(mfd, label){
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;
	
	document.forms[0].CurMusicFd.value = mfd;
	document.forms[0].CurMusicLb.value = label;
	var mt = document.forms[0].MusicType.value;
	
	x = screen.availWidth * 0.02;
	y = screen.availHeight * 0.02;
	
	if(mt == "yes") {
		pl = "addmediamusicmem"
		h = "570";
		w = "352";
	}else{
		pl = "addmediamusicall"
		h = "500";
		w = "320";
	}
		
	var mediabuilder = "/" + dbpath + "/" + pl + "?open&dn=" + dn + gstring  + getSeq();				
	var w = window.open (mediabuilder, 'windowmlink', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,top=' + y + ',left=' + x + ',resizable=0,width=' + w + ',height=' + h );
	w.opener = self;
	w.focus();

}

function createMusicLink(url, desc){
	if (window.opener && !window.opener.closed){
		var parentWindow = window.opener;
		var mydoc = parentWindow.document;
		var mfd = parentWindow.document.forms[0].CurMusicFd.value;
		var fd = "parentWindow.document.forms[0]." + mfd;
		var fdLoc = eval(fd);
		fdLoc.value = url;
		
		var label = parentWindow.document.forms[0].CurMusicLb.value;
		var lb = "parentWindow.document.forms[0]." + label;
		var lbLoc = eval(lb);
		lbLoc.value = desc;
		
		mydoc.focus();
		window.close();	
	}	
}
	
function addMedia() {
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;

	var url = "";
	var mydoc = document.getElementById('edit').contentWindow.document;
	
	var mplayer = mydoc.getElementById("mplayer");
	
	var sel = mydoc.selection.createRange();	
	var x = sel.boundingHeight;	
		
	if( (x == null) || (x == 0) ){
		alert("Place the cursor where you would like to insert the video.");
		return;	
	}	
	
	if(mplayer){
		if(!confirm("You may insert as many Macromedia Flash Player as desires, but only one Windows Media Player per page. Click OK to continue or Cancel to abort.")){
			return;
		}		
	}	
	
	x = screen.availWidth * 0.65;
	y = screen.availHeight * 0.02;
				
	var mediabuilder = "/" + dbpath + "/mediabuilder?open&dn=" + dn + gstring  + getSeq();	
	var w = window.open (mediabuilder, 'windowaTableSite', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,resizable=0,top=' + y + ',left=' + x + ',width=335,height=640');
	w.opener = self;
	w.focus();
}

function addFlash() {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;
	
	var mydoc = document.getElementById('edit').contentWindow.document;
	
	var mplayer = mydoc.getElementById("mplayer");

	var sel = mydoc.selection.createRange();	
	var v = sel.boundingHeight;	
		
	if( (v == null) || (v == 0) ){
		alert("Place the cursor where you would like to insert the flash file.");
		return;	
	}
	
	if(mplayer){
		if(!confirm("You may insert as many Macromedia Flash Player as desires, but only one Windows Media Player per page. Click OK to continue or Cancel to abort.")){
			return;
		}		
	}	
	
	var x = screen.availWidth * 0.60;
	var y = screen.availHeight * 0.02;
				
	var mediabuilder = "/" + dbpath + "/addimportflash?openform&dn=" + dn + gstring  + getSeq();	
	var w = window.open (mediabuilder, 'windowaTableSite', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,resizable=0,top=' + y + ',left=' + x + ',width=352,height=620');
	w.opener = self;
	w.focus();
}

function insertVideoLink(ul){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	var pl = "";
	var h = ""
	var w = "";
	
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;
	
	var mydoc = document.getElementById('edit').contentWindow.document;
	var mydoc = document.getElementById('edit').contentWindow.document;
	
	
	//get current selected range
	var sel = mydoc.selection;
	if (sel!=null) {
		var cont = sel.type
		var rng = sel.createRange();
		var str = rng.text;
	}
	
	if ( (sel == null) || ((cont.toLowerCase() != "control") && (rng.text == null  || rng.text == "")) )    {
		alert("Please select some text or an item first before creating a video link.");
		return;
	}

	x = screen.availWidth * 0.60;
	y = screen.availHeight * 0.02;
	
	if( (ul != null) && (trim(ul, " ") != "" && ul == "link")) {
		pl = "addflashlink"
		h = "605";
		w = "352";
	}else{
		pl = "medialinkbuilder"
		h = "530";
		w = "320";
	}
		
	var mediabuilder = "/" + dbpath + "/" + pl + "?open&dn=" + dn + gstring  + getSeq();				
	var w = window.open (mediabuilder, 'windowmlink', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,top=' + y + ',left=' + x + ',resizable=0,width=' + w + ',height=' + h );
	w.opener = self;
	w.focus();
}

function CreateMediaMLink(url) {
	var docObj = document.forms[0];		
	var v = docObj.VideoTitle.value;
	v = replaceSubstring( v, " ", "+" );
	v = replaceSubstring( v, "&", "<~>" );
	v = replaceSubstring( v, "'", "~ap~" );
	
	var u = docObj.MadeBy.value;
	u = replaceSubstring( u, " ", "+" );
	u = replaceSubstring( u, "&", "<~>" );
	u = replaceSubstring( u, "'", "~ap~" );
	
	url = url + "&title=" + v + "&by=" + u;	
	createMediaLink(url);
}

function createMediaLink(url){
	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener;		
		var pmydoc = parentWindow.document.getElementById('edit');
		if(pmydoc){	
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;
		
			if (editdoc){
				var sel = editdoc.selection.createRange();													
				var urlValue = "javascript:launchMediaLink('" + url + "')";
							
				if(url != "") {				
					editdoc.execCommand("CreateLink", false, urlValue);
				}							
			}
			mydoc.focus();
			window.close();	
			return true;
		} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	} 
	window.close();	
}
 
function createPDFLink(url){
	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener;		
		var pmydoc = parentWindow.document.getElementById('edit');
	
		if(pmydoc){
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;
		
			if (editdoc){
				var sel = editdoc.selection.createRange();
				var urlValue = "javascript:urlLoader('" + url + "')";													
											
				if(url != "") {	
					editdoc.execCommand("CreateLink", false, urlValue);
				}							
			}
			mydoc.focus();
			window.close();	
			return true;
		} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	} 
	window.close();	
}
 
function addDesignerTable(key) {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	var dbpath = parent.document.jsvalue.ILibraryDBJ.value;
	var gstring = parent.document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = parent.document.jsvalue.DomainNameJ.value;

	var url = "";
	var mydoc = parent.document.getElementById('edit').contentWindow.document;
	
	
	var sel = mydoc.selection.createRange();
	parent.bmark = sel;
	var x = sel.boundingHeight;	
	if( (x == null || (x == 0) )){	
		alert("Place the cursor where you would like to insert the designer table.");
		return;	
	}	
						
	var tablebuilder = "/" + dbpath + "/tablebuilder?open&dn=" + dn + "&k=" + key + gstring  + getSeq();
	var w = window.open (tablebuilder, 'windowaTableSite', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=520,height=400');
	w.opener = self;
	w.focus();
}

function creatLinkCustom() {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	var dbpath = document.jsvalue.SiteDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;

	var url = "";
	var mydoc = document.getElementById('edit').contentWindow.document;
	
	//get current selected range
	var sel = mydoc.selection;
	if (sel!=null) {
		var cont = sel.type;
		var rng = sel.createRange();
		var str = rng.text;
	}
			
	if ( (sel == null) || ((cont.toLowerCase() != "control") && (rng.text == null  || rng.text == "")) )    {
		alert("Please select some text or an item first before creating or editing link.");
		return;
	}
	
	var linkbuilder = "/" + dbpath + "/linkbuilder?open&dn=" + dn + gstring  + getSeq();
	var w = window.open (linkbuilder, 'windowaViewSite', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=500,height=540');
	w.opener = self;
	w.focus();
}

function creatPpalLinkCustom() {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;

	var url = "";
	var mydoc = document.getElementById('edit').contentWindow.document;
	
	//get current selected range
	var sel = mydoc.selection;
	if (sel!=null) {
		var cont = sel.type;
		var rng = sel.createRange();
		var str = rng.text;
	}
			
	if ( (sel == null) || ((cont.toLowerCase() != "control") && (rng.text == null  || rng.text == "")) )    {
		alert("Please select some text or an item first before creating or editing PayPal link.");
		return;
	}
	
	var paypallinkbuilder = "/" + dbpath + "/paypallinkbuilder?open&dn=" + dn + gstring  + getSeq();
	var w = window.open (paypallinkbuilder, 'windowaViewSite', 'toolbar=0, location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=350,height=520');
	w.opener = self;
	w.focus();
}


function selectDefaultPage(runjscode) {
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;
	var runjs = "";
	
	if( (runjscode != null) && (runjscode != "")){
		runjs = "&runjscode=" + runjscode;
	}
	
	var dpselector = "/" + dbpath + "/dpselector?open&dn=" + dn + gstring  + runjs + getSeq();
		
	var w = window.open (dpselector, 'windowdpViewSite', 'toolbar=0, location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=530,height=430');
	w.opener = self;
	w.focus();
}

function buildUserLink(title, properties, http){
	parent.document.forms[0].IntLink.value = title;
	parent.document.forms[0].IntLinkProperties.value = properties;
	parent.document.forms[0].HttpProperties.value = http;
}

function insertFlasBannerText(url, urlname, id, w, h){
	var docObj = document.forms[0];		
	var dObj = docObj.MediaType;
	var fg = getRadioButtonSelectValue( dObj );
	docObj.MediaUrl.value = url;
	
	var len = url.length;		
	var swf = url.substring( len - 3, len );
	var pos = url.toLowerCase().indexOf('.swf');	 
	
	if(pos > -1){
	//if((fg == "flash" && swf.toLowerCase() == "swf") || (trim(fg, " ") == "" && swf.toLowerCase() == "swf")){
		docObj.mediaCode.value = docObj.FCode.value;
		setRadioButtonItem(docObj, "MediaType", "flash")		
	//} else if(fg == "flash" && swf.toLowerCase() != "swf") {
	//	alert('The media type you entered is not a Micromedia Flash product. For a flash media, your url should end with a ".swf".');		
	//	return false;
	} else{	
		docObj.mediaCode.value = docObj.MCode.value;
		setRadioButtonItem(docObj, "MediaType", "mplayer")
	}
	insertMediaText(urlname, id, w, h);
}

function insertMediaText(urlname, id, w, h){
	var url = parent.document.forms[0].MediaUrl.value;	
	var tmpstring = parent.document.getElementById("mediaCode").innerText;
	
	if(urlname == null) {
		urlname = "msplayer";
	} 
	
	if(id == null) {
		id = "mplayer";
	} 
	
	if(w == null || trim(w, " ") == "") {
		w = "350";
	} 
	
	if(h == null || trim(h, " ") == "") {
		h = "280";
	} 
				
	tmpstring = UtilityFormatAny(tmpstring, "~w~", w );
	tmpstring = UtilityFormatAny(tmpstring, "~h~", h );
	tmpstring = UtilityFormatAny(tmpstring, "~un~", urlname );		
	tmpstring = UtilityFormatAny(tmpstring, '~url~', url );
	tmpstring = UtilityFormatAny(tmpstring, "~id~", id );
	
	if (window.opener && !window.opener.closed){
		var parentWindow = window.opener;
		var pmydoc = parentWindow.document.getElementById('edit');
		if(pmydoc){	
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;
			if (editdoc){
				
				var mplayer = editdoc.getElementById("mplayer");
				var selectType = getRadioButtonSelectValue( document.forms[0].MediaType );
				if(mplayer && selectType == "mplayer"){
					alert("You may insert as many Macromedia Flash Player as desires, but only one Windows Media Player per page.")
					return;					
				}	
				
				var sel = editdoc.selection.createRange();
				editdoc.focus(); 							
				sel.pasteHTML(tmpstring);	
				
				parentWindow.document.forms[0].AutoStart.value = getRadioButtonSelectValue(document.forms[0].AutoStart);								
			}				
				window.close();	
				return true;
			} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	} 
	window.close();	    
}

function insertFlasBanner(url, urlname, id, w, h){
	var tmpstring = "";
	
	if(trim(w, " ") == "") {
		w = "200";
	}
	
	if(trim(h, " ") == "") {
		h = "180";
	}

	tmpstring = parent.document.getElementById("FCode").innerText;	
				
	tmpstring = UtilityFormatAny(tmpstring, "~w~", w );
	tmpstring = UtilityFormatAny(tmpstring, "~h~", h );
	tmpstring = UtilityFormatAny(tmpstring, "~un~", urlname );	
	tmpstring = UtilityFormatAny(tmpstring, "~id~", id );
	
	url = replaceSubstring(url, "~ap~", "'");
	tmpstring = UtilityFormatAny(tmpstring, "~url~", url );
	
	if (window.opener && !window.opener.closed){
	
		var parentWindow = window.opener;
		var pmydoc = parentWindow.document.getElementById('edit');
		if(pmydoc){			
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;
			if (editdoc){											
				var sel = editdoc.selection.createRange();
				editdoc.focus();																		
				sel.pasteHTML(tmpstring);
											
				if(trim(h, " ", "") != ""){						
					pmydoc.height = h;
					var docobj = parentWindow.document.forms[0];																	
					docobj.TableHeight.options[docobj.TableHeight.options.selectedIndex].text = h + " pixel";	
					docobj.TableHeight.options[docobj.TableHeight.options.selectedIndex].value = h + "px";	
				}											
			}							
			window.close();	
			return true;
			} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	} 
	window.close();	    
}


function insertTableText(){
	var htmcode = parent.document.forms[0].TableProperty.innerText;
	var w = parent.document.forms[0].Width.value;
	var h = parent.document.forms[0].Height.value;
	var tableid = parent.document.forms[0].TableID.value;
	
	if(trim(w, " ") == ""){
		w = "100%";
	}
	
	if (window.opener && !window.opener.closed){

		var parentWindow = window.opener;
		var pmydoc = parentWindow.parent.document.getElementById('edit');
		
		if(pmydoc){	
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;
			if (editdoc){
				myedit = editdoc.body;				
				var sel = editdoc.selection.createRange();
				var bmark = parentWindow.parent.bmark;
				if(!sel.isEqual(bmark)){
					alert("Swiching between windows or clicking outside the editor box before completing inserting your layout table, has caused your cursor to be moved to another location. Place your cursor in the insertion point and try again.");
					window.close();
					return;	
				}
				
				editdoc.focus();
				var nobj = sel.pasteHTML(htmcode);
				tobj = editdoc.getElementById(tableid);
				tobj.style.width = w;
				tobj.style.height = h;
				window.close();
				return;
			} else{
				alert("The window you were editing is no longer available. Click OK to continue.");
			}	
		}							
	} 
	window.close();	    
}

function setTableDispProp(){

	var flag = "";
	var dvHeaderColor = "";
	var dvBorderColor = "";
	var noPadding = "";
	var dSepColor = "";
		
	var dHeaderColor = parent.document.forms[0].TableHeaderProperty.value;
	var docObj = parent.document.forms[0].TableExtraPaddingProperty;
	var docObjv = parent.document.forms[0].Valignment;
	var dExtrapadding = docObj.options[docObj.options.selectedIndex].value;	
	var valign = 'valign=' + docObjv.options[docObjv.options.selectedIndex].value;
	var tableid = parent.document.forms[0].TableID.value;
	
	if(trim(dHeaderColor, " ") == "") {
		dHeaderColor = "class=tdtable_none";		
	}else {
		dHeaderColor = 'class=tdtable_none bgcolor=' + dHeaderColor;
	}	
	
	if(dExtrapadding != "0 px") {
		var dpadding = 'style="padding-left:' + dExtrapadding + '; padding-right:' + dExtrapadding + '; padding-top:1px; padding-bottom:1px;"';
	}

	var dBorderColor = parent.document.forms[0].TableBorderProperty.value;
	if(trim(dBorderColor, " ") == "" ) {
		dvBorderColor = "class=tdtable_none";
	}else {
		var bl = document.forms[0].BLeft.value;
		var br = document.forms[0].BRight.value;
		var bt = document.forms[0].BTop.value;
		var bb = document.forms[0].BBottom.value;
		
		var hl = document.forms[0].HLeft.value;
		var hr = document.forms[0].HRight.value;
		var ht = document.forms[0].HTop.value;
		var hb = document.forms[0].HBottom.value;
		
		flag = false;
		if(hl == "yes"){
			dvHeaderColor = dvHeaderColor + "border-left: 1px solid " + dBorderColor + "; ";
			flag = true;			
		}
		
		if(hr == "yes"){
			dvHeaderColor = dvHeaderColor + "border-right: 1px solid " + dBorderColor + "; ";
			flag = true;
		}

		if(ht == "yes"){
			dvHeaderColor = dvHeaderColor + "border-top: 1px solid " + dBorderColor + "; ";
			flag = true;
		}

		if(hb == "yes"){
			dvHeaderColor = dvHeaderColor + "border-bottom: 1px solid " + dBorderColor + "; ";
			flag = true;
		}
		
		if(flag){
			dvHeaderColor = 'style="' + dvHeaderColor + '"';
		}

		flag = false;
		if(bl == "yes"){
			dvBorderColor = dvBorderColor + "border-left: 1px solid " + dBorderColor + "; ";
			flag = true;
		}
		
		if(br == "yes"){
			dvBorderColor = dvBorderColor + "border-right: 1px solid " + dBorderColor + "; ";
			flag = true;
		}

		if(bt == "yes"){
			dvBorderColor = dvBorderColor + "border-top: 1px solid " + dBorderColor + "; ";
			flag = true;
		}

		if(bb == "yes"){
			dvBorderColor = dvBorderColor + "border-bottom: 1px solid " + dBorderColor + "; ";
			flag = true;
		}
		
		if(flag){
			dvBorderColor = 'style="' + dvBorderColor + '"';			
		}
	}
	
	var dBGColor = parent.document.forms[0].TableBGProperty.value;
	if(	trim(dBGColor, " ") == "" ) {
		dBGColor = '';
	}else {
		dBGColor = 'style=" background-color:' + dBGColor  + '"';
	}
	var dSeparatorColor = parent.document.forms[0].TableSeparatorProperty.value;
	if(	trim(dSeparatorColor, " ") == "" ) {
		dSepColor = '';
	}else {
		dSepColor = '<table class=dtable_none style="background-color:' + dSeparatorColor + '" width="1" height="100%" cellpadding="0" border="0" cellspacing="0"><tr><td width=1><img src="/icons/ecblank.gif" border="0" width="1"></td></tr></table>';
    }
    			
	var dispdoc = parent.document.getElementById("edit1");
	if(dispdoc) {
		var mydoc = dispdoc.contentWindow.document.body;
	
		var tmpstring = parent.document.getElementById("tableCode").innerText;
		
		tmpstring = UtilityFormatAny(tmpstring, '~headercolor~', dHeaderColor );
		tmpstring = UtilityFormatAny(tmpstring, '~headbordercolor~', dvHeaderColor );
		tmpstring = UtilityFormatAny(tmpstring, '~bordercolor~', dvBorderColor );
		tmpstring = UtilityFormatAny(tmpstring, '~bgcolor~', dBGColor );
		tmpstring = UtilityFormatAny(tmpstring, '~separatorcolor~', dSepColor );
		tmpstring = UtilityFormatAny(tmpstring, '~padding~', dpadding );
		tmpstring = UtilityFormatAny(tmpstring, '~vtextalign~', valign );
		tmpstring = UtilityFormatAny(tmpstring, '~id~', "id=" + tableid );
						
		mydoc.innerHTML = tmpstring;
		parent.document.forms[0].TableProperty.innerText = tmpstring;	
	}	
}

function setTableItem(nID){
	parent.document.getElementById("tableCode").innerText = document.getElementById(nID).innerText;	
	
	var headerColor = document.getElementById(nID + "headercolor");
	var borderColor = document.getElementById(nID + "bordercolor");
	var bgColor = document.getElementById(nID + "bgcolor");
	var separatorColor = document.getElementById(nID + "separatorcolor");
	var addExtraPadding = document.getElementById(nID + "AddExtraPadding");
				
	var dHeaderColor = document.getElementById(nID + "header").value;
	var dBorderColor = document.getElementById(nID + "border").value;
	var dBGColor = document.getElementById(nID + "bg").value;
	var dSeparatorColor = document.getElementById(nID + "separator").value;
	var daddExtraPadding = addExtraPadding.value;	
		
	parent.document.forms[0].TableHeaderProperty.value = dHeaderColor;
	parent.document.forms[0].TableBorderProperty.value = dBorderColor;
	parent.document.forms[0].TableBGProperty.value = dBGColor;
	parent.document.forms[0].TableSeparatorProperty.value = dSeparatorColor;
	
	var t_header = parent.document.getElementById("t_header");	
	var hc = t_header.style;	
	if(headerColor.value == "yes"){																
		hc.visibility="visible";							
		setItemColorStyle(parent.document, dHeaderColor, "tableHeader");
	} else {
		hc.visibility="hidden";
		hc.display="none";
	}
	
	var t_border = parent.document.getElementById("t_border");
	var bc = t_border.style;
	if(borderColor.value == "yes"){
		bc.visibility = "visible";		
		setItemColorStyle(parent.document, dBorderColor, "tableBorder");
	} else{
		bc.visibility = "hidden";
		bc.display="none";	
	}

	var t_bg = parent.document.getElementById("t_bg");
	var bgc = t_bg.style;	
	if(bgColor.value == "yes"){		
		bgc.visibility = "visible";
		
		setItemColorStyle(parent.document, dBGColor, "tableBG");
	} else{
		bgc.visibility = "hidden";
		bc.display="none";	
	}
	
	var t_separator = parent.document.getElementById("t_separator");
	var sc = t_separator.style;
	if(separatorColor.value == "yes"){					
		sc.visibility = "visible";		
		setItemColorStyle(parent.document, dSeparatorColor, "tableSeparator");
	} else{
		sc.visibility = "hidden";
		sc.display="none";
	}

	var t_addExtraPadding = parent.document.getElementById("t_addExtraPadding");
	var ap = t_addExtraPadding.style;
	if(daddExtraPadding == "yes"){					
		ap.visibility = "visible";		
	} else{
		ap.visibility = "hidden";
		ap.display="none";
	}
	
	setTableDispProp();
}

function creatDynamicLink(linkType){
	var url = "";
	
	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener;		
		var pmydoc = parentWindow.document.getElementById('edit');
		if(pmydoc){			
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;		
			if (editdoc){																	
				var selectedLink = document.forms[0].SelectedLink.value;
				var httpProperties = document.forms[0].HttpProperties.value;				
				var sel = editdoc.selection;
				if (sel!=null) {
					var cont = sel.type;
					var rng = sel.createRange();
					var str = rng.text;								
				}
				if(linkType == "extv"){
					url = selectedLink;
				} else{	
					selectedLink = replaceSubstring(selectedLink, "'", "\\'");
					if(validateCheckBox("LinkWindowType", document.forms[0])) {
						url = "javascript:newWindowLaunchLink('" + selectedLink + "', '" + httpProperties + "')";
					} else{					
						var fn = queryString(selectedLink, "&fn=");						
						if(fn == "shopping"){
							url = "javascript:userLaunchLink('" + selectedLink + "', '" + httpProperties + "')";
						}else{
							url = "javascript:userLaunchLink('" + selectedLink + "', '" + httpProperties + "')";
						}
					}	
				}
			
				if(url != "") {	
					editdoc.execCommand("CreateLink", false, url);
				}
			}
			mydoc.focus();
			window.close();	
			return true;
		} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	} 
	window.close();	
}

function createDefaultLink(selectedLink, intLinkProperties, runjscode){
	var url = "";
	
	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener;				
		var mydoc = parentWindow.document;
			
		if(mydoc){				
			if( (runjscode) && (runjscode != "") ){
				if(runjscode == "a"){
					parentWindow.runJSCodeA(selectedLink, intLinkProperties);
				}else if(runjscode == "b"){
					parentWindow.runJSCodeB(selectedLink, intLinkProperties);
				}
			}else{
				mydoc.forms[0].DefaultWebPageDisp.value = selectedLink;		
				mydoc.forms[0].DefaultWebPage.value = selectedLink;	
				mydoc.forms[0].DefaultWebPageProp.value = intLinkProperties;
			}			
		
			mydoc.focus();
			window.close();	
			return true;
		} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}				
	} 
	window.close();	
}

function creatLink(linkType) {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	var url = "";
	var mydoc = document.getElementById('edit').contentWindow.document;
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;

	var dn = document.jsvalue.DomainNameJ.value;
	
	//get current selected range
	var sel = mydoc.selection;
	if (sel!=null) {
		var cont = sel.type;
		var rng = sel.createRange();
		var str = rng.text;								
	}
			
	if ( (sel == null) || ((cont.toLowerCase() != "control") && (rng.text == null  || rng.text == "")) )    {
		alert("Please select some text or an item first before creating or editing link.");
	}
	else{
		if(linkType == 'mailto'){	
			url = prompt('Enter An Email Address:', 'mailto:');
			if(url == null){
				return;
			}
			url = removeQueryStringItem(url, "i=");
			url = removeQueryStringItem(url, "set=");
			if(url != null){
				if ((url == "") || (url.toLowerCase() == 'mailto:')) {	
					alert('To create a link, you must enter a target url. (E.g. www.cyberinvader.com)');
				}else{					
					if(url.toLowerCase().indexOf("mailto:",0) > -1){ 					
						mydoc.execCommand("CreateLink", false, url);
					}else{
						mydoc.execCommand("CreateLink", false, 'mailto:' + url);
					}	
				}
			}
		} else if(linkType == 'unlink'){	
			mydoc.execCommand("unlink", false, "");						
		}									
	}
	return;	                                                  
}

function alignImage(alignType){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}

	var mydoc = document.getElementById('edit').contentWindow.document;
	if (mydoc.selection.type == 'Control'){
		var range = mydoc.selection.createRange();

		/* Check if one object is selected */
		if (range.length == 1 && (range(0).tagName == 'IMG' || range(0).tagName == 'img')){
			range(0).align = alignType;
			return;
		}
	}
}

function popupPhoto(imgUrl, alignment, style, border, width, height, pgSymbol, upload){
	var mydoc = null;
	var repeat = "";
	var position = "";
	var attachment = "";
	var range = null;
	var ranges = null;
	var continueFlag = false;

	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener;
		if((parentWindow.document.forms[0].NewGallery) && (pgSymbol == "photogallery" || pgSymbol == "photogallery1" || pgSymbol == "photogallery2" || pgSymbol == "photogallery3" || pgSymbol == "photogallery4" || pgSymbol == "photogallery5")){
			if(parentWindow.document.forms[0].NewGallery.value == "yes"){
				mydoc = parentWindow.parent;
			}else{
				mydoc = parentWindow;
			}
			mydoc.history.go(0);
			window.close();	
			return true;
	 	}
		
		if(pgSymbol == "aplinks"){
			mydoc = parentWindow.parent;			
			mydoc.history.go(0);
			window.close();	
			return true;
	 	}
	 	
		if(pgSymbol == "favorite"){
			mydoc = parentWindow;
			var imgdoc = parentWindow.parent.document;
			if(imgdoc.getElementById('img')){
				var myimgdoc = imgdoc.getElementById('img');
				myimgdoc.src = imgUrl;
				parentWindow.document.forms[0].ImageUrlVal.value = imgUrl; 
				//parentWindow.document.forms[0].ImgUrlVal.value = imgUrl;	
			}	
			mydoc.focus();
			window.close();	
			return true;
	 	}
	 	
	 	if(pgSymbol == "pgtheme"){
	 		var picdoc = null;
			mydoc = parentWindow;
			var imgdoc = parentWindow.parent.document;
			if(imgdoc.getElementById('themeimg')){
				var myimgdoc = imgdoc.getElementById('themeimg');
				myimgdoc.src = imgUrl;
				parentWindow.document.forms[0].PageThemeUrl.value = imgUrl; 
				
				if(imgdoc.getElementById('themepic')){
					picdoc = imgdoc.getElementById('themepic');
					picdoc.style.visibility = "visible";
					picdoc.style.display = "inline";
				}
				
				if(imgdoc.getElementById('themepicbutton')){
					picdoc = imgdoc.getElementById('themepicbutton');
					picdoc.style.visibility = "visible";
					picdoc.style.display = "inline";
				}

			}	
			mydoc.focus();
			window.close();	
			return true;
	 	}
	 			
	 	if( (pgSymbol == "shoppingitem") || (pgSymbol == "shoppingcategory") ){
			mydoc = parentWindow;
			var imgdoc = parentWindow.parent.document;
			if(imgdoc.getElementById('itemimg')){
				var myimgdoc = imgdoc.getElementById('itemimg');
				myimgdoc.src = imgUrl;							
				myimgdoc.border = "1"
				myimgdoc.style.borderWidth = "1px";
				myimgdoc.style.borderColor = "#C0C0C0";	
				myimgdoc.style.borderStyle = "solid"
				
				if(pgSymbol == "shoppingcategory"){
					myimgdoc.height = "80";
				}else{
					myimgdoc.width = "150";
				}
				
				parentWindow.document.forms[0].ShoppingItemUrl.value = imgUrl;
				parentWindow.document.forms[0].ImageKey.value = queryString(imgUrl, "ky=");
				parentWindow.document.forms[0].ImageName.value = queryString(imgUrl, "mg=");
			}	
			mydoc.focus();
			window.close();	
			return true;
	 	}
	 	
		mydoc = parentWindow.document.getElementById("edit").contentWindow;
		var editdoc = mydoc.document;
		
		//if(pgSymbol == "request"){
		//	editdoc.history.go(0);						

		//	mydoc.focus();
		//	window.close();	
		//	return true;
	 	//}

		//range = "";
		range = editdoc.selection.createRange();
		
		/* Check if one object is selected */
		if (range.length == 1 && range(0).tagName.toLowerCase() == 'table'){					
			range(0).style.backgroundImage = "url('" + imgUrl + "')";	
			
			if((document.forms[0].Width) && (document.forms[0].Height) ){
				var width = document.forms[0].Width.value;
				var height = document.forms[0].Height.value;
				
				width = trim(width, " ");
				if(width.toLowerCase() == "default"){
					width = "";
				}
				
				height = trim(height, " ");
				if(height.toLowerCase() == "default"){
					height = "";
				}

				if(trim(width, " ") != ""){
					range(0).style.width = trim(width, " ");
				} 	
				
				if(trim(height, " ")){
					range(0).style.height = trim(height, " ");
				} 			
			}
			
			if (document.forms[0].BackgroundImageRepeat){
				var docObj = document.forms[0].BackgroundImageRepeat.options;
				var pgimgrepeat = docObj[docObj.selectedIndex].value;
				repeat = pgimgrepeat;
			}
				
			if(trim(repeat, " ") == "") {			
				var agree=confirm("Click Ok to have this image repeat or Cancel to have it not repeat.");
				if (agree) {
					repeat = "repeat";
				}else{
					repeat = "no-repeat";
				}
			}
			
			range(0).style.backgroundRepeat = repeat;
							
			if(width != "" && width.toLowerCase() != 'default'){						
				range(0).style.width = trim(width, " ");
			}
								
			if(height != "" && height.toLowerCase() != 'default'){						
				range(0).style.height = trim(height, " ");				
			}
			
			mydoc.focus();
			window.close();	
			return; 	
		}
			
		if( (pgSymbol == "backgroundcolor") || (pgSymbol == "toppanel") ){
		
			if (editdoc.body){																	
				parentWindow.document.forms[0].BackgroundImage.value = imgUrl;
				
				if (document.forms[0].BackgroundImageRepeat){
					var docObj = document.forms[0].BackgroundImageRepeat.options;
					var pgimgrepeat = docObj[docObj.selectedIndex].value;					
					parentWindow.document.forms[0].BackgroundImageRepeat.value = pgimgrepeat;
				}
									
				var pgcolor = parentWindow.document.forms[0].TextBackGrourdColor.value;
				var bgcolor = parentWindow.document.forms[0].BackgroundColor.value;

				if( (trim(pgcolor, " ") != "") && (trim(bgcolor, " ") == "") ){
					parentWindow.document.forms[0].BackgroundColor.value = pgcolor;					
				}
				
				parentWindow.document.forms[0].TextBackGrourdColor.value = "";
				color = parentWindow.document.forms[0].BackgroundColor.value
				
				editdoc.body.style.backgroundImage = "url('" + imgUrl + "')";
				editdoc.body.style.backgroundColor = color;
				
				var fn = parentWindow.document.forms[0].FdName.value;				
				if(fn == "backgroundcolor"){				
					dpObj = parentWindow.document.forms[0];
					repeat = dpObj.Repeat.selectedIndex = "repeat"
					position = dpObj.Position.selectedIndex = "left top";
					attachment = dpObj.Attachment.selectedIndex = "";
								
					editdoc.body.style.backgroundRepeat = repeat;
					editdoc.body.style.backgroundPosition = position;
					editdoc.body.style.backgroundAttachment = attachment;
				} else if(fn == "toppanel"){
					dpObj = parentWindow.document.forms[0];
					repeat = dpObj.TopPanelRepeat.selectedIndex = "repeat";
					position = dpObj.TopPanelPosition.selectedIndex = "left top";
					
					parentWindow.document.forms[0].TPanelRepeat.value = repeat;
					parentWindow.document.forms[0].TPanelPosition.value = position;
					
					editdoc.body.style.backgroundRepeat = repeat;
					editdoc.body.style.backgroundPosition = position;
				}else {
					if(trim(pgimgrepeat, " ") == ""){
						pgimgrepeat = "repeat";
					}
					
					editdoc.body.style.backgroundRepeat = pgimgrepeat;
					editdoc.body.style.backgroundPosition = "";
					editdoc.body.style.backgroundAttachment = "";
				} 
			}	
			mydoc.focus();
			window.close();	
			return true;
		}
											
		width = trim(width," ");		
		height = trim(height," ");
		width = replaceSubstring(width,"%20", "");
		height = replaceSubstring(height,"%20", "");		
		
		if(pgSymbol == "teaser1" || pgSymbol == "teaser2"){			
			var imgdoc = parentWindow.parent.document;
						
			if(imgUrl == ""){
				var pth = imgdoc.jsvalue.ILibraryDBJ.value;			
				imgUrl = "/" + pth + "/" + pgSymbol + ".gif";

				if(imgdoc.getElementById('img')){
					var myimgdoc = imgdoc.getElementById('img');
					myimgdoc.src = imgUrl;
					myimgdoc.border = "0";	
					myimgdoc.width = "128";						
	
					if(imgdoc.getElementById('pic')){
						var picdoc = imgdoc.getElementById('pic');
						picdoc.style.visibility = "hidden";
					}
				}		
			}else{			
				if(imgdoc.getElementById('img')){
					var myimgdoc = imgdoc.getElementById('img');			
					myimgdoc.src = imgUrl;								
					myimgdoc.width = "70";							
					myimgdoc.border = "1";
					
					if(imgdoc.getElementById('pic')){
						var picdoc = imgdoc.getElementById('pic');
						picdoc.style.visibility = "visible";
					}										
				}
			}					
			mydoc.focus();
			window.close();			
			return true;									
		}		
	
		if(pgSymbol == "logo"){
			if(editdoc.getElementById(pgSymbol)){
				var imgobj = editdoc.getElementById(pgSymbol);
			
				mydoc.focus();					
				imgobj.src = imgUrl;		
				imgobj.align = alignment;				
				imgobj.style.borderStyle = style;
				imgobj.style.borderWidth = border;
				
				if(width != "" && width.toLowerCase() != 'default'){						
					imgobj.style.width = trim(width, " ");
				}
											
				if(height != "" && height.toLowerCase() != 'default'){						
					imgobj.style.height = trim(height, " ");
				}
	
				mydoc.focus();	
				window.close();	
				return true;
			}else{
				if(imgUrl == ""){
					mydoc.focus();	
					window.close();	
					return true;
				}	
			}										
		}
	
		mydoc.focus();						
		editdoc.execCommand('InsertImage', false, imgUrl);			
		range = editdoc.selection.createRange();
		
		/* Check if one object is selected */
		if (range.length == 1 && range(0).tagName.toLowerCase() == 'img'){

			if(pgSymbol != "logo"){			
				
				range(0).align = alignment;
								
				if(pgSymbol != "toppanel"){
					range(0).style.margin = '0.3em';
				}
			}	
				
			range(0).style.borderStyle = style;
			range(0).style.borderWidth = border;

			if(width != "" && width.toLowerCase() != 'default'){
		 	
				range(0).style.width = width;				
			}
						
			if(height != "" && height.toLowerCase() != 'default'){		
				range(0).style.height = height;
			}
		
			if(pgSymbol == "logo"){					
				range(0).id = pgSymbol;
			}
				
		} 
		mydoc.focus();
	}
	window.close();	
}

function setPhotoProperty(style, border, width, height, pgSymbol){
				
	var mydoc = document.getElementById('edit').contentWindow;	
	var editdoc = mydoc.document;
	width = trim(width," ");
	height = trim(height," ");
		
	if(editdoc.getElementById(pgSymbol)){
		var imgobj = editdoc.getElementById(pgSymbol);
		
		mydoc.focus();													
		imgobj.style.borderStyle = style;
		imgobj.style.borderWidth = border;
						
		if(width != "" && width.toLowerCase() != 'default'){					
			imgobj.style.width = width;			
		}
							
		if(height != "" && height.toLowerCase() != 'default'){			
			imgobj.style.height = height;
		}

		mydoc.focus();	
	}											
}

function selectImage(imgUrl, id) {
	var picdoc
	
	if(document.getElementById('picimg1')){
		picdoc = document.getElementById('picimg1');
		
		if(picdoc.style.visibility == "visible"){
			picdoc.style.visibility = "hidden";
		}
	}

	if(document.getElementById('picimg2')){
		picdoc = document.getElementById('picimg2');
		
		if(picdoc.style.visibility == "hidden"){
			picdoc.style.visibility = "visible";
		}
	}

	if(document.getElementById('loadimg')){
		var imgobj = document.getElementById('loadimg');							
		imgobj.src = imgUrl;
		document.forms[0].ImageUrl.value = imgUrl
	}						
}

function setObjDefaultProperties(){
	var mydoc = document.getElementById('edit').contentWindow.document;	
		
	if(mydoc){
		var range = mydoc.selection.createRange();			
		if ( (range.length == 1) && ( ( range(0).tagName.toLowerCase() == 'img' ) || ( range(0).tagName.toLowerCase() == 'table' ) || ( range(0).tagName.toLowerCase() == 'object' ))) {						
			if( range(0).tagName.toLowerCase() == 'img' ){
				var agree=confirm("This action will set the selected picture to it's default properties. Click OK to continue and Cancel to stop this action.");
				if (agree) {
					range(0).style.width = "";
					range(0).style.height = "";
				}							
			}else if( range(0).tagName.toLowerCase() == 'table' ){
				var agree=confirm("This action will set the selected Designer Table to it's default properties. Click OK to continue and Cancel to stop this action.");
				if (agree) {
					range(0).style.width = "";
					range(0).style.height = "";
				}					
			}else if( range(0).tagName.toLowerCase() == 'object' ){
				var agree=confirm("This action will set the selected video to it's default properties. Click OK to continue and Cancel to stop this action.");
				if (agree) {					
					range(0).style.width = "";
					range(0).style.height = "";
					range(0).width = "200";
					range(0).height = "186";
				}					
			}
		} else {
			alert('You must first select a "Picture", a "Designer Table" or a "video" icon to reset before clicking this button ');
			return;
		}
	}	
}

function setIcon( prop ) {
	var dbpath = parent.document.jsvalue.ILibraryDBJ.value;

	var iconKey = queryString(prop, "&iconkey=");
	var iconName = queryString(prop, "&iconname=");
	var imgUrl = "/" + dbpath + "/menuiconview/" + iconKey + "/$File/" + iconName;
	
	var mydoc = parent.document.getElementById("loadimg");		
	if(mydoc){
		mydoc.src = imgUrl;
	}	

	parent.document.forms[0].ImgUrl.value = imgUrl;
	parent.document.forms[0].ImgProp.value = prop;
} 		

function insertIcon(fieldName, imgUrl, imgProp){
	if (window.opener && !window.opener.closed){
		var parentWindow = window.opener;				
		var mydoc = parentWindow.document;		
		if(mydoc){	
			var myimgdoc = mydoc.getElementById(fieldName);			
			if(myimgdoc){
				myimgdoc.src = imgUrl;
			}			
			eval("mydoc.forms[0].D" + fieldName).value = imgProp;
			mydoc.focus();
			window.close();	
			//return true;
		} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	} 
	window.close();	
}

function setUserNav( id ){
	var mydoc = document.getElementById(id);
	if(mydoc){
		mydoc.innerHTML = document.forms[0].SMMenu.innerText;
	}
}

function getRowHeight( id ){
	var heightVal = "";
	var fieldHeight = document.forms[0].TableHeight.options[document.forms[0].TableHeight.options.selectedIndex].value;

	var mydoc = document.getElementById(id);
	var editdoc = mydoc.contentWindow;
	//var dh = editdoc.document.body.scrollHeight;
	var dh = editdoc.document.body.clientHeight + 2;
		
	if(trim(fieldHeight, " ") == ""){
		document.forms[0].TableHeight.options[document.forms[0].TableHeight.options.selectedIndex].text = dh + " pixel";	
		document.forms[0].TableHeight.options[document.forms[0].TableHeight.options.selectedIndex].value = dh + "px";	
		setTableHeight(id, dh);	
	}	
}

function setTableHeight(id, ht){
	var mydoc = document.getElementById(id);	
	if (mydoc){	
		mydoc.style.height = ht;
	}
}

function resetAllObjects() {
	var mywindow = document.getElementById('edit').contentWindow;
	var mydoc = mywindow.document;

	var theObjects = mydoc.getElementsByTagName("object");
	if(theObjects){
		for (var i = 0; i < theObjects.length; i++) {
			var fobj = theObjects[i];	
			if( (fobj.name == 'embflash') || (fobj.name == 'msplayer') ){						
				tmpstring = UtilityFormatAny(fobj.outerHTML, '"play" VALUE="0"', '"play" VALUE="-1"');				
				fobj.outerHTML = tmpstring;
			}	
		}
	}
}

function viewFlash(url){
	url = replaceSubstring( url, "<~>", "&" );
	url = replaceSubstring( url, "~ap~", "'" );
	url = replaceSubstring( url, "+", " " );

	document.mplayer.FileName = url;
	document.mplayer.scr = url;
	document.mplayer.Play();
}

function setDefaultItem() {
	var id = document.forms[0].DefaultItemValue.value;
	if(trim(id, " ") != ""){
		var idoc = document.getElementById("d" + id);
		if(idoc) {
			idoc.focus();
		}
	}	
	
}

function loadPage(pgSymbol) {
	var mydoc = null;
	
	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener.parent;
		
		var editwin = parentWindow.document.getElementById("edit");
		if(editwin && editwin.contentWindow){					
			mydoc = editwin.contentWindow;
		} else {
			mydoc = parentWindow;	
		}
		
		if(editwin && pgSymbol == "payment"){
			editwin.style.visibility = "visible";
			editwin.style.display = "";
			mydoc.history.go(0);	
			return;
	 	}

		if(pgSymbol == "request"){
			mydoc.history.go(0);						
	
			mydoc.focus();
			window.close();	
			return;
	 	}
	}			
}

function openPaymentform(unid, sp) {
	var pth = document.jsvalue.RequestsDBJ.value;
	
	if(sp == "new"){
			var url = "/" + pth + "/paymentdocument?OpenForm&ParentUNID=" + unid;		
	} else{
		var url = "/" + pth + "/0/" + unid + "?opendocument";	
	}
	var w = window.open (url, 'pa', 'resizable=no, scrollbars=yes, toolbar=no, location=no, status=yes, top=50, left=50, width=550, height=660');
	w.focus();
}

function historyUpdater(msg){
	if (window.opener && !window.opener.closed){		
		var parentWindow = window.opener.parent;		
		var mydoc = parentWindow.document;
		var mydocs = mydoc;	
			
		if(mydoc){	
			if((mydoc.forms[0].PaymentDoc) && (mydoc.forms[0].PaymentDoc.value == "paymentdoc")){
				var v_parentWindow = parentWindow.window.opener.parent;
				mydoc = v_parentWindow.document;
				mydocs.forms[0].EmailSentFlag.value = "yes"
			}
			
			var myimgdoc = mydoc.getElementById("history");			
			if(myimgdoc){
				var currentTime = new Date();
				var month = currentTime.getMonth() + 1;
				var day = currentTime.getDate();
				var year = currentTime.getFullYear();
				var tdate = month + "/" + day + "/" + year;
			
				var currUserName = mydoc.getElementById("cuname").value;	
				var tmpstring = myimgdoc.innerText;
				
				var strMsg = tdate + ' - (' + currUserName + ') ' + msg;
				if(trim(tmpstring, " ") == "") {
					newstr = strMsg;
				} else{
					newstr = tmpstring + "\r\n\r\n" + strMsg;
				}
				myimgdoc.value = newstr;
			}
			
			var itemObj = mydoc.getElementById("msgitem");
			if( (itemObj)&&(itemObj.style.visibility == "visible") ){
				itemObj.style.visibility = "hidden"
				itemObj.style.display = "none"
			}
							
			mydocs.focus();
			window.close();					
		} 
	window.close();	
	}
}

function addUserIDInfo(){
	
	var myimgdoc = document.getElementById("history");			
	if(myimgdoc){
		var currentTime = new Date();
		var month = currentTime.getMonth() + 1;
		var day = currentTime.getDate();
		var year = currentTime.getFullYear();
		var tdate = month + "/" + day + "/" + year;
		
		var currUserName = document.getElementById("cuname").value;	
		var tmpstring = myimgdoc.innerText;
		
		var strMsg = tdate + ' - (' + currUserName + ') ';
		if(trim(tmpstring, " ") == "") {
			newstr = strMsg;
		} else{
			newstr = tmpstring + "\r\n\r\n" + strMsg;
		}
		myimgdoc.value = newstr;
	}
}

function processUtil( ) {

	if (window.opener && !window.opener.closed){	
		var parentWindow = window.opener;		
		parentWindow.history.go(0);
		window.close();	
		return;
	 }
}	

function setEditor() { 
	myframe = window.frames['editArea'];
			
  	if (myframe && myframe.document && myframe.document.body)      { 
    		myedit = myframe.document.body;    
    		
    		tmpstring = parent.document.forms[0].PageContent.innerText; 
    		var HTMLstring = parent.document.forms[0].PageContent.innerHTML;
        	
    	   	myedit.innerHTML = tmpstring;
	}    
}


function setPageContent(){
    myframe = window.frames['editArea'];
  if (myframe && myframe.document && myframe.document.body && parent.document.forms[0].PageContent){
    myedit = myframe.document.body;
    
	 resetAllObjects();               
      var tmpstring = myedit.innerHTML;  
      var strVal = myedit.innerText;         
      tmpstring = UtilityFormatAny(tmpstring, '&nbsp;&nbsp;', ' &nbsp; ' );      
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/dell', '' );
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www1.cyberinvader.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/dell', '' );     
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvader.com', '' );   
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvader.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/www.cyberinvaders.net', '' );      
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvader.com', '' );   
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvader.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/cyberinvaders.net', '' );   
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvaders.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvaders.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvader.net', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'https:\\/\\/process.cyberinvader.com', '' ); 
      tmpstring = UtilityFormatAny(tmpstring, 'http:\\/\\/webdev.cyberinvader.com', '' );                            
      tmpstring = tmpstring.replace(/<a href=\"http:/ig, '<a target="_blank" href="http:');
     
      var dName = document.jsvalue.DefWWWJ.value;
      w = UtilityFormatAny(dName, '\\/', '\\/' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
      w = UtilityFormatAny(w, 'http', 'https' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
	 
	  var dName = document.jsvalue.WWWJ.value;
      w = UtilityFormatAny(dName, '\\/', '\\/' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
      w = UtilityFormatAny(w, 'http', 'https' ); 
	  tmpstring = UtilityFormatAny(tmpstring, w, '' );
	    	       
	  parent.document.forms[0].PageContent.innerText = tmpstring;
	  	  	                    
  }
}

function switchToEditor( ) {
	setEditor();

	document.forms[0].EditorFlag.value = "";
	var myframe = document.getElementById("edit");
	if (myframe){
		myframe.style.width = document.forms[0].EditorWidth.value;
		myframe.style.height = document.forms[0].EditorHeight.value;
	}
	
	var mycontent = document.getElementById("content");
	if(mycontent){
		mycontent.style.visibility = "hidden";
		mycontent.style.display = "none";
	}
}	

function switchToHTML( ) {
	setPageContent();
	document.forms[0].EditorFlag.value = "1";

	var myframe = document.getElementById("edit");
	if (myframe){
		myframe.style.width = "0";
		myframe.style.height = "0";
	}
	
	var mycontent = document.getElementById("content");
	if(mycontent){
		mycontent.style.visibility = "visible";
		mycontent.style.display = "";
	}
}

function inserPDFLink(){
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	var pl = "";
	var h = ""
	var w = "";
	
	var dbpath = document.jsvalue.ILibraryDBJ.value;
	var gstring = document.jsvalue.GeneralStringViewSiteJ.value;
	var dn = document.jsvalue.DomainNameJ.value;
	
	var mydoc = document.getElementById('edit').contentWindow.document;
	var mydoc = document.getElementById('edit').contentWindow.document;
	
	//get current selected range
	var sel = mydoc.selection;
	if (sel!=null) {
		var cont = sel.type
		var rng = sel.createRange();
		var str = rng.text;
	}
			
	if ( (sel == null) || ((cont.toLowerCase() != "control") && (rng.text == null  || rng.text == "")) )    {
		alert("Please select some text or an item first before creating a video link.");
		return;
	}

	x = screen.availWidth * 0.60;
	y = screen.availHeight * 0.02;
	
	h = "480";
	w = "400";
		
	var mediabuilder = "/" + dbpath + "/pdfbuilder?open&dn=" + dn + gstring  + getSeq();				
	var w = window.open (mediabuilder, 'windowmlink', 'toolbar=0, location=0,status=0,menubar=0,scrollbars=0,top=' + y + ',left=' + x + ',resizable=0,width=' + w + ',height=' + h );
	w.opener = self;
	w.focus();
}

function clearContent() {
	if(parent.document.forms[0].EditorFlag.value == "1"){
		alert(functionalityMsg);
		return;
	}
	
	var agree=confirm("Are you sure you wish to clear all the content? To continue press OK otherwise press Cancel");
	if (agree) {
		clearFieldContent();
	}
}

function IsEditorOrHTML(docObj) {
	if(docObj.EditorFlag.value == "1"){
		alert(functionalityMsg);
		return false;
	}
	return true;
}

function insertShoppingItem(itemListing){		
	if (window.opener && !window.opener.closed){
		var parentWindow = window.opener;
		var pmydoc = parentWindow.document.getElementById('edit');
		if(pmydoc){	
			var mydoc = pmydoc.contentWindow;		
			var editdoc = mydoc.document;
			if (editdoc){				
				var sel = editdoc.selection.createRange();
				editdoc.focus(); 							
				sel.pasteHTML(itemListing);
			}	
		} else{
			alert("The window you were editing is no longer available. Click OK to continue.");
		}							
	}else{
		alert("The window you were editing is no longer available. Click OK to continue.");
	} 
	window.close();	    
}

function launchShoppingItemBuilder( ){
	var dbpath = document.jsvalue.ContentDBJ.value;	
	var gString = document.jsvalue.StringBuilderSiteJ.value;

	var url = "/" + dbpath + "/itembuilder?open" + gString;
	var win = window.open (url, 'windowmedia', 'toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=0,top=200,left=200,width=655, height=470');
	win.focus();
}

function isCursorAvailable(editorID){
	var mydoc = parent.document.getElementById(editorID).contentWindow.document;
	var sel = mydoc.selection.createRange();
	parent.bmark = sel;
	var x = sel.boundingHeight;	
	
	if( (x == null) || (x == 0) ){
		alert("Place the cursor where you would like to insert the designer table.");
		return false;	
	}
	return true;
}

function isCursorObjectAvailable(editorID){
	var mydoc = parent.document.getElementById(editorID).contentWindow.document;
	var range = mydoc.selection.createRange();
	
	var x = range.boundingHeight;
	var flag1 = false;	
	var flag2 = false;
	
	if( (x == null) || (x == 0) ){
		flag1 = true;	
	}

	/* Check if one object is selected */
	if( !(range.length == 1 && range(0).tagName.toLowerCase() == "img") ){
		flag2 = true;	
	}
	
	if(flag1 && flag2){
		alert("Place the cursor or select an object where you would like to insert the designer table.");
		return false;
	}else{
		return true;
	}
}


function addShoppingItem(editorID){
	var docObj = document.forms[0];
	if( (IsEditorOrHTML(docObj)) && (isCursorAvailable(editorID))){
		launchShoppingItemBuilder( );
	}
}


