﻿var layerName1 = 'layerInquiry';
var sid='sLayer';
var did='divIframe';
var stat=false;
var isIE=navigator.appVersion.split("MSIE");
var isIEv=parseFloat(isIE[1]);

function getMaxIndex(){var s=document.getElementsByTagName("DIV"); var temp=1; for(var i=0;i<s.length;i++) temp=Math.max(temp,s[i].style.zIndex); return temp;}
function getMaxLayer(){var s=document.getElementsByTagName("DIV"); if (!s) return null; var temp=0; var j=0; for(var i=0;i<s.length;i++) if(s[i].style.zIndex>temp) {temp=s[i].style.zIndex;j=i;} return s[j];}
function swaplayer(layer1,layer2){var t=layer2.style.zIndex; layer2.style.zIndex=layer1.style.zIndex; layer1.style.zIndex=t;}
function xx_SetTop(obj){var maxzindexlayer=getMaxLayer(); if (maxzindexlayer) swaplayer(maxzindexlayer,obj);}
function xx_BeginMove(id, event){
var elementToDrag = $(id);
var startX = event.clientX, startY = event.clientY;
var origX = elementToDrag.offsetLeft, origY = elementToDrag.offsetTop;
var deltaX = startX - origX, deltaY = startY - origY;
if (document.addEventListener) {
document.addEventListener("mousemove", moveHandler, true);
document.addEventListener("mouseup", upHandler, true);
}
else if (document.attachEvent) {
elementToDrag.setCapture( );
elementToDrag.attachEvent("onmousemove", moveHandler);
elementToDrag.attachEvent("onmouseup", upHandler);
elementToDrag.attachEvent("onlosecapture", upHandler);
}
else {
var oldmovehandler = document.onmousemove;
var olduphandler = document.onmouseup;
document.onmousemove = moveHandler;
document.onmouseup = upHandler;
}
if (event.stopPropagation) event.stopPropagation( );
else event.cancelBubble = true;
if (event.preventDefault) event.preventDefault( );
else event.returnValue = false;
function moveHandler(e) {
if (!e) e = window.event;
if ((e.clientX - deltaX)<=0)
elementToDrag.style.left = "0px";
else
elementToDrag.style.left = (e.clientX - deltaX) + "px";
if ((e.clientY - deltaY)<=0)
elementToDrag.style.top = "0px";
else
elementToDrag.style.top = (e.clientY - deltaY) + "px";
if (e.stopPropagation) e.stopPropagation( );
else e.cancelBubble = true;
}
function upHandler(e) {
if (!e) e = window.event;
if (document.removeEventListener) {
document.removeEventListener("mouseup", upHandler, true);
document.removeEventListener("mousemove", moveHandler, true);
}
else if (document.detachEvent) {
elementToDrag.detachEvent("onlosecapture", upHandler);
elementToDrag.detachEvent("onmouseup", upHandler);
elementToDrag.detachEvent("onmousemove", moveHandler);
elementToDrag.releaseCapture( );
}
else {
document.onmouseup = olduphandler;
document.onmousemove = oldmovehandler;
}
if (e.stopPropagation) e.stopPropagation( );
else e.cancelBubble = true;
}
}
function xx_Layer(x_id,x_title,x_width,x_height,x_left,x_top,content,seeyn){
this.id=x_id;
this.title=x_title;
this.style="overflow:visible;";
this.titlestyle="overflow:hidden;cursor:move;";
this.left=x_left;
this.top=x_top;
this.width=x_width;
this.height=x_height;
this.zIndex=getMaxIndex()+1;
this.seeyn=seeyn;
this.innerHTML=content;
if (content) this.draw();
}
xx_Layer.prototype.bG=function(pngurl){
var tempstyle = ((isIEv && isIEv<7) ? "position: absolute; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + pngurl + "', sizingMethod='scale'); background-repeat: no-repeat;" : "position: absolute; background-image:url(" + pngurl + "); background-repeat: repeat;");
return tempstyle;
};
xx_Layer.prototype.draw=function(){
var xlayer=$(this.id);
if (xlayer){alert("false");return false;}
var xlayer=document.createElement("DIV");
xlayer.setAttribute("id",this.id);
xlayer.style.cssText=this.style + "width:" + this.width + "px;height:" + this.height + "px;left:" + this.left + "px;top:" + this.top + "px;z-index:" + this.zIndex + ";position:absolute;";
xlayer.style.display=(this.seeyn)?"none":"block";
xlayer.onclick=function(){xx_SetTop(xlayer);}
document.body.appendChild(xlayer);
var xlayer_title=document.createElement("DIV");
xlayer_title.style.cssText=this.titlestyle;
xlayer_title.innerHTML='\
<div style="font:12px Arial;" onmousedown="xx_BeginMove(\'' + this.id + '\',event);">\
<div style="font-size:1px;margin-left:5px;margin-right:5px;height:5px;background-color:#4CA39B;">\
<div style="left:0px;top:0px;width:5px;height:5px;' + this.bG("../image/dlayer/corner-nw.png") + '"></div><div style="left:' + (this.width-5) + 'px;top:0px;width:5px;height:5px;' + this.bG("../image/dlayer/corner-ne.png") + '"></div>\
</div>\
<div style="white-space:nowrap;position:absolute;right:5px;top:5px;z-index:' + ((this.zIndex)-1) + '">\
<div style="font-size:9px;float:right;cursor:pointer;"><img sr'+'c="../image/dlayer/panel-cross.gif" onclick="document.getElementById(\'' + this.id + '\').style.display=\'none\';" alt="Close" title="Close" height="15" width="15"></div>\
</div>\
<div style="overflow:hidden;height:1.6em;padding-top:0.1em;padding-left:10px;back'+'ground:url(../image/dlayer/header-gradient.gif) repeat-x center top #4CA39B;">\
<div style="overflow:hidden;position:relative;margin-left:18px;"><div style="overflow:hidden;position:relative;"><a style="overflow:hidden;text-decoration:none;display:block;letter-spacing:1px;white-space:nowrap;font-size:12px;color:#E6EFEE;font-weight:bold;cursor:move;" id="' + this.id + '_title">' + this.title + '</a></div></div>\
</div>\
<div style="position:absolute;left:6px;top:5px;width:16px;height:16px;"><img sr'+'c="../image/tokenul.gif" border="0" height="16" width="16" style="' + this.bG("../image/tokchina.png") + '"></div>\
</div>\
';
xlayer.appendChild(xlayer_title);
var xlayer_child=document.createElement("DIV");
var temp1='\
<div style="overflow:hidden; position:relative; width:' + this.width + 'px; height:' + (this.height-30) + 'px;left:0px; top:0px; back'+'ground:url(../image/bgmail.gif) repeat-x #D9D9D7;">\
<div style="overflow:auto; margin:5px; padding:0px; position:absolute; left:0px; top:0px; width:' + (this.width-10) + 'px; height:' + (this.height-35) + 'px;">\
';
var temp2='\
</div></div>\
<div style="position:relative;margin-left:5px;margin-right:5px;height:5px;font-size:0.1px;background-color:#EAEFF5;">\
<div style="left:-5px;top:0px;width:5px;height:5px;' + this.bG("../image/dlayer/corner-sw.png") + '"></div>\
<div style="left:' + (this.width-10) + 'px;top:0px;width:5px;height:5px;' + this.bG("../image/dlayer/corner-se.png") + '"></div>\
</div>\
';
xlayer_child.innerHTML= temp1 + this.innerHTML + temp2;
xlayer.appendChild(xlayer_child);
var xlayer_bg=document.createElement("DIV");
xlayer_bg.style.cssText="overflow:visible;position:absolute;left:0px;top:0px;z-index:"+((this.zIndex)-10);
xlayer_bg.innerHTML='\
<div style="top:-5px;left:'+(this.width-5)+'px;width:13px;height:13px;font-size:1px;'+this.bG("../image/dlayer/3x-ne.png")+'"></div>\
<div style="top:-5px;left:-5px;width:13px;height:13px;font-size:1px;'+this.bG("../image/dlayer/3x-nw.png")+'"></div>\
<div style="top:-5px;left:8px;width:'+(this.width-13)+'px;height:13px;font-size:1px;'+this.bG("../image/dlayer/3x-n.png")+'"></div>\
<div style="top:'+(this.height-5)+'px;left:-5px;width:13px;height:13px;font-size:1px;'+this.bG("../image/dlayer/3x-sw.png")+'"></div>\
<div style="top:'+(this.height-5)+'px;left:8px;width:'+(this.width-13)+'px;height:13px;font-size:1px;'+this.bG("../image/dlayer/3x-s.png")+'"></div>\
<div style="top:'+(this.height-5)+'px;left:'+(this.width-5)+'px;width:13px;height:13px;font-size:1px;'+this.bG("../image/dlayer/3x-se.png")+'"></div>\
<div style="top:8px;left:'+(this.width-5)+'px;width:13px;height:'+(this.height-13)+'px;font-size:1px;'+this.bG("../image/dlayer/3x-e.png")+'"></div>\
<div style="top:8px;left:-5px;width:13px;height:'+(this.height-13)+'px;font-size:1px;'+this.bG("../image/dlayer/3x-w.png")+'"></div>\
';
xlayer.appendChild(xlayer_bg);
};

var Validator = {
Require : /.+/,
Email : /^\w+([-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
ErrorItem : [document.forms[0]],
ErrorMessage : ["Please Fill Following Message:\t\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 "Group" : 
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;
default :
alert(this.ErrorMessage.join("\n"));
break;
}
return false;
}
return true;
},
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) {
obj.style.background = "#ffffff";
}
function m_r(obj) {
obj.style.background = "#dfefff";
}
function getInfo() {
var now = new Date();
document.Form_mail.Date.value = now.toGMTString();
}

function setAttr() {
if($('Company_Name')){
var set_1 = $('in3');
set_1.setAttribute('dataType','Group');
set_1.setAttribute('msg','"Inquiry For" must check at least one.');
var set_2 = $('Company_Name');
set_2.setAttribute('dataType','Require');
set_2.setAttribute('msg','"Company Name" is required.');
var set_3 = $('Contaction_Person');
set_3.setAttribute('dataType','Require');
set_3.setAttribute('msg','"Contaction Person" is required.');
var set_4 = $('Phone');
set_4.setAttribute('dataType','Require');
set_4.setAttribute('msg','"Phone" is required.');
var set_5 = $('Country');
set_5.setAttribute('dataType','Require');
set_5.setAttribute('msg','"City/Country" is required.');
var set_6 = $('E_mail');
set_6.setAttribute('dataType','Email');
set_6.setAttribute('msg','"E-mail" is error, please check again.');
}
}

function send(stat) {if (stat) {$(sid).style.display='none'; $(did).style.display='block';}; return stat;}
function closeLayer(lid) {$(lid).style.display='none';}
function sub_mit(objform) {getInfo();stat=Validator.Validate(objform,2);return send(stat);}

function x_inquiry(lid,seeyn){
var wh=516;
var ht=500;
var lt=(document.body.clientWidth-wh)/2; lt=(lt<0)?10:lt;
var tp=138;
var locURL=document.location;
var ltitle='Inquiry Form';
var prodnm=($('glk').getElement('h4'))?($('glk').getElement('h4').innerHTML):'';
var sTemp='\
<table width="438" border="0" cellspacing="0" align="center"><tr><td align="center" height="38"><span class="wel"><i style="font-size:20px;">Welcome to</i> <b style="color:#435A5A;font-family:\'Arial Black\';">TOKENCHINA</b></span></td></tr><tr><td align="center" height="38"><span style="font:bold 12px verdana;">Please fill out this form and we will answer you right away.<br></span><span style="font-size:11px">( <font style="color:#F06;">*</font> is required )</span></td></tr></table>\
<form act'+'ion="../email_page.php?submit" target="tokeninquiry" method="post" name="Form_mail" onsubmit="return sub_mit(this)"> <input name="Date" type="hidden"> <input name="Product" type="hidden" value="' + prodnm + '"> <input name="URL" type="hidden" value="' + locURL +'">\
<table width="436" border="0" cellpadding="0" cellspacing="0" align="center" class="table_form"><tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0">\
<tr class="trow"><td colspan="2">The product you inquiry:<br><div class="protd">' + prodnm + '</div></td></tr>\
<tr><td width="125">Inquiry for:<br><font style="color:#F00;font-weight:normal;font-size:10px;">(Multiple Check)</font></td><td valign="top" class="chlab"><input type="checkbox" name="Inquiry_for[]" id="in1" value="Detail of Specifications"> <label for="in1">Specifications</label> <input type="checkbox" name="Inquiry_for[]" id="in2" value="Sample Stocking"> <label for="in2">Samples</label> <input type="checkbox" name="Inquiry_for[]" id="in3" value="Product Quoting"> <label for="in3">Quotation</label></td></tr>\
<tr class="trow"><td>Company Name:</td><td><input id="Company_Name" name="Company_Name" type="text" class="text_form" size="45" onFocus="m_r(this)" onBlur="m_s(this)"> <span class=requ>*</span></td></tr>\
<tr><td>Contaction person:</td><td><input id="Contaction_Person" name="Contaction_Person" type="text" class="text_form" size="36" onFocus="m_r(this)" onBlur="m_s(this)"> <span class=requ>*</span></td></tr>\
<tr class="trow"><td>Phone:</td><td><input id="Phone" name="Phone" type="text" class="text_form" size="36" onFocus="m_r(this)" onBlur="m_s(this)"> <span class=requ>*</span></td></tr>\
<tr><td>FAX:</td><td><input id="Fax" name="Fax" type="text" class="text_form" size="36" onFocus="m_r(this)" onBlur="m_s(this)"></td></tr>\
<tr class="trow"><td>City/Country:</td><td><input id="Country" name="Country" type="text" class="text_form" size="36" onFocus="m_r(this)" onBlur="m_s(this)"> <span class=requ>*</span></td></tr>\
<tr><td>Website URL:</td><td><input id="Website_URL" name="Website_URL" type="text" class="text_form" size="36" onFocus="m_r(this)" onBlur="m_s(this)"></td></tr>\
<tr class="trow"><td>E-mail:</td><td><input id="E_mail" name="E_mail" type="text" class="text_form" size="36" onFocus="m_r(this)" onBlur="m_s(this)"> <span class=requ>*</span></td></tr>\
<tr><td valign="top">Comments:</td><td><textarea id="Remark" name="Remark" class="text_form" rows="4" cols="48" onFocus="m_r(this)" onBlur="m_s(this)"></textarea></td></tr>\
<tr align="center"><td height="35" colspan="2"><input type="submit" value="Send" class="send" onmouseover="this.style.background=\'#fdd\'" onmouseout="this.style.background=\'#A0C2C2\'" onfocus="this.blur()"> <input type="reset" value="Reset" class="send" onmouseover="this.style.background=\'#fdd\'" onmouseout="this.style.background=\'#A0C2C2\'" onfocus="this.blur()"></td></tr>\
</table></td></tr></table><br><center><font style="font:10px verdana;">&copy; 2009 TOKENCHINA</font></center>\
</form>\
';
var divIframe='<iframe name="tokeninquiry" width="' + (wh-20) + '" height="' + (ht-45) + '" sr'+'c="../email_page.htm" frameborder="0" style="margin:0;padding:0;border:0;overflow:hidden;"></iframe>';
var s='<div id="' + sid + '" class="' + sid + '">' + sTemp + '</div><div id="' + did + '" class="' + did + '">' + divIframe + '</div>';
var newlayer1=new xx_Layer(lid,ltitle,wh,ht,lt,tp,s,seeyn);
setAttr();
}
function MM_openBrWindow(aobj) {if($(layerName1)) {$(layerName1).style.display="block";} else {x_inquiry(layerName1);} aobj.blur(); return false;}
function clkinq(){if($('inqdir')) $('inqdir').innerHTML='<a href="#" onclick="return MM_openBrWindow(this)"><span>INQUIRY</span></a>';}
document.writeln('<link hr'+'ef="../opendia.css" rel="stylesheet" type="text/css">');
