var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers

function jobPro(ppath,jpath)
{
	this.previewAdPath	= ppath;
	this.jobProPath		= jpath;
	this.previewad		= showAd;
	this.showIframe		= showIframe;
	createIframe();
}

function calcHeight()
{	
	/*	
	document.getElementById('ifrPreview').width='0%';
	document.getElementById('ifrPreview').height=0;
	*/
	var currentfr=document.getElementById('ifrPreview')        
	if (currentfr && !window.opera)
	{
		currentfr.width='100%';
		
		var fHeight	= 0;			
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) 
		{
			fHeight = currentfr.contentDocument.body.offsetHeight + FFextraHeight ;		
		}
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) 
		{
			fHeight = currentfr.Document.body.scrollHeight;																
		}
		
		currentfr.height = fHeight;			
		currentfr.style.display='block';
	}
	
}
function createIframe()
{	
	var iframeValue	= '<div id="demo1_iframe"><div style="margin-top:80px;position:relative;"><a href="javascript:resizeStyleClose(\'ifrPreview\',10,true);" id="closebutton" style="position:absolute;right:0px;top:0px;"><IMG SRC="http://localhost/job/upload/images/close.gif"></a><div style="width:100%;"><iframe name="ifrPreview" id="ifrPreview"  onLoad="calcHeight();" style="float:right;" frameborder="1" scrolling="no" src="" margin="0"  allowtransparency="no"></iframe></div></div></div>';		
	//var iframeValue	= '<div id="demo1_iframe">'
	//var iframeValue	=	'<div style="margin-top:80px;position:relative;border:1px;">
	//var iframeValue	=	'<a href="javascript:resize();" id="closebutton" style="position:absolute;right:0px;top:0px;"><IMG SRC="http://localhost/job/upload/images/close.gif"></a>'
	//var iframeValue	=	'<div><iframe name="ifrPreview" id="ifrPreview"  onLoad="calcHeight()" style="float:right;" frameborder="0" scrolling="no" src="" margin="0" allowtransparency="yes"></iframe>'
	//var iframeValue	=	'</div></div></div>';		
	document.getElementById('demo_iframe').innerHTML = iframeValue;
}
function showIframe(jobadid,jobid,tempid)
{

	var linkpath= this.jobProPath + "?jobadid="+jobid+"&jobid="+jobadid+"&tempid="+tempid+"";
	var frame = document.getElementById("ifrPreview");
	var frame_center = document.getElementById("demo_iframe");
	var frame_container = document.getElementById("body_opacity");
	frame.src = linkpath;
	frame_container.style.opacity = 0.5;
	frame_container.style.filter = 'alpha(opacity=' + 50 + ')';
	frame_container.style.BACKGROUND = '#c1ced9';
	frame_container.className = "show";
	frame_center.className = "show";	
	//frame.height = '500px';
	//frame.width = '400px';	
}


function showAd(link,status,jobadid,jobid,tempid)
{
	
		if(status == 1 && link != 3)
		{
			
			window.location.href	= this.previewAdPath + "?jobadid="+jobadid+"&jobid="+jobid+"";  // redirecting to same page till new design Ok 
			//this.showIframe(jobadid,jobid,tempid); // uncomment this for seeing the new design
			
			
			
			//resizeStyleOpen('ifrPreview',1,true);			
			//doResizeFrame(600);
			//window.location.href	= this.previewAdPath + "?jobadid="+jobadid+"&jobid="+jobid+"";    
			
		}
		else
		{
			window.location.href	= this.previewAdPath + "?jobadid="+jobadid+"&jobid="+jobid+"";  
		}	
}

//***********************frame resize function 
 
//var FFextraHeight=0;
var diffH = 0;
var diffW = 0;
var iLoop = 0;
function resizeStyleClose(frameid,sec,is1st)
{			
	if(is1st)				
	{
		diffH = 0;
		diffW = 0;
		document.getElementById("closebutton").className="hide";	
	}

	var currentfr=document.getElementById(frameid)        
	if (currentfr && !window.opera)
	{
		currentfr.style.display="block"
		currentfr.scrolling = "no"
		var tHeight = 0;
		var tWidth = 0;
		if( diffH == 0)
		{
			if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) 
			{
				tHeight = currentfr.contentDocument.body.offsetHeight + FFextraHeight ;
				tWidth = currentfr.contentDocument.body.offsetWidth + FFextraHeight ;													
			}
			else if (currentfr.Document && currentfr.Document.body.scrollHeight) 
			{
				tHeight = currentfr.Document.body.scrollHeight;													
				tWidth = currentfr.Document.body.scrollWidth;							
			}	
			diffH = ( tHeight / 100 ) * 10;
			diffW = ( tWidth / 100 ) * 10;					
		}
		else
		{
			tHeight = currentfr.height;
			tWidth = currentfr.width;						
		}			
		currentfr.height = tHeight - diffH;	
		currentfr.width = tWidth - diffW;
		if(currentfr.width > 2)
		{							
			setTimeout("resizeStyleClose('" + frameid + "'," + sec + ",false)", sec );
		}
		else
		{
			diffH = 0;
			diffW = 0;						
			
			var frame = document.getElementById("ifrPreview");
			var frame_center = document.getElementById("demo_iframe");
			var frame_container = document.getElementById("body_opacity");
			
			document.getElementById("closebutton").className="show";	
			frame.src = '';
			frame.className = "hide";			
			frame_center.className = "hide";	
			
			frame_container.style.opacity = 1;
			frame_container.style.filter = 'alpha(opacity=' + 100 + ')';
			frame_container.style.BACKGROUND = '';
			
		}
	}
}
var mHeight = 0;
var mxHeight = 600;
function resizeStyleOpen(frameid,sec,is1st)
{	
	var currentfr=document.getElementById(frameid)        
	if (currentfr && !window.opera)
	{
		var tHeight = 0;
		var tWidth = 0;
		var factor = 7;
		
		if( mHeight == 0)
		{
			if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) 
			{
				mHeight = currentfr.contentDocument.body.offsetHeight + FFextraHeight ;		
			}
			else if (currentfr.Document && currentfr.Document.body.scrollHeight) 
			{
				mHeight = currentfr.Document.body.scrollHeight;															
			}	
			mHeight = (mHeight > mxHeight)? mxHeight : mHeight;
			diffH = ( mHeight / 100 ) * factor;
			diffW = 1 * factor;
			
			currentfr.height = 0;
			currentfr.width = '0%';
			currentfr.scrolling = "no"
			document.getElementById("closebutton").className="hide";
		}
		currentfr.height = Number(currentfr.height) + Number(diffH);
		diffW = diffW + factor;
		currentfr.width = diffW.toString() + '%';
		if(currentfr.height  <= mHeight)
		{
			setTimeout("resizeStyleOpen('" + frameid + "'," + sec + ",false)", sec );
		}
		else
		{
			mHeight	= 0;
			diffH = 0;
			diffW = 0;	
			currentfr.scrolling = "yes"
			document.getElementById("closebutton").className="show";
		}
	}
	
}

