 /*Version: $Id: content_admin.js 1525 2006-01-09 10:12:19Z kglass $*/

/*******************************************/
/* Content list popup toolbox menu            */
/*******************************************/

function doContentPopUp (editor_href, content_alias, site_key, quote_id, published_flag, content_id, can_publish,is_lead,api_version) {
  sH=screen.height - 16;
  sW=screen.width - 16;

  myPopUp = document.getElementById("popOverHelp");
  
  if (!myPopUp) {
    popOverHelp = document.createElement("div");
    popOverHelp.setAttribute("id","popOverHelp");
    popOverHelp.onclick = Function("hidePopOverHelp(document);");

    document.getElementsByTagName("body")[0].appendChild(popOverHelp);
    myPopUp = document.getElementById("popOverHelp");
  } else {
    while (myPopUp.childNodes.length > 0) {
	myPopUp.removeChild(myPopUp.childNodes[myPopUp.childNodes.length - 1]);
    }
  }

  myPopUp.style.backgroundColor = '#eeeeee'; 
  myPopUp.style.border = '1px ridge lightgrey'; 
  myPopUp.style.width = '125px'; 

  containerDiv = document.createElement("div");
  containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");
  myPopUp.appendChild(containerDiv);

  span1 = document.createElement("span");
  span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;cursor:pointer;");
  anchor1 = document.createElement("a");
  anchor1.setAttribute("href", "#");
  anchor1.onclick=Function("window.open(\'" + editor_href + "\', \'contentEditorWindow\', \'top=10px, left=10px, width=900px, height=670px, status=no, scrollbars=no, resizable=yes\');hidePopOverHelp(document);");
  text1 = document.createTextNode("Edit");

  anchor1.className = 'popupItem';
  anchor1.appendChild(text1);
  span1.appendChild(anchor1);
  containerDiv.appendChild(span1);

  containerDiv = document.createElement("div");
  containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");
  myPopUp.appendChild(containerDiv);
	
  span1 = document.createElement("span");
  span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;cursor:pointer;");
  anchor1 = document.createElement("a");
  anchor1.setAttribute("href", "#");
  anchor1.onclick=Function("window.open(\'/cms/artcateditor/" + content_alias + "\', \'contentCatEditorWindow\', \'top=10px, left=10px, width=900px, height=670px, status=no, scrollbars=no, resizable=yes\');hidePopOverHelp(document);");
  text1 = document.createTextNode("Categories");

  anchor1.className = 'popupItem';
  anchor1.appendChild(text1);
  span1.appendChild(anchor1);
  containerDiv.appendChild(span1);

  containerDiv = document.createElement("div");
  containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");
  myPopUp.appendChild(containerDiv);

  span1 = document.createElement("span");
  span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");
  anchor1 = document.createElement("a");
  anchor1.setAttribute("href","#");
  anchor1.onclick = Function("window.open(\'/cms/history/" + content_alias + "\', \'contentEditorWindow\', \'top=10px, left=10px, width=900px, height=600px, scrollbars=yes, resizable=yes\');hidePopOverHelp(document);");
  text1 = document.createTextNode("History");

  anchor1.className = 'popupItem';
  anchor1.appendChild(text1);
  span1.appendChild(anchor1);
  containerDiv.appendChild(span1);

  containerDiv = document.createElement("div");
  containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");
  myPopUp.appendChild(containerDiv);

  span1 = document.createElement("span");
  span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");
  anchor1 = document.createElement("a");

  uri_stub = '/cms/section/'; 
  if ( published_flag == 'Y' || api_version == 2 ) {
     uri_stub = '/site/home/'; 
  } 

  if ( published_flag == 'Y' ) {
     anchor1.setAttribute("href",uri_stub+content_alias);
     text1 = document.createTextNode("View");
  }
  else {
     anchor1.setAttribute("href",uri_stub+content_alias+'?preview=1');
     text1 = document.createTextNode("Preview");
  }
  anchor1.onclick = Function("hidePopOverHelp(document);");

  anchor1.className = 'popupItem';
  anchor1.appendChild(text1);
  span1.appendChild(anchor1);
  containerDiv.appendChild(span1);

  if ( ( published_flag != 'Y' ) && ( can_publish == 1 ) ) {
    containerDiv = document.createElement("div");
    containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");
    containerDiv.setAttribute("class", "menu");
    span1 = document.createElement("span");
    span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");

    form1 = document.createElement("form");
    form1.setAttribute("method", "POST");
    form1.setAttribute("style", "display:none;");
    form1.setAttribute("name", "frmPublish");
    form1.setAttribute("id", "frmPublish");
    form1.setAttribute("action", "/cms/history/"+content_alias);

    hidden1 = document.createElement("input");
    hidden1.setAttribute("type","hidden");
    hidden1.setAttribute("name","published");
    hidden1.setAttribute("value","Y");
    form1.appendChild(hidden1);

    hidden1 = document.createElement("input");
    hidden1.setAttribute("type","hidden");
    hidden1.setAttribute("name","content_id");
    hidden1.setAttribute("value",content_id);
    form1.appendChild(hidden1);
 
    hidden1 = document.createElement("input");
    hidden1.setAttribute("type","hidden");
    hidden1.setAttribute("name","action");
    hidden1.setAttribute("value","publish");
    form1.appendChild(hidden1);
    span1.appendChild(form1);

    anchor1 = document.createElement("a");
    anchor1.setAttribute("href","#");
    anchor1.onclick = Function("document.frmPublish.submit();hidePopOverHelp(document);");
    text1 = document.createTextNode("Publish");

    anchor1.className = 'popupItem';
    anchor1.appendChild(text1);
    span1.appendChild(anchor1);
    containerDiv.appendChild(span1);
    myPopUp.appendChild(containerDiv);

  }


  if (quote_id == '0' ) {

    popUpSeparator(myPopUp);

    containerDiv = document.createElement("div");
    containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");

    span1 = document.createElement("span");
    span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");
    anchor1 = document.createElement("a");
    anchor1.setAttribute("href","#quote");
    anchor1.onclick = Function("window.open('/cms/commenteditor?is_quote=Y&parent_type=element&parent_alias="+content_alias+"&requested_uri=/cms/section/"+content_alias+"\', \'commentEditorWindow\', \'top=20px, left=20px, width=900px, height=670px, scrollbars=no, resizable=yes\');");
    text1 = document.createTextNode("Add quote");
					
    anchor1.className = 'popupItem';
    anchor1.appendChild(text1);
    span1.appendChild(anchor1);
    containerDiv.appendChild(span1);
    myPopUp.appendChild(containerDiv);
    
  } 


  if (  quote_id > 0 ) {
    popUpSeparator(myPopUp);

    containerDiv = document.createElement("div");
    containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");

    span1 = document.createElement("span");
    span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");
    anchor1 = document.createElement("a");
    anchor1.setAttribute("href","#quote");
    anchor1.onclick = Function("window.open('/cms/commenteditor/"+quote_id+"\', \'commentEditorWindow\', \'top=20px, left=20px, width=900px, height=670px, scrollbars=no, resizable=yes\');");
    text1 = document.createTextNode("Edit quote");
    anchor1.className = 'popupItem';					
    anchor1.appendChild(text1);
    span1.appendChild(anchor1);
    containerDiv.appendChild(span1);
    myPopUp.appendChild(containerDiv);
                                           
  }

  if (is_lead == "true") {
        popUpSeparator(myPopUp);
	
	containerDiv = document.createElement("div");
	containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:px;");

	span1 = document.createElement("span");
	span1.setAttribute("style","width:125px;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");
	anchor1 = document.createElement("a");
	anchor1.setAttribute("href","#");
	anchor1.onclick = Function("window.open(\'/cms/relmanager/element/element/fragment/" + content_alias + "\', \'contentEditorWindow\', \'top=0px, left=0px, width=" + sW + "px, height=" + sH + "px, scrollbars=yes, resizable=yes\');hidePopOverHelp(document);");
	text1 = document.createTextNode("Edit relationships");
	anchor1.className = 'popupItem';
	anchor1.appendChild(text1);
	span1.appendChild(anchor1);
	containerDiv.appendChild(span1);
        myPopUp.appendChild(containerDiv);
  }
  else {
     containerDiv = document.createElement("div");
     containerDiv.setAttribute("style", "position:relative;float:none;clear:both;width:125px;height:auto;vertical-align:middle;margin:2px 0px 0px 0px;padding:0px;");
     myPopUp.appendChild(containerDiv);
  }		

  popUpSeparator();

  containerDiv = document.createElement("div");
  containerDiv.setAttribute("style", "position:relative;float:left;clear:both;width:100%;height:auto;vertical-align:middle;margin:0px;padding:0px;");
  myPopUp.appendChild(containerDiv);

  span1 = document.createElement("span");
  span1.setAttribute("style","width:100%;height:auto;position:relative;float:left;margin:0px 0px 0px 0px;padding:0px;");
  anchor1 = document.createElement("a");
  anchor1.setAttribute("href","/cms/logout");
  text1 = document.createTextNode("Logout");
  anchor1.className = 'popupItem';

  anchor1.appendChild(text1);
  span1.appendChild(anchor1);
  containerDiv.appendChild(span1);

}

document.getElementsByClass = function (needle)
{
  var         my_array = document.getElementsByTagName("*");
  var         retvalue = new Array();
  var        i = 0;
  var        j = 0;

  for (i = 0, j= 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}


function showFullSize(theImage) {
  myPopUp = document.getElementById("popImg");

  if (!myPopUp) {
    popOverHelp = document.createElement("div");
    popOverHelp.setAttribute("id","popImg");
    popOverHelp.onclick = Function("hidePopOverHelp(document);");

    document.getElementsByTagName("body")[0].appendChild(popOverHelp);
    myPopUp = document.getElementById("popImg");
  } 
  else {
    while (myPopUp.childNodes.length > 0) {
        myPopUp.removeChild(myPopUp.childNodes[myPopUp.childNodes.length - 1]);
    }
  }

  var img1 = document.createElement("img");
  img1.setAttribute("src",theImage);
}

