function nameValue(ob, focused){
	if(focused)
	{
		if(ob.value == 'Your Name'){
			ob.value = '';
		}
	}
	else
	{
		if(ob.value.replace(/\s+/g,'').length == 0){
			ob.value = 'Your Name'
		}
	}
}

function emailValue(ob, focused){
	if(focused)
	{
		if(ob.value == 'Your Email'){
			ob.value = '';
		}
	}
	else
	{
		if(ob.value.replace(/\s+/g,'').length == 0){
			ob.value = 'Your Email'
		}
	}
}

function signUpProcess(url, vars){
	$.post(
		url, 
		vars,
		function(xmlResponse){
    		root = xmlResponse.getElementsByTagName('root');			
			response = xmlResponse.getElementsByTagName('response')[0].childNodes[0].nodeValue;
			if(response == 'true'){
				$('#newsletter-input').css('display', 'none');
				$('#name').val('Your Name');
				$('#email').val('Your Email');
				alert("Thank You For Your Submission");
			}
			else if(response == 'false'){
				alert('Error - Please try again!');
			}
		}, 
		"xml"
	);
}

function signUp(store){
	var oForm = document.forms['newsletter-input'];
	var error = false;
	
	var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	
	
		if(oForm['name'].value.replace(/\s+/g,"").length == 0 || oForm['name'].value == 'Your Name')
		{
			error = true;
			
			alert('Please enter your name ! ');
			oForm['name'].focus();
		}
		else if(oForm['email'].value.replace(/\s+/g,"").length == 0 || oForm['email'].value == 'Your Email')
		{
			error = true;
			
			alert('Please enter email address ! ');
			oForm['email'].focus();
		}
		else if(oForm['email'].value.search(regexp) == -1)
		{
			error = true;
			
			alert('Please enter valid email address ! ');
			oForm['email'].focus();
		}
		
		if(error)
		{
			return false;
		}
		else
		{
			var url = 'ajax/newsletter.php';
			var vars = 'name=' + oForm['name'].value + '&email=' + oForm['email'].value + '&store=' + store
			signUpProcess(url, vars);
		}		
}
