// Email Validation. Written by PerlScriptsJavaScripts.com
function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){
			return (false);
		}
	}

	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);
		}
	}
}

function check_form(f) { // f is the form (passed using the this keyword)

	// check the first email address ( the exclamation means "not" )
	if(!check_email(f.email.value)){
		alert("Invalid email detected.");
		f.email.focus();
			// if the browser is Netscape 6 or IE
			if(document.all || document.getElementByID){
				// change the color of text field
				f.email.style.background = "yellow";
			}
		// make sure the form is not submitted
		return false;
	}
	return true;
}

function check_form_name_email(f) { // f is the form (passed using the this keyword)
	if(f.name.value.length < 1){
		alert("You entered less than one character in the name field.");
		f.name.focus(); // put the prompt in the name field
		// if the browser is Netscape 6 or IE
		if(document.all || document.getElementByID){
			// change the color of text field
			f.name.style.background = "yellow";
		}
		// make sure the form is not submitted
		return false;
	}

	// check the first email address ( the exclamation means "not" )
	if(!check_email(f.email.value)){
		alert("Invalid email detected.");
		f.email.focus();
		// if the browser is Netscape 6 or IE
		if(document.all || document.getElementByID){
			// change the color of text field
			f.email.style.background = "yellow";
		}
		// make sure the form is not submitted
		return false;
	}
	
	return true;
}

function previewArticle()
{
	window.open('','preview','scrollbars=yes,width=790,height=500,resizable=yes');
	document.article.action2take.value = 'Preview';
	document.article.target = 'preview';
	document.article.action = '../index.php?p=1';
	document.article.submit();
	document.article.target = '_self';
	document.article.action = 'addArticleSubmit.php';
	document.article.preview.value = 'no';
}

function addImage(imagename){

	document.article.image.value = imagename;

}

function format_sel(v) {
  var str = document.selection.createRange().text;
  document.article.article_body.focus();
  var sel = document.selection.createRange();
  sel.text = "<" + v + ">" + str + "</" + v + ">";
  return;
}

function format_insert(v) {
  var str = document.selection.createRange().text;
  document.article.article_body.focus();
  var sel = document.selection.createRange();
  sel.text = "<" + v + ">";
  return;
}

function insert_link(type) {
  var str = document.selection.createRange().text;
  document.article.article_body.focus();
  if(type == 'mail'){
	var my_link = prompt("Enter email:","mailto: ");
	if (my_link != null) {
	  var sel = document.selection.createRange();
	  sel.text = "<a href=\"" + my_link + "\">" + str + "</a>";
	}
  } else{
	var my_link = prompt("Enter URL:","http://");
	if (my_link != null) {
	  var sel = document.selection.createRange();
	  sel.text = "<a href=\"" + my_link + "\">" + str + "</a>";
	}
  }
  return;
}


function alignDiv(v) {
  var str = document.selection.createRange().text;
  document.article.article_body.focus();
  var sel = document.selection.createRange();
  sel.text = "<DIV align=\"" + v + "\">" + str + "</DIV>";
  return;
}

function maketable() {
  var str = document.selection.createRange().text;
  document.article.article_body.focus();
  var sel = document.selection.createRange();
  sel.text = "<TABLE><TR><TD>" + str + "</TD></TR></TABLE>";
  return;
}

function y2k(number)    { return (number < 1000) ? number + 1900 : number; }

var today = new Date();
var day   = today.getDate();
var month = today.getMonth();
var year  = y2k(today.getYear());

function padout(number) { return (number < 10) ? '0' + number : number; }

function restart() {
    document.article.date.value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
    mywindow.close();
}

function newWindow() {
    mywindow=open('../html/static/cal.htm','myname','resizable=no,width=350,height=270');
    mywindow.location.href = '../html/static/cal.htm';
    if (mywindow.opener == null) mywindow.opener = self;
}

function mouseover(el) {
  el.className = "raised";
}

function mouseout(el) {
  el.className = "button";
}

function mousedown(el) {
  el.className = "pressed";
}

function mouseup(el) {
  el.className = "raised";
}

function viewImages(by)
{
	window.open('viewImages.php?by=' + by,'jav','scrollbars=yes,width=600,height=320,resizable=yes');
}

function openPopup(page){

	window.open(page,'newWin','scrollbars=no,width=400,height=320,resizable=yes');

}