function $(id) {return document.getElementById(id);}

function CzyNaPewno(url,pytanie) {
	if (window.confirm(pytanie)){
		window.location.href=url;
	}
}

function showElement(element_id) {
	if($(element_id)) {
		$(element_id).style.display = 'block'; 
	}
}
function hideElement(element_id) {
	if($(element_id)) {
		$(element_id).style.display = 'none'; 
	}
}

function showhideElement(element_id, hideText, showText) {
	hideText = hideText || 'schowaj';
	showText = showText || 'zobacz wiêcej';
	if($(element_id).style.display == 'none') {
		$(element_id).style.display = 'block';
		if($(element_id+"_link")) {
			$(element_id+"_link").innerHTML = hideText;
		}
	} else {
		$(element_id).style.display = 'none'; 
		if($(element_id+"_link")) {
			$(element_id+"_link").innerHTML = showText;
		}
	}
}

function searchArt() {
	showElement('searchResult');
	advAJAX.submit(document.getElementById("searchForm"), {
		onLoading : function(obj) { 
			$('searchResult').innerHTML = "Trwa wyszukiwanie";
		},
		onSuccess : function(obj) {
			$('searchResult').innerHTML = obj.responseText;
		}
	}
	);
}
function incrementStart() {
	$('search').value=$('start').value - 30;
}
function przechwyc(e) {
	var kod = (window.event) ? window.event.keyCode : e.which;
	if(kod == 13) {	
		searchArt();
	} else if(kod == 27) {
		hideElement('searcher');
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Prosze podac poprawny adres Email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Prosze podac poprawny adres Email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Prosze podac poprawny adres Email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Prosze podac poprawny adres Email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Prosze podac poprawny adres Email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Prosze podac poprawny adres Email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Prosze podac poprawny adres Email")
		    return false
		 }

 		 return true;
	}


function verifyForm(frm){
	if (!compare(frm)) 
	return false
}
function compare(frm) {
	var haslo1=frm.newPassword.value
	var haslo2=frm.newPassword2.value
	
	var emailID= frm.newEmail;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Prosze podac poprawny adre Email")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus();
		//alert("Prosze podac poprawny adre Email");
		return false
	}
	
	if (haslo1!=haslo2){
		alert("Wprowadziles dwa rozne hasla!") 
		return false
	}
	return true
}