function EmailContent()
{
	var strBuilder="";		
	strBuilder+='<iframe id="MailIFrame" onload="DisableSelectMail(\'MailIFrame\');" src="" frameborder="0" scrolling="no" style="width:600px;position: absolute;visibility: hidden; top: 203px;left: 505px;border: solid 1px #red;height:170px;"></iframe>'; 		
	strBuilder += '<div id="MailDiv"   onmousedown=EmailZindex(); style="width: 600px;Z-index=1000; position: absolute; visibility: hidden; top: 203px;left: 505px; border: solid 2px #a7c7e7;" >';
	strBuilder += '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
	strBuilder += '<tr id="trHeadMail" title="Email - Double Click here to Minimize/Expand this window" style="height: 23px; cursor:move;  background: url(/images/bgMainMenuActive.gif) repeat-x;" onmousedown="dragMailBox(document.getElementById(\'MailDiv\'),event,document.getElementById(\'MailIFrame\')); return false;" ondblclick="">';
	strBuilder += '<td id="idSelect" style="width: 35%;text-align: left; border-bottom: solid 1px #a7c7e7;padding-left: 6px;">';
	strBuilder += '<b style="color:White; font-size:12px;">Send this link to a friend</b></td>';
	strBuilder += '<td style="text-align: right;width: 65%; padding: 0px 0px 0px 0px;margin: 5px 0px 5px 0px; border-bottom: solid 1px #a7c7e7;">';
	strBuilder += '<b id="idMin" style="cursor:pointer; font-size:16px; color:White;" title ="Minimize" onmouseover="ShadeMail(this)" onmouseout="RShadeMail(this)" onclick="MinimizeMailWindow(\'Email\');">';
	strBuilder += '&nbsp;_&nbsp;';
	strBuilder += '</b> <img id="idMax" src="/images/shape_square.png" title="Maximize" alt="Maximize" style="display:none;vertical-align:middle;border:solid 1px white;width:12px;height:12pxcursor:hand;cursor:pointer;" onclick="MinimizeMailWindow(\'Email\');"/>';
	strBuilder += '<b style="cursor:pointer; vertical-align:middle; font-size:16px; color:White;" id="CloseL" title="Close" onmouseover="ShadeMail(this)" onmouseout="RShadeMail(this)" onclick="HideDiv();">';
	strBuilder += '&nbsp;X&nbsp;';
	strBuilder += '</b></td></tr></table>';
	strBuilder += '<div id="Email" style="visibility:hidden; background-color:White;">';
	strBuilder+='<table border="0" cellpadding="0" celspacing="0">'; 
	strBuilder +='<tr>';
	strBuilder +='<td style="width:150px;text-align:right;padding-right:5px;vertical-align:top;color:#2F6496;">'; 
	strBuilder+='<b>Send To:</b>';
	strBuilder+='</td>';
	strBuilder +='<td>';
	strBuilder+='<input type="text" id="txtTo" name="txtTo" value="" style="width:450px;height:16px;"/>';  
	strBuilder+='</td>';
	strBuilder +='</tr>';
	strBuilder+='<tr>'; 
	strBuilder +='<td style="text-align:right;padding-right:5px;vertical-align:top;color:#2F6496;">';
	strBuilder +='<b>Comment :</b>'; 
	strBuilder+='</td>';
	strBuilder +='<td>';
	strBuilder+='<textarea id="txtComment" name="txtComment" value="" style="width:450px;height:80px;"></textarea>';  
	strBuilder+='</td>';
	strBuilder +='</tr>';
	strBuilder +='<tr>';
	strBuilder +='<td colspan="2" align="center">';
	strBuilder +='<button id="button" style="width:90px;cursor:hand;BORDER:0px; background-color: #fff;" onclick="javascript:PopupMail();return false;"><span style="DISPLAY: block; PADDING-LEFT: 4px;COLOR:#fff; FONT-WEIGHT: bold; BACKGROUND: url(/images/buttonBlue.png) no-repeat left 0px; LINE-HEIGHT: 17px; HEIGHT: 19px"><span id="emailright" style="PADDING-RIGHT: 4px; DISPLAY: block; FONT-WEIGHT: bold; BACKGROUND: url(/images/buttonBlue.png) no-repeat right 0px; LINE-HEIGHT: 17px; HEIGHT: 19px; TEXT-ALIGN: center;COLOR:#fff;">Send mail</span></span></button>';
	strBuilder +='</td>';
	strBuilder +='</tr>';
	strBuilder += '</table>';	
	strBuilder += '</div>';	
	strBuilder += '</div>';	
	return strBuilder;
}

function EmailZindex()
{	
	var id=document.getElementById('MailDiv');	
	var eid=document.getElementById('TimeZoneDiv');	
	var cid=document.getElementById('CalcMainDiv');	
	document.getElementById('trHeadMail').style.background="url(/images/bgMainMenuActive.gif) repeat-x";	
	if(eid)eid.style.zIndex="100";
	if(cid)cid.style.zIndex="100";	
	if(id)id.style.zIndex="2000";	
	document.getElementById('trHeadMail').style.background="url(/images/bgMainMenuActive.gif) repeat-x";	
}

var userEmailId=GetCookie("TN_UserId");
function showMailDiv(idValue)
{	
	//document.getElementById("EmailDiv").innerHTML = EmailContent();
			
	if(userEmailId!='')
	{
		var browsertype=window.navigator.userAgent;
		if(idValue!='shareDiv')
		{		
		var pos;
		if($('setperf')==null)
		{
		pos=getPosition("setprofile");
		}
		else
		{
		 pos=getPosition("setperf"); 
		}
		var top=document.body.clientTop?document.body.clientTop:0;
		top=top+parseInt(pos.y)+22;
		if(browsertype.indexOf("MSIE 7.0")>=0)
		{	
			document.getElementById('MailDiv').style.top=top;
			document.getElementById('MailIFrame').style.top=top;
		}else if(browsertype.indexOf("MSIE 6.0")>=0) 
		{
			 document.getElementById('MailDiv').style.top=top-71;
			 document.getElementById('MailIFrame').style.top=top-71;	 
		} else
		{
			document.getElementById('MailDiv').style.top=top+"px";
			document.getElementById('MailIFrame').style.top=top+"px";
		}
		document.getElementById('MailDiv').style.visibility='visible';
		document.getElementById('Email').style.visibility='visible';
		document.getElementById('MailIFrame').style.visibility='';	
		document.getElementById('MailIFrame').style.height='170px';
		document.getElementById('MailDiv').style.left='505px';
		document.getElementById('MailIFrame').style.left='505px';
		document.getElementById('MailDiv').style.zIndex="1000";				
		document.getElementById("MailDiv").style.height = '170px';
		document.getElementById("Email").style.height = '146px';				
		document.getElementById("idMin").style.display = '';
		document.getElementById("idMax").style.display = 'none';	
		EmailZindex();
		document.getElementById('trHeadMail').style.background="url(/images/bgMainMenuActive.gif) repeat-x";
		}else if(idValue=='shareDiv')
		{
			var pos;
			pos=getPosition("shareDiv");
			var top=document.body.clientTop?document.body.clientTop:0;
			top=top+parseInt(pos.y)+32;
			$("FooterMailDiv").innerHTML=EmailContent();
			if(browsertype.indexOf("MSIE 7.0")>=0)
			{	
				document.getElementById('MailDiv').style.top=top;
				document.getElementById('MailIFrame').style.top=top;
			}else if(browsertype.indexOf("MSIE 6.0")>=0) 
			{
				 document.getElementById('MailDiv').style.top=top-71;
				 document.getElementById('MailIFrame').style.top=top-71;	 
			} else
			{
				document.getElementById('MailDiv').style.top=top+"px";
				document.getElementById('MailIFrame').style.top=top+"px";
			}
			document.getElementById('MailDiv').style.visibility='visible';
			document.getElementById('Email').style.visibility='visible';
			document.getElementById('MailIFrame').style.visibility='';	
			document.getElementById('MailIFrame').style.height='170px';
			document.getElementById('MailDiv').style.left='300px';
			document.getElementById('MailIFrame').style.left='300px';
			document.getElementById('MailDiv').style.zIndex="1000";				
			document.getElementById("MailDiv").style.height = '170px';
			document.getElementById("Email").style.height = '146px';				
			document.getElementById("idMin").style.display = '';
			document.getElementById("idMax").style.display = 'none';	
			EmailZindex();
			document.getElementById('trHeadMail').style.background="url(/images/bgMainMenuActive.gif) repeat-x";	
		}		
	}else
	{
		alert('Please Login');
	}
}

function HideDiv()
{
	document.getElementById('MailDiv').style.visibility='hidden';
	document.getElementById('Email').style.visibility='hidden';
	document.getElementById('MailIFrame').style.visibility='hidden';
}

function DisableSelectMail(id) 
{	
	document.getElementById(id).onselectstart = function() {return false;} // ie
	document.getElementById(id).onmousedown = function() {return false;} // mozilla
	
}
function getValues()
{
	var recepient=document.getElementById('txtTo').value;
	var comment=document.getElementById('txtComment').value;
	var url=location.href;	
}


//Global Variables for Email.
var AgainOpn=false;
var strMemory="0";
var PrimaryNo=parseFloat("0");
var CurrentOpn="";
var OpnSelected=false;

//Minimize Window is the function to Minimise Currency Gadjet Window.
//To Minimise Current Window to Bottom.
//<params> Div Id  </params>
function MinimizeMailWindow(divID)
{
	//Code here for Minimising Div.
	if(document.getElementById(divID).style.visibility == 'visible')
	{	
		document.getElementById(divID).style.visibility = 'hidden';
		document.getElementById("MailDiv").style.height = '21px';		
		document.getElementById("Email").style.height = '21px';		
		document.getElementById("MailIFrame").style.height = '21px';
		document.getElementById("idMin").style.display = 'none';
		document.getElementById("idMax").style.display = '';			
	}
	else
	{
		document.getElementById(divID).style.visibility = 'visible';
		document.getElementById("MailDiv").style.height = '170px';
		document.getElementById("Email").style.height = '146px';		
		document.getElementById("MailIFrame").style.height = '170px';
		document.getElementById("idMin").style.display = '';
		document.getElementById("idMax").style.display = 'none';								
	}	
}

///Drag Object.
// This will Drag object corresponding to the Cursor Movement.
function $(s) 
{ 
	return(document.getElementById(s)); 
}

function Mailagent(s) 
{ 
	return(Math.max(navigator.userAgent.toLowerCase().indexOf(s),0)); 
}

function xy(e,s) 
{ 
	return(s?(Mailagent('msie')?event.clientY+document.body.scrollTop:e.pageY):(Mailagent('msie')?event.clientX+document.body.scrollTop:e.pageX)); 
} 
//document.getElementById('trHeadMail');
function dragMailBox(d,e,ifid) 
{ 		
	function drag(e) 
	{ 
		document.getElementById('trHeadMail').style.background="url(/images/bgMainMenuActive.gif) repeat-x";
		if(!stop) 
		{ 
			d.style.top=(tX=xy(e,1)+oY-eY+'px'); 
			d.style.left=(tY=xy(e)+oX-eX+'px'); 
			ifid.style.top=(tX=xy(e,1)+oY-eY+'px'); 
			ifid.style.left=(tY=xy(e)+oX-eX+'px'); 
			//alert(document.getElementById('MailDiv').style.top+','+document.getElementById('MailDiv').style.left);
			//controlDrag(d,ifid);
		} 
	} 	
	var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop; 	
	document.onmousemove=drag; document.onmouseup=function()
	{ 
		stop=0; 
		document.getElementById('trHeadMail').style.background="url(/images/bgMainMenuActive.gif) repeat-x";
		document.onmousemove=''; 
		document.onmouseup=''; 
	}; 
}

//Make shading while Cursor Moves.

function ShadeMail(ctl)
{
	ctl.style.background="#1A5083";
}

// Remove Shading while Cursor Out.
function RShadeMail(ctl)
{
	ctl.style.background="";	
}

function PopupMail()
{				
	if(ValidateForm()==true){
	var to=document.getElementById('txtTo').value; 
	var Message=document.getElementById('txtComment').value; 
	var url=location.href; 
	var logUserName=document.getElementById('logeduserName').value;
	
	var test=FinancialExpress.EmailComponent.EmailCreator.sendPopupMail(to,Message,url,logUserName,emailSiteCode+','+emailSitemailid+','+emailDomain+','+emailSiteName+','+siteUserEmail);	
	document.getElementById('txtTo').value=''; 
	document.getElementById('txtComment').value=''; 
	document.getElementById('MailDiv').style.visibility='hidden';
	document.getElementById('Email').style.visibility='hidden';	
	document.getElementById('MailIFrame').style.visibility='hidden';	
	}
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

	 if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

	 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

	 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

	 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		if(str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
 		 return true
	}
	function ValidateForm(){	
	if(document.getElementById('MailDiv').style.visibility=="visible")
	{
		var emailID=document.getElementById('txtTo');			
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
		return true
	}
 }
 


function controlDrag(d,ifid)
{			
	var totalLeft=parseInt(d.style.left.replace('px',''))+600;	
	var totalTop=parseInt(d.style.top.replace('px',''))+d.style.height.replace('px','');		
	var pageWidth =window.screen.width;		
	var pageHeight=window.screen.height;
	
	if(totalLeft>(pageWidth-1))
	{	
		if(d.style.top.replace('px','')<0 || (d.style.top<"0px"))
		{			
			if (navigator.appName.indexOf("Microsoft") == -1) {
				d.style.left=pageWidth-605+"px";
				ifid.style.left=pageWidth-605+"px";
			}							
				d.style.left=pageWidth-605;
				ifid.style.left=pageWidth-605;
				
			d.style.top=0;
			ifid.style.top=0;
			if (navigator.appName.indexOf("Microsoft") == -1) {
			 d.style.top=0+"px";
			 ifid.style.top=0+"px";			
			 }
		}else if(totalTop>(pageHeight))
		{
			if (navigator.appName.indexOf("Microsoft") == -1) {
				d.style.left=pageWidth-605+"px";
				ifid.style.left=pageWidth-605+"px";
			}							
				d.style.left=pageWidth-605;
				ifid.style.left=pageWidth-605;
			if (navigator.appName.indexOf("Microsoft") == -1) {
				var topmoz=pageHeight -d.style.height.replace('px','');
				d.style.top=topmoz+"px";
				ifid.style.top=topmoz+"px";
			}
			d.style.top=pageHeight-d.style.height.replace('px','');	
			ifid.style.top=pageHeight-d.style.height.replace('px','');				 
		}else
		{
			if (navigator.appName.indexOf("Microsoft") == -1) {
				d.style.left=pageWidth-605+"px";
				ifid.style.left=pageWidth-605+"px";
			}							
			d.style.left=pageWidth-605;
			ifid.style.left=pageWidth-605;		
		}
	}	
	else if(d.style.left.replace('px','')<0|| (d.style.left<'0px'))
	{	
		if(d.style.top.replace('px','')<0 || (d.style.top<"0px"))
		{					
			d.style.left=0;	
			ifid.style.left=0;	
			if (navigator.appName.indexOf("Microsoft") == -1) {
			 d.style.left=0+"px";
			 ifid.style.left=0+"px";
			}	
			d.style.top=0;
			ifid.style.top=0;
			if (navigator.appName.indexOf("Microsoft") == -1) {
			 d.style.top=0+"px";
			 ifid.style.top=0+"px";
			 }
		}else if(totalTop>(pageHeight))
		{
			d.style.left=0;	
			ifid.style.left=0;	
			if (navigator.appName.indexOf("Microsoft") == -1) {
			 d.style.left=0+"px";
			 ifid.style.left=0+"px";
			}	
			if (navigator.appName.indexOf("Microsoft") == -1) {
				var topmoz=pageHeight -d.style.height.replace('px','');
			d.style.top=topmoz+"px";
			ifid.style.top=topmoz+"px";
			}
			d.style.top=pageHeight-d.style.height.replace('px','');			
			ifid.style.top=pageHeight-d.style.height.replace('px','');			
		}
		else
		{						
			d.style.left=0;
			ifid.style.left=0;	
			if (navigator.appName.indexOf("Microsoft") == -1) {
			 d.style.left=0+"px";
			 ifid.style.left=0+"px";
			}	
		}			
	}	
	else if(totalTop>(pageHeight))
	{					
		if (navigator.appName.indexOf("Microsoft") == -1) {
			var topmoz=pageHeight -d.style.height.replace('px','');
			d.style.top=topmoz+"px";
			ifid.style.top=topmoz+"px";
		}
		d.style.top=pageHeight-d.style.height.replace('px','');
		ifid.style.top=pageHeight-d.style.height.replace('px','');		
	}	
	else if(d.style.top.replace('px','')<0 || (d.style.top<"0px"))
	{
		d.style.top=0;
		ifid.style.top=0;
		if (navigator.appName.indexOf("Microsoft") == -1) {
		 d.style.top=0+"px";
		 ifid.style.top=0+"px";
		}	
	}				
}