﻿//var DivPage	= createTag("div","id","PageBg");
//var DivBox	= createTag("div","id","PopBox");
var page	= document.getElementById("PageBg");
var pb		= document.getElementById("PopBox");
var PageWidth	= document.body.clientWidth;
var PageHeight	= document.body.clientHeight;
var ConTainer	= "srcContainer";
var iFrameId	= "iFrameConTainer";
var LoadImgId	= "LoadingImg";
var LoadImgSrc	= "/images/DSFBox/loading.gif";
var TopLeftImg	= "TopLeftImage";
var TopLeftSrc	= "/images/DSFBox/topleft.gif";
var TopRightImg	= "TopRightImage";
var TopRightSrc	= "/images/DSFBox/topright.gif";
var BtmLeftImg	= "BtmLeftImage";
var BtmLeftSrc	= "/images/DSFBox/btmleft.gif";
var BtmRightImg	= "BtmRightImage";
var BtmRightSrc	= "/images/DSFBox/btmright.gif";
var PrintId	= "BoxPrint";
var PrintSrc	= "/images/DSFBox/print.gif";
var OpenId	= "BoxOpen";
var OpenSrc	= "/images/DSFBox/newopen1.gif";
var OpenSrcOver	= "/images/DSFBox/newopen2.gif";
var OpenAnchorId= "OpenAnchor";
var OpenAnchorT	= "_blank";
var CloseId	= "BoxClose";
var CloseSrc	= "/images/DSFBox/close1.gif";
var CloseSrcOver= "/images/DSFBox/close2.gif";
var DummySrc	= "/images/dummy.gif";
var FirstAnima  = true;

/* you can modify variables as below */
var PageBgColor	= "gray";
var PageOpacity	= 90;
var PageClose	= true;					// Click the Page Background to close or not
var BoxWidth	= 960;
var BoxHeight	= 500;
var BoxLeftPos	= 0.5;
var BoxTopPos	= 0.25;
var EnlargeSize	= 10;					// present in percentage, min = 10, max = 100
var Speed	= 20;					// speed of each enlarge (ms)
var BoxMaxSize	= 0.95;					// this size for auto resize when the box size over the browser
var BoxSecAnima = false;				// play the animation in second times or not
var FrameScroll = "auto";
var ToolPrint 	= true;
var ToolClose 	= true;
var ToolOpen 	= true;
var isPrint	= true;

//Terry 20111103 support safari & chrome
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
//Terry 20111103 support safari & chrome */

var l = 1;
langs 		= new Array();
langs[0]	= new Array();
langs[1]	= new Array("C","列印","開新頁","關閉","是否確定關閉 ?");
langs[2]	= new Array("P","print","open new page","close","close it ?");
langs[3]	= new Array("E","print","open new page","close","close it ?");

if (typeof(window["lang"]) != "undefined")
  if (window["lang"].toLowerCase() == "pt-pt") l = 2;
  else if (window["lang"].toLowerCase() == "en-us") l = 3;

for (i=1; i<langs[l].length; i++) langs[0][i] = langs[l][i];

var initBWidth 	= BoxWidth;
var initBHeight	= BoxHeight;

var isIE    = (navigator.appName=="Microsoft Internet Explorer")?true:false;

// variable checking
//BoxWidth = BoxWidth > PageWidth ? PageWidth*0.95 : BoxWidth;
//BoxHeight = BoxHeight > PageHeight ? PageHeight*0.95 : BoxHeight;
EnlargeSize = EnlargeSize>100?100:EnlargeSize<10?10:EnlargeSize;
/*
var pagebody	= document.getElementsByTagName('body')[0];

DivBox.style.width = "50";
DivBox.style.height = "50";
DivBox.style.position = "absolute";
DivBox.style.left = "-300";
DivBox.style.top = "-300";
pagebody.appendChild(DivBox);
*/
addListener(window, "resize", function(){BrowserResize()}, false);

var r = true;
var resizeTimer;

function BrowserResize() {
  if (r) {
    r = false;
    if (page.style.display == "block")
      resizeTimer = setTimeout("r=true; adjustBox(); window.clearTimeout(resizeTimer)", 200);
  }
}


var anchors = (this.isFrame) ? window.parent.frames[window.name].document.getElementsByTagName('a') : document.getElementsByTagName('a');
var imgareas= (this.isFrame) ? window.parent.frames[window.name].document.getElementsByTagName('area') : document.getElementsByTagName('area');

checkPrint = 0;
if (anchors.length>0 || imgareas.length>0) {

  if (anchors.length>0)
  for (var i = 0; i < anchors.length; i++) {
    var anchor = anchors[i];
    var relAttribute = String(anchor.getAttribute('boxname'));

    if (anchor.getAttribute('href') && relAttribute.toLowerCase().match('dsfpopbox')) {
	anchor.onclick = function () { BoxAction(this); return false; }

    }
  }


  if (imgareas.length>0)
  for (var i = 0; i < imgareas.length; i++) {
    var imgarea = imgareas[i];
    var relAttribute = String(imgarea.getAttribute('boxname'));

    if (imgarea.getAttribute('href') && relAttribute.toLowerCase().match('dsfpopbox')) {
	imgarea.onclick = function () { BoxAction(this); return false; }
    }
  }



  createTable(anchor);
}





/*	function	*/
function setPageSize() {

}

function addListener(element, type, expression, bubbling){
	bubbling = bubbling || false;
	if(window.addEventListener){ // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}


function createTable(anchor) {
var PBoxDiv = document.getElementById("PopBox");

//Terry 20111103 support safari & chrome
var rev = splitAttrs(anchor.getAttribute('rev'));
BoxWidth = getArraryPos(rev,"width")>=0?rev[getArraryPos(rev,"width")].split(":")[1].replace("px","").replace(" ",""):BoxWidth;
PageWidth	= document.body.clientWidth;
var BWidth = BoxWidth > PageWidth ? PageWidth*0.95 : BoxWidth;
if (arguments.length<=1) var ss = EnlargeSize;
else ss = arguments[1] + EnlargeSize;
var bw = Math.floor(BWidth * ss / 100);
bw = (bw > BWidth ? BWidth : bw);
//var w	= BoxWidth > PageWidth ? PageWidth*0.95 : BoxWidth;
var TBwidth = BrowserDetect.browser == "Chrome" ? (bw*10) : BrowserDetect.browser == "Safari" ? (bw*10) : "100%";
//Terry 20111103 support safari & chrome */


var myTable = document.createElement("table");
    myTable.setAttribute("border","0");
    myTable.setAttribute('id','BoxTable');
    myTable.setAttribute('width','100%');
    myTable.setAttribute('height','100%');
    myTable.setAttribute('cellSpacing','0');
    myTable.setAttribute('cellPadding','0');

var myTbody = document.createElement("tbody");

var myTRs = new Array();
    myTRs[0] = createTag('tr','id','tr_0','vAlign','top','height','23');
    myTRs[1] = createTag('tr','id','tr_1','height','100%');
    myTRs[2] = createTag('tr','id','tr_2','vAlign','bottom','height','23');

var myTDs = new Array();
    myTDs[0] = createTag('td','id','td_0_1');
    myTDs[0].appendChild(createTag('img','id',TopLeftImg,'src',TopLeftSrc));
    //Terry 20111103 support safari & chrome
    //myTDs[1] = createTag('td','id','td_0_2','width','100%','bgColor','white', 'vAlign', 'bottom');
    myTDs[1] = createTag('td','id','td_0_2','width',TBwidth,'bgColor','white', 'vAlign', 'bottom');
    //Terry 20111103 support safari & chrome */
    myTDs[1].appendChild(createToolBar());
    myTDs[2] = createTag('td','id','td_0_3');
    myTDs[2].appendChild(createTag('img','id',TopRightImg,'src',TopRightSrc));

    myTDs[3] = createTag('td','id','td_1_0','colSpan','3','bgColor','white','vAlign','middle','align','center');
var ConTainerDiv = createTag('div','id',ConTainer);
    ConTainerDiv.appendChild(createTag("img","id",LoadImgId,"src",LoadImgSrc));
    myTDs[3].appendChild(ConTainerDiv);
//    myTDs[3].innerHTML = "test";

    myTDs[4] = createTag('td','id','td_2_0');
    myTDs[4].appendChild(createTag('img','id',BtmLeftImg,'src',BtmLeftSrc));
    myTDs[5] = createTag('td','id','td_2_1','bgColor','white');
    myTDs[6] = createTag('td','id','td_2_2');
    myTDs[6].appendChild(createTag('img','id',BtmLeftImg,'src',BtmRightSrc));

    myTable.appendChild(myTbody);

    myTbody.appendChild(myTRs[0]);
    myTRs[0].appendChild(myTDs[0]);
    myTRs[0].appendChild(myTDs[1]);
    myTRs[0].appendChild(myTDs[2]);

    myTbody.appendChild(myTRs[1]);
    myTRs[1].appendChild(myTDs[3]);

    myTbody.appendChild(myTRs[2]);
    myTRs[2].appendChild(myTDs[4]);
    myTRs[2].appendChild(myTDs[5]);
    myTRs[2].appendChild(myTDs[6]);

    PBoxDiv.appendChild(myTable);
}


function createToolBar() {



var TmpDiv = new Array();
    TmpDiv[0] = createTag('div','id','ToolsBar');
    TmpDiv[1] = createTag('div','id','LeftTools','style','float:left');
    TmpDiv[1].style.styleFloat = "left";
    TmpDiv[2] = createTag('div','id','RightTools','style','float:right');
    TmpDiv[2].style.styleFloat = "right";

var TmpFunc = new Array();
    TmpFunc[0] = createTag('img','id',PrintId,'src',PrintSrc,'alt',langs[0][1]);
//    TmpFunc[0] = createTag('img','id',PrintId,'src',PrintSrc,'alt',printparam);

//    TmpFunc[0] = createTag('img','id',PrintId,'src',(isPrint?PrintSrc:DummySrc),'alt',langs[0][1]);
    TmpFunc[0].style.marginLeft = "6px";
    TmpFunc[0].style.visibility = (isPrint?"visible":"hidden");
    TmpFunc[0].style.cursor = "pointer";
    TmpFunc[1] = createTag('img','id',OpenId,'src',OpenSrc,'border','0','alt',langs[0][2]);
    TmpFunc[1].onmouseover = function () {this.src=OpenSrcOver;}
    TmpFunc[1].onmouseout = function () {this.src=OpenSrc;}
    TmpFunc[1].style.marginRight = "5px";
    TmpFunc[2] = createTag('img','id',CloseId,'src',CloseSrc,'alt',langs[0][3]);
    TmpFunc[2].onmouseover = function () {this.src=CloseSrcOver;}
    TmpFunc[2].onmouseout = function () {this.src=CloseSrc;}
    TmpFunc[2].style.marginRight = "9px";
    TmpFunc[2].style.cursor = "pointer";

var OpenAnchor = createTag('a','id',OpenAnchorId,'href','#','target',OpenAnchorT);

    if (ToolPrint)	TmpDiv[1].appendChild(TmpFunc[0]);
    if (ToolOpen)	{OpenAnchor.appendChild(TmpFunc[1]); TmpDiv[2].appendChild(OpenAnchor);}
    if (ToolClose)	TmpDiv[2].appendChild(TmpFunc[2]);
    TmpDiv[0].appendChild(TmpDiv[1]);
    TmpDiv[0].appendChild(TmpDiv[2]);

return TmpDiv[0];
}


function createTag() {
  var TmpTag;
  if (arguments[0]) {
    TmpTag = document.createElement(arguments[0]);

      if (arguments.length>1 && ((arguments.length-1) % 2 == 0))
	for (var j=1; j < arguments.length; j+=2) TmpTag.setAttribute(arguments[j], arguments[j+1]);
    return TmpTag;
  }
}


function splitAttrs(){
  if (arguments[0]==""||arguments[0]==null) return null;
  else return arguments[0].split(";");
}

function getArraryPos(){
  var result=-1;

  try {
    for(var i=0;i<arguments[0].length;i++) {
      if (arguments[0][i].toLowerCase().search(arguments[1].toLowerCase())>=0) {
        result = i;
        i=arguments[0].length;
      }
    }
  } catch(err) {}

  return result;
}


function BoxAction() {
var rev = splitAttrs(arguments[0].getAttribute('rev'));


var printParam  = '';					//Terry 2011/02/23
var openParam  = '';					//Terry 2011/02/23

if (rev!=null){
  printParam = getArraryPos(rev,"print")>=0?rev[getArraryPos(rev,"print")].split(":")[1].replace(" ",""):"true"; //Terry 2011/02/23
  openParam = getArraryPos(rev,"open")>=0?rev[getArraryPos(rev,"open")].split(":")[1].replace(" ",""):"true"; //Terry 2011/02/23
  BoxWidth = getArraryPos(rev,"width")>=0?rev[getArraryPos(rev,"width")].split(":")[1].replace("px","").replace(" ",""):BoxWidth;
  BoxHeight = getArraryPos(rev,"height")>=0?rev[getArraryPos(rev,"height")].split(":")[1].replace("px","").replace(" ",""):BoxHeight;
  FrameScroll = getArraryPos(rev,"scrolling")>=0?rev[getArraryPos(rev,"scrolling")].split(":")[1].replace(" ",""):"auto";
  PageClose = (getArraryPos(rev,"confirm")>-1) ? (toBoolean(rev[getArraryPos(rev,"confirm")].split(":")[1])!=null) ? toBoolean(rev[getArraryPos(rev,"confirm")].split(":")[1]) : PageClose : PageClose;

  isPrint=(printParam=="false"?false:true); 		//Terry 2011/02/23
  openParam=(openParam=="false"?false:true); 		//Terry 2011/02/23
}else{
  openParam=true;					//Terry 2011/04/04
  isPrint=true;
}


  if (arguments[0]!="undefined") {
    OpenBox();
    var anchorHref = arguments[0].getAttribute('href');

/* setting the PageBackground */
//    page.style.width 		= document.body.clientWidth;
//    page.style.height		= document.body.clientHeight;
    var GetSize = getPageSize();
    page.style.width 		= GetSize[0];
    page.style.height		= GetSize[1];

    page.style.backgroundColor= PageBgColor;


    if (parseInt(pb.style.width.replace("px", "")) < BoxWidth) {
      page.style.filter		= "alpha(opacity="+PageOpacity+")";	// for MSIE
      page.style.opacity	= (PageOpacity/100);			// for FF
/* PopBox */
      pb.style.zIndex	= document.getElementById("PageBg").style.zIndex+1;
      pb.style.width	= 0;
      pb.style.height	= 0;
    } else FirstAnima = false;


//    if (Right(anchorHref, 4) == ".pdf") document.getElementById(PrintId).style.display = "none";
//    else document.getElementById(PrintId).style.display = "block";
    if (Right(anchorHref, 4) == ".pdf") document.getElementById(PrintId).style.visibility = "hidden";
    else if (isPrint) document.getElementById(PrintId).style.visibility = "visible";	//vernon
    else if (!isPrint) document.getElementById(PrintId).style.visibility = "hidden";	//Terry 2011/02/23

    document.getElementById(LoadImgId).style.display = "block";

//    if (openParam) document.getElementById(OpenId).style.visibility = 'visible';	//Terry 2011/02/23
//    else if (!openParam) document.getElementById(OpenId).style.visibility = 'hidden';	//Terry 2011/02/23

    if (openParam) document.getElementById(OpenId).style.display = '';			//Terry 2011/02/23
    else if (!openParam) document.getElementById(OpenId).style.display = 'none';	//Terry 2011/02/23


    if (FirstAnima || BoxSecAnima) BoxEnlarge(anchorHref);
    else BoxAlpha(anchorHref, 20);
//    else BoxEnlarge(anchorHref, 100);
  }
}


function BoxEnlarge() {
  PageWidth	= document.body.clientWidth;
  PageHeight	= document.body.clientHeight;

  var BWidth = BoxWidth > PageWidth ? PageWidth*0.95 : BoxWidth;
  var BHeight = BoxHeight > PageHeight ? PageHeight*0.95 : BoxHeight;


  if (arguments.length<=1) var ss = EnlargeSize;
  else ss = arguments[1] + EnlargeSize;

  var bw = Math.floor(BWidth * ss / 100);
  var bh = Math.floor(BHeight * ss / 100);
  bw = (bw > BWidth ? BWidth : bw);
  bh = (bh > BHeight ? BHeight : bh);
  var bl = Math.floor((PageWidth - bw) * BoxLeftPos);
  var bt = Math.floor((PageHeight - bh) * BoxTopPos);

  pb.style.left		= bl;
  pb.style.top		= bt + getPageScroll();
  pb.style.width	= bw;
  pb.style.height	= bh;
//  alert(PageWidth + ":" + PageHeight + ":" + BoxWidth + ":" + BoxHeight + ":" + BWidth + ":" + BHeight + ":" + bw + ":" + bh);

  if (ss<100) timer = setTimeout("BoxEnlarge('"+arguments[0]+"', "+ss+")", Speed);
  else {
    window.clearTimeout(timer);

    if (PageClose) page.onclick = function () { if (confirm(langs[0][4])) CloseBox(); return false; }
    else page.onclick = function () { CloseBox(); return false;}
    AssignFunc(arguments[0]);
    createContext(arguments[0]);
   
    checkAllLink();
  }

}


function BoxAlpha() {
  PageWidth		= document.body.clientWidth;
  PageHeight		= document.body.clientHeight;
  var BWidth 		= BoxWidth > PageWidth ? PageWidth*0.95 : BoxWidth;
  var BHeight 		= BoxHeight > PageHeight ? PageHeight*0.95 : BoxHeight;
  pb.style.width	= BWidth;
  pb.style.height	= BHeight;
  var bl 		= Math.floor((PageWidth - BWidth) * BoxLeftPos);
  var bt 		= Math.floor((PageHeight - BHeight) * BoxTopPos);
  pb.style.left		= bl;
  pb.style.top		= bt + getPageScroll();

  if (arguments[1]<=PageOpacity) {
    page.style.filter	= "alpha(opacity="+arguments[1]+")";
    page.style.opacity	= (arguments[1]/100);
    timer = setTimeout("BoxAlpha('"+arguments[0]+"',"+(arguments[1]+=10)+")", Speed);
  } else {
    window.clearTimeout(timer);
    createContext(arguments[0]);
    

    checkAllLink();
  }
  
}


function adjustBox(){
//alert(page.style.display);

  if (page.style.display == "block") {
    var GetSize = getPageSize();
    TmpPageWidth = document.body.clientWidth;
    TmpPageHeight= document.body.clientHeight;

    TmpBoxWidth	 = initBWidth > TmpPageWidth ? TmpPageWidth*0.95 : initBWidth;
    TmpBoxHeight = initBHeight > TmpPageHeight ? TmpPageHeight*0.95 : initBHeight;
    TmpBoxLeft	 = Math.floor((TmpPageWidth - TmpBoxWidth) * BoxLeftPos);
    TmpBoxTop	 = Math.floor((TmpPageHeight - TmpBoxHeight) * BoxTopPos);

//    page.style.width = TmpPageWidth; 
//    page.style.height = TmpPageHeight;
    page.style.width 		= GetSize[0];
    page.style.height		= GetSize[1];

    pb.style.width = TmpBoxWidth;
    pb.style.height = TmpBoxHeight;
    pb.style.left = TmpBoxLeft;
    pb.style.top = TmpBoxTop + getPageScroll();

    document.getElementById(iFrameId).style.width = TmpBoxWidth - 20;
    document.getElementById(iFrameId).style.height = TmpBoxHeight - 60;
  }
}


function hideFunc(){
  if(isIE){
    parent.frames[iFrameId].document.onclick = function() {
      if (parent.frames[iFrameId].event.srcElement.tagName == 'A'){
	document.getElementById(PrintId).style.visibility = 'hidden';
	document.getElementById(OpenId).style.visibility = 'hidden';
      }
    };
  } else {
    window.frames[iFrameId].onclick = function(evt) {
      if (evt.target.tagName == 'A'){
	document.getElementById(PrintId).style.visibility = 'hidden';
	document.getElementById(OpenId).style.visibility = 'hidden';
      }
    };
  }
}



//Terry check print all link
function checkAllLink(){

  if(isIE){
    parent.frames[iFrameId].document.onclick = function() {
       // alert(parent.frames[iFrameId].event.srcElement.getAttribute('dsf'));
      //alert(parent.frames[iFrameId].event.srcElement.tagName.getAttribute('dsf'));
      if (parent.frames[iFrameId].event.srcElement.tagName == 'A'){
//	document.getElementById(PrintId).style.display = 'none';
	document.getElementById(PrintId).style.visibility = 'hidden';
	document.getElementById(OpenId).style.visibility = 'hidden';
      }else if(parent.frames[iFrameId].event.srcElement.tagName == 'TD'){
        if(parent.frames[iFrameId].event.srcElement.getAttribute('dsf') == "a"){
            document.getElementById(PrintId).style.visibility = 'hidden';
	        document.getElementById(OpenId).style.visibility = 'hidden';
        }
      }
    };
  } else {
    window.frames[iFrameId].onclick = function(evt) {
      if (evt.target.tagName == 'A'){
        //	document.getElementById(PrintId).style.display = 'none';
	        document.getElementById(PrintId).style.visibility = 'hidden';
	        document.getElementById(OpenId).style.visibility = 'hidden';
      }else if(evt.target.tagName == 'TD'){
        if(evt.target.getAttribute('dsf') == "a"){
            document.getElementById(PrintId).style.visibility = 'hidden';
            document.getElementById(OpenId).style.visibility = 'hidden';
        }
      }
    };
  }

}


//Terry check print external link
function checkExternalLink(){
    

    if(isIE){


    parent.frames[iFrameId].document.onclick = function()
        {

            //To check if user is navigating from the page by clicking on a hyperlink.
            if (parent.frames[iFrameId].event.srcElement.tagName == 'A'){
                    //alert(parent.frames[iFrameId].event.srcElement.tagName);     //To not popup the warning message
		    if(parent.frames[iFrameId].event.srcElement.href.indexOf("http")==-1){
			    document.getElementById(PrintId).style.display = 'block';
    			
			    //iframe.src = parent.frames[frname].event.srcElement.href;
			    //alert(iframe.src)
		    }else{
    			
			    document.getElementById(PrintId).style.display = 'none';
			    //iframe.src = parent.frames["test"].event.srcElement.href;
			    //alert(iframe.src)
			    
		    }
	    }
            else
                    {}    //To popup the warning message
        }
    }
    else{

	    window.frames[iFrameId].onclick = function(evt)
	    {
		    if (evt.target.tagName == 'A'){
                   // alert(evt.target.tagName);     //To not popup the warning message
		    if(evt.target.href.indexOf("http")==-1 ){
			    document.getElementById(PrintId).style.display = 'block';
		    }else{
			    document.getElementById(PrintId).style.display = 'none';
		    }
		    }
        	    else
                    {}    //To popup the warning message
	    };

    }
}

function createContext() {
  var c = document.getElementById(ConTainer);
  var w	= BoxWidth > PageWidth ? PageWidth*0.95 : BoxWidth;
  var h	= BoxHeight > PageHeight ? PageHeight*0.95 : BoxHeight;

  var ConType = "iframe";

  if (arguments.length>0) {
    if (document.getElementById(iFrameId)) document.getElementById(c).removeChild(document.getElementById(iFrameId));
//    if (Right(arguments[0], 4) == ".pdf") ConType = "embed";

    var fc = createTag(ConType,"id",iFrameId,"name",iFrameId,"width",w-30,"height",h-60);
    
    fc.setAttribute("src",arguments[0]);
    fc.setAttribute("scrolling", FrameScroll);
    fc.setAttribute("marginwidth","0");
    fc.setAttribute("framespacing","0");
    fc.setAttribute("marginheight","0");
    fc.setAttribute("frameborder","0", false);
    fc.style.display = "none";
 }

//  document.getElementById(LoadImgId).style.display = "none";
  c.appendChild(fc);
     
//  document.getElementById(LoadImgId).style.display = "none";
//  document.getElementById(iFrameId).style.display = "block";
  setTimeout("CheckLoaded("+iFrameId+")",1000);
//    mm(iFrameId);
}


function toBoolean(s){
  if (s.toLowerCase()=="true") return true;
  else if (s.toLowerCase()=="false") return false;
  else return null;
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function AssignFunc() {
  document.getElementById(CloseId).onclick = function () {CloseBox(); return false;}
  document.getElementById(OpenAnchorId).onclick = function () {document.getElementById(OpenAnchorId).href = document.getElementById(iFrameId).src; CloseBox();}
//  document.getElementById(OpenId).onclick = function () {parent.location = document.getElementById(iFrameId).src; return false;}
  document.getElementById(PrintId).onclick = function () { if(isIE){parent.frames[iFrameId].focus(); parent.frames[iFrameId].print();}else{window.frames[iFrameId].focus(); window.frames[iFrameId].print();} return false;}
}

function OpenBox() {
  page.style.display 	= "block";
  pb.style.display	= "block";
  
}

function CloseBox() {
  page.style.display 	= "none";
  pb.style.display	= "none";
	
   if (document.getElementById(iFrameId)) document.getElementById(ConTainer).removeChild(document.getElementById(iFrameId));
}

function doit() {
var x = document.getElementById(PrintId);
//x.click();
//x.setActive();
//x.focus();
x.print();
}





function CheckLoaded(f) {
  document.getElementById(LoadImgId).style.display = "none";
  document.getElementById(iFrameId).style.display = "block";

  var ifSrc = document.getElementById(iFrameId).src;
//  alert(ifSrc.lastIndexOf(".pdf"));
  if (ifSrc.search("#")>-1 && ifSrc.lastIndexOf(".pdf")<0 && ifSrc.lastIndexOf(".zip")<0 && ifSrc.lastIndexOf(".xls")<0) document.getElementById(iFrameId).src = document.getElementById(iFrameId).src;

//  document.getElementById("ta").value += window.frames[iFrameId].document.readyState;
//alert(window.frames[iFrameId].document.readyState);

/*
  if (navigator.appName=="Microsoft Internet Explorer") {
    try {
      if (window.frames[iFrameId].document.readyState != "complete") CheckLoaded();
      else   document.getElementById("ta").value += window.frames[frname].document.documentElement.outerText;
    } catch(err) {}
  }
*/

}


function mm(frname) {
  var t = true;
//  document.getElementById(frname).onload = "";

  if (navigator.appName=="Microsoft Internet Explorer") {
    try {
      if (window.frames[frname].document.readyState != "complete")
        setTimeout("mm("+frname+")", 1000);
      else {
	var abc = window.frames[frname].document.documentElement.outerText;
	if (abc.indexOf("HTTP 404")>-1) 
	t = false;
//	alert("404");
      }
    } catch(err) { //	alert("pdf ok");
      document.getElementById(LoadImgId).style.display = "none";
      document.getElementById(iFrameId).style.display = "block";
    }
  } else {
    var aa = window.frames[frname].document.activeElement.innerHTML;
//	alert(window.frames[frname].document.activeElement.innerHTML);
    try {
      if (aa.length >0 && aa.indexOf("HTTP 404") != -1)
	t = false;
        //alert("404");
    //}
    else{
        //alert("ok");
        //alert(aa);
      document.getElementById(LoadImgId).style.display = "none";
      document.getElementById(iFrameId).style.display = "block";
    }
    } catch(err) {
//        alert(err)

    }
    
    
    }
    



//if (!t) //alert("404")
//window.frames[frname].location.href="error404.aspx?aspxerrorpath="+att;
//document.getElementById(iFrameId).innerHTML = "File Not Found!"
}




getPageSize = function() {
           var xScroll, yScroll, windowWidth, windowHeight;
           if (window.innerHeight && window.scrollMaxY) {
                     xScroll = document.scrollWidth;
                     yScroll = (this.isFrame ? parent.innerHeight : self.innerHeight) + (this.isFrame ? parent.scrollMaxY : self.scrollMaxY);
           } else if (document.body.scrollHeight > document.body.offsetHeight){
                     xScroll = document.body.scrollWidth;
                     yScroll = document.body.scrollHeight;
           } else {
                     xScroll = document.getElementsByTagName("html").item(0).offsetWidth;
                     yScroll = document.getElementsByTagName("html").item(0).offsetHeight;
                     xScroll = (xScroll < document.body.offsetWidth) ? document.body.offsetWidth : xScroll;
                     yScroll = (yScroll < document.body.offsetHeight) ? document.body.offsetHeight : yScroll;
           }

           if (self.innerHeight) {
                     windowWidth = (this.isFrame) ? parent.innerWidth : self.innerWidth;
                     windowHeight = (this.isFrame) ? parent.innerHeight : self.innerHeight;
           } else if (document.documentElement && document.documentElement.clientHeight) {
                     windowWidth = document.documentElement.clientWidth;
                     windowHeight = document.documentElement.clientHeight;
           } else if (document.body) {
                     windowWidth = document.getElementsByTagName("html").item(0).clientWidth;
                     windowHeight = document.getElementsByTagName("html").item(0).clientHeight;
                     windowWidth = (windowWidth == 0) ? document.body.clientWidth : windowWidth;
                     windowHeight = (windowHeight == 0) ? document.body.clientHeight : windowHeight;
           }
           var pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
           var pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
           return new Array(pageWidth, pageHeight, windowWidth, windowHeight);
}


getPageScroll = function() {
	if (self.pageYOffset) {
		return this.isFrame ? parent.pageYOffset : self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		return document.documentElement.scrollTop;
	} else if (document.body) {
		return document.body.scrollTop;
	}
}

//alert(getPageScroll());
