

function WYSIWYG_Editor(instance_name, content, path, fwidth, fheight, styleHref){
    // for each of the passed parameters, we need to be sure they are defined, or we will use a default value

    // the name used to create the object - used to define the name of the field that contains the HTML on submission
    if(typeof(instance_name)=='undefined'){
        alert("ERROR: No instance name was passed for the editor.");
        return false;
    }else{
        this.instance_name=instance_name;
    }

    // the initial HTML source content for the editor
    if(typeof(content)=='undefined'){
        this.content='';
    }else{
        this.content=content;
    }

    // define the path to use for the editor components like images
    if(typeof(path)=='undefined'){
        this.wysiwyg_path='.'; // default value
    }else{
        path.replace(/[\/\\]$/,''); // remove trailing slashes
        this.wysiwyg_path=path;
    }

    // define the pixel dimensions of the editor
    if(typeof(fwidth)=='number' && Math.round(fwidth) > 50){
        this.frame_width=Math.round(fwidth); // default value
    }else{
        this.frame_width=548; // default width
    }
    if(typeof(fheight)=='number' && Math.round(fheight) > 50){
        this.frame_height=Math.round(fheight);
    }else{
        this.frame_height=250; // default height
    }

    // define the stylesheet to use for the editor components like images
    if(typeof(styleHref)=='undefined'){        
		this.stylesheet='';
    }else{
        this.stylesheet=styleHref;
    }

    
    // properties that depended on the validated values above
	this.wysiwyg_div=this.instance_name+'_div';   
    this.wysiwyg_content=this.instance_name+'_WYSIWYG_Editor';  // the editor IFRMAE element id
    this.wysiwyg_hidden=this.instance_name+'_content';          // the editor's hidden field to store the HTML in for the post    
    this.ta_rows=Math.round(this.frame_height/15);              // number of rows for textarea for unsupported browsers
    this.ta_cols=Math.round(this.frame_width/8);                // number of cols for textarea for unsupported browsers

    // other property defaults
    this.viewMode=1;                                        // by default, set to design view
    this._X = this._Y = 0;                                  // these are used to determine mouse position when clicked
    
}

/**
*   WYSIWYG_Editor::prepareSubmit
*
*   Use this in the onSubmit event for the form that the editor is displayed inside.
*   Puts the HTML content into a hidden form field for the submission
**/
WYSIWYG_Editor.prototype.prepareSubmit = function (){
    if(this.viewMode == 2){
        // be sure this is in design view before submission
        this.toggleMode();
    }
    var htmlCode=document.getElementById(this.wysiwyg_content).contentWindow.document.body.innerHTML;
    document.getElementById(this.wysiwyg_hidden).value=htmlCode;		
	return true;
}

/**
*   WYSIWYG_Editor::display
*
*   Display the editor interface for the user
**/
WYSIWYG_Editor.prototype.display = function (){   
	if(this.isSupported()){
        this._display_editor();
        this._load_content();
		
		var thedoc = document.getElementById(this.wysiwyg_content).contentWindow.document;
        thedoc.designMode='On';
        // MSIE has caching problems...
        // http://technet2.microsoft.com/WindowsServer/en/Library/8e06b837-0027-4f47-95d6-0a60579904bc1033.mspx
        thedoc = document.getElementById(this.wysiwyg_content).contentWindow.document;
        thedoc.open();
        thedoc.write('<html><head>');
        if(this.stylesheet){
            // must be done after the document has been opened
            thedoc.write('<style type="text/css">@import url('+this.stylesheet+');</style>');
        }
		thedoc.write('<style>p { text-align:left; margin: 0px;} IMG {-moz-user-select:none;} </style>')
        if (sEnvironment=='xxx'){
			thedoc.write('</head><body style="line-height: 14px; margin-top:2px; margin-left:2px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color:#353535;	color: #cacaca; ">');
		}
		else {
			thedoc.write('</head><body style="line-height: 14px; margin-top:2px; margin-left:2px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; ">');
		}
        thedoc.write(this.content);				
        thedoc.write('</body></html>');
        thedoc.close();		
		
		//editor is my iFrame, and objectID is a the id of a span i have inside the iFrame. Again, I know there has to be a better way becuase I’ve seen it, just can’t reproduce it.
		try {
		  document.getElementById(this.wysiwyg_content).contentDocument.execCommand("undo", false, null);
		}  catch (e) {
		  //empty
		}		    	
			
    }else{
        this._display_textarea();
        this._load_content();
    }
}
WYSIWYG_Editor.prototype.display_reply = function (){
    if(this.isSupported()){
        this._display_reply_editor();
        this._load_content();				
    }else{
        this._display_textarea();
        this._load_content();
    }
	
}
WYSIWYG_Editor.prototype.load_reply = function (){
		var thedoc = document.getElementById(this.wysiwyg_content).contentWindow.document;
        thedoc.designMode='On';
        // MSIE has caching problems...
        // http://technet2.microsoft.com/WindowsServer/en/Library/8e06b837-0027-4f47-95d6-0a60579904bc1033.mspx
        thedoc = document.getElementById(this.wysiwyg_content).contentWindow.document;
        thedoc.open();
        thedoc.write('<html><head>');
        if(this.stylesheet){
            // must be done after the document has been opened
            thedoc.write('<style type="text/css">@import url('+this.stylesheet+');</style>');
        }
		thedoc.write('<style>p { text-align:left; margin: 0px;} IMG {-moz-user-select:none;} </style>')
        if (sEnvironment=='xxx'){
			thedoc.write('</head><body style="line-height: 14px; margin-top:2px; margin-left:2px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color:#353535;	color: #cacaca; ">');
		}
		else {
			thedoc.write('</head><body style="line-height: 14px; margin-top:2px; margin-left:2px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; ">');
		}		
        thedoc.write(this.content);				
        thedoc.write('</body></html>');        
		thedoc.close();	
				
		try {
		  document.getElementById(this.wysiwyg_content).contentDocument.execCommand("undo", false, null);
		}  catch (e) {
		  //empty
		}		    	
		document.getElementById(this.wysiwyg_content).contentWindow.focus() ;  				
}

/**
*   WYSIWYG_Editor::_display_textarea
*
*   Used to display a substitute for the wysiwyg editor HTML interface to non-supported browsers
**/
WYSIWYG_Editor.prototype._display_textarea = function (){
    document.write('<p style="background-color: yellow; color: red; padding: 3px;"><b>WARNING:</b> Your browser does not support the WYSIWYG_Editor class. The script you are posting to may expect HTML code.</p>');
    document.write('<textarea name="'+this.wysiwyg_hidden+'" id="'+this.wysiwyg_hidden+'" rows="'+this.ta_rows+'" cols="'+this.ta_cols+'"></textarea><br>');
}

/**
*   WYSIWYG_Editor::_display_editor
*
*   Used to display the actual wysiwyg editor HTML interface to supported browsers
**/
WYSIWYG_Editor.prototype._display_editor = function (){
    if(bBlocked==1 && !bAlerted) {
		strBlocked = "Deze persoon heeft jou geblokkeerd,\nhierdoor is het helaas niet mogelijk om te reageren!";		
		document.write('<textarea name="'+this.wysiwyg_hidden+'" id="'+this.wysiwyg_hidden+'" cols="50" rows="4" style="width:414px;" onfocus="alert(strBlocked);this.blur();"></textarea><br />')
		if (sEnvironment=='xxx'){ 
			document.write('<div style="border:solid #cacaca 1px; width:'+this.frame_width+'px; height:'+this.frame_height+'px; visibility:hidden;display:none;">');
		}else {
			document.write('<div style="border:solid #7F9DB9 1px; width:'+this.frame_width+'px; height:'+this.frame_height+'px; visibility:hidden;display:none;">');
		}
		document.write('      <iframe frameborder="0" name="'+this.wysiwyg_content+'" id="'+this.wysiwyg_content+'" style="margin-left: 0px; margin-top: 0px; background-color: white; color: black; width:'+this.frame_width+'px; height:'+this.frame_height+'px;" onfocus="if(bBlocked==1 && !bAlerted){bAlerted=true;alert(\'Deze persoon heeft jou geblokkeerd, hierdoor is het helaas niet mogelijk om te reageren!\'); this.blur();}"></iframe>');	
		document.write('</div>');	
	}
	else {
		document.write('<textarea name="'+this.wysiwyg_hidden+'" id="'+this.wysiwyg_hidden+'" style="visibility:hidden;display:none;"></textarea>');   
    	if (sEnvironment=='xxx'){ 
			document.write('<div style="border:solid #cacaca 1px; width:'+this.frame_width+'px; height:'+this.frame_height+'px;">');
		}else {
			document.write('<div style="border:solid #7F9DB9 1px; width:'+this.frame_width+'px; height:'+this.frame_height+'px;">');
		}
		
		document.write('      <iframe frameborder="0" name="'+this.wysiwyg_content+'" id="'+this.wysiwyg_content+'" style="margin-left: 0px; margin-top: 0px; background-color: white; color: black; width:'+this.frame_width+'px; height:'+this.frame_height+'px;" onfocus="if(bBlocked==1 && !bAlerted){bAlerted=true;alert(\'Deze persoon heeft jou geblokkeerd, hierdoor is het helaas niet mogelijk om te reageren!\'); this.blur();}"></iframe>');	
		document.write('</div>');		
	}
}

WYSIWYG_Editor.prototype._display_reply_editor = function (){
    document.write('<textarea name="'+this.wysiwyg_hidden+'" id="'+this.wysiwyg_hidden+'" style="visibility:hidden;display:none;"></textarea>');   
    if (sEnvironment=='xxx'){ 
		document.write('<div id="'+this.wysiwyg_div+'" style="border:solid #cacaca 1px; width:'+this.frame_width+'px; height:'+this.frame_height+'px; ">');
	}else {
		document.write('<div id="'+this.wysiwyg_div+'" style="border:solid #7F9DB9 1px; width:'+this.frame_width+'px; height:'+this.frame_height+'px; ">');
	}	
	document.write('      <iframe frameborder="0" id="'+this.wysiwyg_content+'" style="margin-left: 0px; margin-top: 0px; background-color: white; color: black; width:'+this.frame_width+'px; height:'+this.frame_height+'px;" onfocus="if(bBlocked==1 && !bAlerted){bAlerted=true;alert(\'Deze persoon heeft jou geblokkeerd, hierdoor is het helaas niet mogelijk om te reageren!\'); this.blur();}"></iframe>');	
	document.write('</div>');		
}

/**
*   WYSIWYG_Editor::_load_content
*
*   Puts the passed content into the editor or textarea (Use this one *after* displaying the editor.)
*
*   @param  content string  The string containing the properly-formatted HTML source to use
*/
WYSIWYG_Editor.prototype._load_content = function (){
    document.getElementById(this.wysiwyg_hidden).value=this.content;
}


/**
*   WYSIWYG_Editor::isSupported
*
*   Checks that the browser supports this programming by writing an invisible IFRAME and testing its properties
*/
WYSIWYG_Editor.prototype.isSupported = function () {
    // This is to get rid of the browser UA check that was previously implemented for this class.
    // should be called from somewhere in the body of the document for best results
    document.write('<iframe id="WYSIWYG_Editor_Testing_Browser_Features" style="display: none; visibility: hidden;"></iframe>');
    test = typeof(document.getElementById('WYSIWYG_Editor_Testing_Browser_Features').contentWindow);
    if(test == 'object'){
        return true;
    }else{
        return false;
    }
    return this.supported;
}

/**
*   WYSIWYG_Editor::isMSIE
*
*   Checks if browser is MSIE by testing the document.all property that is only supported by MSIE and AOL
*/
WYSIWYG_Editor.prototype.isMSIE = function (){
    if(typeof(document.all)=='object'){
        return true;
    }else{
        return false;
    }
}


WYSIWYG_Editor.prototype.addImage2 = function (thisimage){    
    if(bBlocked==1 && !bAlerted ) {
		strBlocked = "De eigenaar van deze video heeft jou geblokkeerd,\nhierdoor is het helaas niet mogelijk op deze video te reageren!";		
		alert(strBlocked);
		return false;
	}
	
	document.getElementById(this.wysiwyg_content).contentWindow.focus()    
	if(this.isMSIE()) {	
		var cursor=document.getElementById(this.wysiwyg_content).contentWindow.document.selection.createRange();
		
		if(this.viewMode==1){		
			cursor.pasteHTML('<IMG unselectable="on" align="absbottom" src="' + thisimage + '"> ');
    	}
	}
	else {
		var x=document.getElementById(this.wysiwyg_content).contentWindow.document;
    	x.execCommand('insertimage', false, thisimage);			
	}	
}

