﻿function closeAll() {
var n=1;
while ($('TList_'+n)) {
$('TList_'+n).style.display='none';
$('aList_'+n).style.cssText='background-color:#eee';
$('pmImg_'+n).src='../image/dlayer/plusr.gif';
n++;
}
}
function catalogClick(pro_ID) {
if($('TList_'+pro_ID).style.display){
closeAll();
$('TList_'+pro_ID).style.display='';
$('aList_'+pro_ID).style.cssText='background-color:#ccc';
$('pmImg_'+pro_ID).src='../image/dlayer/minus.gif';
}
else{
closeAll();
}
return false;
}
var nIndex = 0;
var newObj = new Object();
newObj = new Array(newObj);
function newChild(appendTo, appendTag, appendContent, appendURL) {
str = "<a href=\"" + appendURL + "\" onclick=\"return false\" onfocus=\"this.blur()\">" + appendContent + "</a>";
obj = appendTo.appendChild(document.createElement(appendTag));
obj.innerHTML = str;
return obj;
}
function ToList(meObj, aid, name, url) {
var inObj = document.getElementById(aid);
var listID = document.getElementById("allList"); //-ID<allList>
if(inObj.innerHTML) {
if(inObj.innerHTML == '[+]') {
inObj.innerHTML = '[-]'; inObj.style.color = '#00F';
meObj.title = '從列表中移除此項.';
newObj[nIndex] = newChild(listID, 'li', name, url);
nIndex++;
} else {
inObj.innerHTML = '[+]'; inObj.style.color = '#F00';
meObj.title = '將此項添加至列表.';
for(i=0;i<nIndex;i++){
if(newObj[i].firstChild.innerHTML == name){
listID.removeChild(newObj[i]);
for(;i<nIndex;i++) newObj[i]=newObj[i+1];
nIndex--;
return false;
}
}
}
}
return false;
}
function clearList() {
var d = $('allList'); //-ID<allList>
var a = $('product').getElementsByTagName("a"); //-ID<product>
var u = $('product').getElementsByTagName("li"); //-ID<product>
for(i=0;i<a.length;i++) {
if(a[i].firstChild.nodeValue=='[-]') {a[i].firstChild.nodeValue='[+]';a[i].style.color = '#F00';}
}
for(i=0;i<u.length;i++) {
u[i].title = '將此項添加至列表.';
}
while(d.childNodes.length>0) d.removeChild(d.childNodes[0]);
nIndex = 0;
return false;
}

Validator = {
Require : /.+/,
Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
Phone : /^((\(\d{3}\))|(\d{3}\-)|(\d{3}))?(\(0\d{2,3}\)|(0\d{2,3}\-)|(0\d{2,3}))?[0-9]\d{5,7}$/,
Mobile : /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/,
Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
IdCard : /^\d{15}(\d{2}[A-Za-z0-9])?$/,
Currency : /^\d+(\.\d+)?$/,
Number : /^\d+$/,
Zip : /^[1-9]\d{5}$/,
Integer : /^[-\+]?\d+$/,
Double : /^[-\+]?\d+(\.\d+)?$/,
English : /^[A-Za-z]+$/,
Chinese :  /^[\u0391-\uFFE5]+$/,
UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
IsSafe : function(str){return !this.UnSafe.test(str);},
SafeString : "this.IsSafe(value)",
Limit : "this.limit(value.length,getAttribute('min'),  getAttribute('max'))",
LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
Range : "getAttribute('min') < value && value < getAttribute('max')",
Custom : "this.Exec(value, getAttribute('regexp'))",
Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
ErrorItem : [document.forms[0]],
ErrorMessage : ["Please check following message:   \t\t"],
Validate : function(theForm, mode){
var obj = theForm || event.srcElement;
var count = obj.elements.length;
this.ErrorMessage.length = 1;
this.ErrorItem.length = 1;
this.ErrorItem[0] = obj;
for(var i=0;i<count;i++){
with(obj.elements[i]){
var _dataType = getAttribute("dataType");
if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined")  continue;
this.ClearState(obj.elements[i]);
if(getAttribute("require") == "false" && value == "") continue;
switch(_dataType){
case "Repeat" :
case "Range" :
case "Custom" :
case "Group" : 
case "Limit" :
case "LimitB" :
case "SafeString" :
if(!eval(this[_dataType])){
this.AddError(i, getAttribute("msg"));
}
break;
default :
if(!this[_dataType].test(value)){
this.AddError(i, getAttribute("msg"));
}
break;
}
}
}
if(this.ErrorMessage.length > 1){
mode = mode || 1;
var errCount = this.ErrorItem.length;
switch(mode){
case 2 :
for(var i=1;i<errCount;i++)
this.ErrorItem[i].style.color = "red";
case 1 :
alert(this.ErrorMessage.join("\n"));
this.ErrorItem[1].focus();
break;
case 3 :
for(var i=1;i<errCount;i++){
try{
var span = document.createElement("SPAN");
span.id = "__ErrorMessagePanel";
span.style.cssText="color:red;font-size:12px;font-family:verdana;font-weight:normal;";
this.ErrorItem[i].parentNode.appendChild(span);
span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"<img sr"+"c=../image/dlayer/inquiry_notice.gif border=0>");
}
catch(e){alert(e.description);}
}
this.ErrorItem[1].focus();
break;
default :
alert(this.ErrorMessage.join("\n"));
break;
}
return false;
}
return true;
},
limit : function(len,min, max){
min = min || 0;
max = max || Number.MAX_VALUE;
return min <= len && len <= max;
},
LenB : function(str){
return str.replace(/[^\x00-\xff]/g,"**").length;
},
ClearState : function(elem){
with(elem){
if(style.color == "red")
style.color = "";
var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
if(lastNode.id == "__ErrorMessagePanel")
parentNode.removeChild(lastNode);
}
},
AddError : function(index, str){
this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ": " + str;
},
Exec : function(op, reg){
return new RegExp(reg,"g").test(op);
},
MustChecked : function(name, min, max){
var groups = document.getElementsByName(name);
var hasChecked = 0;
min = min || 1;
max = max || groups.length;
for(var i=groups.length-1;i>=0;i--)
if(groups[i].checked) hasChecked++;
return min <= hasChecked && hasChecked <= max;
}
}

function m_s(obj,tn) {
obj.style.background = "#ffffff";
if($('jtr'+tn)) $('jtr'+tn).className='';
}
function m_r(obj,tn) {
obj.style.background = "#ffffe8";
if($('jtr'+tn)) $('jtr'+tn).className='imtr';
}
function setAttr() {
if($('Company_Name')){
var set_1 = $('in3');
set_1.setAttribute("dataType","Group");
set_1.setAttribute("msg","至少需要選擇一項");
var set_2 = $('Company_Name');
set_2.setAttribute("dataType","Require");
set_2.setAttribute("msg","此欄為必填項");
var set_3 = $('Contaction_Person');
set_3.setAttribute("dataType","Require");
set_3.setAttribute("msg","此欄為必填項");
var set_4 = $('rad4');
set_4.setAttribute("dataType","Group");
set_4.setAttribute("msg","請選擇其中一項");
var set_5 = $('Country');
set_5.setAttribute("dataType","Require");
set_5.setAttribute("msg","此欄為必填項");
var set_6 = $('E_mail');
set_6.setAttribute("dataType","Email");
set_6.setAttribute("msg","電子郵箱地址不正確");
var set_7 = $('Phone');
set_7.setAttribute("dataType","Require");
set_7.setAttribute("msg","此欄為必填項");
var set_8 = $('FaxNum');
set_8.setAttribute("dataType","Require");
set_8.setAttribute("msg","此欄為必填項");
var set_9 = $('authim');
set_9.setAttribute("dataType","Require");
set_9.setAttribute("msg","此欄為必填項");
}
}
function trfh(){
$('antispn').src='../antispn.php?'+Math.random();
return false;
}


new Asset.javascript('cssjs/niftys.js');
new Asset.css('cssjs/niftys.css');
window.addEvent('domready', function(){
Nifty("div#pmainz","transparent");
Nifty("div.drow","transparent");
Nifty("div.drow em","transparent small");

if($('navline')){
fancyMnav = new SlideList($E('ul', 'navline'), {
transition: Fx.Transitions.backOut, 
duration: 500, 
onClick: function(ev, item) {}
});
}

setAttr();

var pds = $$('div.drow');
pds.each(function(ddrw,i) {
if(ddrw.getElement('h3')){
var strh = ddrw.getElement('h3');
if (i!=1) {
var mVS = new Fx.Slide(ddrw.getElement('div'), {duration:300});
strh.addEvent('click', function(){mVS.toggle();});
if ((ddrw.title)!="") {mVS.slideOut();strh.title=ddrw.title;ddrw.title='';}
}
strh.style.cssText='cursor:pointer';
strh.addEvent('mouseenter', function(){this.style.backgroundColor='#feff8f';}); //#e8eef2
strh.addEvent('mouseleave', function(){this.style.backgroundColor='';});
if (i==1){
strh.removeEvents('click');
strh.addEvent('click', function(){
ddrw.getElement('div').style.display=(ddrw.getElement('div').style.display=='')?'none':'';
});
ddrw.getElement('div').style.display='none';
}
}
});

var alla = $$('a');
alla.each(function(ael){ael.onfocus=function(){ael.blur();}});
if (/MSIE (5\.5|6\.)/.test(navigator.userAgent)) $('pmainz').style.backgroundImage='none';

});
