﻿//** Ajax Tabs Content script v2.0- ?Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Updated Oct 21st, 07 to version 2.0. Contains numerous improvements
//** Updated Feb 18th, 08 to version 2.1: Adds a public "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically. Only .js file changed from v2.0.
//** Updated April 8th, 08 to version 2.2:
//   -Adds support for expanding a tab using a URL parameter (ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0) 
//   -Modified Ajax routine so testing the script out locally in IE7 now works 

var xmlHttp,pwd;


////NO NEED TO EDIT BELOW////////////////////////

function CreateXmlHttp(){
	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
		try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
		xmlHttp = new XMLHttpRequest()
	else
		return false
}

function selSend(){
  //alert("sds");
  CreateXmlHttp();
  if(xmlHttp==null){
    alert("Sorry!Your browser does not support AJAX!");
    return false;
  }
  var str=document.getElementById("sheng").options[document.getElementById("sheng").options.selectedIndex].value;
  //alert(encodeURIComponent(str));
  var url="city.asp?city="+encodeURIComponent(str);
  //window.location.href=url;
  //alert(url);
  xmlHttp.onreadystatechange=getXml;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function getXml(){
  var xmlDoc;
  //alert("dsaf");
  if(xmlHttp.readyState==4 && xmlHttp.status==200){
    //alert(xmlHttp.responseText);
    xmlDoc=xmlHttp.responseXML.documentElement;
    document.getElementById("shi").options.length=0;
    var node=xmlHttp.responseXML.documentElement.childNodes;
    for(i=0;i<node.length;i++){
      var shiOption=new Option(node.item(i).text,node.item(i).text);
      document.getElementById("shi").options.add(shiOption);
    }
  }
}


function checkUsr(usr,type){
  var reg=/^[a-zA-Z0-9_\$#@-]*$/
  if(!reg.exec(usr)){
     document.getElementById("usrname").innerHTML="<table><tr><td><div class='regincorrect'><td></td><td>您輸入的帳戶名不符合條件！請輸入字母或數字,請重新輸入!</td></tr></table>";
     return false;
  }
  if(usr.length<4){
    document.getElementById("usrname").innerHTML="<table><tr><td><div class='regincorrect'><td></td><td>帳戶名長度不滿足條件！請重新輸入!</td></tr></table>";
  }else{
    CreateXmlHttp();
    if(xmlHttp==null){
      alert("Sorry!Your browser does not support AJAX!");
      return false;
    }
    //alert(usr);
    var url="CheckUsr.asp?type="+type+"&usr="+usr;
    //alert(url);
    xmlHttp.onreadystatechange=docheckUsr;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
   }
}

function docheckUsr(){
  var xmlDoc;
  //alert(xmlHttp.responseText);
  if(xmlHttp.readyState==4 && (xmlHttp.status==200 || window.location.href.indexOf("http")==-1)){
    if(xmlHttp.responseText=="true"){
      //alert("xcx");
      //document.getElementById("usrname").value=xmlHttp.responseText;
      document.getElementById("usrname").innerHTML="<table><tr><td><div class='regcorrect'></div></td><td>譔會員可以使用！</td></tr></table>";
    }else{
      //alert("asdfasdf");
      //document.getElementById("usrname").focus();
      document.getElementById("usrname").innerHTML="<table><tr><td><div class='regincorrect'><td></td><td>譔會員已經存在！請重新輸入新會員名!</td></tr></table>";
    }
  }
}

function jump(){
  //alert(encodeURIComponent("台南"));
  //alert("ddsds");
  //var str="台南"；
  var first=document.getElementById("sheng1").options[document.getElementById("sheng1").options.selectedIndex].value;
  window.location.href="city.asp?city="+first;
}


function chkpwd(str){
  //var str=document.getElementById("password").value;
  //alert(str);
  pwd=str;
  if(str.length<6){
    document.getElementById("pwd").innerHTML="<table><tr><td><div class='regincorrect'><td></td><td>密碼長度不滿足條件！請重新輸入!</td></tr></table>";
  }else{
    document.getElementById("pwd").innerHTML="<table><tr><td><div class='regcorrect'></div></td><td>填寫正確！</td></tr></table>";
  }
}

function rechkpwd(str){
  var strpwd=document.getElementById("userpass").value;
  //alert(str);
  //alert(pwd);
  if(str==pwd && str!=""){
    document.getElementById("repwd").innerHTML="<table><tr><td><div class='regcorrect'></div></td><td>填寫正確！</td></tr></table>";
  }else{
    if(str==""){
      document.getElementById("repwd").innerHTML="<table><tr><td><div class='regincorrect'></div></td><td>此處不為能空！請重新輸入!</td></tr></table>";
    }else{
      document.getElementById("repwd").innerHTML="<table><tr><td><div class='regincorrect'></div></td><td>兩次密碼輸入不一致！請重新輸入!</td></tr></table>";
    }
  }
}

function chktel(str,div){
  var smail=/^[0-9]+(\-?[0-9]+)+$/;
  //alert(document.getElementById("divemail").innerHTML);
  if(smail.exec(str)){
    document.getElementById(div).innerHTML="<table><tr><td><div class='regcorrect'></div></td><td>填寫正確！</td></tr></table>";
  }else{
    //alert("incorrected!");
    document.getElementById(div).innerHTML="<table><tr><td><div class='regincorrect'></div></td><td>號碼填寫不正確！請重新輸入!</td></tr></table>";
  }
}

function chkmail(str){
  var smail=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  //alert(document.getElementById("divemail").innerHTML);
  if(smail.exec(str)){
    document.getElementById("divemail").innerHTML="<table><tr><td><div class='regcorrect'></div></td><td>填寫正確！</td></tr></table>";
  }else{
    //alert("incorrected!");
    document.getElementById("divemail").innerHTML="<table><tr><td><div class='regincorrect'></div></td><td>郵件地址不正確！請重新輸入!</td></tr></table>";
  }
}


function sel(){
var varItem,first,sec;
var xhai_xml = new ActiveXObject("Microsoft.XMLDOM");
xhai_xml.async=false;
try{
 xhai_xml.load("city.xml");
 }
catch(e){
 alert("failue to open!");
}
//for (var i = 0; i<(document.getElementById("id").options.length-1); i++) {        
//}
//first=document.getElementById("typeid").options[document.getElementById("typeid").options.selectedIndex].value;
//alert(first+"safa");
var nodes=xhai_xml.documentElement.childNodes;
document.getElementById("shi1").options.length=0;
for(i=0;i<nodes.length;i++)
{
  sec=nodes.item(i).text;
  //document.write(sec);
  if(first!=i){
    varItem = new Option(sec,sec);      
    document.getElementById("shi1").options.add(varItem);
  }
}
}

