function openPOPupWindow(actionPage,t,key)
{
	var rootPath = WWWROOT;

	var w = (screen.width - 530)/2;
	var h = (screen.height - 380)/2 - 60;

	features= 'width='+510+',height='+280+',top='+h+',left='+w;
	LoginPage = rootPath+"/custompages_popup_login.php?t="+t+"&key="+key+"&apage="+actionPage;

	popupWindow('overlay',LoginPage,440,235,'<b>LOGIN</b>');
	o();
	/*
	win = window.open(LoginPage,'Login',features);
	if (parseInt(navigator.appVersion) >= 4)
	{
			win.window.focus();
	}
	*/
}

function o()
{
	el = document.getElementById("overlay");
	//el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	el.style.visibility = (el.style.visibility == "hidden") ? "visible" : "visible";
	
	e2 = document.getElementById("overlayMain");
	//e2.style.visibility = (e2.style.visibility == "visible") ? "hidden" : "visible";
	e2.style.visibility = (e2.style.visibility == "hidden") ? "visible" : "visible";
			
}
		
function removeElement() 
{
	/*if(!mortgageForm)
	{
		mortgageForm = '';	
	}
	if(mortgageForm == 'mortgage')
	{
		alert('here');
		if(newLinks == 1)
			parent.window.location.href = '/custompages_formsubmitted.php';	
		else
			parent.window.location.href = 'custompages_formsubmitted.php';	
	}*/

	var b_version=navigator.appVersion;
	if(b_version.match('MSIE 6.0')!=null) //MSIE 6.0  Done by bhawdeep
	{
		if(parent.window.document.forms.length>0)
		{
			for(var j=0; j<parent.window.document.forms.length ;j++)
			{
				if(parent.window.document.forms[j])
				{
					 var arrSelect=parent.window.document.forms[j].getElementsByTagName("SELECT");
					  for (var i=0; i<arrSelect.length; i++)
					  {
							if (arrSelect[i].type == 'select-one' || arrSelect[i].type == 'select-multiple')
							{
								arrSelect[i].style.display='';
							}
					   }
				  }
			  }
		 }
   }

	if(parent.document.getElementById('txtMsgContents'))
		parent.document.getElementById('txtMsgContents').focus();
	if(parent.document.getElementById('txtFirstName'))
		parent.document.getElementById('txtFirstName').focus();

	var d = document.getElementById('overlayMain');
	var olddiv = document.getElementById('overlay');
	d.removeChild(olddiv);
  
	e2 = document.getElementById("overlayMain");
	e2.style.visibility = (e2.style.visibility == "visible") ? "hidden" : "visible";

	
	//e2.style.visibility =  "hidden" ;
}

function removeElement1() 
{
	var b_version=navigator.appVersion;
	if(b_version.match('MSIE 6.0')!=null) //MSIE 6.0  Done by bhawdeep
	{
		if(parent.window.document.forms.length>0)
		{
			for(var j=0; j<parent.window.document.forms.length ;j++)
			{
				if(parent.window.document.forms[j])
				{
					 var arrSelect=parent.window.document.forms[j].getElementsByTagName("SELECT");
					  for (var i=0; i<arrSelect.length; i++)
					  {
							if (arrSelect[i].type == 'select-one' || arrSelect[i].type == 'select-multiple')
							{
								arrSelect[i].style.display='';
							}
					   }
				  }
			  }
		 }
   }

	if(document.getElementById("hdnIsRefresh") && document.getElementById("hdnIsRefresh").value == 1)
		parent.window.location.href = parent.window.location.href; //parent.window.location.href = "idx_detail.php?id=<?=$_GET['id']?>";	
	
	removeElement();
}

function popupWindow(name, url, width, height, title)
{
	var b_version=navigator.appVersion;
	if(b_version.match('MSIE 6.0')!=null) //MSIE 6.0  Done by bhawdeep
	{
		if(parent.window.document.forms.length>0)
		{
			for(var j=0; j<parent.window.document.forms.length ;j++)
			{
				if(parent.window.document.forms[j])
				{
					 var arrSelect=parent.window.document.forms[j].getElementsByTagName("SELECT");
					  for (var i=0; i<arrSelect.length; i++)
					  {
							if (arrSelect[i].type == 'select-one' || arrSelect[i].type == 'select-multiple')
							{
								arrSelect[i].style.display='none';
							}
					   }
				  }
			  }
		 }
   }

	var strSiteRoot = WWWROOT;
	//var strUrl = strSiteRoot + "/"+ url;
	
	var strUrl = url;
				
	var ua = navigator.userAgent.toLowerCase();
	isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
	isGecko = (ua.indexOf("gecko") != -1);
	isSafari = (ua.indexOf("safari") != -1);
	isKonqueror = (ua.indexOf("konqueror") != -1);
	
	if (window.innerHeight && window.scrollMaxY) 
	{
		// Firefox
		browseHeight = window.innerHeight + window.scrollMaxY;
		//browseWidth = window.innerWidth + window.scrollMaxX;
		browseWidth = window.innerWidth - 20;
	}
	 /*else if (screen.availHeight > document.body.offsetHeight){ // all but Explorer Mac
		browseHeight = screen.availHeight;
		browseWidth = screen.availWidth;
		
		//browseHeight = document.body.scrollHeight;
		//browseWidth = document.body.scrollWidth;
	} */
	else 
	{ 
		// works in Explorer 6 Strict, Mozilla (not FF) and Safari

		browseHeight = document.body.scrollHeight;
		browseWidth = screen.availWidth - 22;
		//browseHeight = document.body.offsetHeight;
		//browseWidth = document.body.offsetWidth;
	}
	
	/*******************************************************/
	
	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
	position = 2;
	var version4 = (navigator.appVersion.charAt(0) == "4"); 
	evnt = version4 ? event : null;
	
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
		screenY = document.body.offsetHeight + 150;
		screenX = window.screen.availWidth;
		//screenY = document.body.scrollTop;
		//screenX = window.screen.availWidth;
	}
	else 
	{
		screenY = window.outerHeight;
		screenX = window.outerWidth;
	}

	leftvar = (screenX - width) / 2;
	rightvar = (screenY - height) / 2;
	//rightvar = screenY;
	
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
		//leftprop = leftvar;
		//topprop = rightvar;
		
		leftprop = document.body.scrollLeft + ((screenX - width) / 2);
		
		if (window.pageYOffset)
		{
			  topprop = window.pageYOffset
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		{
			topprop = document.documentElement.scrollTop
		}
		else if (document.body)
		{
			  topprop = document.body.scrollTop
		}				
		topprop = topprop + 30; 
		//topprop = document.documentElement.scrollTop + 40;
	}
	else 
	{
		//leftprop = (leftvar - pageXOffset);
		//topprop = parseInt(rightvar - pageYOffset);
		
		leftprop = pageXOffset  + ((screenX - width) / 2);
		topprop = parseInt(pageYOffset + 40,10);
   }

	/********************************************************/
	
	if(screen.height >= height)
		{windowTop = ((screen.height - height)/2) - 80;}
	else
		{windowTop = 0;}
		
	if(screen.width >= width)
		{windowLeft = (screen.width - width)/2;}
	else
		{windowLeft = 0;}
	//alert(windowTop);
	
	windowLeft = leftprop;
	windowTop = topprop;
	//alert(topprop);
	//alert('Page : ' + pageYOffset + ', ' + pageXOffset + ' ---Screen : ' + windowTop + ', ' + windowLeft + ' --- Window : ' + browseHeight + ', ' + browseWidth);
	
	if(isIE)
	{
		frameDivWidth = width;
		frameInnerDivWidth = width;
		frameDivHeight = height-28;
		frameWidth = '100%';
		frameHeight = frameDivHeight - 10;
		lastRowHeight = "8";
	}	
	else
	{
		frameDivWidth = width;
		frameInnerDivWidth = width;
		frameDivHeight = height-20;
		frameWidth = '100%';
		frameHeight = frameDivHeight - 10;
		lastRowHeight = "8";				
	}
	InerframeTableHeight = frameDivHeight - 40;
	if(document.getElementById("overlay"))
	{
		var d = document.getElementById('overlayMain');
		var olddiv = document.getElementById('overlay');
		d.removeChild(olddiv);
	  
		e2 = document.getElementById("overlayMain");
		e2.style.visibility = (e2.style.visibility == "visible") ? "hidden":'';	
	}
	
	var newMainDiv=document.createElement('div');
	newMainDiv.setAttribute('id','overlayMain');
	newMainDiv.style.width= browseWidth+'px';
	newMainDiv.style.height=  browseHeight+'px';
	
	newMainDiv.style.padding = "0px";
	newMainDiv.style.textAlign = "left";
	newMainDiv.style.left = "0px";
	newMainDiv.style.top = "0px";

	newMainDiv.style.position="absolute";
	newMainDiv.style.visibility="hidden";
	newMainDiv.style.backgroundImage = "url(/images/overlay.gif)";
	
	/*** Inner Main Div ***/
	var newDiv=document.createElement('div');
	var h = height;
	var w = width;
	
	 newDiv.setAttribute('id',name);
	
	newDiv.className="divBorderStyle";
	//newDiv.style.border = borderClass;
	newDiv.style.width= w + "px";
	newDiv.style.height= h + "px";
	newDiv.style.padding = "0px";
	newDiv.style.textAlign = "left";
	newDiv.style.left = windowLeft+"px";
	newDiv.style.top = windowTop+"px";

	newDiv.style.position="relative";
	newDiv.style.visibility="hidden";
	newDiv.style.overfilter="Alpha(opacity=90)";
	//alert("FW" + frameDivWidth);
	var middleTDwidth1 = frameDivWidth  - 24;
	var middleTDwidth2 = frameDivWidth  - 16;
	
if(url.indexOf("idx_editshowing.php") != -1 || url.indexOf("local_editshowing.php") != -1){
newDiv.innerHTML = '<div  class="divBgImage" style="verticle-align:top;overflow:hidden;border:0px; text-align:left;width:'+frameDivWidth+'px;cursor:default;color:#ffffff; font-family:MS Sans Serif, Arial, Helvetica, sans-serif; font-size:1px; font-weight:bold; margin:0px; padding:0px 0px 0px 0em; white-space:nowrap" ><table border=0 height=28 width="+frameDivWidth+" cellpadding="0" cellspacing="0" style="border:none;"><tr><td width="8"><img src="'+strSiteRoot+'/images/popleft.gif" border="0" width=8></td><td width='+middleTDwidth1+' background="'+strSiteRoot+'/images/popcenter.gif" style="font-size:12px;color:#365a94;font-family:sans-serif;">&nbsp;&nbsp;<b>'+title+'</b></td><td width="8" valign="middle" background="'+strSiteRoot+'/images/popcenter.gif"><a href="" title="Close" onClick="removeElement1();return false;"><img alt="" align=right valign="middle" border=0 src="'+strSiteRoot+'/images/close-btn.gif" /></a></td><td width="8" height=28><img src="'+strSiteRoot+'/images/popright.gif"  border="0"></td></tr></table></div><div style="border:none; padding-top:40px; text-align:left;width:'+frameInnerDivWidth+'px;height:'+ frameDivHeight +'px;cursor:default; color:#ffffff; font-family:MS Sans Serif, Arial, Helvetica, sans-serif; font-size:8px; font-weight:bold; margin:0px; padding:0px 0px 0px 0em; white-space:nowrap" style="background-repeat:no-repeat;"><table border=0 bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" width="+frameDivWidth+" height='+ frameDivHeight +'px; style="border:none;"><tr><td width="8"  background="'+strSiteRoot+'/images/popbodyleft.gif" style="background-repeat:repeat-y; "></td><td width='+middleTDwidth2+' valign="middle" colspan="2"><iframe allowtransparency="true" frameborder="0" style=" margin-right:0px;margin-bottom:5px;" name="testFrame" id="testFrame" width="'+frameWidth+'" height="'+frameHeight+'" src="'+strUrl+'" scrolling="YES" >If you see this you browser dosen\'t support iframes.</iframe></td><td width="8"  background="'+strSiteRoot+'/images/popbodyright.gif" style="background-repeat:repeat-y; "></td></tr><tr height="'+lastRowHeight+'"><td width="8" height="'+lastRowHeight+'" background="'+strSiteRoot+'/images/popfooterleft.gif" style="background-repeat:no-repeat;vertical-align:bottom;"></td><td width="534" height="'+lastRowHeight+'" valign="middle" colspan="2" background="'+strSiteRoot+'/images/popfootercenter.gif" style="background-repeat:repeat-x;vertical-align:bottom;"></td><td width="8" height="'+lastRowHeight+'" background="'+strSiteRoot+'/images/popfooterright.gif" style="background-repeat:no-repeat;vertical-align:bottom;"></td></tr></table></div>';
//alert(newDiv.innerHTML);
}
else{


	newDiv.innerHTML = '<div  class="divBgImage" style="verticle-align:top;overflow:hidden;border:0px; text-align:left;width:'+frameDivWidth+'px;cursor:default;color:#ffffff; font-family:MS Sans Serif, Arial, Helvetica, sans-serif; font-size:1px; font-weight:bold; margin:0px; padding:0px 0px 0px 0em; white-space:nowrap"><table border=0 height=28 width="+frameDivWidth+" cellpadding="0" cellspacing="0" style="border:none;"><tr><td width="8"><img src="'+strSiteRoot+'/images/popleft.gif" border="0" width=8></td><td width='+middleTDwidth1+' background="'+strSiteRoot+'/images/popcenter.gif" style="font-size:12px;color:#365a94;font-family:sans-serif;">&nbsp;&nbsp;<b>'+title+'</b></td><td width="8" valign="middle" background="'+strSiteRoot+'/images/popcenter.gif"><a href="" title="Close" onClick="removeElement1();return false;"><img alt="" align=right valign="middle" border=0 src="'+strSiteRoot+'/images/close-btn.gif" /></a></td><td width="8" height=28><img src="'+strSiteRoot+'/images/popright.gif"  border="0"></td></tr></table></div><div style="border:none; padding-top:40px; text-align:left;width:'+frameInnerDivWidth+'px;height:'+ frameDivHeight +'px;cursor:default; color:#ffffff; font-family:MS Sans Serif, Arial, Helvetica, sans-serif; font-size:8px; font-weight:bold; margin:0px; padding:0px 0px 0px 0em; white-space:nowrap" style="background-repeat:no-repeat;"><table border=0 bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" width="+frameDivWidth+" height='+ frameDivHeight +'px; style="border:none;"><tr><td width="8"  background="'+strSiteRoot+'/images/popbodyleft.gif" style="background-repeat:repeat-y; "></td><td width='+middleTDwidth2+' valign="middle" colspan="2"><iframe allowtransparency="true" frameborder="0" style=" margin-right:0px;margin-bottom:5px;" name="testFrame" id="testFrame" width="'+frameWidth+'" height="'+frameHeight+'" src="'+strUrl+'" >If you see this you browser dosen\'t support iframes.</iframe></td><td width="8"  background="'+strSiteRoot+'/images/popbodyright.gif" style="background-repeat:repeat-y; "></td></tr><tr height="'+lastRowHeight+'"><td width="8" height="'+lastRowHeight+'" background="'+strSiteRoot+'/images/popfooterleft.gif" style="background-repeat:no-repeat;vertical-align:bottom;"></td><td width="534" height="'+lastRowHeight+'" valign="middle" colspan="2" background="'+strSiteRoot+'/images/popfootercenter.gif" style="background-repeat:repeat-x;vertical-align:bottom;"></td><td width="8" height="'+lastRowHeight+'" background="'+strSiteRoot+'/images/popfooterright.gif" style="background-repeat:no-repeat;vertical-align:bottom;"></td></tr></table></div>';
//alert(newDiv.innerHTML);
}

	document.body.appendChild(newMainDiv);
	document.getElementById('overlayMain').appendChild(newDiv);
}


        
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    {dragObj.elNode = document.getElementById(id);}
  else {
    if (browser.isIE)
      {dragObj.elNode = window.event.srcElement;}
    if (browser.isNS)
      {dragObj.elNode = event.target;}

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      {dragObj.elNode = dragObj.elNode.parentNode;}
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) {dragObj.elStartLeft = 0;}
  if (isNaN(dragObj.elStartTop))  {dragObj.elStartTop  = 0;}

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    {event.preventDefault();}
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

/*window.onresize = resizeLayer;

function resizeLayer()
{
	if (window.innerHeight && window.scrollMaxY) 
	{
		// Firefox
		
		browseHeight = window.innerHeight + window.scrollMaxY;
		browseWidth = window.innerWidth + window.scrollMaxX;
		
		document.getElementById("overlayMain").style.width= browseWidth+'px';
        document.getElementById("overlayMain").style.height=  browseHeight+'px';
	} 
	else 
	{ 
		// works in Explorer 6 Strict, Mozilla (not FF) and Safari
		
		browseHeight = document.body.scrollHeight - 100;
		browseWidth = screen.availWidth - 22;
		
		//e2 = document.getElementById("overlayMain");
		//e2.style.visibility = "hidden";
		
		document.getElementById("overlayMain").style.width= browseWidth+'px';
        document.getElementById("overlayMain").style.height=  browseHeight+'px';	
		//e2.style.visibility = "visible";
	}	
}
*/

function DoExtPopup2(page,style,centered,popwidth,popheight,scrollbars,resizable)
{
	var ppleft;
	var pptop;

	// style=1 - same window; 2=new default; 3=new with parms below
	if (style==3) {
		if (centered && popwidth && popheight) {
			ppleft = (window.screen.width - popwidth) / 2;
			pptop = (window.screen.height - popheight) / 2;
		}
		else {
			ppleft = 0;
			pptop = 0;
		}

		popwin = window.open(page,'external',
		'width=' + popwidth + ','+',height=' + popheight + ',left=' + ppleft + ','+
		'top=' + pptop + ',scrollbars=' + scrollbars + ','+
		'resizable=' + resizable + ',status=0,menubar=0,toolbar=0,'+
		'location=0,directories=0,copyhistory=0');
	}
	else if (style==2){
		popwin = window.open(page,'external');
	}
	else {
			window.location = page;
	}
}
