// JohnGrieco.com Core JS

function addSubscriber(source) {
	new Ajax.Request('/addSubscriber.php', {
					 method: 'post',
					 parameters: { email: document.emailadd.email.value },
					 onLoading: function() { 
					 	if (source != 2) 
					 		$('preemail').innerHTML = "<span>Adding</span> your email to the list, one moment please...";
						else
							$('inner_signup').innerHTML = '<p class="noind"><span>Adding</span> your email to the list, one moment please...</p>';
					 },
					 onSuccess: function(serviceReturned) {
						 var response = serviceReturned.responseText;
						 if (response == "Success") {
							 if (source != 2) 
							 	$('signup').innerHTML = "<span>Added.</span> Thanks for taking the time and I'll drop you a line soon!";
							else
								$('inner_signup').innerHTML = '<p class="noind"><span>Added.</span> Thanks for taking the time and I\'ll drop you a line soon!</p>';
						 }
						 else {
							 if (source != 2) 
							 	$('signup').innerHTML = "<span>Something went wrong.</span> Please try again later.";
							else 
								$('inner_signup').innerHTML = '<p class="noind"><span>Something went wrong.</span> Please try again later.</p>';
							 
						 }
						
					 },
					 onFailure: function() {
					 	if (source != 2)
							$('signup').innerHTML = "<span>Something went wrong.</span> Please try again later.";
						else
							$('inner_signup').innerHTML = '<p class="noind"><span>Something went wrong.</span> Please try again later.</p>';
					 }
					 });
}

function focused() { 
	if (document.emailadd.email.value == "your@email.com") {
		document.emailadd.email.value = "";
		document.emailadd.email.style.color = "#333";
	}
}

function blurred() {
	if (document.emailadd.email.value == "") {
		document.emailadd.email.value = "your@email.com";
		document.emailadd.email.style.color = "#000";
	}
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }