
function parseForm(FormName){
	thisForm = document.forms["mailForm"];
	operation = thisForm.operation.value;
	
	switch(operation) {
	
		case "1"	: alert("1");break;
		case "sendmail"	:
				  mailing_id = thisForm.mailing_id.value; //thisForm.mailing_id[thisForm.mailing_id.selectedIndex].value;
				  sendto = radioValue(thisForm.sendto)
				  tomail = thisForm.tomail.value;
				  qstr = "mailer.asp?id=" +mailing_id + "&sendto=" + sendto + "&tomail=" + tomail;
				  document.intframe.location.href=qstr;
				  document.all.intframe.style.display = '';
				  //alert(qstr)
				  break;
		default		: break;
	}
	
}


function radioValue(radioButton,output)
{
    for (i = 0; i <= radioButton.length; i++)
    {
        if (radioButton[i].checked == true) {
        	if(output=='index') {
        		return i;
        	}else{
     			return radioButton[i].value; 
     		}
     	}
    } 
         // if it didn't find anything, return the .value  (behaviour of single radio btn)
        return 'empty';
}


function validEmail(formvalue,showalert)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(formvalue)){return true;}
	else { if(showalert!=0) alert('S.v.p. een geldig emailadres opgeven.'); return false;}
}

function validZipcode(formvalue,showalert)
{
	var filter  = /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/;
	if (filter.test(formvalue)){return true;}
	else { if(showalert!=0) alert('S.v.p. een geldig emailadres opgeven.'); return false;}
}

function validPhone(formvalue,showalert)
{
	var filter  = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{3,4})(( x| ext)\d{1,5}){0,1}$/;
	if (filter.test(formvalue)){return true;}
	else { if(showalert!=0) alert('S.v.p. een geldig telefoonnummer opgeven.'); return false;}
}

function validForm(name,tabbed){

	var validated=true;
	var fieldcol  = '#f6f162';
	var inputs=document.forms[name].getElementsByTagName("input");
	if (tabbed || tabbed==1){
		tabbed=1;
	}else{
		tabbed=0;
	}
	
	//init
	var inputs=document.forms[name].getElementsByTagName("input");
	for(var i=0;i<inputs.length;i++)
		{
		if(inputs[i].getAttribute("validate")){
			inputs[i].style.background = '';
			}
	}
	
	//init
	var selects=document.forms[name].getElementsByTagName("select");
	for(var i=0;i<selects.length;i++)
		{
		if(selects[i].getAttribute("validate")){
			selects[i].style.background = '';
			}
	}	
	
	if(tabbed==1){
		for(var i=1;i<4;i++)
			{
				markTab('tab'+i,'#dddddd');
			}
	}
	
	for(var i=0;i<inputs.length;i++)
		{
			if(inputs[i].getAttribute("validate"))
				{
					if(inputs[i].getAttribute("validate")=='yes' && inputs[i].value.length==0){
						inputs[i].style.background = fieldcol;
						tabname = inputs[i].getAttribute("tab");
						if(tabbed==1){markTab(tabname,fieldcol)}
						validated = false;
						msg = 'S.v.p. de verplichte velden invullen';
					}
					if(inputs[i].getAttribute("validate")=='email' && !validEmail(inputs[i].value,0)){
						inputs[i].style.background = fieldcol;
						tabname = inputs[i].getAttribute("tab");
						if(tabbed==1){markTab(tabname,fieldcol)}
						validated = false;
						msg = 'S.v.p. een geldig emailadres opgeven.';
					}
					if(inputs[i].getAttribute("validate")=='zipcode' && !validZipcode(inputs[i].value,0)){
						inputs[i].style.background = fieldcol;
						tabname = inputs[i].getAttribute("tab");
						if(tabbed==1){markTab(tabname,fieldcol)}
						validated = false;
						msg = 'S.v.p. een geldig postcode opgeven.';
					}
					if(inputs[i].getAttribute("validate")=='phone' && !validPhone(inputs[i].value,0)){
						inputs[i].style.background = fieldcol;
						tabname = inputs[i].getAttribute("tab");
						if(tabbed==1){markTab(tabname,fieldcol)}
						validated = false;
						msg = 'S.v.p. een geldig telefoonnummer opgeven.';
					}
					if(inputs[i].getAttribute("validate")=='checked' && inputs[i].checked){
						val_action = inputs[i].getAttribute("validate_action");
						val_value = parseFloat(inputs[i].getAttribute("validate_value"));
						if(val_action=="skip"){
							i=i+val_value;
						}
						
					}
				}
		}
		
	for(var i=0;i<selects.length;i++)
			{
			if(selects[i].getAttribute("validate"))
				{	
						if(selects[i].getAttribute("validate")=='yes' && selects[i].selectedIndex==0){
						selects[i].style.background = fieldcol;
						tabname = selects[i].getAttribute("tab");
						if(tabbed==1){markTab(tabname,fieldcol)}
						validated = false;
						msg = 'S.v.p. de een keuze maken uit het menu';
					}				
				}
		}
		
	if(!validated) alert (msg);
	return validated
}



function markTab(tab,color){
	document.getElementById(tab).childNodes[1].style.background = color;
}

function isInput(evt){
	if(!evt)var evt=window.event;
	if(this.tagName.toUpperCase().indexOf("INPUT")!=-1)
	{
	   this.style.background='white';
	}else{
	   //evt.cancelBubble=true;
	}
}


//Tabs en panels
var panels = new Array('panel0','panel1', 'panel2', 'panel3', 'panel4', 'panel5', 'panel6');
var selectedTab = null;
function showPanel(tab, name, type)
      { 
        if (selectedTab) 
        {
          selectedTab.style.fontWeight = '';
          /*
          selectedTab.style.backgroundColor = '';
          selectedTab.style.paddingTop = '';
          selectedTab.style.paddingBottom = ''
          */
        }
        selectedTab = tab;
        //selectedTab.style.backgroundColor = 'white';
        selectedTab.style.fontWeight = 'bold';
        //selectedTab.style.paddingTop = '6px';
 
	for(i = 0; i < panels.length; i++)
	{
	 
	  if(document.getElementById(panels[i]))
		{
		document.getElementById(panels[i]).style.display = (name == panels[i]) ? 'block':'none';
		}
	}

        return false;
}