var site_url = 'http://www.pediworld.com/';

function myaccount() {
		//new Ajax.Request('http://192.168.10.126/7strategy/pediworld/my_account/login/1', {
		new Ajax.Request('http://www.pediworld.com/my_account/login/1',{
			method: 'get',
			onSuccess:function(response) {
				var opacity_div = document.createElement('div');
				opacity_div.id = 'opacity_div';
				
				opacity_div.style.position = 'absolute';
				opacity_div.style.top = '0px';
				opacity_div.style.left = '0px';
				opacity_div.style.height = sizes(1).toString() + 'px';
				opacity_div.style.width = '100%';
				opacity_div.style.backgroundColor = '#000000';
				opacity_div.style.zIndex = '10';
				opacity_div.style.opacity = '0.5';
				opacity_div.style.filter = 'alpha(opacity=50)';
				
				var general = document.getElementById('general');
				general.appendChild(opacity_div);
				
				var div = document.createElement('div');
				div.id = 'login_div';
				
				div.style.position = 'absolute';
				div.style.top = '150px';
				div.style.width = '771px';
				div.style.height = '524px';
				div.style.zIndex = '20';
			
				var main = document.getElementById('main');
			
				div.innerHTML = response.responseText;
				
				$('main').insertBefore(div,$('main').firstChild);

				$('close').onclick = function () {
					main.removeChild(div);
					general.removeChild(opacity_div);
				
					var select_list = document.getElementsByTagName('select');
					var select;
					for (var a = 0; select = select_list[a]; a++) {
						$(select).show()
					}

					return;
				}
				
				var forms = $('login').getElementsByTagName('form');
				
				for (var a = 0; a < forms.length; a++) {
					forms[a].onsubmit = function() {
						var parameters = $(this).getElementsByTagName('input');
						var values = {};
						for (var b = 0; b < parameters.length; b++) values[parameters[b].name] = parameters[b].value;

							new Ajax.Request(this.action + '/1',{
							method: 'post',
							parameters: $H(values).toQueryString(),
							onSuccess: function(response) {
								if (response.responseText.indexOf('http') === 0) location.href = response.responseText;
								else $('error').innerHTML = response.responseText;
							}
						});
						return false;
					}
				}
				
				var select_list = document.getElementsByTagName('select');
				var select;
				for (var a = 0; select = select_list[a]; a++) {
					$(select).hide()
				}
			},
			onFailure: function (error) {
				alert(error);
			}
		});
		
		return;
	}

function forgot_pass() {
	var confirmation = confirm("If you proceed, your password will be reseted and a new password will be sent to your email address");
	var mail = $('login_email').value;
	if(!mail) {
		alert("Please insert your email address so we can send you a new password");
		return;
	}
	if(mail.indexOf('@')<1 || mail.indexOf('.') < 1) {
		alert("Please insert a valid email address");
		return;
	}
	new Ajax.Request(site_url + 'my_account/forgot_pass',{
		method: 'post',
		parameters: {mail:mail},
		onSuccess: function(trans){
			try{
				var response = eval('('+trans.responseText+')');
			} catch(e) {
				alert("Wrong response from the server. Please try Again");
				return;
			}
			if(response.error) {
				alert(response.error);
				return;
			} else {
				alert("A new password has been sent to your email address");
				//window.location.reload();
				return;
			}
		}
	});
}

Event.observe(window,'load',function(){
	var myaccount_bt = $('floating_menu_my_account');
	if(myaccount_bt) myaccount_bt.onclick = function() {myaccount(); return false;};
});

function sizes(type){
	if( window.innerHeight && window.scrollMaxY ) // Firefox 
	{
		pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY;
	}
	else {
		if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
		{
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
		}
		else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		{ pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
		  pageHeight = document.body.offsetHeight + document.body.offsetTop; 
		}
	}
	
	if(type==0)
		return pageWidth;
	else
		return pageHeight;
}