function disp_confirm() {
  var r=confirm("Do you really want to cancell?")
  if (r==true) {
    cancel();
  } 
}
function open(url,name) {
	
	var url_id = document.getElementById(url);
	
	if (url_id != null) url_id.style.display = "block";
	document.getElementById(name).style.color = "#C21212";
	/*document.getElementById(name).style.background = "#f6f6f2";*/
	document.getElementById(name).style.backgroundImage = "url('img/arrow_link.gif')";
	document.getElementById(name).style.backgroundRepeat = "no-repeat";;
	document.getElementById(name).style.backgroundPosition = "2px 6px";
	/*document.getElementById(name).style.borderRightColor = "#F76A01";*/
	}

function send() {
	document.getElementById("keepMe").submit();
}
function cancel() {
	document.getElementById('registerForm').reset();
}

/* walidacja formularza rejestracyjnego *************************/
function handleClick(id) {
        				var obj = "";

                	// Check browser compatibility
                	if(document.getElementById)
                      obj = document.getElementById(id);
                	else if(document.all)
                        obj = document.all[id];
               	else if(document.layers)
                        obj = document.layers[id];
                	else return 1;

                	if (!obj) {return 1;}
                	else if (obj.style) {
                        obj.style.display = ( obj.style.display != "none" ) ? "none" : "";
                	} else {
                        obj.visibility = "show";
                	}
               }//koniec function handleClick
         function sprawdz(formularz) {
         for (i = 0; i < formularz.length; i++) {
              var pole = formularz.elements[i];
              var n =  new Array;
                  n[0] = 'title';
                  n[1] = 'fname';
                  n[2] = 'sname';
                  n[3] = 'jobtitle';
                  n[4] = 'zip';
				  n[5] = 'company';
				  n[6] = 'address';
				  n[7] = 'zip';
				  n[8] = 'city';
				  n[9] = 'country';
				  n[10] = 'mailadr';
              if (pole.type == 'text') {
                  for (j=0; j< n.length; j++) {
                    if (pole.name == n[j] && pole.value == '') {
                        alert('Please fill in all required elements!');
                        if(pole.focus) pole.focus();
                        return false;
                      }
                    }
                  }
              }
              return true;
         }//koniec function sprawdz
         
   function check_select(formularz,n) {
	for (i = 0; i < formularz.length; i++) {
    	var pole = formularz.elements[i];
        if ((pole.name == n) && pole.value == '')  {
             alert('Please fill in all required elements!');
             if(pole.focus)
             pole.focus();
             return false;
        	}
    	}
    	return true;
   }
   
   function validate_zip(field) {
                var valid = "0123456789-"
                var ok = "yes";
                var temp;
                for (var i=0; i<field.value.length; i++) {
                temp = "" + field.value.substring(i, i+1);
                if (valid.indexOf(temp) == "-1") ok = "no";
                }
                if (ok == "no") {
                alert("Incorrect post code!");
                field.focus();
                field.select();
                return false;
                }
                return true;
                }
    
    function email_check(field) {
  var str=field.value;
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Incorrect e-mail address!");
     field.focus();
     return false;
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Incorrect e-mail address!");
     field.focus();
     return false;
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Incorrect e-mail address!");
      field.focus();
      return false;
  }
   if (str.indexOf(at,(lat+1))!=-1){
      alert("Incorrect e-mail address!");
      field.focus();
      return false;
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Incorrect e-mail address!");
      field.focus();
      return false;
   }
   if (str.indexOf(dot,(lat+2))==-1){
      alert("Incorrect e-mail address!");
      field.focus();
      return false;
   }
   if (str.indexOf(" ")!=-1){
      alert("Incorrect e-mail address!");
      field.focus();
      return false;
   }
   return true
}

function confirm_terms()  {	
	if (!document.getElementById("confirm_terms").checked) {
		alert("Please read terms of registration and cancellation and accept them before submiting this registration form!");
		document.getElementById("register_confirm_terms").style.fontWeight = "bold";
		document.getElementById("register_confirm_terms").style.color = "#c21212";
		return false;
	}
	return true;
}

function chceckForm(form) {
    if(sprawdz(form) &&
    	check_select(form,'title') &&    	    	
        email_check(form.mailadr)  &&
        confirm_terms()) return true;
    return false;
}

function register(form) {
	if (chceckForm(form)) {
		form.submit();
	}
}