﻿// JavaScript Document
var xmlHttp;
var xmlDoc;
var xmlAuth;
var xmlRecode;
function ajaxGetData(a, b) {
    createXMLHttpRequest();
    xmlHttp.open("GET", "apiAuth.aspx?ID=" + a + "&PW=" + b, false);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send();
    xmlDoc = xmlHttp.responseXML;
    //xmlDoc.async = false;
};
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
};
function StupidSpace(a, b, c) {
    if (c) {
        if (a.getElementsByTagName(b)[0].hasChildNodes())
            return a.getElementsByTagName(b)[0].attributes.getNamedItem(c).value;
        else
            return "";
    } else {
        if (a.getElementsByTagName(b)[0].hasChildNodes())
            return a.getElementsByTagName(b)[0].firstChild.nodeValue;
        else
            return "";
    }
};

function $(a){
	return document.getElementById(a);	
};
function isNumber(val){
	var reg = /^[0-9]*$/;
	return reg.test(val);
};
function setLoad(){
	
};

function checkReport(){
	if($("entry_5").value==""){
		$("msg").style.display ="block";
		$("msg").innerHTML="研經聚會人數為空白。";
		alert("研經聚會人數為空白。");
		return false;
	}
	if($("entry_6").value==""){
		$("msg").style.display ="block";
		$("msg").innerHTML="培靈聚會人數為空白。";
		alert("培靈聚會人數為空白。");
		return false;
	}
	if($("entry_2").value==""){
		$("msg").style.display ="block";
		$("msg").innerHTML="請填寫參加轉播改進建議。";
		alert("請填寫參加轉播改進建議。");
		return false;
	}
};
function checkLogin(){
	if($("txtID").value==""){
		$("msg1").style.display ="none";
		$("msg2").style.display ="block";
		$("msg2").innerHTML="未輸入帳號。";
		return false;
	}
	if($("txtPW").value==""){
		$("msg1").style.display ="none";
		$("msg2").style.display ="block";
		$("msg2").innerHTML="未輸入密碼。";
		return false;
	}
	conferenceid="87e71df4-0593-4e6d-b413-0f43d836943f";
	if (window.ActiveXObject) {
		
		var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
		xmlDoc.async = false;
		xmlDoc.load("account.xml");
	
		var n = xmlDoc.getElementsByTagName("User");
	
		for (i = 0; i < n.length; i++) {
			var userid = n[i].getElementsByTagName("ID")[0].firstChild.nodeValue;
			var displayname = n[i].getElementsByTagName("DisplayName")[0].firstChild.nodeValue;
			var password = n[i].getElementsByTagName("Password")[0].firstChild.nodeValue;
			if ($("txtID").value == userid && $("txtPW").value == password) {
				
				
				//成功
				//
//				var fMysumOUT = new ActiveXObject("Scripting.FileSystemObject");
//				
//				var WriteOUT = fMysumOUT.OpenTextFile("mysum.txt",2,true);
//				var RowData,EachData,Member;
//				//var Sum = 0;
////				while(ReadIN.AtEndOfLine==false)
////				{
////				RowData = ReadIN.ReadLine();
////				EachData = RowData.split(",");
////				for(Member in EachData)
////				{
////				Sum+=parseInt(EachData[Member].replace(" ",""));
////				WriteOUT.WriteLine(Sum + " " + parseInt(EachData[Member].replace(" ","")));
////				}
////				}
//				WriteOUT.WriteLine("Sum");
//				WriteOUT.close();
//				
//				
				
				
				//document.location="http://59.124.126.34:100/API/ConferenceLaunch.html?PortalName=dlbc&PortalKey=A3D5E22BF53B25C89306&ConferenceID="+conferenceid+"&UserID="+userid+"&DisplayName="+displayname;
				document.location="play.html?UserID="+userid+"&DisplayName="+encodeURI(displayname);
				return false;
			}
		}
	
		$("msg1").style.display ="none";
		$("msg2").style.display ="block";
		$("msg2").innerHTML="帳號或密碼錯誤。";
		return false;
	}
    else {
		createXMLHttpRequest();
		xmlHttp.open("GET", "account.xml", false);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send();
		xmlAuth = xmlHttp.responseXML;
		xmlAuth.async = false;
		
		var Auth = xmlAuth.getElementsByTagName("User");
		for (i = 0; i < Auth.length; i++) {
			userid = StupidSpace(Auth[i], "ID");
			displayname = StupidSpace(Auth[i], "DisplayName");
			password = StupidSpace(Auth[i], "Password");
	
			if (userid == $("txtID").value) {
				if (password == $("txtPW").value) {
					//成功
					//document.location="http://59.124.126.34:100/API/ConferenceLaunch.html?PortalName=dlbc&PortalKey=A3D5E22BF53B25C89306&ConferenceID="+conferenceid+"&UserID="+userid+"&DisplayName="+displayname;
					document.location="play.html?UserID="+userid+"&DisplayName="+encodeURI(displayname);
					return false;
				} else {
					$("msg1").style.display ="none";
					$("msg2").style.display ="block";
					$("msg2").innerHTML="帳號或密碼錯誤。";
					return false;
				}
			}
		}
		$("msg1").style.display ="none";
		$("msg2").style.display ="block";
		$("msg2").innerHTML="帳號或密碼錯誤。";
		return false;
	}
};
function play700(){
	a = document.location.href;
	a = a.split("&");
	a = a[0].split("=");
	UserID = a[1];
	a = document.location.href;
	a = a.split("&");
	a = a[1].split("=");
	DisplayName = a[1];
	
	conferenceid="b6cd49e0-a7c7-4ea0-8b54-368b42cc3493";
	document.location="http://59.124.126.34:100/xshare/ConferenceLaunch.html?PortalName=dlbc&PortalKey=A3D5E22BF53B25C89306&ConferenceID="+conferenceid+"&UserID="+UserID+"&DisplayName="+DisplayName;
};
function play300(){
	a = document.location.href;
	a = a.split("&");
	a = a[0].split("=");
	UserID = a[1];
	a = document.location.href;
	a = a.split("&");
	a = a[1].split("=");
	DisplayName = a[1];
	
	conferenceid="9db0b59d-4a29-4e82-b5d8-a4366381b4e1";
	document.location="http://59.124.126.34:100/xshare/ConferenceLaunch.html?PortalName=dlbc&PortalKey=A3D5E22BF53B25C89306&ConferenceID="+conferenceid+"&UserID="+UserID+"&DisplayName="+DisplayName;
};
