// JavaScript Document
function requestclose(){
	document.body.removeChild($('feedbackoverlay-requestcontact')); 
	document.body.removeChild($('feedbackouter-requestcontact'));
	document.body.scroll = 'auto';
	document.getElementsByTagName('html')[0].style.overflow = 'auto';
	document.getElementsByTagName('html')[0].style.overflowX = 'hidden';
	$('feedlink-requestcontact').setAttribute('onclick', 'loadContactWindow();');
	$('feedlink-requestcontact').style.cursor = 'pointer';
}
	
function loadContactWindow(symbol) {
	var feedbackoverlay = document.createElement('div');
	var feedbackouter = document.createElement('div');
	var fin1 = 0;
	var fin2 = 0;
	var scrollOffset = document.viewport.getScrollOffsets();
	var height = document.viewport.getHeight();
	var width = document.viewport.getWidth();
	var horizontalMargin = (width/2) - (724/2) + scrollOffset[0];
	var verticalMargin = (height/2) - (455/2) + scrollOffset[1];

	feedbackoverlay.setAttribute('id', 'feedbackoverlay-requestcontact');
	feedbackouter.setAttribute('id', 'feedbackouter-requestcontact');
	feedbackouter.setAttribute('style', 'position: absolute; top:'+verticalMargin+'px; left:'+horizontalMargin+'px;');
	
	url = "/request_contact/index/"+symbol;

	new Ajax.Request(url, {
		method: 'get', onCreate:function(){} ,
		onSuccess: function(transport){
			var response = transport.responseText;		
			
			feedbackouter.innerHTML = feedbackouter.innerHTML+response;
			
			document.body.appendChild(feedbackoverlay);
			feedbackoverlay.style.height = height + 5000 + "px";
			feedbackoverlay.style.width = width + 2000 + "px";
			
			document.body.appendChild(feedbackouter);
			feedbackouter.style.position = "absolute";
			feedbackouter.style.top = verticalMargin +'px'; 
			feedbackouter.style.left = horizontalMargin +'px';
			document.body.style.overflow = 'hidden';
			document.body.scroll = 'no';
			document.getElementsByTagName('html')[0].style.overflow = 'hidden'; 		
			$('feedlink-requestcontact').setAttribute('onclick', '');
			$('feedlink-requestcontact').style.cursor = 'default';
		}
	});		
}

function requestsubmit(symbol){
	$('onpage-requestcontact').value = document.location.href; 
	if (!$('phoneMethod').checked && !$('emailMethod').checked){
		alert('Please choose a communication method preference.');	
		return false;
	}		
	else if ($('comment-requestcontact').value == ""){
		alert('Please explain the nature of your request.');	
		return false;
	}
	else{	
		var url = "/request_contact/submit/"+symbol;
		new Ajax.Request(url,{
			parameters: $('feedbackform-requestcontact').serialize(true),
			method: 'post', onCreate:function(){
					$('feedbackmain-requestcontact').style.textAlign = 'center';
					$('feedbackmain-requestcontact').innerHTML = '<p>Sending...</p>';
			},
			onSuccess: function(transport){
				var response = transport.responseText;		
				
				//  need to remove random white space that suddenly is showing up? (Tim Fernihough: Jan 15, 2010)
				response = (response).replace(/^\s*|\s*$/g,'');
				
				if(response != 'success'){
					$('feedbackmain-requestcontact').innerHTML = '<p>'+response+'</p>';
				}
				else {
					document.body.removeChild($('feedbackoverlay-requestcontact')); 
					document.body.removeChild($('feedbackouter-requestcontact'));
					document.body.scroll = 'auto';
					document.getElementsByTagName('html')[0].style.overflow = ''; 
					$('feedlink-requestcontact').setAttribute('onclick', 'loadContactWindow();');
					$('feedlink-requestcontact').style.cursor = 'pointer';
				}			
			}
		});
	}
}
