var _module;
var _contentId;
var _templateModuleId;
var _accessKey;
var _serverGateway;

function uxcm_outline(module) {
    
    module.style.borderStyle = 'solid dashed dashed dashed';
    module.style.borderWidth = '15px 1px 2px 1px';
    module.style.borderColor = '#F00';
}

function uxcm_removeoutline(module) {
    module.style.borderStyle = 'none';
    module.style.borderWidth = '0px 0px 0px 0px';
    module.style.borderColor = '#FFF';
}

function uxcm_edit(module){
  
   //this will take parameters this,contentId,templateModuleId,moduleLabel,editorType	
   // $("#cmx_edit_window").css({ width: '750px', height : '1000px' });
   $("#cmx_edit_window").css("display","block");
   
   //$("#close").css("display","block");
    setConfigSettings(module.getAttribute('tmid'),module.getAttribute('label'),module.getAttribute('editor'));
     $("#form1").hide();
      $("#form1").css("display","none");
    // alert("working");
}

function setConfigSettings(tmid,label,editor){
   try{
         _accessKey= accessKey;
	 _module=label;
	_contentId=contentId;
	_templateModuleId=tmid;
	_serverGateway="/UXCM.cfm"
	//alert("setconfigsettings");
	getFlexApp("CMXModuleEditor").configSettingsChanged();
   }catch(E){
 	//alert("Error in setConfigSettings :"+E);
   }
}

function getFlexApp(appName)
{
	
  if (navigator.appName.indexOf ("Microsoft") !=-1)
  {
    
    return window[appName];
  }
  else
  {
    return document[appName];
  }
}

function getConfigSettings(){
	//alert("getConfigSettings==1");	
	if (_serverGateway!=undefined && _accessKey!=undefined && _contentId!=undefined && _templateModuleId!=undefined && _module!=undefined){
		//alert("getConfigSettings==2");	
		getFlexApp('CMXModuleEditor').saveNewConfigSettings(_serverGateway,_accessKey,_contentId,_module,_templateModuleId);
	}else{
	}
}

function showWYSIWYGEditor(value){
	
	var container = document.getElementById('form1');
      if(container == null || container == undefined){
	    var text = value;
	    //var layer ='z-index';
	    var container = document.createElement('div');
	   	
	    container.id = 'form1';
	    //container.style.width = '687px';
	    container.style.position = 'absolute';//'absolute';//'absolute' ;
	    container.style.top = '60px' ;
	    container.style.right = '40px' ;
	    container.style.display = 'none';
	    container.style.zIndex = '999';
	    document.body.appendChild(container);
	    container.innerHTML = '<div id = "divform1" style =\'width:687px;background-color:#666666;\'>'+
	    '<input type="button" id ="done" value="Done" onClick="setText()" style =\'background-color:#00ca00;\'/>'+
	    '<input type="button" id ="HTML" value="View Code" onClick="setHTMLText()" />'+
	    '<input type="button" id ="Cancel" value="Cancel" onClick="dismiss()" style =\'\'/></div>'+
	    '<textarea name="text1" cols="82" rows="30" id="text1"></textarea>';
	    document.getElementById('text1').value = text;
	    /* $(function()
	    { */
	    $('#text1').wysiwyg();
	    container.style.display = 'block';
	    //});
	    //alert("Completed");
    }else{
	  $('#text1').wysiwyg('setContent',value);
	  $("#form1").show();  
    }
}
function dismiss(){
	  var container = document.getElementById('form1');
	  //container.parentNode.removeChild(container);
	  $("#form1").hide();
	  getFlexApp('CMXModuleEditor').focusOut();
}

function setText(){
	try{
		 var container = document.getElementById('form1');
		 var x = document.getElementById('text1').value;
		// container.parentNode.removeChild(container
		$("#form1").hide();
		 getFlexApp('CMXModuleEditor').setRTEText(x);
	}catch(E){
		//alert("error in setText()Done : "+E);
	}
}

function setHTMLText(){
	 var container = document.getElementById('form1');
	 var x = document.getElementById('text1').value;
	// container.parentNode.removeChild(container);
	$("#form1").hide();
	 getFlexApp('CMXModuleEditor').openRegularEditor(x);
}

function close_editor() {
	 /*var container = document.getElementById('form1');
	  //container.parentNode.removeChild(container);
	  $("#form1").hide();
	   $("#form1").css("display","none");*/
	 dismiss();
	$("#cmx_edit_window").css("display","none");
    
   // $("#close").css("display","none");
}

