var page='rejestracja';function checkForm(){if(document.form_rejestracja.nick.value.length<=0){alert("Please fill in your username");document.form_rejestracja.nick.focus();return false;}
if(document.form_rejestracja.name.value.length<=0){alert("Please fill in your name");document.form_rejestracja.name.focus();return false;}
if(document.form_rejestracja.email.value.length<=0){alert("Please fill in your email");document.form_rejestracja.email.focus();return false;}
if(!checkEmail(document.form_rejestracja.email)){alert('Improper email!');document.form_rejestracja.email.focus();return false;}
if(document.form_rejestracja.country_id.value.length<=0){alert("Please choose a country");document.form_rejestracja.country_id.focus();return false;}
if(document.form_rejestracja.city_id.value.length<=0&&document.form_rejestracja.city_name.value.length<=0){alert("Please choose or fill in a city");document.form_rejestracja.city_id.focus();return false;}
if(document.form_rejestracja.phone_no.value.length<=0){alert("Please fill in your phone number");document.form_rejestracja.phone_no.focus();return false;}
if(document.form_rejestracja.terms.checked==false){alert("You have to agree to the terms and conditions");document.form_rejestracja.terms.focus();return false;}
if(document.form_rejestracja.main_photo_uploaded.value==''){if(document.form_rejestracja.main_photo.value==''){alert('Please attach your photo.');document.form_rejestracja.main_photo.focus();return false;}
var fNameSplit=document.form_rejestracja.main_photo.value.split('.');var extension=fNameSplit.pop();extension=extension.toLowerCase();if((extension=='gif'||extension=='jpg'||extension=='jpeg'||extension=='png')===false){alert('Improper file format. Allowed formats are gif, jpg and png.');document.form_rejestracja.main_photo.focus();return false;}}
if(document.form_rejestracja.dob_day.value.length<=0){alert("Please select day");document.form_rejestracja.dob_day.focus();return false;}
if(document.form_rejestracja.dob_month.value.length<=0){alert("Please select month");document.form_rejestracja.dob_month.focus();return false;}
if(document.form_rejestracja.dob_year.value.length<=0){alert("Please select year");document.form_rejestracja.dob_year.focus();return false;}
oMyForm=document.form_rejestracja;var firstDate=new Date();var secondDate=new Date(oMyForm.dob_year.value,oMyForm.dob_month.value-1,oMyForm.dob_day.value);var firstYear=firstDate.getFullYear();var secondYear=secondDate.getFullYear();if(firstYear<secondYear){firstYear=firstYear+ 100;}
var years=firstYear- secondYear;var firstMonth=firstDate.getMonth();var secondMonth=secondDate.getMonth();if(firstMonth<secondMonth){yeardiff=years- 1;}
if(firstMonth>secondMonth){yeardiff=years;}
if(firstMonth==secondMonth){var firstDay=firstDate.getDate();var secondDay=secondDate.getDate();if(firstDay<secondDay){yeardiff=years- 1;}
if(firstDay>=secondDay){yeardiff=years;}}
if(yeardiff<18){alert('You are under age!');oMyForm.dob_year.focus();return false;}
if(document.form_rejestracja.password.value.length<=0){alert("Please fill in the password");document.form_rejestracja.password.focus();return false;}
if(document.form_rejestracja.password2.value.length<=0){alert("Please retype the password");document.form_rejestracja.password2.focus();return false;}}
function uploadOn(){if($('main_photo_uploaded').value=='')$('upload_button').show();$('checkuser').show();$('checkuser').onclick=checkuser;$('form_rejestracja').nick.focus();$('main_photo_fileinput').onchange=autoLoad;}
function autoLoad(){if($('main_photo_fileinput').value!='')doLoad($('main_photo_fileinput'));}
function checkuser(){if(document.form_rejestracja.nick.value==''){$('checkuserkom').update('Please write username first');return;}
$('checkuser').hide();$('checkuserkom').update('Please wait...');var reqCU=new JsHttpRequest();reqCU.onreadystatechange=function(){if(reqCU.readyState==4){if(reqCU.responseJS.check==0){$('checkuserkom').update('You can use this username');}
else{$('checkuserkom').update('This username is already taken');$('checkuser').show();}}}
reqCU.open(null,'js_checknick.php',true);reqCU.send({q:document.form_rejestracja.nick.value});}
function doLoad(value){var fNameSplit=$('form_rejestracja').main_photo.value.split('.');var extension=fNameSplit.pop();extension=extension.toLowerCase();if((extension=='gif'||extension=='jpg'||extension=='jpeg'||extension=='png')===false){alert('Improper file format. Allowed formats are gif, jpg and png.');$('form_rejestracja').main_photo.focus();return false;}
$('result').show();var req=new JsHttpRequest();req.onreadystatechange=function(){if(req.readyState==4){if(req.responseJS.file_error==0){$('result').update('Choose your thumbnail:<br /><img src="uploadedfiles/'+ req.responseJS.new_name+'" border="0" id="main_photo_img" />');$('result').setStyle('height',req.responseJS.q_size[1]+30);$('main_photo_uploaded').value=req.responseJS.new_name;$('form_rejestracja').main_photo.value='';$('upload_button').hide();$('main_photo_fileinput').hide();}
else{$('result').update('An error '+req.responseJS.file_error+' has occured. Please try again.');}
$('debug').update('Debug:<br />'+req.responseText);}}
req.open(null,'upl_backend.php',true);req.send({q:value});}
var cropperOn=false;new PeriodicalExecuter(function(pe){try{if(!cropperOn&&$('main_photo_img').height>0)doCropper();}
catch(exc){}},1);function doCropper(){cropperOn=true;$('result').setStyle('text-align','center');new Cropper.Img('main_photo_img',{ratioDim:{x:144,y:120},minWidth:144,minHeight:120,displayOnInit:true,onEndCrop:onEndCrop});}
function onEndCrop(coords,dimensions){$('main_photo_x1').value=coords.x1;$('main_photo_y1').value=coords.y1;$('main_photo_x2').value=coords.x2;$('main_photo_y2').value=coords.y2;$('main_photo_newwidth').value=dimensions.width;$('main_photo_newheight').value=dimensions.height;}
function checkEmail(oEl){var inputvalue=oEl.value;if(inputvalue=='')return true;var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;if(pattern.test(inputvalue)){return true;}else{return false;}}
var dtCh="-";var minYear=1900;var maxYear=2100;function isInteger(s){var i;for(i=0;i<s.length;i++){var c=s.charAt(i);if(((c<"0")||(c>"9")))return false;}
return true;}
function stripCharsInBag(s,bag){var i;var returnString="";for(i=0;i<s.length;i++){var c=s.charAt(i);if(bag.indexOf(c)==-1)returnString+=c;}
return returnString;}
function daysInFebruary(year){return(((year%4==0)&&((!(year%100==0))||(year%400==0)))?29:28);}
function DaysArray(n){for(var i=1;i<=n;i++){this[i]=31;if(i==4||i==6||i==9||i==11){this[i]=30;}
if(i==2){this[i]=29;}}
return this;}
function isDate(dtStr){var daysInMonth=DaysArray(12);var pos1=dtStr.indexOf(dtCh);var pos2=dtStr.indexOf(dtCh,pos1+1);var strYear=dtStr.substring(0,pos1);var strMonth=dtStr.substring(pos1+1,pos2);var strDay=dtStr.substring(pos2+1);strYr=strYear;if(strDay.charAt(0)=="0"&&strDay.length>1)strDay=strDay.substring(1);if(strMonth.charAt(0)=="0"&&strMonth.length>1)strMonth=strMonth.substring(1);for(var i=1;i<=3;i++){if(strYr.charAt(0)=="0"&&strYr.length>1)strYr=strYr.substring(1);}
month=parseInt(strMonth);day=parseInt(strDay);year=parseInt(strYr);if(pos1==-1||pos2==-1){alert("Improper date format. Should be: rrrr-mm-dd");return false;}
if(strMonth.length<1||month<1||month>12){alert("Please write proper month.");return false;}
if(strDay.length<1||day<1||day>31||(month==2&&day>daysInFebruary(year))||day>daysInMonth[month]){alert("Please write proper day.");return false;}
if(strYear.length!=4||year==0||year<minYear||year>maxYear){alert("Please enter a four-digit year between "+minYear+" and "+maxYear);return false;}
if(dtStr.indexOf(dtCh,pos2+1)!=-1||isInteger(stripCharsInBag(dtStr,dtCh))==false){alert("Please give proper date");return false;}
return true;}
