﻿// Client.js
onload=function()
{
	return;
	//检查首页
	var url=window.location+"";
	if(url.toLowerCase()=="http://www.foresight.net.cn/" || url.toLowerCase()=="http://www.foresight.net.cn" )
	{
		ShowPageTopTip("PageTop","迈迪『企业品牌管理能力自测系统』<strong>免费</strong> 测试&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><a href=\"/foresightQA/onlineTest.html\">点击这里开始测试</a></strong>");
	}
}

var isIE4plus = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0,1) >= "4");


/// user login
var ajaxRequest;
var loginFormHtml="";
function Login(oForm)
{
    var obj=document.getElementById("LoginMessage");
    if(oForm.uname.value.replace(/ /g,"")==""){
        obj.innerHTML="<font color=red>请输入帐号</font>";
        return false;
    }
    if(oForm.upass.value.replace(/ /g,"")==""){
        obj.innerHTML="<font color=red>请输入密码</font>";
        return false;
    }
    obj.innerHTML="Login...";
    oForm.commandLogin.disabled=true;
    
    loginFormHtml=document.getElementById("LoginForm").innerHTML;
    
    ajaxRequest=new AjaxRequest("/users/login.aspx","LoginBox");
    ajaxRequest.setUsePOST();
    ajaxRequest.addFormElements('loginPostForm');
    ajaxRequest.setPostRequest(LoginResponse);
    ajaxRequest.sendRequest();
    return false;
}

function LoginResponse()
{
    if(document.getElementById("LoginBox").innerText.indexOf("failed")!=-1)
    {
        document.getElementById("LoginForm").innerHTML=loginFormHtml;
        document.getElementById("LoginMessage").innerHTML="<font color=red>登录失败!</font>";
        document.getElementById("commandLogin").disabled=false;
    }
    else
    {
        if(getCookie("FORESIGHT_LoginOption")=="hidden")
        {
            document.getElementById("LoginStateMessage").innerHTML=document.getElementById("LoginBox").innerText.split(",")[0];
        }
    }
}



function switchLoginBox()
{
    var box=document.getElementById("LoginBox");
    var boxHead=document.getElementById("LoginHead2");
    var arrow=document.getElementById("LoginFormArrow");
    var isHide=false;
    if(box.style.display=="none") isHide=true;
    
    box.style.display = isHide ?"":"none";
    boxHead.className = isHide ?"LoginHead2":"LoginHead2_2";
    try{
        if(box.style.display=="none")
        {
            saveCookie("FORESIGHT_LoginOption", "hidden", 365, "/", "");
            arrow.src="/images/arrow_loginForm2.gif";
        }
        else
        {
            saveCookie("FORESIGHT_LoginOption", "show", 365, "/", "");
            arrow.src="/images/arrow_loginForm.gif";
        }
    }
    catch(e)
    {
        //do nothing
    }
}

function initLoginBoxDisplayState()
{
    try{
        var box=document.getElementById("LoginBox");
        var boxHead=document.getElementById("LoginHead2");
        var arrow=document.getElementById("LoginFormArrow");
        if(getCookie("FORESIGHT_LoginOption")!="hidden"){
    		box.style.display="";
    		boxHead.className = "LoginHead2";
    		arrow.src="/images/arrow_loginForm.gif";
	    }
	    else
	    {
    	    box.style.display="none";
    	    boxHead.className = "LoginHead2_2";
    	    arrow.src="/images/arrow_loginForm2.gif";
	    }
	}
	catch(e)
	{
	    //do nothing
	}
}

function FlashPlayer(m,w,h)
{
	var flashStr="";
	//flashStr+="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+w+"\" height=\""+h+"\">";
	//flashStr+="<param name=\"movie\" value=\""+m+"\" />";
	//flashStr+="<param name=\"quality\" value=\"high\" />";
	//flashStr+="<param name=\"menu\" value=\"false\" />";
	flashStr+="<embed src=\""+m+"\" width=\""+w+"\" height=\""+h+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" menu=\"false\"></embed>";
	//flashStr+="</object>";
	
	document.write(flashStr);
}


function isEmail(email)
{
    var reg=/^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return reg.test(email);
}

function matchTelFromString(str)
{
    /*if(str=="") return "";
    
    //str.replace(/ /g,"");
    var reg=new RegExp("(\d{3}-\d{8})|(\d{4}-\d{7})","ig");
    //alert(reg.test(str));
    reg.exec(str);
    return reg.$1;*/
    return str;
}

function search()
{
    var oForm=document.getElementById("SearchForm");
    if(oForm.key.value=="")
    {
        return;
    }
    
    oForm.submit();
}

function showConsultionWindow()
{
    var oDiv;
    if(document.getElementById("ConsultionContainor"))
    {
        oDiv=document.getElementById("ConsultionContainor");
        document.body.removeChild(oDiv);
    }
    
    oDiv=document.createElement("DIV");
    oDiv.id="ConsultionContainor";
    oDiv.style.position="absolute";
    oDiv.style.width=302;
    oDiv.style.height=475;
	
	if(isIE4plus)
	{
		oDiv.style.left=document.body.offsetWidth-350;
		oDiv.style.top=260;//(document.body.offsetHeight-475)/2+100;
	}else
	{
		oDiv.left=10;
		oDiv.top=260;//(document.body.offsetHeight-475)/2+100;
	}
    
    oDiv.innerHTML="<div style=\"text-align:right;padding:5px;background-image:url(/images/bg_head_consultionOnline.gif);background-repeat:repeat-x;\"><a href=\"javascript:closeConsultionWindow();\"><img src=\"/images/btn_close2.gif\" border=\"0\" alt=\"关闭\" /></a></div><div style=\"border:1px solid #E5E5E5;\"><embed src=\"/images/ConsultionOnline.swf?rnd="+Math.random()+"\" bgcolor=\"#ffffff\" menu=\"false\" quality=\"high\" scale=\"noscale\" salign=\"lt\" width=\"300\" height=\"450\" name=\"ForesightQA\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></div>";
    document.body.appendChild(oDiv);
}

function closeConsultionWindow()
{
    if(document.getElementById("ConsultionContainor"))
    {
        oDiv=document.getElementById("ConsultionContainor");
        document.body.removeChild(oDiv);
    }
}

function SignupStep1(oForm)
{
    if(oForm.courseid)
    {
        var hasChecked=false;
        var cid=0;
        if(oForm.courseid.length)
        {
            for(var i=0;i<oForm.courseid.length;i++)
            {
                if(oForm.courseid[i].checked==true)
                {
                    hasChecked=true;
                    cid=oForm.courseid[i].value;
                    break;
                }
            }
        }
        else
        {
            if(oForm.courseid.checked==true)
            {
                hasChecked=true;
                cid=oForm.courseid.value;
            }
        }
        
        if(hasChecked && cid!=0)
        {
            window.location="SignupNext.aspx?cid="+cid;
        }
        else
        {
            alert("请选择一个您希望参与培训的课程！");
        }
    }
    else
    {
        event.srcElement.disabled=true;
    }
    
    return false;
}

//控制金牌课程树展开收缩
function SwitchTreeNode(id)
{
    if(document.getElementById(id))
    {
        var obj=document.getElementById(id);
        obj.style.display=obj.style.display!="none"?"none":"block";
    }
}


//页头提示栏
function ShowPageTopTip(beforeEleId,msg)
{
	var oDiv;
    if(document.getElementById("PAGE_TOP_TIP"))
    {
        return;
    }

	oDiv=document.createElement("DIV");
	oDiv.style.borderBottom="1px solid #FFCC00";
	oDiv.style.backgroundColor="#FFFFCC";
	oDiv.style.padding="8px";
	oDiv.style.textAlign="left";
	oDiv.style.color="#F00";

	oDiv.innerHTML="<img src=\"/images/arrow_grayBtn.gif\" alt=\"\" style=\"margin-bottom:-2px;\"/> "+msg;

	document.body.insertBefore(oDiv,document.getElementById(beforeEleId));
}

// save Cookie
function saveCookie(name, value, expires, path, domain, secure){
  var strCookie = name + "=" + value;
  if (expires){
     var curTime = new Date();
     curTime.setTime(curTime.getTime() + expires*24*60*60*1000);
     strCookie += "; expires=" + curTime.toGMTString();
  }
  strCookie +=  (path) ? "; path=" + path : ""; 
  //strCookie +=  (domain) ? "; domain=" + domain : "";
  //strCookie +=  (secure) ? "; secure" : "";
  document.cookie = strCookie;
}

// get Cookie value, null表示Cookie不存在
function getCookie(name){
  var strCookies = document.cookie;
  var cookieName = name + "=";  // Cookie名称
  var valueBegin, valueEnd, value;
  valueBegin = strCookies.indexOf(cookieName);
  if (valueBegin == -1) return null;  // 没有此Cookie
  valueEnd = strCookies.indexOf(";", valueBegin);
  if (valueEnd == -1)
      valueEnd = strCookies.length;  // 最後一个Cookie
  value = strCookies.substring(valueBegin+cookieName.length,valueEnd);
  return value;
}
// check Exist
function checkCookieExist(name){
  if (getCookie(name))
      return true;
  else
      return false;
}

// delete Cookie
function deleteCookie(name, path, domain){
  var strCookie;
  if (checkCookieExist(name)){
    strCookie = name + "="; 
    strCookie += (path) ? "; path=" + path : "";
    strCookie += (domain) ? "; domain=" + domain : "";
    strCookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    document.cookie = strCookie;
  }
}
