
function checkForm(form) { 

 pattern = /^[0-9]+\.[0-9]{2}$/;
 pattern_2 = /^[0-9]+$/;
 price = form.price.value;
 result = price.match(pattern);
 result_2 = price.match(pattern_2);
 
 if ( result == null && result_2  == null )  { 
   alert("Bad price format.\nFor example, correct prize is 12.21 or 21");
   form.price.focus();
   return false;
 } 


  if ( !checkEmail(form) ) return false;
  
  return true;
}


function myPrompt() {
return confirm("Are you sure want delete this item ??");
}

function checkEmail(form) {

  email = form.email.value;
  i = email.lastIndexOf("@");
  local = email.substring( 0, i );
  domain = email.substring( i, email.length );
   
  pattern = /^[a-zA-Z0-9\._\-\+\=]+$/;
  result = local.match(pattern);
  if ( result == null ) { 
    alert("Bad email format.\nFor example, correct email is mail@mail.pl");
    form.email.focus();
    return false;
  }

  pattern = /^@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)+$/;
  result = domain.match(pattern);
  if ( result == null ) { 
    alert("Bad email format.\nFor example, correct email is mail@mail.pl"); 
    return false;
  }
 return true;

}

function showBigPicture(picName) {

  newWindow = window.open('', '', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width=500, height=500');
  newWindow.document.open();
  newWindow.document.writeln('<html>\n<body>\n');
  newWindow.document.writeln('<p align=center><img src=\"./img/' + picName + '\" id=img ></p>\n');
  newWindow.document.writeln("<p align=center><a href=\"javascript:window.close();\">Close window</a></p>\n");
  newWindow.document.writeln(" <script type=\"text/javascript\">");
  newWindow.document.writeln(" var elem = document.getElementById(\"img\");");
  newWindow.document.writeln(" width = elem.width + 50;" );
  newWindow.document.writeln(" height = elem.height + 120 ;" );
  newWindow.document.writeln(" var positionTop = (screen.height-height)/2; ")
  newWindow.document.writeln(" var positionLeft = (screen.width-width)/2; ");
  
  newWindow.document.writeln(" if ( width > 800 ) width = 900; " );
  newWindow.document.writeln(" if ( height > 800 ) height = 900; " );
  newWindow.document.writeln(" self.resizeTo(width ,height ); ");
  newWindow.document.writeln(" self.moveTo(positionLeft,positionTop); ");
  newWindow.document.writeln(" </script> ");
  newWindow.document.writeln('</body>\n</html>\n');
  newWindow.document.close();
  newWindow.focus();

}

function onChange() {
	textarea = document.getElementById('text');
	alert(textarea.value);
	if ( textarea.value.length > 40 ) {
		textarea.value = textarea.value.substring(0,40);
	}
}