// JavaScript Document

function asf_check(element, do_check) {
	var elts      = document.asfform.elements[element];
	var elts_cnt  = (typeof(elts.length) != 'undefined') ? elts.length: 0;

	if (elts_cnt) {
		for (var i = 0; i < elts_cnt; i++) {
			elts[i].checked = do_check;
		}
	} else {
		elts.checked = do_check;
	}
}

function asf_cdel(name, id) {
	if(confirm('Wollen Sie ' + name + ' wirklick l' + unescape('%F6') + 'schen?')) {
		window.location.href = window.location.pathname + '?asf_delete=' + id;
	} else {
		// nothing
	}
}

function asf_el(s) {
	return (document.getElementById)?document.getElementById(s):document.all[s];
}

function go_pager(val) {
	field = asf_el('asf_gopage');
	field.value = val;
	document.asf_res.submit();
}

function asf_go(url) {
	document.location.href = url;
}

function asf_as() {
	field = asf_el('asf_as');
	field.value = 'sp';
}

function asf_as2() {
	field = asf_el('asf_as2');
	field.value = 'sp';
}

function asf_rate_text(i) {
	if (i == 1) return 'okay';
	if (i == 2) return 'gut';
	if (i == 3) return 'besser';
	if (i == 4) return 'sehr gut';
	if (i == 5) return 'tadellos';
	return '';
}

function asf_rate_hl(type, i, file) {
	for (j = 1; j <= 5; j++) {
		imgid = 'asf_rate_' + type + '_' + j;
		img = asf_el(imgid);
		dir = '/wp-content/themes/autoservicefinder/images/';
		
		if (j > i) {
			img.src = dir + 'rate_0.gif';
		} else {
			img.src = dir + file;
		}
	}
}

function asf_rate_reset(type) {
	asf_rate_hl(type, 0, 'rate_0.gif');
	field = asf_el('asf_rate_field_' + type);
	if (field.value != '') {
		asf_rate_hl(type, field.value, 'rate_1.gif');
		
		text = asf_rate_text(field.value);
		tcont = asf_el('asf_rate_text_' + type);
		tcont.innerHTML = text;
	}
}

function asf_rate_set(type, i) {
	asf_rate_hl(type, i, 'rate_1.gif');

	text = asf_rate_text(i);
	tcont = asf_el('asf_rate_text_' + type);
	tcont.innerHTML = text;
	field = asf_el('asf_rate_field_' + type);
	field.value = i;
}

function asf_rate(type, i) {
	asf_rate_hl(type, i, 'rate_.gif');
} 

function asf_details() {
	document.asf_details_form.submit();
}

function asf_as_mx(a, b, c) {
	document.write('<a h'+'ref'+'=\"#');
	document.write('\" oncl'+'ick='+'\"asf_as_mxx(\''+a);
	document.write('\',\''+b);
	document.write('\','+c+');\">'+a+'@'+b+'<');
	document.write('/a>');
}

function asf_as_mxx(a, b, c) {
	document.location.href='mail'+'to:'+a+'@'+b;
	asf_notify_server(c);
}

// al little ajax
function asf_notify_server(uid) {
	var url = '/test/zzajax?asf_action=clem&asf_uid=' + uid;
	asf_ajax_call(url);
}

function asf_ajax_call(url) {
	var request = false;
	
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request = new ActiveXObject('Microsoft.XMLHTTP');
	}
	
	if (!request) {
		request = new ActiveXObject('Msxml2.XMLHTTP');
	}
	
	if (request) {
		request.open('GET', url, true);
		request.send(null);
	}
}

function asf_print_search(params) {
	window.open('/drucksuche?' + params,'print','menubar=yes,scrollbars=yes,resizable=yes,width=800,height=700');
}

function asf_print_details(params) {
	window.open('/druckdetails?' + params,'print','menubar=yes,scrollbars=yes,resizable=yes,width=800,height=700');
}

function asf_password_new() {
	var length=8;
	var sPassword = '';
	var noPunction = true;

	for (i=0; i < length; i++) {

		numI = asf_rand_num();
		while (asf_char_check(numI)) { 
			numI = asf_rand_num(); 
		} 

		sPassword = sPassword + String.fromCharCode(numI);
	}

	document.asfform.pw_new.value = sPassword;
}

function asf_rand_num() {
	var rndNum = Math.random()
	rndNum = parseInt(rndNum * 1000);
	rndNum = (rndNum % 94) + 33;
	return rndNum;
}

function asf_char_check(num) {
	if ((num >=33) && (num <=47)) { 
		return true; 
	}
	if ((num >=58) && (num <=64)) { 
		return true; 
	}
	if ((num >=91) && (num <=96)) { 
		return true; 
	}
	if ((num >=123) && (num <=126)) { 
		return true; 
	}
	return false;
}
