function pasIntTimeOut(){
	if (isNaN(intAjaxTimeOut) || intAjaxTimeOut==""){intAjaxTimeOut=6000;}
	if (parseInt(intAjaxTimeOut)<2000){intAjaxTimeOut=2000;}
}

// 延时下拉菜单) Copyright 2006-2007 javascript-array.com // 由 haphic (esloy.com) 使用 JQ 完善和改进.
var timeout	= 200;
var closetimer	= 0;
var ddmenuitem	= 0;
function mopen(ftmenu){
	mcancelclosetime();
	if(ddmenuitem){if(ddmenuitem.parent('li').children('a').text()!==$(ftmenu).text()){ddmenuitem.css('display','none');ddmenuitem.parent('li').children('a').removeClass('dropmenuhover');}}
	ddmenuitem = $(ftmenu).parent('li').children('ul');
	ddmenuitem.css('display','block');
	ddmenuitem.parent('li').children('a').addClass('dropmenuhover');
}
function mclose(){
	if(ddmenuitem){ddmenuitem.parent('li').children('a').removeClass('dropmenuhover');ddmenuitem.css('display','none');}
}
function mclosetime(){
	closetimer = window.setTimeout(mclose, timeout);
}
function mcancelclosetime(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
function mcloseimm(){
	var ddmenuall = $('#navBar>ul>li');
	ddmenuall.children('ul').css('display','none');
	ddmenuall.children('a').removeClass('dropmenuhover');
}
document.onclick = mcloseimm;

function navBarBgFix(){
	var iWidth=0;
	$('#navBar>ul>li>a').each(function(){
		iWidth=$(this).width()+18;
		$(this).parent('li').children('ul').css('background-position',iWidth+'px 0');
	});
}
function navBarDropMenuInit(){
	$('#navBar>ul>li>a').each(function(){
		this.onmouseover = function(){mopen(this);}
		this.onmouseout = function(){mclosetime();}
		//$(this).hover(function(){mopen(this);},function(){mclosetime();})
	});
	$('#navBar>ul>li>ul').each(function(){
		this.onmouseover = function(){mcancelclosetime();}
		this.onmouseout = function(){mclosetime();}
		//$(this).hover(function(){mcancelclosetime();},function(){mclosetime();})
	});
}

//Creat Hint TimeOut
var hintTimer=0;
var hintTimeOut=600;

function getOrder(sNum,nProv,nCity,nLocal){
	window.clearTimeout(hintTimer);
	hintTimer = null;
	var $globalHint=$('#globalHint>span');
	$globalHint.hide();

	var $objContent = $('#orderForm');
	if ($objContent.css('display')=='none'){
		$('#orderButton').addClass('formOpen');
	}else{
		if(sNum==''){$('#orderButton').removeAttr('class');}
	}
	if ($objContent.html()==''){
		$globalHint.html(iconAjaxLoading+langLoadingData).css('display','inline');
		var bLoaded=false;
		pasIntTimeOut();
		$.ajax({
			type: 'GET', dataType: 'html', timeout: intAjaxTimeOut,
			url: str00+'themes/'+strThemeName+'/plugin/user/order.asp',
			error: function(){
				$globalHint.html("<a href=\"javascript:void(0)\" onclick=\"getOrder('"+sNum+"','"+nProv+"','"+nCity+"','"+nLocal+"')\">"+langErrorThenRetry+"</a>");
				bLoaded=true;
			},
			success: function(data){
				data=data.replace(/%地区%/g,nLocal).replace(/%省份%/g,nProv).replace(/%城市%/g,nCity);
				$objContent.html(data);
				$('#verifyImg').attr("src",str00+"function/c_validcode.asp?name=commentvalid"+"&random="+Math.random());
				$('#orderForm:hidden').slideDown('slow');
				$('#cnumber').val(sNum);
				hintTimer = window.setTimeout(function(){$globalHint.html('').hide();}, hintTimeOut);
				if(chkNum(sNum)==false){return false;}
				bLoaded=true;
			}
		});
		setTimeout(function(){
				if(bLoaded==false){
					$globalHint.html(iconAjaxLoading+langStillWorking);
				}
			},parseInt(intAjaxTimeOut/2)
		);
	}else{
		if(sNum==''){
			$objContent.slideToggle("slow");
		}else{
			if($objContent.css('display')=='none'){$objContent.slideDown('normal');}
			var cNumber=$('#cnumber').val();
			if(cNumber.indexOf(sNum)==-1){
				cNumber=cNumber+", "+sNum;
			}else{
				cNumber=cNumber.replace(sNum,'');
			}
			cNumber=cNumber.replace(/[^\d]+/g,', ').replace(/^,\s+/g,'').replace(/,\s+$/g,'');
			if(chkNum(cNumber)==false){return false;}
			$('#cnumber').val(cNumber);
		}
	}
	//return false;
}

function chkNum(sNumList){
	if(sNumList.length>100){alert('你选择的号码数量超出限制!');return false;}
	$('a[@rel^=num#]').each(function(){
		if(sNumList.indexOf($(this).attr('rel').replace('num#',''))==-1){
			$(this).removeClass('numSeled');
		}else{
			$(this).addClass('numSeled');
		}
	});
	return true;
}

function orderNum(obj){
	getOrder($(obj).attr('rel').replace('num#',''),'','','');
	//return false;
}

function getCities(){
	window.clearTimeout(hintTimer);
	hintTimer = null;
	var $globalHint=$('#globalHint>span');
	$globalHint.hide();

	var nProv=$('#cprovince').val();

	var $objContent = $('#selCity');
	$globalHint.html(iconAjaxLoading+langLoadingData).css('display','inline');
	var bLoaded=false;
	pasIntTimeOut();
	$.ajax({
		type: 'POST', dataType: 'html', timeout: intAjaxTimeOut,
		data: 'p='+nProv,
		url: str00+'themes/'+strThemeName+'/plugin/user/licities.asp',
		error: function(){
			$globalHint.html("<a href=\"javascript:void(0)\" onclick=\"getCities()\">"+langErrorThenRetry+"</a>");
			bLoaded=true;
		},
		success: function(data){
			if (data.indexOf('noData')==-1){
				$objContent.html(data);
				$objContent.show();
			}
			hintTimer = window.setTimeout(function(){$globalHint.html('').hide();}, hintTimeOut);
			bLoaded=true;
		}
	});
	setTimeout(function(){
			if(bLoaded==false){
				$globalHint.html(iconAjaxLoading+langStillWorking);
			}
		},parseInt(intAjaxTimeOut/2)
	);
	return false;
}

function hideSel(){
	$('#selProvince').hide();
	$('#selCity').hide();
}

function getQuery(){
	window.clearTimeout(hintTimer);
	hintTimer = null;
	var $globalHint=$('#globalHint>span');
	$globalHint.hide();

	var $objContent = $('#queryForm');
	if ($objContent.css('display')=='none'){
		$('#queryButton').addClass('formOpen');
	}else{
		$('#queryButton').removeAttr('class');
	}
	if ($objContent.html()==''){
		$globalHint.html(iconAjaxLoading+langLoadingData).css('display','inline');
		var bLoaded=false;
		pasIntTimeOut();
		$.ajax({
			type: 'GET', dataType: 'html', timeout: intAjaxTimeOut,
			url: str00+'themes/'+strThemeName+'/plugin/user/query.asp',
			error: function(){
				$globalHint.html("<a href=\"javascript:void(0)\" onclick=\"getQuery()\">"+langErrorThenRetry+"</a>");
				bLoaded=true;
			},
			success: function(data){
				$objContent.html(data);
				$('#queryForm:hidden').slideDown('normal');
				hintTimer = window.setTimeout(function(){$globalHint.html('').hide();}, hintTimeOut);
				bLoaded=true;
			}
		});
		setTimeout(function(){
				if(bLoaded==false){
					$globalHint.html(iconAjaxLoading+langStillWorking);
				}
			},parseInt(intAjaxTimeOut/2)
		);
	}else{
		$objContent.slideToggle("normal");
	}
	//return false;
}

var queryTimer=0;
function postQuery(){
	window.clearTimeout(queryTimer);
	window.clearTimeout(hintTimer);
	hintTimer = null;
	var $globalHint=$('#globalHint>span');
	$globalHint.hide();

	var sNumber=$('#number').val();
	var sRate=$('#rate').val();
	var sType=$('#type').val();
	var sPage=$('#page').val();

	var $objContent = $('#queryResult');
	$globalHint.html(iconAjaxLoading+langLoadingData).css('display','inline');
	var bLoaded=false;
	var sdate = new Date();
	pasIntTimeOut();
	$.ajax({
		type: 'GET', dataType: 'html', timeout: intAjaxTimeOut,
		data: 'number='+sNumber+'&rate='+sRate+'&type='+sType+'&page='+sPage,
		url: str00+'themes/'+strThemeName+'/plugin/user/querypost.asp?time='+sdate.getTime(),
		error: function(){
			$globalHint.html("<a href=\"javascript:void(0)\" onclick=\"postQuery()\">"+langErrorThenRetry+"</a>");
			bLoaded=true;
		},
		success: function(data){
			if (data=="<!--RETRY-->"){
				queryTimer=setTimeout(function(){postQuery();},2500);
			}else{
				$objContent.css("padding","8px 2px");
				$objContent.html(data);
				hintTimer = window.setTimeout(function(){$globalHint.html('').hide();}, hintTimeOut);
				if ($('#cnumber').size()>0){chkNum($('#cnumber').val());}
			}
			bLoaded=true;
		}
	});
	setTimeout(function(){
			if(bLoaded==false){
				$globalHint.html(iconAjaxLoading+langStillWorking);
			}
		},parseInt(intAjaxTimeOut/2)
	);
	return false;
}

//*********************************************************
// 目的：    验证信息
// 输入：    无
// 返回：    无
//*********************************************************
function clearError(obj){
	$(obj).removeClass('error');
}
function postOrder() {

	$('#orderForm input').removeClass('error');
	$("#CommentPosting").html("");

	var cnumber=$("#cnumber").val();
	var ccompany=$("#ccompany").val();
	var cname=$("#cname").val();
	var cprovince=$("#cprovince").val();
	var ccity=$("#ccity").val();
	var ctel=$("#ctel").val();
	var ccell=$("#ccell").val();
	var cqqmsn=$("#cqqmsn").val();
	var cemail=$("#cemail").val();

	var errorOccus=false;
	var errorDesc="";

	if(cname==""){
		$("#cname").addClass('error');
		errorDesc=errorDesc+'您的姓名不能为空!\n';
		errorOccus=true;
	}else{
		re = new RegExp("^[.A-Za-z0-9\u4e00-\u9fa5]+$");
		if (!re.test(cname)){
			errorDesc=errorDesc+'姓名格式不对或其中有非法字符!\n';
			errorOccus=true;
		}
	}

	if(ctel=="" && ccell==""){
		$("#ctel").addClass('error');
		$("#ccell").addClass('error');
		errorDesc=errorDesc+'固定电话和手机必须填写一种!\n';
		errorOccus=true;
	}else{
		re = new RegExp("^[0-9\-\(\)\+\s]{5,30}$");
		if (ctel!==""){
			if (!re.test(ctel)){
				$("#ctel").addClass('error');
				errorDesc=errorDesc+'电话号码格式错误!\n';
				errorOccus=true;
			}
		}
		if (ccell!==""){
			if (!re.test(ccell)){
				$("#ccell").addClass('error');
				errorDesc=errorDesc+'电话号码格式错误!\n';
				errorOccus=true;
			}
		}
	}

	if(cqqmsn!==""){
		re = new RegExp("(^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$)|(^[0-9]+$)");
		if (!re.test(cqqmsn)){
			$("#cqqmsn").addClass('error');
			errorDesc=errorDesc+'QQ或MSN格式不正确!\n';
			errorOccus=true;
		}
	}

	if(cemail!==""){
		re = new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
		if (!re.test(cemail)){
			$("#cemail").addClass('error');
			errorDesc=errorDesc+'电子邮件格式错误!\n';
			errorOccus=true;
		}
	}

	if (errorOccus){
		$("#CommentPosting").html(iconAjaxDecline);
		alert(errorDesc);
		return false;
	}

	if(cnumber==""){cnumber='------'}
	if(ccompany==""){ccompany='------'}
	if(cname==""){cname='------'}
	if(cprovince==""){cprovince='------'}
	if(ccity==""){ccity='------'}
	if(ctel==""){ctel='------'}
	if(ccell==""){ccell='------'}
	if(cqqmsn==""){cqqmsn='------'}
	if(cemail==""){cemail='------'}

	var tmpArticle="";
	tmpArticle=tmpArticle+'姓名: '+cname+' \n';
	tmpArticle=tmpArticle+'所选号码: '+cnumber+' \n';
	tmpArticle=tmpArticle+'固话: '+ctel+' \n';
	tmpArticle=tmpArticle+'手机: '+ccell+' \n';
	tmpArticle=tmpArticle+'qq/msn: '+cqqmsn+' \n';
	tmpArticle=tmpArticle+'Email: '+cemail+' \n';
	tmpArticle=tmpArticle+'公司: '+ccompany+' \n';
	tmpArticle=tmpArticle+'省份: '+cprovince+' \n';
	tmpArticle=tmpArticle+'城市: '+ccity+' \n';

	//ajax comment begin
	$("#orderSumbit :submit").attr("disabled","disabled");
	$("#CommentPosting").html(iconAjaxLoadingTiny+"正在提交订单, 请稍候...");
	$.post(str00+'themes/'+strThemeName+'/plugin/user/orderpost.asp?key='+$('#orderSumbit').attr('name'),
		{
		"inpID":0,
		"inpVerify":(document.getElementById("cverify")?$("#cverify").val():""),
		"inpEmail":(cemail=="------"?"":cemail),
		"inpName":cname,
		"inpArticle":tmpArticle,
		"inpHomePage":""
		},
		function(data){
			var s =data;
			if((s.search("faultCode")>0)&&(s.search("faultString")>0)){
				$("#CommentPosting").html(iconAjaxDecline);
				if (s.search("验证码输入错误")>0){$("#cverify").addClass('error');}
				alert(s.match("<string>.+?</string>")[0].replace("<string>","").replace("</string>",""))
			}else{
				$("#CommentPosting").html("");
				$("#orderForm").html(s);
			}
			if(document.getElementById("cverify")){
				$("#cverify").val("");
				$('#verifyImg').attr("src",str00+"function/c_validcode.asp?name=commentvalid"+"&random="+Math.random());
			}

			$("#orderSumbit :submit").attr("disabled","");

		}
	);



	return false;
	//ajax comment end

}
