﻿// JScript 文件
var boolEmail = false;
var boolName = false;
var boolPassword = false;
var boolQQ = false;
var boolTelNo = false;
var boolValidateCode = false;
var contact,email,qq,telNo;//ajax参数列表
var ajaxObj;
//设置提示信息和颜色
//id：控件Id
//color：颜色
//msg:提示信息
function setMessageAndColor(id,color,msg)
{
    var msgObj = document.getElementById(id);
    if(msgObj)
    {
        msgObj.style.color = color;
        msgObj.innerHTML = msg;
    }
}

//验证Email地址
function validateEmail()
{
    var strEmail = document.getElementById('txtEmail').value.trim();
    if (!strEmail)
    {
        setMessageAndColor('clueOnEmail','red','邮箱不能为空！');
        boolEmail = false;
        return false;
    }
    if (!strEmail.isEmail())
    {
        setMessageAndColor('clueOnEmail','red','请输入合法邮箱！');
        boolEmail = false;
        return false;
    }
     setMessageAndColor('clueOnEmail','green','');
     boolEmail = true;
     email=strEmail;
     return true;
} 

//验证联系人
function ValidateName()
{
    var strName = document.getElementById('txtContact').value.trim();  
    if (!strName)
    {
        setMessageAndColor('clueOnName','red','联系人不能为空！');
        boolName = false;
        return false;
    }
    setMessageAndColor('clueOnName','green','');
    boolName = true;
    contact=strName;
    return true;
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

//验证QQ或MSN
function ValidateQQ()
{
    var strQQ = document.getElementById('txtQQ').value.trim();  
    if (!strQQ)
    {
        setMessageAndColor('clueOnQQ','red','QQ或MSN任填一个！');
        boolQQ = false;
        return false;
    }
    setMessageAndColor('clueOnQQ','green','');
    boolQQ = true;
    qq=strQQ;
    return true;
}
//验证手机或电话
function ValidateTelNo()
{
    var strTelNo = document.getElementById('txtTelNo').value.trim();  
    if (!strTelNo)
    {
        setMessageAndColor('clueOnTelNo','red','手机或电话任填一个！');
        boolTelNo = false;
        return false;
    }
    setMessageAndColor('clueOnTelNo','green','');
    boolTelNo = true;
    telNo=strTelNo;
    return true;
}
//检查验证码格式
function CheckCode()
{
    var strCode = document.getElementById('txtCode').value.trim();
    if (!strCode)
    {
        setMessageAndColor('clueOnCode','red','验证码不能为空！')
        boolValidateCode = false;
        return false;
    }
    if (strCode.length != 4)
    {
       setMessageAndColor('clueOnCode','red','验证码为4位！');
       boolValidateCode = false;
       return false;
    }
    
    if(ajaxObj)
    {
        ajaxObj.abort();
    }
    ajaxObj = ajax({type:'check_vilidate_code',value:strCode},validateCodeBack)
}

//验证码ajax返回
function validateCodeBack(o)
{
     // 是否发生错误
	if(o.isError)
	{
		// 处理错误信息
		alert(o.error);
		return ;
	}
	
	if (o.data == "0")
	{
	    setMessageAndColor('clueOnCode','green','验证码可用');
	    boolValidateCode = true;
	}
	if (o.data == "1")
	{
	    setMessageAndColor('clueOnCode','red','验证码错误');
	    boolValidateCode = false;
	}
}


//重置按钮
function imageReset()
{ 
    boolEmail = false;
    boolName = false;
    boolPassword = false;
    boolQQ = false;
    boolTelNo = false;
    boolValidateCode = false;
    setMessageAndColor('clueOnName','red','');
    setMessageAndColor('clueOnEmail','red','');
    setMessageAndColor('clueOnQQ','red','');
    setMessageAndColor('clueOnTelNo','red','');
    setMessageAndColor('clueOnCode','red','');
    document.getElementById('rendimage').src='/Controls/rndimage.aspx?'+Math.random();
    document.getElementById('txtCode').value=''; 
    form1.reset();
   
}

//回车事件
function btnOkClick()
{
  if( $('#ImageSubmit').focus())
  {
    return;
  }
   if(window.event.keyCode == 13)
   {
        $('#ImageSubmit').click();
   }
}
//申请团购
apply=function()
{
	navigate('/PhookProduct/Index.aspx');
//     if(!isLogin){  
//        alert('您未登陆！');
//        return;
//     }
//     MessageBox("申请团购","divApplyMsg");
}
//确认申请团购
confirmApply=function()
{
    CheckCode();
    var agreeObj = document.getElementById('CheckBox1');
    if (!agreeObj.checked)
    {
        alert('您未同意协议！');
        return false;
    }
    if (!(boolEmail && boolName && boolQQ && boolTelNo && boolValidateCode))
    {
        return;
    }
    var params='ajax=TeamAction&type=add_apply';
    params+='&contact='+contact;
    params+='&email='+email;
    params+='&qq='+qq;
    params+='&telNo='+telNo;
    processAjax(params,disposeApply,'POST');
}
disposeApply=function(data)
{
    if(data=="OK"){
        MessageBox_NoClose('申请团购','divApplyLoading');
        auto=window.setInterval(countDown,1000);
        imageReset();
        var firstRow=document.getElementById('firstRow');
        if(firstRow)  firstRow.click();
    }
}
//更换行背景
changeRow=function(sender)
{
    var divApplyMsg=document.getElementById('divApplyMsg');
    var rowList=divApplyMsg.getElementsByTagName('div');
    var divTip=document.getElementById('divTip');
    if(divTip)
    {   
        sender.appendChild(divTip);
    }
    for(var i=0;i<rowList.length;i++)
    {
        var row=rowList[i];
        if(row.className.indexOf('divApply')!=-1 && row!=sender)
        {
            row.className='divApply';
        }
    }
    sender.className='divApply divApplyAppend';
}
//倒计时
var startIndex=4;
var curIndex=startIndex;
var auto;
countDown=function()
{
    if(curIndex<=1)
    {
        window.clearInterval(auto);
        document.getElementById('tagNum').innerText=startIndex;
        curIndex=startIndex;
        MessageBox_Close();
        alert('申请成功！');
        return;
    }
    curIndex--;
    document.getElementById('tagNum').innerText=curIndex;
}

removeSpace=function(o)
{
    if(o)
    {
        o.value=o.value.trim();
    }
}

