function emailCheckString(emailStr, target_field) {

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
			alert("Email address seems incorrect (check @ and .'s)");
			document.getElementById(target_field).focus();
			return ;
		}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			document.getElementById(target_field).focus();
			return ;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				alert("Ths domain name contains invalid characters.");
				document.getElementById(target_field).focus();
				return ;
			}
		}
		if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		document.getElementById(target_field).focus();
		return ;
		}
	var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Destination IP address is invalid!");
					document.getElementById(target_field).focus();
					return ;
				   }
				}//for
			return true;
		}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
		alert("The domain name does not seem to be valid.");
		document.getElementById(target_field).focus();
		return ;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		document.getElementById(target_field).focus();
		return ;
	}
	
	if (len<2) {
		alert("This address is missing a hostname!");
		document.getElementById(target_field).focus();
		return;
	}
	// If we've gotten this far, everything's valid!
	return true;
	
}











function save_form()  {
	
	if(document.getElementById("opt_in_email").value=="" || document.getElementById("opt_in_email").value=="Your email address"){
		alert("Enter a valid email address.");
		document.getElementById("opt_in_email").focus();
		return false;
	}
	emailStr=document.getElementById("opt_in_email").value;
	if(!emailCheckString (emailStr,"opt_in_email"))	return false;
	
	
	
	//document.getElementById("opt_in").action = "opt_in.php";
	//document.getElementById("opt_in").submit();
	
	
	/*save_mode = "save";
	field1 = document.getElementById('opt_in_email').value;
	field_vars = 
	"&save_mode="+escape(save_mode)+
	"&field1="+escape(encodeURIComponent(field1));
		
	sendRequestPostDetail('opt_in_process.php',field_vars,"");*/
	
	
	
	$.fancybox({
			'width'				: 670,
			'height'			: 415,
			'autoScale'			: false,
			'autoDimensions' 	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'href'				: 'https://www.goldgenie.com/opt_in.php?opt_in_email='+$("#opt_in_email").val()
		});
	
	
	return false;
	
}


function createRequestObject() {	
	var req;	
	if(window.XMLHttpRequest){
		// Firefox, Safari, Opera...
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		// Internet Explorer 5+
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		// There is an error creating the object,
		// just as an old browser is being used.
		alert('There was a problem creating the XMLHttpRequest object');
	}	
	return req;
}

// Make the XMLHttpRequest object
var http = createRequestObject();
	
function sendRequestPostDetail(phpscript,act,con) {
	http.open('post', phpscript+"?sid="+Math.random());
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function(){if(http.readyState==4){handleResponsePost(http,con)}};
	http.send(act);

}
function handleResponsePost(http,con) {	
	var containerID=con;
	if (!con) containerID = "ajaxbody";
	if(http.readyState == 4 && http.status == 200){	
		// Text returned from PHP script
		var response = http.responseText;	
		if(response) {
				// Update ajaxTest content
				var div = document.getElementById(containerID);
				div.innerHTML = response;
				//timer();
				var x = div.getElementsByTagName("script");    
				for( var i=0; i < x.length; i++) {     
					eval(x[i].text);
				}
			}

	}
}

	function opt_in_submit () {
	
		document.getElementById("opt_in_email").value = "Your email address"
			
		$.fancybox({
			'width'				: 670,
			'height'			: 350,
			'autoScale'			: false,
			'autoDimensions' 	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'href'				: 'https://www.goldgenie.com/opt_in_success.php'
		});
	}
	
	
	
$(window).load(function() {
	
	if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
		
		$(".countries").css("height", 'auto');
		
		$('.countries_list').hover(function() {
		  $(this).removeClass('normal'); 
		  $(this).addClass('hover');
		  $(this).height($(".countries").height()+25);
		   }, 
		   function() {
			  $(this).removeClass('hover'); 
			  $(this).addClass('normal');
		   });
	}
	
});
	
	

