function subscribe()
{
	var form = document.formsubscribe;
	
	var send = true;
	
	var fields = new Array('email');
	
	var inputField = form.email;
	var value = inputField.value;
	
	if(value == '') 
	{
		inputField.style.color = '#FFFFFF';
		inputField.style.background = '#FE7547';
		inputField.value = missingEmail;
		send = false;
	}
	else if(!checkEmail(inputField)) 
	{
		inputField.style.color = '#FFFFFF';
		inputField.style.background = '#FE7547';
		email = inputField.value;
		inputField.value = wrongEmail;
		send = false;
	}
		
	if(send)
	{
		form.submit();
		//url = 'subscribe.php?email='+getFieldValue('email')+'&lang='+getFieldValue('lang');
		//window.location = url;
		//makeRequest(url, onSubscribe, null, true);
	}	
	
}

function recover(inputField, color) 
{
	var value = inputField.value;
	
	inputField.style.background = color;
	inputField.style.color = '#3490B9';
	//inputField.focus();
	if(value == missingEmail || value == tradEmail) 
	{
		inputField.value = '';
	}
	else if(value == wrongEmail) inputField.value = email;
}

function onSubscribe(xmldoc, arg)
{
	//alert(xmldoc);
	var subscribe_node = xmldoc.getElementsByTagName('subscribe')[0];
	
	var success = 0;
	var msg = "";
	
	if(subscribe_node.getElementsByTagName('success')[0].firstChild != null) success = Number(subscribe_node.getElementsByTagName('success')[0].firstChild.data);
	if(subscribe_node.getElementsByTagName('msg')[0].firstChild != null) msg = subscribe_node.getElementsByTagName('msg')[0].firstChild.data;
	
	
	//if(success) fillElement('subscribe_response', msg);
	//else fillElement('subscribe_response', msg);
	
	var form = document.formsubscribe;
	
	form.email.value = msg;
	
	if(success != -1)
	{
		//form.user_name.value = '';
		//form.user_email.value = '';
		//form.info.checked = 0;
	}
}

function fillElement(parent, content)
{
	var parentDiv = document.getElementById(parent);
	parentDiv.innerHTML = content;
}

function getFieldValue(nameField)
{
	return document.formsubscribe[nameField].value;
}

function makeRequest(url, onEnd, arg, return_xml)
{
   var http_request = false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!http_request) {
       alert('Unfortunatelly you browser doesn\'t support this feature.');
       return false;
   }
   
   http_request.onreadystatechange = function() 
   {
       if (http_request.readyState == 4) 
	   {
           if (http_request.status == 200) 
		   {
             //alert(http_request.responseText);
			  if (return_xml) 
			   {
				   onEnd(http_request.responseXML, arg);
               } else {
                  onEnd(http_request.responseText, arg);
               }
           } else {
               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }

	http_request.open('GET', url, true);
	http_request.send(null);
}

function checkEmail(inputField) {
	var emailarray = inputField.value.split('@');
	var valid = false;
	if(emailarray.length == 2){
		var first = emailarray[0];
		var second = emailarray[1];
		if(first.length >0 && second.length>0)
		{
			if(checkchars(first) && checkchars(second))
			{
				var dotarray = second.split('.');
				
				l = dotarray.length;
				
				if(l >= 2)
				{
					valid = true;
					for(i = 0; i<l; i++ )
					{
						minchars = 1;
						if(i == l - 1) minchars = 2;
						
						if(dotarray[i].length < minchars)
						{
							valid = false;
							break;
						}   

					}
				}
			}
		}
	}
	return(valid);
}

function checkchars(string) {
	var validchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqurstuvwxy01234567890-_.';	
	var valid = true;
	for(var i=0; i<string.length; i++){
		var index = validchars.indexOf(string.charAt(i));
		if(index == -1){
			valid = false;
			break;
		}
	}
	return(valid);
}

function changeColor(inputfield, color)
{
	inputfield.style.background = color;	
}