function showsub(idname) {document.getElementById(idname).style.display = 'block';}
function hidesub(idname) {document.getElementById(idname).style.display = 'none';}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
	
function sendemail() {

	var name = document.contactform.name.value;
	var email = document.contactform.email.value;
	var msg = document.contactform.msg.value;
	document.contactform.send.disabled=true; 
	document.contactform.send.value='Wysyłanie...';

	document.contactform.email.style.background = '#fff';
	
    http.open('get', 'sendEmail.php?name='+name+'&email='+email+'&msg='+msg+'&action=send'+Math.random());
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
		if(http.status == 200){
			var response = http.responseText;
			var update = new Array();
		
			switch(response.charAt(0)){				
						case 'e' :
							document.contactform.email.style.background = '#ff6e6e';	
							document.contactform.email.focus();		
							document.contactform.send.disabled=false; 
							document.contactform.send.value='Wyślij';
							window.alert('Podaj poprawny adres e-mail'); break;
						case 'n' : 
							document.contactform.send.disabled=false; 
							document.contactform.send.value='Wyślij';
							window.alert('Wypełnij wszystkie obowiązkowe pola'); break;
			}
			
			if(response.indexOf('|' != -1)) {
				update = response.split('|');
				document.getElementById(update[0]).innerHTML = update[1];
			}
		}	
    }
}
