﻿var commentFlag = true;	//提交评论状态
var emailFlag = true;	//提交邮件地址状态
var tQFlag = true;	//TQ联系状态

//////////////////////////////////////////////////////////

var _postXmlHttpProcessPostChangeCallBack;
var _xmlHttpRequestObj;
var _loadingFunction;
//第一个参数：URL；第二个参数：回调函数；第三个参数：显示图片加载函数loadFunc
function postXmlHttp(submitUrl, callbackFunc)
{
	_postXmlHttpProcessPostChangeCallBack = callbackFunc;
  //_loadingFunction = loadFunc;
  if(window.createRequest)
  {
    try{
      _xmlHttpRequestObj=window.createRequest();
      _xmlHttpRequestObj.open('POST',submitUrl,true);
      _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
      _xmlHttpRequestObj.send();
    }
    catch(ee){}
  }
  else if(window.XMLHttpRequest)//针对Firefox,IE7,IE8,Mozilla,Opera,safari
  {
    _xmlHttpRequestObj=new XMLHttpRequest();
    if(window.overrideMimeType){//针对某些特定版本mozilla浏览器的bug修正
		_xmlHttpRequestObj.overrideMimeType('text/xml');
	}
    _xmlHttpRequestObj.open('POST',submitUrl,true);
    _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
    _xmlHttpRequestObj.send("");
  }
  else if(window.ActiveXObject)//针对IE5.0 ,IE5.5 ,IE6.0
  {
    _xmlHttpRequestObj=new ActiveXObject("Microsoft.XMLHTTP");
    _xmlHttpRequestObj.open('POST', submitUrl, true);
    _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
    _xmlHttpRequestObj.send();
  }
};

function postXmlHttpProcessPostChange()
{
  if( _xmlHttpRequestObj.readyState==4 && _xmlHttpRequestObj.status==200 )
  {
    setTimeout( _postXmlHttpProcessPostChangeCallBack, 2 );
  }
  if ( _xmlHttpRequestObj.readyState==1 )
  {
    //setTimeout( _loadingFunction, 2 );
  }
}



//////////////////////////////////////////////////////////
/**邮箱收集Aj**/
function emailSubmit(){
	if(emailFlag){
		var emailStr = document.getElementById('email').value;
		/*验证邮箱*/
		if(!checkEmail(emailStr)){
			return;
		};
		var commentUrl='addEcAjEmail.action';
		var params=encodeURI("email="+emailStr);
		postXmlHttp(commentUrl+'?'+params, callBackEmail);
	}else{
		//alert('请不要频繁提交邮箱！');
		document.getElementById('email').value = '不要频繁提交...';
		setTimeout("clearEmail();", 2000);
	}
}
function callBackEmail(){
	var emailEle = document.getElementById('email');
	if(_xmlHttpRequestObj.responseText==1){
		emailFlag = false;
		emailEle.value = '提交成功...';
		setTimeout("clearEmail();", 2000);
	}else if(_xmlHttpRequestObj.responseText==2){
		emailEle.value = '该邮箱已经存在...';
		setTimeout("clearEmail();", 2000);
	}else{
		emailEle.value = '提交失败...';
		setTimeout("clearEmail();", 2000);
	}
}
function clearEmail(){
	document.getElementById('email').value="";
}
/**邮箱校验**/
function checkEmail(str){
	var reEmail =/(\S)+[@]{1}(\S)+[.]{1}(\w)+/;
	if(str.match(/^\s*$/g)){
		document.getElementById('email').value = '邮箱不能为空...';
		setTimeout("clearEmail();", 2000);
		return false;
	}else{
		var temp=reEmail.test(str);
		if(temp==false){
			document.getElementById('email').value = '邮箱格式错误...';
			setTimeout("clearEmail();", 2000);
			return false;
		}
	}
	return true;
}

//////////////////////////////////////////////////////////
/**弹出窗口Aj**/
function clickAj(flag){
	//alert('-----clickAj()-- flag ='+ flag);
	if(true){
		var clickUrl = 'clickAjStarLive.action';
		postXmlHttp(clickUrl, eval('callBackClickAj'+flag));
	}else{
		alert('请不要频繁点击！');
	}
}
function callBackClickAj1(){//订票
	tQFlag = false;
	var httpUrl = _xmlHttpRequestObj.responseText;
	webUrl = 'http://vip.tq.cn/vip/leavemsg.do?admiuin=8867990&uin=8867990&ltype=1&iscallback=1&agentid=0&clientid=&comtimes=149&color=10&style=1&tq_right_infocard_url=&page='+httpUrl+'/list.action?df=all*fr=3*se=11&localurl='+httpUrl+'/jsp.action?w=changdi*fr=2*se=6&tq_bottom_ad_url=';
	openWindow(webUrl, 600, 480);
}
function callBackClickAj2(){//租赁
	tQFlag = false;
	var httpUrl = _xmlHttpRequestObj.responseText;
	webUrl = 'http://vipwebchat.tq.cn/sendmain.jsp?admiuin=8867990&uin=8873301&ltype=1&rand=3382370181134192&iscallback=1&agentid=0&clientid=&comtimes=149&buttonsflag=101011111&is_appraise=1&color=10&style=1&isSendPreWords=1&page='+httpUrl+'/list.action?df=all*fr=3*se=11&localurl='+httpUrl+'/jsp.action?w=changdi*fr=2*se=6&spage='+httpUrl+'/list.action?df=all*fr=3*se=11&nocache=0.8865575664762694';
	openWindow(webUrl, 600, 480);
}
//新弹开网页窗口
function openWindow(url,width,height){
	var name='测试窗口名称';
	var iWidth=width+50;										//弹出窗口的宽度;
	var iHeight=height+50;										//弹出窗口的高度;
	var iTop = (window.screen.availHeight-30-iHeight)/2;		//获得窗口的垂直位置;
	var iLeft = (window.screen.availWidth-10-iWidth)/2;			//获得窗口的水平位置;
	window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}
//新弹开对话框窗口
function openDialog(url,name,width,height){
	var isRefresh=false;
	var obj = new Object();
		obj.name = name;
		obj.code = '';
	var ret = window.showModalDialog(url,obj,"dialogWidth:" + width + "px;dialogHeight:" + height + "px;status:0;resizable:0;center:1;help:0;scroll:no;");
	if(isRefresh)
		window.location.href = window.location.href;
	if(ret == true){
		event.returnValue = false;
		return obj;
	}else{
		return null;
	}	
	return obj;
}