
var gOptions = new Object();
function ClosePopup() {
	var Elem = top.document.getElementById('ShowIFrame_Cover');
	if(Elem)Elem.style.display = 'none';
	var Elem = top.document.getElementById('PopupLayerBorder');
	if(Elem)Elem.style.display = 'none';
	if(PopupTitleTimer) {
		window.clearInterval(PopupTitleTimer);
		PopupTitleTimer = null;		
	}
	
}

function ShowPopup(URL, width, height, Options) {
	Elem1 = makeFrame2('ShowIFrame_Cover');
	Elem1.style.display = 'none';
	Elem1.style.zIndex = 9000;

  var Size = WinSize();		

  /*Convert Width and height to string and check its a percentage*/
  var sWidth = width + '';
  var sHeight = height + '';
  if(sWidth.substr(sWidth.length-1,1) == '%') {
    var nWidth = parseInt(sWidth);
    width = parseInt(Size.width * nWidth / 100);
  }
  if(sHeight.substr(sHeight.length-1,1) == '%') {
    var nHeight = parseInt(sHeight);
    height = parseInt(Size.height * nHeight / 100);
  }
  /* End of Percentage Changes */

	var Center = WinCenter(width,height);	

	var OffsetY = 0;
	if(!top.window.pageYOffset) {
		if(!(top.window.document.documentElement.scrollTop == 0)) {
			offsetY = top.window.document.documentElement.scrollTop;
		} else {
			offsetY = top.window.document.body.scrollTop;
		}
	}	else {
		offsetY = top.window.pageYOffset;
	}
	offsetY += Size.height;
	Elem1.style.height=offsetY + 'px';

	//Show the layer
	var PopupLayer = top.document.getElementById('PopupLayerBorder');
	if(!PopupLayer) {		
		PopupLayer = top.window.document.createElement('DIV');
		top.window.document.body.appendChild(PopupLayer ); 
	}


	PopupLayer.id = 'PopupLayerBorder';
	PopupLayer.style.position='absolute';
	PopupLayer.style.zIndex = 9009;
	PopupLayer.style.position = 'absolute';
  PopupLayer.style.overflow = 'hidden';
	PopupLayer.style.top = Center.y + 'px';
	PopupLayer.style.left = Center.x + 'px';
	PopupLayer.style.width = width + 'px';
	PopupLayer.style.height= height + 'px';
	PopupLayer.style.display ='block';
	PopupLayer.style.border = '1px red none';

	PopupLayer.innerHTML = getPopupLayerContent(URL, width, height,Options);	
	
	if(Elem1) Elem1.style.display='block';	
	SetTitle();
	PopupTitleTimer = window.setInterval('SetTitle();',1000);	
}

function frameshowloading(ContentFrame) {
 if(ContentFrame.src!='about:blank') {
   document.getElementById('div_showloading').style.display='none';
 }
}

function getContentFromIframe(iFrameName) {
    var myIFrame = document.getElementById(iFrameName);
    var content = myIFrame.contentWindow.document.body.innerHTML;
    alert(myIFrame.contentWindow.document.forms.length)
    return content ;
    //Do whatever you need with the content    

}


function ActionOK() {
	//var IFRAME = top.window.frames['PopupIFrame'];
	if(!document.all){
	  var myIFrame = document.getElementById('PopupIFrame');
      var IFRAME = myIFrame.contentWindow
    }else {
      var IFRAME = top.window.frames['PopupIFrame'];
     }
     
	//If the function loaded inside the PopupURL call that;
	if(IFRAME.ActionOK_Modify) {
	  IFRAME.ActionOK_Modify();
	  return false;
	}

	var frames = '';
	var FormID = 0;
	var FrmObj = top.window.frames

	if(!IFRAME) return;

	if(IFRAME.document.forms.length == 0) {
  	  //  ClosePopup();
		return;
	}
	
	var FORMS = IFRAME.document.forms;
	if(FORMS['qListForm']) FormID = 'qListForm';
	var FORM = FORMS[FormID];
	
	var OnSubmit = FORM.onsubmit;
	var TheReturn = false;	
	if(OnSubmit) {
		TheReturn = OnSubmit();
		if(!TheReturn) return;
	}
	FORM.submit();

}

function getPopupLayerContent(URL, width, height, Options) {
	if(!Options) Options = new Object();
	if(Options['ButtonOk']+'' == 'undefined') Options['ButtonOk'] = 0;
	if(Options['ButtonOkOnClick']+'' == 'undefined') Options['ButtonOkOnClick'] = '0';
	if(Options['ButtonCancel']+'' == 'undefined') Options['ButtonCancel'] = 0;
	if(Options['ButtonCancelOnClick']+'' == 'undefined') Options['ButtonCancelOnClick'] = '0';
	if(Options['ButtonOkText']+'' == 'undefined') Options['ButtonOkText'] = 'Ok';
	if(Options['ButtonCancelText']+'' == 'undefined') Options['ButtonCancelText'] = 'Close';
	if(Options['HTMLPrefix']+'' == 'undefined') Options['HTMLPrefix'] = '';
	if(Options['HTMLSuffix']+'' == 'undefined') Options['HTMLSuffix'] = '';
	gOptions = Options

	var H = height - 80;

	var Content = '<form method="post" action="default.asp">\n'+
	'<table border="0" style="width:' + width + 'px; height:' + height + 'px;" cellspacing="0" cellpadding="0" class="popup_table">\n'+
	'<tr>\n'+
	'  <td class="r1c1">&nbsp;</td>\n'+
	'  <td class="r1c2"><a onclick="' + Options['ButtonCancelOnClick'] + ';ClosePopup(); return false;" class="close_button" href="#">&nbsp;</a>\n'+
	'  <div id="popup_head">...</div>\n'+
	'  </td>\n'+
	'  <td class="r1c3">&nbsp;</td>\n'+
	'</tr>\n'+
	'<tr>\n'+
	'  <td class="r2c1" style="height:' + H + 'px;">&nbsp;</td>\n'+
	'  <td class="r2c2" style="height:' + H + 'px;" valign="top">\n'+
	'  <iframe id="PopupIFrame" onload="frameshowloading(this);" name="PopupIFrame"  border="0" style="background-color:white; width: 100%; height: ' + H + 'px; border: 0px;" \n'+
	'  frameborder="0" src="'+ URL +'"></iframe></td>\n'+
	'  <td class="r2c3" style="height:' + H + 'px;">&nbsp;</td>\n'+
	'</tr>\n';

     Content +=
	  '<tr>\n'+
	  '  <td class="r3c1">&nbsp;</td>\n'+
	  '  <td class="r3c2" style="text-align: right; padding-bottom:8px;"><div id="TDPopupButtons" style="height:26px; overflow:hidden">';
	
	  if(Options['HTMLPrefix']!='') Content +=
	  Options['HTMLPrefix'] + '\n'
	  if(Options['ButtonOk']!=0) Content +=
	  '<input onClick="' + Options['ButtonOkOnClick'] + ';ActionOK(); return false"" name="PopupButtonOk" id="PopupButtonOk" type="submit" value="'+ Options['ButtonOkText'] +'">\n'
	  if(Options['ButtonCancel']!=0) Content +=
	  '<input onclick="'+ Options['ButtonCancelOnClick'] +';ClosePopup();" name="PopupButtonCancel" id="PopupButtonCancel" type="button" value="'+ Options['ButtonCancelText'] +'">';
	  if(Options['HTMLSuffix']!='') Content +=
	  Options['HTMLSuffix'] + '\n'

	  Content +=
	  '</div></td>\n' +
	  '  <td class="r3c3">&nbsp;</td>\n'+
	  '</tr>\n';

  Content +=
	'</table>\n'+
	'</form>';
	
	Content += 
	'<div id="div_showloading" style="padding:20px;">Loading...</div>';

	return Content;
}

function SetTitle(doc) {
  	try{
		var FRAME = top.frames['PopupIFrame'];
		top.document.title = FRAME.document.title;
		if(FRAME) {		
		top.document.getElementById('popup_head').innerHTML = FRAME.document.title;
		}
	} catch (e) {
	  if(top.name=='#CloseWindow') {
      top.name='';
      ClosePopup();
	  }
	  if(top.name=='#SubmitWindow') {
      top.name='';
      ClosePopup();
      if(gOptions['ButtonOk'] == 0){
        if(gOptions['ButtonOkOnClick'] != 0) eval(gOptions['ButtonOkOnClick'])
     	}
	  }
	//	alert(e.message)
	}
}
function makeFrame2(name) { 
	var ifrm = top.window.document.getElementById(name);
	if(!ifrm) {
	  ifrm = top.window.document.createElement("IFRAME"); 
	  ifrm.setAttribute("src", "about:blank"); 
	  ifrm.setAttribute("id", name); 
	  ifrm.setAttribute("name", name);
	  ifrm.setAttribute("frameborder", "0");  
	  ifrm.setAttribute("border", "0");  
	  top.window.document.body.appendChild(ifrm); 
	}
	return ifrm;
} 



function CloseFolder() {
	var Elem1 = document.getElementById('ShowIFrame_Content');
	if(Elem1) Elem1.style.display='none';
	var Elem2 = document.getElementById('ShowIFrame_Cover');
	if(Elem2) Elem2.style.display='none';
}

function WinCenter(width, height) {
	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	//IE
	if(!top.window.pageYOffset)
	{
		//strict mode
		if(!(top.window.document.documentElement.scrollTop == 0))
		{
			offsetY = top.window.document.documentElement.scrollTop;
			offsetX = top.window.document.documentElement.scrollLeft;
		}
		//quirks mode
		else
		{
			offsetY = top.window.document.body.scrollTop;
			offsetX = top.window.document.body.scrollLeft;
		}
	}
	//w3c
	else
	{
		offsetX = top.window.pageXOffset;
		offsetY = top.window.pageYOffset;
	}

	var Size = WinSize();
	_x = ((Size.width-width)/2)+offsetX;
	_y = ((Size.height-height)/2)+offsetY;

	return{x:_x,y:_y};
}

function WinSize() {
	var w = 0;
	var h = 0;

	//IE
	if(!top.window.innerWidth)
	{
		//strict mode
		if(!(top.window.document.documentElement.clientWidth == 0))
		{
			w = top.window.document.documentElement.clientWidth;
			h = top.window.document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = top.window.document.body.clientWidth;
			h = top.window.document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = top.window.innerWidth;
		h = top.window.innerHeight;
	}
	return {width:w, height:h};
}
//----------- above code added by mohammed on 09 aug,2009



