function checkEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
}

function confirmSubmit(text) {
	var agree=confirm(text);
	if(agree) return true;
	else return false ;
}

function imagePreview(picture,value) {
	if(value!="") picture.src = "file://localhost/" + value;
}

function imageResizeWidth(img,maxWidth) {
	if(img.width>maxWidth) img.width=maxWidth; 
	img.height=maxWidth*(img.height/img.width);
}

function imageResizeHeight(img,maxHeight) {
	if(img.height>maxHeight) img.height=maxHeight; 
	img.width=maxHeight*(img.width/img.height);
}

function popup(mypage,myname,w,h,features) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else {
		winl = 0;
		wint =0;
	}

	if(winl<0) winl = 0;
	if(wint<0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
	if(!win.opener) win.opener = self;
}

function protectMail(name, domain) {
	window.location = 'mailto:' + name + '@' + domain;	
}

function validateDate(day,month,year) {
	var date=new Date(year.value,month.value-1,day.value)
	day.value=date.getDate()
	month.value=date.getMonth()+1
	year.value=date.getFullYear()
}
