// $URL: https://svn.pvtool.net/svn/day_vwcms/trunk/contentbus/filesystem/files/apps/vwcms_interaktiv/docroot/vwcms_interaktiv/js/javascriptinclude_render.js $
// $Id: javascriptinclude_render.js,v 1.3 2007/08/08 14:55:08 aburkhardt Exp $

// **** Dynamic JavaScript Include - Render implementations ****

// ########### fahrzeugdaten include ###########
function render_fahrzeugdaten(pInclude, pObjectName) {
  
  var isLocked = false;
  if (pInclude.required_role) {
    if (pInclude.required_role!="") {
      isLocked = (pInclude.required_role.indexOf(eprofile_role) < 0);
    }
  }

  document.write("<div class=\"title_teaser\">" + pInclude.title + "</div>");
  document.write("<div class=\"teaser_line\"></div>");

  document.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:375px\">");
  document.write("<tr valign=\"top\">");
   
  document.write("<td class=\"space_ri\">");
  render_image(pInclude.image, 180, 110);
  document.write("</td>");

  document.write("<td>");
  document.write("<div class=\"space_top3\"></div>");
  if (!isLocked) {
    document.write("<div>");
  } else {
    document.write("<div class=\"locked\">");
  }
  for (index=0; index<pInclude.cardata.length; index++) {
    document.write(pInclude.cardata[index]);
    document.write("<br>");
  }
  document.write("</div>");

  if (isLinkValid(pInclude.link)) {
   document.write("<div class=\"link_arrow\">");
   render_link(pInclude.link, "<img src=\"" + global_staticpath_images + "/arrow_orange.gif\" width=\"10\" height=\"8\" alt=\"&gt;\" class=\"arrow\">", isLocked, pInclude);
   document.write("</div>");
 }

  document.write("</td>");

  document.write("</tr>");
  document.write("</table>");

  document.write("<div class=\"space_16\"></div>");
}

// ########### faz_news include ###########
function render_faz_news(pInclude, pObjectName) {

  var isLocked = false;
  if (pInclude.required_role) {
    if (pInclude.required_role!="") {
      isLocked = (pInclude.required_role.indexOf(eprofile_role) < 0);
    }
  }

	document.write("<div class=\"title_teaser\">");
	document.write("<div class=\"title_teaser_info\">" + pInclude.date + "</div>");
	document.write(pInclude.title);
	document.write("</div>");
	
	document.write("<div class=\"pic_teaser_withline\"></div>");
	
	if (!isLocked) {
	   document.write("<div>");
	} else {
	   document.write("<div class=\"locked\">");
	}
	document.write(pInclude.text_intro);
	document.write("</div>");

	for (index=0; index<pInclude.links_news.length; index++) {
		if (isLinkValid(pInclude.links_news[index])) {
			document.write("<div class=\"link_arrow\">");
			render_link(pInclude.links_news[index], "<img src=\"" + global_staticpath_images + "/arrow_orange.gif\" width=\"10\" height=\"8\" alt=\"&gt;\" class=\"arrow\">", isLocked, pInclude);
			document.write("</div>");
		}
	}

	if (isLinkValid(pInclude.link_more)) {
		document.write("<div class=\"link_arrow\">");
		render_link(pInclude.link_more, "<img src=\"" + global_staticpath_images + "/arrow_orange.gif\" width=\"10\" height=\"8\" alt=\"&gt;\" class=\"arrow\">", isLocked, pInclude);
		document.write("</div>");
	}

	document.write("<div class=\"space_16\"></div>");
}

// ########### focus include ###########
function render_focus(pInclude, pObjectName) {

  var isLocked = false;
  if (pInclude.required_role) {
    if (pInclude.required_role!="") {
      isLocked = (pInclude.required_role.indexOf(eprofile_role) < 0);
    }
  }

	document.write("<div class=\"title_teaser\">");
	document.write("<div class=\"title_teaser_info\">");
	if (pInclude.issue && pInclude.issue.length!=0) {
		document.write("Nr. " + pInclude.issue);
	}
	if (pInclude.issue && pInclude.issue.length!=0 && pInclude.date && pInclude.date.length!=0) {
		document.write(", ");
	}
	document.write(pInclude.date);
	document.write("</div>");
	document.write(pInclude.title);
	document.write("</div>");
	
	document.write("<div class=\"pic_teaser_withline\">");
	render_image(pInclude.image, 180, 70);
	document.write("</div>");
	
	for (index=0; index<pInclude.teasers.length; index++) {
		if (!isLocked) {
		   document.write("<div>");
		} else {
		   document.write("<div class=\"locked\">");
		}
		document.write(pInclude.teasers[index].text);
		document.write("</div>");
	
		if (isLinkValid(pInclude.teasers[index].link)) {
			document.write("<div class=\"link_arrow\">");
			render_link(pInclude.teasers[index].link, "<img src=\"" + global_staticpath_images + "/arrow_orange.gif\" width=\"10\" height=\"8\" alt=\"&gt;\" class=\"arrow\">", isLocked, pInclude);
			document.write("</div>");
		}
	}

	document.write("<div class=\"space_16\"></div>");

}

// ########### kostenkalkulator include ###########
function render_kostenkalkulator(pInclude, pObjectName) {

  var isLocked = false;
  if (pInclude.required_role) {
    if (pInclude.required_role!="") {
      isLocked = (pInclude.required_role.indexOf(eprofile_role) < 0);
    }
  }

  document.write("<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" style=\"width:250px\">");
   
  document.write("<tr>");
  document.write("<th>" + pInclude.title + "</th>");
  document.write("</tr>");

  document.write("<tr>");
  document.write("<td>");
   
  var formname = pObjectName + "_form";
  document.write("<form name=\"" + formname + "\">");

  document.write("<p>");
  document.write("Fahrzeug:<br>");
  document.write("<select name=\"cboModel\">");
  for (index=0; index<pInclude.models.length; index++) {
    document.write("<option value=\"" + pInclude.models[index].value + "\""
      + (pInclude.models[index].selected ? " selected" : "") + ">"
      + pInclude.models[index].text + "</option>");
  }
  document.write("</select>");
  document.write("</p>");
   
  document.write("<p>");
  document.write("Kostenart<br>");
  document.write("<select name=\"cboCostType\">");
  for (index=0; index<pInclude.costtypes.length; index++) {
    document.write("<option"
      + (pInclude.costtypes[index].value ? " value=\"" + pInclude.costtypes[index].value + "\"" : "") + ">"
      + pInclude.costtypes[index].text + "</option>");
  }
  document.write("</select>");
  document.write("</p>");
   
  document.write("<p>");
  document.write("<input type=\"button\" value=\"Anzeigen\" "
    + "onclick=\"" + pObjectName + ".execute("
    + "document." + formname + ".cboModel.options[document." + formname + ".cboModel.selectedIndex].value,"
    + "document." + formname + ".cboCostType.options[document." + formname + ".cboCostType.selectedIndex].value)\">");
  document.write("</p>");
   
  document.write("<ul>");
  for (index=0; index<pInclude.links.length; index++) {
    document.write("<li><a href=\"" + pInclude.links[index].href + "\""
      + (pInclude.links[index].target ? " target=\"" + pInclude.links[index].target + "\"" : "") + ">"
      + pInclude.links[index].title + "</a></li>");
  }
  document.write("</ul>");

  document.write("</td>");
  document.write("</tr>");

  document.write("</table>");
}


// ########### Render common objects ###########
function isImageValid(pImage) {
  return (pImage && pImage.url && pImage.url!='');
}

function isLinkValid(pLink) {
  return (pLink && pLink.href && pLink.href!='');
}

function render_image(pImage, pWidth, pHeight) {
  if (isImageValid(pImage)) {
	  if (isLinkValid(pImage.link)) {
	    render_link_anchortag(pImage.link);
	  }
	  document.write("<img border=\"0\" src=\"" + pImage.url + "\" "
	    + "width=\"" + (pWidth ? pWidth : pImage.width) + "\" "
	    + "height=\"" + (pHeight ? pHeight : pImage.height) + "\" "
	    + "alt=\"" + pImage.alttext + "\">");
	  if (isLinkValid(pImage.link)) {
	    document.write("</a>");
	  }
  }
}

function render_link_anchortag(pLink, pIsLocked, pInclude) {
	var href = pLink.href;
	if (!pIsLocked) {
		document.write("<a href=\"" + pLink.href + "\""
			+ (pLink.target ? " target=\"" + pLink.target + "\"" : "") + ">");  
	}
	else {
		var href = document.location.href;
		var dotIndex = href.lastIndexOf(".");
		var baseURL = href.substring(0, dotIndex);
		var extension = "htx";
		var pageSelector = "pc_popup";
		
		// Determine page selector dependend on current role and required role
		if (eprofile_role=="P") {
		  if (pInclude.required_role.indexOf("I")>=0) {
		    pageSelector = "pi_popup";
		  }
		  else if (pInclude.required_role.indexOf("C")>=0) {
		    pageSelector = "pc_popup";
		  }
		}
		else if (eprofile_role=="I") {
		  if (pInclude.required_role.indexOf("C")>=0) {
		    pageSelector = "ic_popup";
		  }
		}

		var openMethod = "window.open('" + baseURL + "." + pageSelector + "." + extension + "', '_blank', 'width=800,height=490');";
		document.write("<a href=\"javascript://\" onclick=\"" + openMethod + "\">");  
	}
}

function render_link(pLink, pArrow, pIsLocked, pInclude) {
  if (isLinkValid(pLink)) {
    render_link_anchortag(pLink, pIsLocked, pInclude);
  }
  if (pArrow) {
    document.write(pArrow);
  }
  document.write(pLink.title);
  if (pIsLocked) {
  	document.write("<img width=\"10\" height=\"11\" class=\"icon\" border=\"0\" src=\"" + global_staticpath_images + "/icon_locked.gif\" alt=\"\">");
  }
  if (isLinkValid(pLink)) {
	  document.write("</a>");
  }
}

