

var old = '';

function update()
{
  	
  var textarea = document.f2.oob_template;
  
  if (textarea.value == ''){
     var temp_main = document.f2.oob_template_main.value;
    
     var temp_main2 = replace(temp_main,"SAMPLE_PROFILE","");
    
     textarea.value = temp_main2;
     
     //load();
  }
  	  
  var d = parent.oob_display.document; 

  if (old != textarea.value)
  {
    old = textarea.value;

    d.open();
    d.write(old);
    d.close();
  }

  window.setTimeout(update, 150);
}


function load() { var t = document.getElementById("t"); if (t.addEventListener){ t.addEventListener('keyup', oc, false); t.addEventListener('click', oc, false); } else if (t.attachEvent){ t.attachEvent('onkeyup', oc); t.attachEvent('onclick', oc); } } 

//----------------------------------------

function xhp(strU, cid) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strU, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring(cid));
}

function getquerystring(cid) {
    qstr = 'id=' + escape(cid) // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    document.f1.oob_code.value = str;
    
    var temp_main = document.f2.oob_template_main.value;
    
    var temp_main2 = replace(temp_main,"SAMPLE_PROFILE",str);
    
    document.f2.oob_template.value = temp_main2;
}

//----------------------------------------


function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

//----------------------------------------