//custom js file

//general
var blankreg=RegExp("^[ ]*$");
var emailreg=new RegExp("^[a-z0-9A-Z-_. ']+@[a-z0-9A-Z-_]+[.]([a-z0-9A-Z-_]+[a-z0-9A-Z-_. ']*[0-9a-zA-Z]+)+$");
var numreg=new RegExp("^[1-9][0-9]*$");
//date/month/year
function date_month_year(){
var d,m;
var date='Date: <select name="date" id="date">';
for(i=1;i<32;i++){
d=i<10?'0'+i:i;
date+='<option value="'+d+'">'+d+'</option>';
}
date+='</select>';

var month='Month: <select name="month" id="month">';
for(i=1;i<13;i++){
m=i<10?'0'+i:i;
month+='<option value="'+m+'">'+m+'</option>';
}
month+='</select>';

var year='Year: <select name="year" id="year">';
for(i=1909;i<2050;i++){
year+='<option value="'+i+'">'+i+'</option>';
}
year+='</select>';
var thedate=date+month+year;
document.write( thedate);
}

//subscription
function chk_subscription(){
	if(document.forms['subscription-form'].memberemail.value.match(emailreg)==null){
	document.getElementById('warnmsg').innerHTML="Invalid email";
	document.forms['subscription-form'].memberemail.style.background='#c6e09f';
	document.forms['subscription-form'].memberemail.focus();
	return false;
	}
	document.forms['subscription-form'].submit();
}
//registration
function chk_registration(){
var len=document.forms['registration-form'].elements.length-2;
var errormsg=new Array();
errormsg[0]="Invalid entry";
errormsg[1]="Invalid entry";
errormsg[7]="Invalid email";
errormsg[8]="Password must consist of 6 to 12 characters withou any space";
errormsg[9]="2 entries for password don't match";

for(i=0;i<len;i++){
if((i==7 && document.forms['registration-form'].elements[i].value.match(emailreg)==null) || (i==8 && (document.forms['registration-form'].elements[i].value.indexOf(' ')!=-1 || document.forms['registration-form'].elements[i].value.length<6)) || (i==9 && document.forms['registration-form'].elements[i].value!=document.forms['registration-form'].elements[i-1].value) || document.forms['registration-form'].elements[i].value.match(blankreg)!=null){
document.getElementById('warnmsg1').innerHTML=errormsg[i];	
document.forms['registration-form'].elements[i].focus();
document.forms['registration-form'].elements[i].style.background='#c6e09f';
return false;
}else{
	document.getElementById('warnmsg1').innerHTML='';
	document.forms['registration-form'].elements[i].style.background='none';
}
}
}
//member login validation
function member_login(){
if(document.forms['form-login'].email.value.match(emailreg)==null){
document.getElementById('warnmsg2').innerHTML='Invalid email';		
document.forms['form-login'].email.focus();
document.forms['form-login'].email.style.background='#c6e09f';
return false;
}else{
	document.forms['form-login'].email.style.background='none';
}
if(document.forms['form-login'].pswd.value.match(blankreg)!=null){
document.getElementById('warnmsg2').innerHTML='Please enter your password';		
document.forms['form-login'].pswd.focus();
document.forms['form-login'].pswd.style.background='#c6e09f';
return false;
}else{
		document.forms['form-login'].pswd.style.background='none';
}
}
