var newwin;
function launchwin(winurl,winname,winfeatures)
{
	newwin = window.open(winurl,winname,winfeatures);
	if(javascript_version > 1.0) {
		setTimeout('newwin.focus();',250);
	}
}
function ValidateNoHTML(theinput)
{
	s=theinput.value
	if(s.length==0) return true;
	var ht = new RegExp(/http\:\/\/|https\:\/\/|ftp\:\/\//i);
	var re = new RegExp("<[^<>]+>");
	if (s.match(re)) {
		return false
	} else if (s.match(ht)) {
		return false
	} else {
		return true
	}
}
function ValidateEmailOrNull(theinput)
{
	s=theinput.value
	if(s.length==0) return true;
	if(s.search)
	{
		return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0)
	}
	if(s.indexOf)
	{
		at_character=s.indexOf('@')
		if(at_character<=0 || at_character+4>s.length)
			return false
	}
	if(s.length<6)
		return false
	else
		return true
}

function ValidateHyperlinkOrNull(theinput)
{
	s=theinput.value
	if(s.length==0) return true;

	var RegExp = /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.{0,1}[A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?/i;
				
    if(RegExp.test(s)){ 
        return true;
    }else{
        return false;
    } 	
}

function ValidateEmailOrPhone(theinput)
{
	s=theinput.value
	if(theinput.form.phone.value.length!=0) return true;
	if(s.search)
	{
		return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0)
	}
	if(s.indexOf)
	{
		at_character=s.indexOf('@')
		if(at_character<=0 || at_character+4>s.length)
			return false
	}
	if(s.length<6)
		return false
	else
		return true
}

function ValidateEmail(theinput)
{
	s=theinput.value
	if(s.search)
	{
		return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0)
	}
	if(s.indexOf)
	{
		at_character=s.indexOf('@')
		if(at_character<=0 || at_character+4>s.length)
			return false
	}
	if(s.length<6)
		return false
	else
		return true
}

function editImage(image) 
{
	var url = "/lib/ImageManager/editor.php?img="+image;
	Dialog(url, function(param) 
	{
		if (!param) // user must have pressed Cancel
			return false;
		else
		{
			return true;
		}
	}, null);		
}

function ta_hover(id) {
	document.getElementById('row_' + id).style.background='#fff';
}
function ta_unhover(id) {
	document.getElementById('row_' + id).style.background='#eee';
}

function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}
function ValidatePhone(theinput)
{

	var _p=theinput.value;
	var RegExp1= /[^\d]/g;
	var x=_p.replace(RegExp1,'');
	var RegExp2= /^(\d{3})(\d{3})(\d{4})$/;
	if(x.match(RegExp2))
	{
	  theinput.value=reformat(x,"",3,"",3,"",4);
	  return true;
	}
	else
	return false;
}
function removeAccents(s)
{
	var s;
	var diacritics =[
	/[\300-\306]/g, /[\340-\346]/g, // A, a
	/[\310-\313]/g, /[\350-\353]/g, // E, e
	/[\314-\317]/g, /[\354-\357]/g, // I, i
	/[\322-\330]/g, /[\362-\370]/g, // O, o
	/[\331-\334]/g, /[\371-\374]/g,  // U, u
	/[\321]/g, /[\361]/g, // N, n
	/[\307]/g, /[\347]/g, // C, c
	];
	var chars = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
	for (var i = 0; i < diacritics.length; i++)
	{
		s = s.replace(diacritics[i],chars[i]);
	}
	return s;
}
function formValidateLoginForm(theform) {
	if(theform.username.value=='') {
		alert('[E-mailadres] is een verplicht veld.');
		theform.username.focus();
		theform.username.old_className = theform.username.className;
		theform.username.className = 'input1_error';
		return false;
	}else if(ValidateEmailOrNull(theform.username)==false) {
		alert('Het ingevoerde E-mailadres is niet geldig. U moet een geldig E-mailadres invullen')
		theform.username.focus();
		theform.username.old_className = theform.username.className;
		theform.username.className = 'input1_error';
		return false;
	} else { 
		theform.username.className = 'input1';
	} 
	if(theform.password.value=='') {
		alert('[Wachtwoord] is een verplicht veld.');
		theform.password.focus();
		theform.password.old_className = theform.password.className;
		theform.password.className = 'input1_error';
		return false;
	} else { 
		theform.password.className = 'input1';
	} 
	return true;
}
function searchformValidate(theform) {
	if(theform.search.value.length<4) {
		alert('Geef een zoekterm op die bestaat uit minimaal 4 karakters.');
		theform.search.focus();
		theform.search.old_className = theform.search.className;
		theform.search.className = 'input1_error';
		return false;
	} else { 
		theform.search.className = 'input1';
	} 
	return true;
}
function formValidateSubscribe(theform) {
	if(theform.name.value=='') {
		alert('[naam] is een verplicht veld.');
		theform.name.focus();
		theform.name.old_className = theform.name.className;
		theform.name.className = 'input1_error';
		return false;
	} else { 
		theform.name.className = 'input1';
	} 
	if(theform.email.value=='') {
		alert('[e-mail] is een verplicht veld.');
		theform.email.focus();
		theform.email.old_className = theform.email.className;
		theform.email.className = 'input1_error';
		return false;
	} else { 
		theform.email.className = 'input1';
	} 
	if(ValidateEmail(theform.email)==false)
	{
		alert('Het ingevoerde e-mailadres is niet geldig. Geef een geldig e-mailadres op.')
		theform.email.focus()
		theform.email.old_className = theform.email.className;
		theform.email.className = 'input1_error';
		return false;
	} else { 
		theform.email.className = 'input1';
	} 				
}
function formValidateContact(theform) {
	if(theform.cf_name.value=='') {
		alert('[Naam] is een verplicht veld.');
		theform.cf_name.focus();
		theform.cf_name.old_className = theform.cf_name.className;
		theform.cf_name.className = 'input1_error';
		return false;
	} else { 
		theform.cf_name.className = 'input1';
	} 
	if(theform.cf_telephone.value!='' && ValidatePhone(theform.cf_telephone)==false)
	{
		alert('Het ingevoerde telefoonummer is niet geldig. Geef een 10-cijferige telefoonnummer op.')
		theform.cf_telephone.focus();
		theform.cf_telephone.old_className = theform.cf_telephone.className;
		theform.cf_telephone.className = 'input1_error';
		return false;
	} else { 
		theform.cf_telephone.className = 'input1';
	} 
	if(theform.cf_email.value=='') {
		alert('[E-mail] is een verplicht veld.');
		theform.cf_email.focus();
		theform.cf_email.old_className = theform.cf_email.className;
		theform.cf_email.className = 'input1_error';
		return false;
	} else { 
		theform.cf_email.className = 'input1';
	} 
	if(ValidateEmailOrNull(theform.cf_email)==false)
	{
		alert('Het ingevoerde e-mailadres is niet geldig. Geef een geldig e-mailadres op.')
		theform.cf_email.focus()
		theform.cf_email.old_className = theform.cf_email.className;
		theform.cf_email.className = 'input1_error';
		return false;
	} else { 
		theform.cf_email.className = 'input1';
	} 
	if(theform.cf_message.value=='') {
		alert('[Bericht] is een verplicht veld.');
		theform.cf_message.focus();
		theform.cf_message.old_className = theform.cf_message.className;
		theform.cf_message.className = 'input1_error';
		return false;
	} else { 
		theform.cf_message.className = 'input1';
	} 
	return true;
}
