// JavaScript Document

function countryChange()
{
	if (document.getElementById("country").value!="Magyarország")
	{
		document.getElementById("copyLink").style.display='none'; 
	}					
	else
	{
		document.getElementById("copyLink").style.display='block';
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
var currentfocus = null;
function prepareInputsForHints() {
	
	var inputs = document.getElementsByTagName("input");		
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = inputs[i].onmouseover = function (e) {
				if (!e) e = window.event;
				if (e.type=="focus")
					{
						currentfocus = this.parentNode;
					}
				else
					this.parentNode.getElementsByTagName("span")[0].style.zIndex = 9999;
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = inputs[i].onmouseout = function (e) {
				if (!e) e = window.event;
				if (document.getElementById("lastname"))  { check_lastname(document.getElementById("lastname"))};
				if (document.getElementById("firstname")) { check_firstname(document.getElementById("firstname"))};
				if (document.getElementById("phone"))     { check_phone(document.getElementById("phone"))};
				if (document.getElementById("email"))     { check_email(document.getElementById("email"))};
				if (document.getElementById("email2"))     { check_email(document.getElementById("email2"))};
				if (document.getElementById("city"))      { check_city(document.getElementById("city"))};
				if (document.getElementById("zip"))       { check_zip(document.getElementById("zip"))};			
				if (document.getElementById("address"))   { check_address(document.getElementById("address"))};
				
				if (document.getElementById("lastname_s"))  { check_lastname_s(document.getElementById("lastname_s"))};
				if (document.getElementById("firstname_s")) { check_firstname_s(document.getElementById("firstname_s"))};
				if (document.getElementById("phone_s"))     { check_phone_s(document.getElementById("phone_s"))};
				if (document.getElementById("email_s"))     { check_email_s(document.getElementById("email_s"))};
				if (document.getElementById("address_s"))   { check_address_s(document.getElementById("address_s"))};
				if (document.getElementById("city_s"))      { check_city_s(document.getElementById("city_s"))};
				//if (document.getElementById("country_s"))   { check_country_s(document.getElementById("country_s"))};
				
				if (document.getElementById("zip_s"))       { check_zip_s(document.getElementById("zip_s"))};
				//alert(e);
				if (document.getElementById("payphone")) { check_payphone(document.getElementById("payphone"))};	
				
				if (document.getElementById("cardname")) { check_cardname(document.getElementById("cardname"))};	
				if (document.getElementById("cardnum"))  { check_cardnum(document.getElementById("cardnum"))};					
				if (document.getElementById("cardcvc"))  { check_cardcvc(document.getElementById("cardcvc"))};	
			
				
				this.parentNode.getElementsByTagName("span")[0].style.zIndex = 999;
				
				/*check_lastname(document.getElementById("lastname_input"));
				check_firstname(document.getElementById("firstname_input"));
				check_phone(document.getElementById("phone_input"));
				check_email(document.getElementById("email_input"));
				check_city(document.getElementById("city_input"));
				check_zip(document.getElementById("zip_input"));			
				check_address(document.getElementById("address_input"));
				
				if (document.getElementById("lastname_s_input"))  { check_lastname_s(document.getElementById("lastname_s_input"))};
				check_firstname_s(document.getElementById("firstname_s_input"));
				check_phone_s(document.getElementById("phone_s_input"));
				check_email_s(document.getElementById("email_s_input"));
				check_address_s(document.getElementById("address_s_input"));
				check_city_s(document.getElementById("city_s_input"));
				check_country_s(document.getElementById("country_s_input"));
				check_zip_s(document.getElementById("zip_s_input"));				
				
				check_payphone(document.getElementById("payphone_input"));	
				check_cardname(document.getElementById("cardname_input"));	
				check_cardnum(document.getElementById("cardnum_input"));					
				check_cardcvc(document.getElementById("cardcvc_input"));	*/
				//if ( e.type=="blur" ) alert(currentfocus.name);
				if ( currentfocus!=this.parentNode || e.type=="blur") {
					if (this.parentNode.getElementsByTagName("span")[0])  { this.parentNode.getElementsByTagName("span")[0].style.display = "none"};
					if (this.parentNode.getElementsByTagName("span")[2])  { this.parentNode.getElementsByTagName("span")[2].style.display = "none"};
					if (this.parentNode.getElementsByTagName("span")[4])  { this.parentNode.getElementsByTagName("span")[4].style.display = "none"};
					if (this.parentNode.getElementsByTagName("span")[6])  { this.parentNode.getElementsByTagName("span")[6].style.display = "none"};
				}
				if ( e.type=="blur") {
					currentfocus = null;
				}
				//alert('meghivtak');
			}
	
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);

