function isValidEmail(str) {

   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
 
}



function optin_stats(ad_id) {


var http_request = false;

	// If *POST* occurs in Netscape (disables script in MSIE if not run inside an IF statement!)
	if (http_request.overrideMimeType)
	{ http_request.overrideMimeType('text/xml');
	}

// Create a xmlhttp request...

	// Mozilla, Safari, etc
	if (window.XMLHttpRequest)
	{ http_request = new XMLHttpRequest();
	}
	// MSIE
	else if (window.ActiveXObject)
	{ http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{ alert('Your browser settings don\'t seem to support AJAX,\n or you need to upgrade your browser :(');
	return false;
	}

// Javascript function to call as the xmlhttp request is processed and sent back
http_request.onreadystatechange = function() { alertContents(http_request, ad_id); };

// Were're ready to make the xmlhttp request now...

// SEND GET DATA
http_request.open('GET', script_path + 'link.php?id=' + ad_id + '&admin=1', true);
http_request.send(null);

}

//////////////////////////////////////////////////////////////////////////////////////

function alertContents(http_request, ad_id) {

/* 
Display "Loading...", and see if the request has been responded to, and that it wasn't a 404/500 etc...
*/
	if (http_request.readyState == 4 && http_request.status == 200) {
	// MSIE needs the "value" attribute used instead of "inerHTML" for data that includes HTML tags, or it throws an error
	//document.getElementById("ad_headline").value = http_request.responseText;
	//document.getElementById("ad_headline").innerHTML = http_request.responseText;
	}
	else if (http_request.readyState == 4 && http_request.status != 200) {
	//document.getElementById("ad_headline").innerHTML = "There was a problem with the request. \n Please Try Again.";
	}
	else {
	//document.getElementById("ad_headline").innerHTML = "Loading, Please Wait...";
	}

}


///////////////////////////////////////////////////////////////////////////////////////


function validate_catchall(ad_id) {

	var loop = 0;
	while ( loop < document.forms.length ) {
	
		var loop2 = 0;
		while ( loop2 < document.forms[loop].elements.length ) {
	
		
			if ( document.forms[loop].elements[loop2].type
			&& document.forms[loop].elements[loop2].type != 'hidden'
			&& !document.forms[loop].elements[loop2].value ) {
			alert('Sorry, please fill in all fields...thank you.');
			return;
			}
			
			if ( (document.forms[loop].elements[loop2].value.indexOf(".") > 0)
			&& (document.forms[loop].elements[loop2].value.indexOf("@") > 0) ) {
			var ok = 1;
			}
		
		
		var loop2 = loop2 + 1;
		}
	
	var loop = loop + 1;
	}

	if ( ok ) {
	optin_stats(ad_id);
	return ok;
	}
	else {
	alert(' Sorry, no email address was detected. \n Please verify all fields were completed correctly...thank you. ');
	return;
	}
	
}

///////////////////////////////////////////////////////////////////////////////////////////////////////




function check_these() {

	if ( document.getElementById('toggle').checked == true ) {
	// Purge any current value(s) added to avoid duplicates
	document.mass_reset.selected_ads.value = '';
	
		var count_forms = 0;
		while (  document.forms.length > count_forms ) {
		
			var count_checkboxes = 0;
			while (  document.forms[count_forms].elements.length > count_checkboxes ) {
			
				if ( document.forms[count_forms].elements[count_checkboxes].type == 'checkbox'
				&& document.forms[count_forms].elements[count_checkboxes].name != 'toggle' ) {
				
				document.forms[count_forms].elements[count_checkboxes].checked = true;
				document.mass_reset.selected_ads.value = document.mass_reset.selected_ads.value + "|" + document.forms[count_forms].elements[count_checkboxes].value + "|";
				}
				
			
			count_checkboxes = count_checkboxes + 1;
			}
		
		count_forms = count_forms + 1;
		}
	
	}
	
	else if ( document.getElementById('toggle').checked == false ) {
	
		var count_forms = 0;
		while (  document.forms.length > count_forms ) {
		
			var count_checkboxes = 0;
			while (  document.forms[count_forms].elements.length > count_checkboxes ) {
			
				if ( document.forms[count_forms].elements[count_checkboxes].type == 'checkbox'
				&& document.forms[count_forms].elements[count_checkboxes].name != 'toggle' ) {
				
				document.forms[count_forms].elements[count_checkboxes].checked = false;
				document.mass_reset.selected_ads.value = '';
				}
			
			
			count_checkboxes = count_checkboxes + 1;
			}
		
		count_forms = count_forms + 1;
		}
	
	}
	
//alert('finished');
//alert(document.mass_reset.selected_ads.value);
}

function replace_text(saved_id, string_id, new_text_id) {

document.getElementById(string_id).value = document.getElementById(saved_id).value;

	while ( document.getElementById(string_id).value.search(/CUSTOM_VAR_HERE/) != -1 ) {
	document.getElementById(string_id).value = document.getElementById(string_id).value.replace('CUSTOM_VAR_HERE', document.getElementById(new_text_id).value);
	}

}
