/*________________________________________________________________________________________

	processing page events - acrev.js 
	02/2010 (c) Krisztian Gulyas
  ______________________________________________________________________________________*/

  
var URLROOT = "http://acrev.reziduum.hu";
  
function geh(_e) {

	var _obj = _e.target || _e.srcElement;
	var _id = _obj.id || _obj.name;
	
	/*
	var _cur = {x:0, y:0};	
    if (_e.pageX) {
	    _cur.x = _e.pageX - (window.screen.width/2 - 400) + 50;
        _cur.y = _e.pageY - 200;
    } 
    else {
        _cur.x = _e.x;
        _cur.y = _e.y;
    }
	*/

	//alert(_id + " " + _e.type + " --- " + _cur.x + " " + _cur.y);


	switch (_e.type) {
		case "change":
			break;
		case "keyup":
			break;
		case "mouseover":
			break;
		case "mouseout":
			break;
		case "click":
			switch(_id) {
				case "btnSubmitNewSubscribtion":
					if (!checkNewSubscribtionForm()) {
						with (document.forms.NewSubscribtion) {
							action = URLROOT + "/index.php?p=newsubscribtion";
							submit();
						}
					}		
					break;
				case "ddIssue":	
					dd('Issue');
					break;
				case "chbdataPost":
					sw('dataPost', 'visibility', 'visible', 'hidden');
					break;
				case "Code":
					genNewCode();
					break;	
			}		
			break;
		case "submit":
			break;
	}
}

// _______________________________________________________________________________________

function checkCode () {
	var ajax = getXmlHttpRequestObject();
	var url = URLROOT + '/lib/php/checkCAPTCHACode.php';
	var form = document.forms.NewSubscribtion;
	var strPOST = "x=" + encodeURIComponent(form.x.value);
	_err = Number(makeSJAXRequest (ajax, url, strPOST));
	if (_err) {
		alert("Sajnos ez nem valami jó megoldás!");
	}
	return(_err);
}

// _______________________________________________________________________________________

function genNewCode() {
	var _img = document.getElementById("Code");
	_img.src = URLROOT + "/lib/php/genCAPTCHAImage.php?par=" + Math.random();
}

// _______________________________________________________________________________________

function checkNewSubscribtionForm () {

	var _form = document.forms.NewSubscribtion;
	if (!document.getElementById('chbdataPost').checked) {
		var _fields = [
			["Name", "name", 1, 5, 0],
			["IName", "name", 1, 5, 0],
			["City", "name", 1, 3, 0],
			["Postcode", "postcode", 1, 4, 0],
			["Address", "address", 1, 3, 0],
			["Email", "email", 1, 5, 0],
			["Phone", "phone", 1, 6, 0],
			["noAR2010_a", "number", 0, 0, 0],
			["noAR2009_1", "number", 0, 0, 0],
			["noAR2009_2", "number", 0, 0, 0],
			["noAR2009_3", "number", 0, 0, 0],
			["noAR2009_4", "number", 0, 0, 0],
			["noAR2008_1", "number", 0, 0, 0],
			["PName", "name", 1, 5, 0],
			["PCity", "name", 1, 3, 0],
			["PPostcode", "postcode", 1, 4, 0],
			["PAddress", "address", 1, 3, 0],
			];
		}	
	else {
		var _fields = [
			["Name", "name", 1, 5, 0],
			["IName", "name", 1, 5, 0],
			["City", "name", 1, 3, 0],
			["Postcode", "postcode", 1, 4, 0],
			["Address", "address", 1, 3, 0],
			["Email", "email", 1, 5, 0],
			["Phone", "phone", 1, 6, 0],
			["noAR2010_a", "number", 0, 0, 0],
			["noAR2009_1", "number", 0, 0, 0],
			["noAR2009_2", "number", 0, 0, 0],
			["noAR2009_3", "number", 0, 0, 0],
			["noAR2009_4", "number", 0, 0, 0],
			["noAR2008_1", "number", 0, 0, 0],
			];
	}
		
	// Check form
	
	
	if (checkForm(_form, _fields)) return(1);							// fields
	
	noAR2010_a = str2int(_form.noAR2010_a.value); 
	noAR2009_1 = str2int(_form.noAR2009_1.value);
	noAR2009_2 = str2int(_form.noAR2009_2.value);
	noAR2009_3 = str2int(_form.noAR2009_3.value);
	noAR2009_4 = str2int(_form.noAR2009_4.value);
	noAR2008_1 = str2int(_form.noAR2008_1.value);
	
	if (noAR2010_a==0 && noAR2009_1==0 && noAR2009_2==0 && noAR2009_3==0 && noAR2009_4==0 && noAR2008_1==0) {
		alert("Nincs megrendelt lapszám!");
		return(1);
	}
	
	if (checkCode()) return(1);
	
	return(0);
}	



