/**
** These functions validate searchforms, if validated the form is submitted
** @author Anders Raabo, Bitsi.dk.
** @version 0.1
**/
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) 
	{
	
    //new re = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    //new re_two = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
	
	re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
		return (-1);		
		} 

	}

}
function islessthantwochars(s)
{
var l = s.length;

if(l<2)
return true;
else
return false;
}
/////
function isblank(s)
{
	for (var i = 0; i < s.length; i++)
	{
	var c = s.charAt(i);
	if((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}
/////

/////
function VerifyForm(f,order) 
{
//var f = document.orderform;
//alert("yesss");
var msg;
var empty_fields = "";
var errors = "";
for(var i = 0; i < f.length; i++)
{
var e = f.elements[i];
	//if(((e.type == "text" || (e.type == "textarea")) && !e.optional)
	if(((e.type == "text") || (e.type == "textarea")) && e.required)
	{
		if((e.value == null) || (e.value == "") || isblank(e.value) || islessthantwochars(e.value))
		//if((e.value == null) || (e.value == ""))
		{
		empty_fields += "\n            " + e.trans;
		continue;
		}
	}
	if(e.checkemail)
	{
		if(!check_email(e.value))
		{
		 errors += "- Den indtastede email-adresse er ikke gyldig\n";
		 //alert("email er ok");
		}
	}

}
//alert(empty_fields);
if(!empty_fields && !errors)
{
//order = order.replace(/|/g,","); 
//alert(order);

  // confirm(order);
  if(order != '')
  {
		if(confirm(order))
		{
		
		return true;
		}
		else
		{
		return false;
		//var flag = 1;
	 	}
   }
   else
   return true;

}

//
msg = "______________________________________\n\n";
msg += "Din formular blev ikke afsendt p.g.a nedenstående fejl.\n";
msg += "______________________________________\n\n";
	if(empty_fields)
	{
	msg += "- Følgende krævede felter er tomme:" + empty_fields + "\n";
	if(errors) msg += "\n";
	
	}
msg += errors;
alert(msg);
//if(!flag) alert(msg);
return false;

}


/**
** This function validate searchforms, if validated the form is submitted
** @author Michael Lund Pedersen, Mimas Group.
** @version 0.1
**/
function submitSearch(strSearchType, intMinChars, strPath)
{
	
	strSearchString = "document." + strSearchType + ".p_" + strSearchType + "_string.value";
	strSearchString = eval(strSearchString);
	
	if(strSearchString.length >= intMinChars)
	{
		strPath = "document." + strSearchType + ".action = \"" + strPath + "\";";
		eval(strPath);
		
		strFormToSubmit = "document." + strSearchType + ".submit()";
		eval(strFormToSubmit);
	}
	else
	{
		alert("Du skal søge på mindst " + intMinChars + " tegn!");
	}
}

var w;
function login_open(login_page)
{
	X = 250;
	Y = 100;
	if(document.all){
		pos_settings = "top=" + Y + ", left=" + X;
	}
	if(document.layers){
		pos_settings = " screenX=" + X + ", screenY=" + Y;
	}
	if(document.getElementsByTagName){
		pos_settings = "top=" + Y + ", left=" + X;
	}
	//w = window.open(login_page ,"login", "height=70,width=250, scrollbars=no, status=no," + pos_settings);
	w = window.open(login_page ,"login", "height=70,width=250,scrollbars=no,resizable=yes,status=no,maximize=yes," + pos_settings);
}

function login_close(url)
{
	if (url == "nothing")
	{
		opener.document.location.href = opener.document.location.href;
	}
	else
	{
		opener.document.location.href = url;
	}
	window.close();
}


function openSmallWindow(url) 
{
	window.open(url,"smallWindow","width=400,height=500,scrollbars=0,resizable,top=100,left=300");
	return false;
}
function openWindow(url) 
{
	window.open(url,"smallWindow","width=650,height=400,scrollbars=0,resizable,top=100,left=300");
	return false;
}
function reload_opener()
{
window.opener.location.reload(); 
window.close(); 
}
                        function validate(form)
                        {
                                if ((form.navn.value=="")||
                                (form.gade.value=="")||
                                (form.zip.value=="")||
                                (form.city.value==""))
                                {
                                        alert ("Udfylde venligst alle de med * angivne felter!");
                                        return false;
				}
			}
      

///
