
var cp = new ColorPicker('window'); // Popup window
var cp2 = new ColorPicker(); // DIV style

//----------------------------------------

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) {
    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());
}

function getquerystring() {
    var form     = document.forms['f1'];
    var bg_color = form.bg_color.value;
    var bg_image = form.bg_image.value;
    var link_font_face = form.link_font_face.value;
    var link_underline = form.link_underline.value;
    var link_font_size = form.link_font_size.value;
    var font_face = form.font_face.value;
    var font_color = form.font_color.value;
    var font_size = form.font_size.value;
    var link_color = form.link_color.value;
    var link_hover = form.link_hover.value;
    
    qstr = 'bg_color=' + escape(bg_color) // NOTE: no '?' before querystring
    qstr = qstr + '&bg_image=' + escape(bg_image);  
    qstr = qstr + '&link_font_face=' + escape(link_font_face);  
    qstr = qstr + '&link_underline=' + escape(link_underline);      
    qstr = qstr + '&link_font_size=' + escape(link_font_size);      
    qstr = qstr + '&font_face=' + escape(font_face);      
    qstr = qstr + '&font_color=' + escape(font_color);      
    qstr = qstr + '&font_size=' + escape(font_size);  
    qstr = qstr + '&link_color=' + escape(link_color);  
    qstr = qstr + '&link_hover=' + escape(link_hover);  
    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 show_url(val1, val2) { 
  
  var opt = document.getElementById(val1).value;
  
  if(opt == 'Yes'){
	document.getElementById(val2).style.display="block";  	
	document.getElementById(val1).value = 'Cancel'; 
  }else{
	document.getElementById(val2).style.display="none";  	  
	document.getElementById(val2).value =  'http://';  
	document.getElementById(val1).value =  'Yes';  
  }	  	
    
} 

//----------------------------------------

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;
}

//----------------------------------------