var g_leftWebIndex = 0;
var g_leftWebLength = 0;
var g_rightWebIndex = 0;
var g_rightWebLength = 0;
var g_leftFramePrefix = "left_frame_";
var g_rightFramePrefix = "right_frame_";
var g_leftWebDivId = "left_web_div";
var g_rightWebDivId = "right_web_div";
function S(element) {
return document.getElementById(element);
}
function showElement(id) {
var element = S(id);
if(element && element.style) {
element.style.display = "block";
}
}
function hideElement(id) {
var element = S(id);
if(element && element.style) {
element.style.display = "none";
}
}
function generateSingleWebFrameHtml(frameId, frameClass, src) {
var html = "<iframe id='";
html += frameId;
html += "' class='";
html += frameClass;
html += "' scrolling='no' src='";
html += src;
html += "'></iframe>";
return html;
}
// @param elements: all elements [web, image, excel]
function initWebHtml(webDivId, framePrefix, frameClass, elements) {
// no webs to show
if(!checkArray(elements))
return;
var html = "<div id='";
html += webDivId;
html += "' class='";
if(elements.name == Elements.LeftWeb) {
html += "div-web-left'>";
} else if(elements.name == Elements.RightWeb) {
html += "div-web-right'>";
}
var index = 0;
for(var i=0;i<elements.length;++i) {
if(isWeb(elements[i])) {
var frameId = framePrefix + index;
html += generateSingleWebFrameHtml(frameId, frameClass, elements[i]);
index++;
}
}
html += "</div>";
if(elements.name == Elements.LeftWeb) {
g_leftWebLength = index;
} else if(elements.name == Elements.RightWeb) {
g_rightWebLength = index;
}
// alert("init web html ============== " + html);
return html;
}
function refreshWebHtml(webDivId, framePrefix, frameClass, elements) {
// no webs to show
if(!checkArray(elements))
return;
var webDiv = S(webDivId);
if(!webDiv) {
alert("parameter webDivId is not valid, pls check");
return;
}
//debugger;
var index = 0;
for(var i=0;i<elements.length;++i) {
if(isWeb(elements[i])) {
var frameId = framePrefix + index;
var frame = S(frameId);
if(frame) {
frame.src = elements[i];
// alert("" + frameId + " src is " + elements[i]);
index++;
}
}
}
}
function showWebFrame(elemName) {
//debugger;
switch(elemName) {
case Elements.LeftWeb:
var frameId = g_leftFramePrefix + g_leftWebIndex;
showElement(frameId);
//hide previous web frame if total count of webs greater than 1
if(g_leftWebLength > 1) {
if(g_leftWebIndex == 0) {
var preFrameId = g_leftFramePrefix + (g_leftWebLength - 1);
hideElement(preFrameId);
} else {
var preFrameId = g_leftFramePrefix + (g_leftWebIndex - 1);
hideElement(preFrameId);
}
g_leftWebIndex++;
if(g_leftWebIndex >= g_leftWebLength) {
g_leftWebIndex = 0;
}
}
break;
case Elements.RightWeb:
var frameId = g_rightFramePrefix + g_rightWebIndex;
showElement(frameId);
//hide previous web frame if total count of webs greater than 1
if(g_rightWebLength > 1) {
if(g_rightWebIndex == 0) {
var preFrameId = g_rightFramePrefix + (g_rightWebLength - 1);
hideElement(preFrameId);
} else {
var preFrameId = g_rightFramePrefix + (g_rightWebIndex - 1);
hideElement(preFrameId);
}
g_rightWebIndex++;
if(g_rightWebIndex >= g_rightWebLength) {
g_rightWebIndex = 0;
}
}
break;
default:
return;
}
}