function ch_class(ctl_id, cls)
{
	var ctl = document.getElementById(ctl_id);
	if (ctl && ctl.className != cls)
	{
		ctl.old_cls = ctl.className;
		ctl.className = cls;
	}
}

function revert_class(ctl_id)
{
	var ctl = document.getElementById(ctl_id);
	if (ctl && (typeof(ctl.old_cls) != 'undefined'))
	{
		ctl.className = ctl.old_cls;
	}
}

function isEmail(emailStr){
	var atPos = emailStr.indexOf("@");
	var isEmail = (atPos>-1);
	if (isEmail){
		isEmail = IsDomain(emailStr.substring(0,atPos)+emailStr.substring(atPos+1,emailStr.length));
	}
	return isEmail;
}




function printPost(user){
	var _txt = '';
	_txt += '<a href="mail';
	_txt += 'to:' + user + '@' + 'amayama.co.jp">';
	_txt += user + '@' + 'amayama.co.jp</a>';
	document.write(_txt);
}


function printPostFull(domain,user){
	var _txt = '';
	_txt += '<a href="mail';
	_txt += 'to:' + user + '@' + domain + '">';
	_txt += user + '@' + domain + '</a>';
	document.write(_txt);
}




function changeBg(mode, el){
	var d = document.getElementById(el);
	if (mode == 1) {
		d.style.background = 'url(/images/skin/descrip_bg_on.gif) no-repeat left top';
	} else {
		d.style.background = 'url(/images/skin/descrip_bg.gif) no-repeat left top';
	}
}


function checkField(name, label){
	if (name=='' || label=='') return true;
	var current = '';
	for(i=0; i<document.getElementsByName(name).length; i++) {
		current = document.getElementsByName(name).item(i);
		if (current.tagName == 'input') break;
	}

	if (current == ''){
		alert("Error: can't find input - " + name);
		return false;
	}
	if (current.value == ''){
		current.focus();
		alert('Выдолжны заполнить поле  "' + label + '"');
		return false;
	}
	return true;
}


function checkForm(formName){
	if (formName == 'order'){
		if (checkField('firm', 'Фирма, модель')==false) return false;
		if (checkField('year', 'Год выпуска')==false) return false;
		if (checkField('fuel', 'Топливо')==false) return false;
		if (checkField('drive', 'Привод')==false) return false;
		if (checkField('city', 'Город')==false) return false;
		if (checkField('email', 'E-mail')==false) return false;
		
		var mail = document.getElementsByName('email')[0];
		if (mail && !isEmail(mail.value)){
			alert("Вы неправильно ввели e-mail. Он должен иметь вид aaa@bbb.ccc");
			return false;
		}
		
		return true;
	}

	return false;
}




function imgWin(img){
	var scr='/images/preview.htm';
	var x = screen.width/2 - 400/2;
	var y = screen.height/2 - 300/2;
	var wn=window.open(scr+'?'+escape(img),'win','resizable,width=400,height=300,top='+y+',left='+x+',screenX='+x+',screenY='+y+',status=0');
	wn.focus();
	return false;
}





var flashVersion = 0;
var defErrorHandle = window.onerror;

function Flash () {
	this._swf = '';
	this._width = 0;
	this._height = 0;
	this._params = new Array();
	this._divClass = '';
}


Flash.prototype.setSWF = function (_swf, _width, _height, _divClass){
	this._swf = _swf;
	this._width = _width;
	this._height = _height;
	this._divClass = _divClass;
}


Flash.prototype.setParam = function (paramName, paramValue){
	this._params[this._params.length] = paramName+'|||'+paramValue;
}


Flash.prototype.display = function () {
	if (flashVersion < 6) return false;
	
	var _txt = '';
	var params = '';
	var _param = '';
	var i = 0;

	_txt += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+this._width+'" height="'+this._height+'">\n';
	_txt += '<param name="movie" value="'+this._swf+'" />\n'
	_txt += '<param name="quality" value="high" />\n';
	for ( i=0;i<this._params.length;i++ ) {
	_param = this._params[i].split ('|||');
	_txt += '\t<param name="'+_param[0]+'" value="'+_param[1]+'" />\n';
	_txt += '\t<param name="menu" value="false" />\n';
	params += _param[0]+'="'+_param[1]+'" ';
	}

	_txt += '<embed menu="false" width="'+this._width+'" height="'+this._height+'" src="'+this._swf+'" '+params+' quality="high" type="application/x-shockwave-flash"></embed>\n';
	_txt += '</object>\n';
	
	document.write (_txt);
}


function GetFlashVersion() {
	/* GetFlashVersion - must be last function in file */
	window.onerror = function() {
		return true;
	}
	var ie=0
	var fz=0
	var n=navigator

	if (n.platform=='Win32' && !window.opera && n.appName!='Netscape') {
		ie=1
		for (var i=3;i<10;i++) {
			if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.'+i+'")')) {
				flashVersion = i;
			}
		}
	}


	if ((ie==0)&&(n.plugins)) {
		for (var i=0;i<n.plugins.length;i++) {
			if (n.plugins[i].name.indexOf('Flash')> -1) {
				fz = parseInt(n.plugins[i].description.charAt(16));
				if (fz > flashVersion) flashVersion = fz;
			}
		}
	}
}
GetFlashVersion();
window.onerror = defErrorHandle;
