//PROJECT_URL = "<?=$CONFIG['script_http_addr'] . '/'?>";
hChatPage = null;

function onBodyLoad() {
    initCalendarFields();
}

function showMaximized(url, width, height) {
    var left = ((screen.width-width)/2);
    var top = ((screen.height-60-height)/2);
    if(left < 0) left=0;
    if(top < 0) top = 0;
    var openedWindow = window.open("about:blank", "_blank", "height="+height+", width="+width+", left="+left+",top="+top+",location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=no");
    openedWindow.document.open();
    var html = "<html><head><title>Camzed</title></head><body style=\"padding:0px;margin:0px;background-color:#000000;\">";
    html += "<div style=\"width:"+width+"px;height:"+height+"px;background:url("+url+") no-repeat scroll center;\">&nbsp;</div>";
    html += "</body></html>";    
    openedWindow.document.write(html);
    openedWindow.document.close();
}

function trim(text) {
  return text.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function redirect(url) {
  document.location.href = url;
}

function openChat(customer_id, room_id) {
    if (!hChatPage || hChatPage.closed) {
        hChatPage = window.open(PROJECT_URL + "user/chat.php?pid=" + customer_id + "&rid=" + room_id, "chat_page", "width=960,height=720,location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no");
        hChatPage.focus();
    } else {
        hChatPage.focus();
    }
}
function openFreeChat(customer_id, room_id) {
    if (!hChatPage || hChatPage.closed) {
        hChatPage = window.open(PROJECT_URL + "user/chat_free.php?pid=" + customer_id + "&rid=" + room_id, "chat_page", "width=960,height=720,location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no");
        hChatPage.focus();
    } else {
        hChatPage.focus();
    }
}
function openAdminChat(customer_id, room_id) {
    if (!hChatPage || hChatPage.closed) {
        hChatPage = window.open(PROJECT_URL + "admin/chat.php?pid=" + customer_id + "&rid=" + room_id, "chat_page", "width=800,height=700,location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no");
        hChatPage.focus();
    } else {
        hChatPage.focus();
    }
}


function initCalendarFields() {
  var els = document.getElementsByTagName("INPUT");
  for(var i=0; i<els.length; i++) {
    var className = " " + els[i].className + " ";
    if(className.indexOf(' calendar-input ') != -1) {
      var el = document.createElement("IMG");
      el.className = "calendar-img";
      el.align = "absmiddle";
      el.src = "images/1x1tr.gif";
      els[i].parentNode.insertBefore(el, els[i].nextSibling);
      Calendar.setup({
        inputField : els[i],
        button : el, 
        ifFormat : _calendar_date_format,
        weekNumbers : false,
        showsTime : false,
        cache : true
      });
    }
  }
}

function imageprompt()
{
    var imageurl=prompt("Enter Image URL","http://");
    if (imageurl!=null && imageurl!="")
    {
       document.getElementById("newCommentMessage").value +="[img]" + imageurl + "[/img]";    
     }
}