// JavaScript Document
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}
function validateForm(formname, textfields, names, email, errortext,erroremail, errorspam){
	if(textfields.length != names.length){
		alert("Names and textfields don't match");
	}
	if(!isArray(textfields)){
		alert("textfields is not an array");
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	var txt = "";
	for (i=0; i< textfields.length;i++){
		if(IsEmpty(document[formname][textfields[i]])){
			txt+= names[i]+"\n";
			}
	}
	if(txt != ""){
		alert(errortext+":\n"+txt);
		return false;
	}
	else{
	//alert(isValidEmail(document.form1.email.value));
		if (!isValidEmail(document[formname][email].value)) { 
        	alert(erroremail+"\n");
			return false;
	   }
	   else if (document[formname]["test"].value != 5) { 
        	alert(errorspam+"\n");
			return false;
	   }else{
	  	 return true;
	   }
	}	
}
function isValidEmail(str){
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
	apos=str.indexOf("@");
	dotpos=str.lastIndexOf(".");
	lastpos=str.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2){
		return false;
	}
	else {
		return true;
		}
}

/*
function isValidEmail(str) {
   //return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
   return ((str.indexOf("@") > 0);
}
*/
function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	

function open_win(content)
      {
	OpenWindow=window.open("", "newwin", "width=700,height=600,toolbar=no,scrollbars=yes,menubar=no");
	OpenWindow.document.write(content)

     }
function preview_template(id){
	OpenWindow=window.open("mail_preview.php?id="+id, "newwin", "toolbar=no,scrollbars=yes,menubar=no");
	//OpenWindow.document.write(id);
}	 

function redirect(url){
	window.parent.location = url
}
function popup(myImage,myWidth,myHeight,origLeft,origTop) {
myHeight += 24;
myWidth += 24;
origLeft = (screen.availWidth/2) - (myWidth/2);
origTop = 50;
TheImgWin = window.open(myImage,'image','height=' + myHeight + ',width=' + myWidth +',toolbar=no,directories=no,status=no,' +'menubar=no,scrollbars=no,resizable=no');
TheImgWin.moveTo(origLeft,origTop);
TheImgWin.resizeTo(myWidth+2,myHeight+30);

TheImgWin.focus();
}