// If its not IE then it adds the mouse event
if (!document.all)
document.captureEvents(Event.MOUSEMOVE)

// On the move of the mouse, it will call the function getPosition
document.onmousemove = getPosition;

// These varibles will be used to store the position of the mouse
var X = 0
var Y = 0

// This is the function that will set the position in the above varibles 
function getPosition(args) 
{
  // Gets IE browser position
  if (document.all) 
  {
    X = event.clientX + document.body.scrollLeft
    Y = event.clientY + document.body.scrollTop
  }
  
  // Gets position for other browsers
  else 
  {  
    X = args.pageX
    Y = args.pageY
  }  
}
function backgroundFilter()
{
    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('backgroundFilter'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['backgroundFilter']; 
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&div.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the background is hidden ('none') then it will display it ('block').
    // If the background is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
}

function popUp()
{
    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('popupWindow'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['popupWindow']; 
    
	// if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&div.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the PopUp is hidden ('none') then it will display it ('block').
    // If the PopUp is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
    
    // Off-sets the X position by 15px
    X = X + 15;
    
    // Sets the position of the DIV
    //div.style.left = (X-305)+'px';
    //div.style.top = Y+'px';
	
}
function emailThisPost()
{
	//uem, una, rna, rem, comments
	var uem = "lexisONE.customer.support@cert.lexis-nexis.com";
	var una = document.getElementById('sendName').value;
	var uemail = document.getElementById('sendEmail').value;
	var rna = document.getElementById('recName').value;
	var rem  = document.getElementById('recEmail').value;
	var comments = document.getElementById('message').value;
	var url = escape(location.href);
	var tagLine = "( mailto:" + uemail +") has sent you the following link from the lexisONE Community.\n\n";
	var subj = "lexisONE Community";
	try
    {   new Ajax.Request('/lx1/emailThisPage',   
        {method:'post',     
		 onSuccess: function(transport)
		      {      
		       //alert("Success! \n\n" + transport.status); 
		       document.getElementById('sendName').value = '';
			   document.getElementById('sendEmail').value = '';
			   document.getElementById('recName').value = '';
			   document.getElementById('recEmail').value = '';
			   document.getElementById('message').value = '';
			   emailSent();
			   },     
		       onFailure: function()
		       { 
				alert("Failure! \n\n" + transport.status); 
		       } 
			    , parameters : "comments=" + comments + "&uem=" + uem + "&una=" + una + "&rna=" + rna + "&rem=" + rem +"&tagl=" + tagLine + "&subj=" +subj + "&url=" + url 
	           }
	        );
	 }
	 catch(err){
		 alert(err);
	 }
}
function emailSent()
{
    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('emailsent'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['emailsent']; 
	//apear for two second and then fade away..
	div.style.weight = 'bold';
	Effect.toggle('emailsent','appear');
	Effect.Fade('emailsent',{ duration:2.0 });
	Effect.toggle('popupWindow','slide',{ duration:2.0});
	backgroundFilter();

}

function checkEmailThis()
{
	var pass = true;			
	if(document.getElementById('recName').value.length == 0){
		pass = false;
		reqValChange('recName', false);
	}else{
		reqValChange('recName', true);
	}
	if(document.getElementById('recEmail').value.length == 0){
		pass = false;
		reqValChange('recEmail', false);
	}else{
		if(!checkEmailVal('recEmail')){
     		pass = false;
			reqValChange('recEmail', false);
		}else{
			reqValChange('recEmail', true);
		}
	}
	if(document.getElementById('sendName').value.length == 0){
		pass = false;
		reqValChange('sendName', false);
	}else{
		reqValChange('sendName', true);
	}
	if(document.getElementById('sendEmail').value.length == 0)
	{
		pass = false;
		reqValChange('sendEmail', false);
	}else{
		//CHECK FORMATING
		if(!checkEmailVal('sendEmail')){
			pass = false;
			reqValChange('sendEmail', false);
		}else{
			reqValChange('sendEmail', true);
		}
	}	
	//alert(pass);
	
	if(pass){
		emailThisPost();
	}	
}	 
function reqValChange(obj, b)
{
	var div;
    if(document.getElementById)
    div = document.getElementById(obj+"_div"); 
    else if(document.all) 
    div = document.all[obj+"_div"]; 
	if(b){
		div.style.color = '#000000';
	}else{
		div.style.color = '#cc0033';
	}
}
function checkEmailVal(obj)
{
	
  //check for @ and . in email address
  var emailVal = document.getElementById(obj).value;  
  var at_pos = -1;
  var dot_pos = -1;
  var tmp_pos;
  for (tmp_pos = 0; ((tmp_pos < emailVal.length) && (at_pos == -1)); tmp_pos++)
    if (emailVal.substr(tmp_pos, 1) == '@')
      at_pos = tmp_pos;
  for (tmp_pos = 0; ((tmp_pos < emailVal.length) && (dot_pos == -1)); tmp_pos++)
    if (emailVal.substr(tmp_pos, 1) == '.')
      dot_pos = tmp_pos;

  if ((at_pos < 1) || (dot_pos < 0)){
    return false;
  } else {
  	return true;
  }
  
}

