// JavaScript Document
var InternetExplorer = navigator.appName.indexOf('Microsoft') != -1;
var client_browse = '';
if(document.getElementById)
{client_browse = 'ie5';}	// IE5+,NN6+	document.getElementById('id')
else if(document.all)
{client_browse = 'ie4';}	// IE4	document.all('id');
else if(document.layers)
{client_browse = 'ns4';}	// NN4	document.layers['id'];

function $(strname)
{
	switch(client_browse){
		case 'ie5':
			return document.getElementById(strname);
			break;
		case 'ns4':
			return document.layers[strname];
			break;
		default:	// 'ie4'
			return document.all(strname);
			break;
	}
}

String.prototype.Trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function checkObj(str,re){
	var obj_re=re;
	if(!obj_re.test(str))
		return true;
	else
		return false;
}

function movePro(id, d){
	var bn = id.replace('i','n');
	if($(id).style.left == '') $(id).style.left = '0px';
	if($(bn).style.left == '') $(bn).style.left = '0px';

	setTimeout(function(){moveStep(id, d, 0, 107*1)},0);
}

function moveStep(id, d, n, c){
	var w = parseInt($(id).style.width.replace('px',''));
	var bn = id.replace('i','n');

	n = n + 1;
	if(n <= c){
		if(d == 'l'){
			if(parseInt($(id).style.left.replace('px',''))-c*4 > -w){ //width:1284px;
				$(id).style.left = parseInt($(id).style.left.replace('px','')) - (1) + 'px';
				$(bn).style.left = parseInt($(bn).style.left.replace('px','')) - (1) + 'px';
			}else{return false;}
		}else if(d == 'r'){
			if(parseInt($(id).style.left.replace('px','')) < 0){
				$(id).style.left = parseInt($(id).style.left.replace('px','')) + (1) + 'px';
				$(bn).style.left = parseInt($(bn).style.left.replace('px','')) + (1) + 'px';
			}else{return false;}
		}

		setTimeout(function(){moveStep(id, d, n, c)},0);
	}
}

function LoadDcls(lang){
	if(lang == '') lang='cn';
	var ajx = new Ajax.Request('/inc/script.asp?type=dcls&lang='+ lang +'&'+ Math.random(), {method: 'get', onComplete: SetDcls});
}

function LoadPcls(lang){
	if(lang == '') lang='cn';
	var ajx = new Ajax.Request('/inc/script.asp?type=pcls&lang='+ lang +'&'+ Math.random(), {method: 'get', onComplete: SetPcls});
}

function SetDcls(o){
	var ovalue = $('area').options[0].text;
	var ostr = o.responseText.split('//');

	$('area').options.length = 0;
	$('area').options.add(new Option(ovalue, 'all'));

	for(i=0; i<=ostr.length - 1; i++)
		$('area').options.add(new Option(ostr[i].split('/')[0], ostr[i].split('/')[1]));
}

function SetPcls(o){
	var ovalue = $('category').options[0].text;
	var ostr = o.responseText.split('//');

	$('category').options.length = 0;
	$('category').options.add(new Option(ovalue, 'all'));

	for(i=0; i<=ostr.length - 2; i++)
		$('category').options.add(new Option(ostr[i].split('/')[0], ostr[i].split('/')[1]));
}

function SetMDealer(lang, e){
	if(lang == '') lang='cn';

	$('container').style.display = 'none';
	$('dealer').style.display = 'block';
	$('dealer').innerHTML = '<p>Load Data ...</p>' + '<p><a onclick="displaymap();" href="javascript:void(0);">&lt;&lt; '+ $('ret').value +'</a></p>';
	
	var ajx = new Ajax.Request('/inc/script.asp?type=mdealer&category='+ e.value +'&lang='+ lang +'&'+ Math.random(), {method: 'get', onComplete: SetMDealerHtml});
}

function SetMDealerHtml(o){
	if(o.responseText == '')
		$('dealer').innerHTML = '<p class="dealerli"><strong>'+ $('nodata').value +'</strong></p>';
	else
		$('dealer').innerHTML = o.responseText;

	$('dealer').innerHTML += '<p><a onclick="displaymap();" href="javascript:void(0);">&lt;&lt; '+ $('ret').value +'</a></p>'
}

function SetDealer(lang){
	if(lang == '') lang='cn';

	$('search').style.display = 'none';
	$('dealer').style.display = 'block';
	$('dealer').innerHTML = '<p>Load Data ...</p>' + '<p><a onclick="displaysearch();" href="javascript:void(0);">&lt;&lt; '+ $('ret').value +'</a></p>';

	var ajx = new Ajax.Request('/inc/script.asp?type=sdealer&category='+ $('category').value +'&area='+ $('area').value +'&lang='+ lang +'&'+ Math.random(), {method: 'get', onComplete: SetDealerHtml});
}

function SetDealerHtml(o){
	if(o.responseText == '')
		$('dealer').innerHTML = '<p class="dealerli"><strong>'+ $('nodata').value +'</strong></p>';
	else
		$('dealer').innerHTML = o.responseText;

	$('dealer').innerHTML += '<p><a onclick="displaysearch();" href="javascript:void(0);">&lt;&lt; '+ $('ret').value +'</a></p>'
}

function checkformat(src){
	var check = new String(src);
	var check = check.toLowerCase();
	var source = new String("0123456789");
	for(i=0; i<check.length; i++){
		pos = source.indexOf(check.charAt(i));
		if(pos < 0)
			return false;
	}
	return true;
}

function gopage(v, c, view, pn){
	if(checkformat(v)){
		if(!(v>c || v<=0)){
			if(v==1){
				this.location.href = 'index.asp?view='+ view +'&pn='+ pn;
			}else{
				this.location.href = 'index.asp?view='+ view +'&pn='+ pn +'&page='+ v;
			}
		}
	}
}

function gopage2(v, c){
	if(checkformat(v)){
		if(!(v>c || v<=0)){
			if(v==1){
				this.location.href = '?';
			}else{
				this.location.href = '?page='+ v;
			}
		}
	}
}

function gopage3(v, c, k, view, pn){
	if(checkformat(v)){
		if(!(v>c || v<=0)){
			if(v==1){
				this.location.href = 'index.asp?view='+ view +'&pn='+ pn +'&k='+ k;
			}else{
				this.location.href = 'index.asp?view='+ view +'&pn='+ pn +'&page='+ v +'&k='+ k;
			}
		}
	}
}

function fview(ids, o, t){
	var id = ids.split(",");

	if(t==1){
		o.src = '/image/tree_shrink.gif';
		o.onclick = function(){fview(ids, o, 2)};
	}else{
		o.src = '/image/tree_unfold.gif';
		o.onclick = function(){fview(ids, o, 1)};
	}

	for(i=0; i<=id.length-1; i++)
		$('li_'+ id[i]).style.display = (t==1) ? 'block' : 'none';
}

function SetClassStyle(id, pid){
	if(pid) fview(pid, this, 1);
	if(id) $('li_'+ id).getElementsByTagName('A')[0].className = 'classAct';	
}
