var adwords=readCookie("adwords");
var sPage = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
var div;
var div2;
function send_form(obj,fields,obj2)
{
	if (!check_fields(fields)) {return false;}
	div=obj;
	div2=obj2;
	var poststr="";
	for (a=0;a<fields.length;a=a+2)
	{
		if (document.getElementsByName(fields[a]).length==1)
			poststr=poststr + fields[a] +"="+encodeURI(document.getElementById(fields[a]).value) +"&";
		else //if (document.getElementsByName(fields[a]).type=="radio")
			poststr=poststr + fields[a] +"="+encodeURI(get_radio_value(fields[a])) +"&";
	}

	 poststr = poststr + "adwords=" + encodeURI(adwords) +
                "&page=" +encodeURI(sPage);
      makePOSTRequest2('feedback.php', poststr);

}

function get_radio_value(obj)
{
	myOption = -1;
	var rads=document.getElementsByName(obj);
	for (i=rads.length-1; i > -1; i--) {
		if (rads[i].checked) {
			myOption = i; i = -1;
		}
	}
	return document.getElementsByName(obj)[myOption].value;
}

function check_fields(fields)
{
	for (a=0;a<fields.length;a=a+2)
	{
		if (fields[a+1]=="1" && document.getElementById(fields[a]).value=='')
		{
			alert('Kérlek minden adatot tölts ki!');
			return false;
		}
	}
	return true;
}
var http_request2 = false;
function makePOSTRequest2(url, parameters) {
  http_request2 = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request2 = new XMLHttpRequest();
     if (http_request2.overrideMimeType) {
     	// set type accordingly to anticipated content type
        //http_request2.overrideMimeType('text/xml');
        http_request2.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request2 = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request2 = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request2) {
     //alert('Cannot create XMLHTTP instance');
     return false;
  }
  
  http_request2.onreadystatechange = alertContents_feedback;
  http_request2.open('POST', url, true);
  http_request2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request2.setRequestHeader("Content-length", parameters.length);
  http_request2.setRequestHeader("Connection", "close");
  http_request2.send(parameters);
}
function alertContents_feedback() {
  if (http_request2.readyState == 4) {
     if (http_request2.status == 200) {
        //alert(http_request2.responseText);
        result = http_request2.responseText;
        document.getElementById(div).innerHTML = document.getElementById(div2).innerHTML;            
        
     } else {
        alert('There was a problem with the request.\n'+ http_request2.readyState +","+http_request2.status+","+http_request2.responseText);
     }
  }
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

