//window.onload = new_window;

function new_window() {
  //Create this elements
      var myobjBody = document.getElementsByTagName("body").item(0);
	  var ArrayPageSize = GetPageSize();
      myobjBody.style.zIndex = "1";
      var bodyHeight = 500;
      
      //OverLay
      var myOverlay = document.createElement("div");
      myOverlay.setAttribute('id','myoverlay');
      var arrayPageSize = getSize();      //get pagesize to set Overlay size
      myOverlay.style.width = "100%";
	  myOverlay.style.height = ArrayPageSize[1]+'px';
      myOverlay.style.position = "absolute";
      myOverlay.style.zIndex = "105";
      myOverlay.style.top = "0";
      myOverlay.style.left = "0";
      myOverlay.style.backgroundColor = "#85BBEF";
      myOverlay.style.opacity = 7/10;
      myOverlay.style.filter = 'alpha(opacity=' + 7*10 + ')';
      myOverlay.style.display = "none";
      myobjBody.appendChild(myOverlay);
      
      
      var myLightbox = document.createElement("div");
      myLightbox.setAttribute('id','myLightbox');
      myLightbox.style.width ="100%";
      myLightbox.style.position = "absolute";
      myLightbox.style.top = "0";
      myLightbox.style.left = "0";
      myLightbox.style.zIndex = "120";
      myLightbox.style.display = "none";
      myobjBody.appendChild(myLightbox);
      
      //Iframewrap
      var iframeWrap = document.createElement("div");
      iframeWrap.setAttribute('id','iframewrap');
	  var height =(document.getElementById('new_window_main_height')== null)?"478px":document.getElementById('new_window_main_height').value;
      iframeWrap.style.height =height;
      iframeWrap.style.width = "720px";
      iframeWrap.style.position = "relative";
      iframeWrap.style.margin = "40px auto";
      iframeWrap.style.padding = "10px";
      iframeWrap.style.backgroundColor = "#fff";
      myLightbox.appendChild(iframeWrap);
      
      //Close Button
      var closeBut = document.createElement("img");
      closeBut.setAttribute('src','/new-images/close2.gif');
      closeBut.setAttribute('style','float:right');
      closeBut.style.cursor = "pointer";
      closeBut.onclick = function() {
        document.getElementById('myoverlay').style.display = 'none';
        document.getElementById('myLightbox').style.display = 'none';
        document.getElementById('myFrame').setAttribute('src','');
      }
      iframeWrap.appendChild(closeBut);
      
      //Iframe
      var myFrame = document.createElement("iframe");
	  myFrame.frameborder = "0";
      myFrame.setAttribute('style','margin-top: 10px;border: none');
      myFrame.setAttribute('id','myFrame');
      myFrame.setAttribute('width','100%');
	  var frame_height =(document.getElementById('new_window_iframe_height')== null)?'450':document.getElementById('new_window_iframe_height').value;
      myFrame.setAttribute('height',frame_height);
      myFrame.setAttribute('scrolling','auto');
      myFrame.setAttribute('frameborder','0');
      iframeWrap.appendChild(myFrame);

    elements = document.getElementsByTagName('a');
	if(elements){
		if(elements.length){
			for( i = 0; i < elements.length; i++){
			    linkOj = elements[i];
				set_new_window_function(linkOj,"720px",frame_height);
			}
		}else{
			linkOj = elements;
			set_new_window_function(linkOj,"720px",frame_height);
		}
	}
}





function new_window_custom(src,iframe_width_,new_window_main_height_) {
  //Create this elements
  	   iframe_width = typeof(iframe_width_) == 'undefined' ?"720px":iframe_width_;

	  var myobjBody = document.getElementsByTagName("body").item(0);
	  var ArrayPageSize = GetPageSize();
      myobjBody.style.zIndex = "1";
      var bodyHeight = 500;
      //OverLay
      var myOverlay = document.createElement("div");
      myOverlay.setAttribute('id','myoverlay');
      var arrayPageSize = getSize();      //get pagesize to set Overlay size
      myOverlay.style.width = "100%";
	  myOverlay.style.height = ArrayPageSize[1]+'px';
      myOverlay.style.position = "absolute";
      myOverlay.style.zIndex = "105";
      myOverlay.style.top = "0";
      myOverlay.style.left = "0";
      myOverlay.style.backgroundColor = "#85BBEF";
      myOverlay.style.opacity = 7/10;
      myOverlay.style.filter = 'alpha(opacity=' + 7*10 + ')';
      myOverlay.style.display = "none";
      myobjBody.appendChild(myOverlay);
      
      
      var myLightbox = document.createElement("div");
      myLightbox.setAttribute('id','myLightbox');
      myLightbox.style.width ="100%";
      myLightbox.style.position = "absolute";
      myLightbox.style.top = "0";
      myLightbox.style.left = "0";
      myLightbox.style.zIndex = "120";
      myLightbox.style.display = "none";
      myobjBody.appendChild(myLightbox);
      
      //Iframewrap
      var iframeWrap = document.createElement("div");
      iframeWrap.setAttribute('id','iframewrap');
      iframeWrap.style.position = "relative";
      iframeWrap.style.margin = "40px auto";
      iframeWrap.style.padding = "10px";
      iframeWrap.style.backgroundColor = "#fff";
      myLightbox.appendChild(iframeWrap);
      
      //Close Button
      var closeBut = document.createElement("img");
      closeBut.setAttribute('src','/new-images/close2.gif');
      closeBut.setAttribute('style','float:right');
      closeBut.style.cursor = "pointer";
      closeBut.onclick = function() {
        document.getElementById('myoverlay').style.display = 'none';
        document.getElementById('myLightbox').style.display = 'none';
        document.getElementById('myFrame').setAttribute('src','');
      }
      iframeWrap.appendChild(closeBut);
      
      //Iframe
      var myFrame = document.createElement("iframe");
	  
		myFrame.frameborder = "0";
		myFrame.setAttribute('style','margin-top: 10px;border: none');
		myFrame.setAttribute('id','myFrame');
		myFrame.setAttribute('width','100%');
		myFrame.setAttribute('scrolling','auto');
		myFrame.setAttribute('frameborder','0');
		iframeWrap.appendChild(myFrame);
		iframe_height = typeof(new_window_main_height_) == 'undefined' ?"478px":new_window_main_height_;
		document.getElementById('myFrame').setAttribute('src', src);
		document.getElementById('myFrame').style.height =iframe_height;
		document.getElementById('iframewrap').style.width = iframe_width;
		document.getElementById('myoverlay').style.display = "block";
		document.getElementById('myLightbox').style.display = "block";
		document.getElementById('myFrame').style.height =typeof(new_window_main_height_) == 'undefined' ?document.getElementById('iframewrap').offsetHeight +'px':new_window_main_height_;
		document.getElementById('iframewrap').height = document.getElementById('myFrame').style.height ;
	window.scroll(0,0);
	
}











function set_new_window_function(linkObj){
	if(linkObj.className.indexOf('new_window')>=0){
		linkOj.onclick = function() {
			anchor = this.href;
			if(anchor){
				new_window_custom(anchor);
/*				document.getElementById('myFrame').setAttribute('src', anchor);
				document.getElementById('myoverlay').style.display = "block";
				document.getElementById('myLightbox').style.display = "block";
				document.getElementById('myFrame').style.height =iframe_height;
				document.getElementById('iframewrap').style.width = iframe_width;
*/				window.scroll(0,0);
				//DO not redirect my page. Will you?
				return false;
			}
		}
	}
}
function GetPageSize(){
	var xScroll, yScroll;
	var windowWidth, windowHeight;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	dyWindowArrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return dyWindowArrayPageSize;
}
function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  
 var out = Array();
 out[0] = myWidth;
 out[1] = myHeight;
 return out;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

function addEvent(elm, evType, fn, useCapture){
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	}
}

addEvent (window,'load',new_window);