// Toggle Elements

function toggleLoc(select,id){
	loc = select.options[select.options.selectedIndex].value;
    ul = "ul_" + id;
    ulElement = document.getElementById(ul);
    if (ulElement){
            if ( loc == '0' ){
                    ulElement.className = "shown";
                    }else{
                    ulElement.className = "hidden";
                    }
            }
    }


// Check form

var W3CDOM = (document.getElementsByTagName && document.createElement);

function validate(chkform,password,table) {
	errstr = '';
	var x = chkform.elements;

// check if name field is specified
	if ( !x['m_name'].value )
		errstr += writeError(x['m_name'],'This field is required.');
	if ( x['m_name'].value.length < 3 )
		errstr += writeError(x['m_name'],'The name is too short.');
// check if phone field contains only numbers when specified
	if ( x['m_tel'].value && !x['m_tel'].value.match(/^[0-9\ ]+$/) )
		errstr += writeError(x['m_tel'],'The phone number should only contain digits separated by spaces.');
// check if fax field contains only numbers when specified
	if ( x['m_fax'].value && !x['m_fax'].value.match(/^[0-9\ ]+$/) )
		errstr += writeError(x['m_fax'],'The fax number should only contain digits separated by spaces.');
// check if e-mail address is correct when specified
	if ( x['m_mail'].value && !x['m_mail'].value.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/) )
		errstr += writeError(x['m_mail'],'This does not seem to be a correct e-mail address.');

	if ( table == 'uecbv' ) {
// check if e-mail address is specified when newsletter active
		if ( x['m_newsletter'].checked && !x['m_mail'].value )
			errstr += writeError(x['m_mail'],'Please specify an e-mail-address to allow newsletter sending!');
// check if e-mail address is specified when login allowed
		if ( x['m_inside'].checked && !x['m_mail'].value )
			errstr += writeError(x['m_mail'],'Please specify an e-mail-address to allow access to the members area!');
// check if password is specified when login allowed
		if ( x['m_inside'].checked && !x['m_pw'].value && !password )
			errstr += writeError(x['m_pw'],'Please specify a password to allow access to the members area!');
	}

// return warnings or submit
	if ( !errstr ) {
		return true;
	} else {
		if ( !W3CDOM )
			alert( errstr );
		return false;
	}
}

function yemcoform(chkform,lang) {
	errstr = '';
	var x = chkform.elements;

// check if first name field is specified
	if ( !x['mfirst'].value )
		errstr += writeError(x['mfirst'],'Please, specify your first name.');
	if ( x['mfirst'].value.length < 3 )
		errstr += writeError(x['mfirst'],'The name you have entered is too short.');
// check if last name field is specified
	if ( !x['mlast'].value )
		errstr += writeError(x['mlast'],'Please, specify your last name.');
	if ( x['mlast'].value.length < 3 )
		errstr += writeError(x['mlast'],'The name you have entered is too short.');
// check if company field is specified
	if ( !x['mco'].value )
		errstr += writeError(x['mco'],'Please, specify your company\'s name.');
	if ( x['mlast'].value.length < 3 )
		errstr += writeError(x['mlast'],'The company name you have entered is too short.');
// check if address field is specified
	if ( !x['mstreet'].value )
		errstr += writeError(x['mstreet'],'Please, specify your address.');
// check if zip code field is specified
	if ( !x['mzip'].value )
		errstr += writeError(x['mzip'],'Please, specify your postal code.');
// check if city field is specified
	if ( !x['mcity'].value )
		errstr += writeError(x['mcity'],'Please, specify your city.');
// check if country field is specified
	if ( !x['mloc'].value )
		errstr += writeError(x['mloc'],'Please, specify your country.');
// check if phone field is specified
	if ( !x['mtel'].value && !x['mmob'].value )
		errstr += writeError(x['mtel'],'Please, specify your phone number.');
// check if phone field contains only numbers
	if ( x['mtel'].value && !x['mtel'].value.match(/^[0-9\ ]+$/) )
		errstr += writeError(x['mtel'],'The phone number should only contain digits separated by spaces.');
// check if mobile field contains only numbers
	if ( x['mmob'].value && !x['mmob'].value.match(/^[0-9\ ]+$/) )
		errstr += writeError(x['mmob'],'The mobile number should only contain digits separated by spaces.');
// check if fax field contains only numbers
	if ( x['mfax'].value && !x['mfax'].value.match(/^[0-9\ ]+$/) )
		errstr += writeError(x['mfax'],'The facsimile number should only contain digits separated by spaces.');
// check if mail field is specified
	if ( !x['mmail'].value )
		errstr += writeError(x['mmail'],'Please, specify your e-mail address.');
// check if e-mail address is correct
	if ( x['mmail'].value && !x['mmail'].value.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/) )
		errstr += writeError(x['mmail'],'This does not seem to be a correct e-mail address.');

// return warnings or submit
	if ( !errstr ) {
		return true;
	} else {
		if ( !W3CDOM )
			alert( errstr );
		return false;
	}
}

function writeError(obj,message) {
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' errorbox';
		obj.onchange = removeError;
		var sp = document.createElement( 'span' );
		sp.className = 'errormsg';
		sp.appendChild( document.createTextNode( message ) );
		obj.parentNode.appendChild( sp );
		obj.hasError = sp;
	}
	else {
		obj.hasError = true;
	}
	var errorstring = obj.name + ': ' + message + '\n';
	return errorstring;
}

function removeError()
{
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}
