// JavaScript Document


function in_array(haystack, needle) 
{
    for(var i=0; i<haystack.length; i++) 
	{
        if (haystack[i] == needle) return true;
    }
}

function check_aweber_data(obj_form)
{
	
	var str = '';
	var elem = obj_form.elements;
	
	var radios = new Array();
	
	for(var i = 0; i < elem.length; i++)
	{
		if (elem[i].type.indexOf('radio', 0) >= 0)
		{
			if (!in_array(radios, elem[i].name))
			{
				radios.unshift(elem[i].name);
			}
		}
		else if ((elem[i].type.indexOf('text', 0) >= 0) || (elem[i].type.indexOf('select', 0) >= 0))
		{
			str += encodeURI(elem[i].name) + '=' + encodeURI(elem[i].value) + '&';
		}
	} 
	
	var radio_elem;
	
	for(var i = 0; i < radios.length; i++)
	{
		radio_elem = document.getElementsByName(radios[i]);
		
		for(var j = 0; j < radio_elem.length; j++)
		{
			if (radio_elem[j].checked)
			{
				str += encodeURI(radios[i]) + '=' + encodeURI(radio_elem[j].value) + '&';
			}
		}
	}
	str = str.substr(0, str.length - 1);
	
	while(str.indexOf('%20') >= 0)
	{
		str = str.replace('%20', '_-_-');
	}
	
	//alert(str);
		
	var xmlhttp;
	try 
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
		xmlhttp = new XMLHttpRequest();
		
		//xmlhttp.open('POST', 'http://74.53.126.221/~posting1/aweber/aweber_post.php', true);

		//xmlhttp.open('POST', 'http://localhost/noplaymedia/upload_scripts/aweber_post.php', true);
		
		xmlhttp.open('POST', 'aweber_grabber.php', true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) 
			{
				if(xmlhttp.status == 200) 
				{
					var message = xmlhttp.responseText;	
					//alert(message);
				}

			}
		};		
		xmlhttp.send(str);
	}


	return true;
}

