
var q = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

var TransformView = Class.create();

TransformView.prototype = {
	initialize: function(container, slider, parameter, count, options) {
	if(parameter <= 0 || count <= 0) return;
		var oContainer = q(container), oSlider = q(slider), oThis = this;
	
		this.Index = 0;
		
		this._timer = null;//定时器
		this._slider = oSlider;//滑动对象
		this._parameter = parameter;//切换参数
		this._count = count || 0;//切换数量
		this._target = 0;//目标参数
		
		this.SetOptions(options);
		
		this.Up = !!this.options.Up;
		this.Step = Math.abs(this.options.Step);
		this.Time = Math.abs(this.options.Time);
		this.Auto = !!this.options.Auto;
		this.Pause = Math.abs(this.options.Pause);
		this.onStart = this.options.onStart;
		this.onFinish = this.options.onFinish;
		
		oContainer.style.overflow = "hidden";
		oContainer.style.position = "relative";
		
		oSlider.style.position = "absolute";
		oSlider.style.top = oSlider.style.left = 0;

		//oContainer.appendChild(oSlider.cloneNode(true));
	},

	SetOptions: function(options) {
		this.options = {
			Up:			true,
			Step:		10,
			Time:		10,
			Auto:		true,
			Pause:		4000,
			onStart:	function(){},
			onFinish:	function(){}
		};
		Object.extend(this.options, options || {});
	},

	Start: function() {
		if(this.Index < 0){
			this.Index = this._count - 1;
		} else if (this.Index >= this._count){ this.Index = 0; }
		
		this._target = -1 * this._parameter * this.Index;
		this.onStart();
		this.Move();
	},
  
	Move: function() {
		clearTimeout(this._timer);
		var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow);
		
		if (iStep != 0) {
			this._slider.style[style] = (iNow + iStep) + "px";
			this._timer = setTimeout(function(){ oThis.Move(); }, this.Time);
		} else {
			this._slider.style[style] = this._target + "px";
			this.onFinish();
			if (this.Auto) { this._timer = setTimeout(function(){ oThis.Index++; oThis.Start(); }, this.Pause); }
		}
	},

	GetStep: function(iTarget, iNow) {
		var iStep = (iTarget - iNow) / this.Step;
		if (iStep == 0) return 0;
		if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
		return iStep;
	},

	Stop: function(iTarget, iNow) {
		clearTimeout(this._timer);
		this._slider.style[this.Up ? "top" : "left"] = this._target + "px";
	}
};

window.onload=function(){
	function Each(list, fun){
		for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
	};
	
	var objs = q("idNum").getElementsByTagName("li");
	
	var tv = new TransformView("idTransformView", "idSlider", 585, 4, {
		onStart: function(){ Each(objs, function(o, i){ o.className = tv.Index == i ? "on" : ""; }) },
		Up: false
	});
	
	tv.Start();
	
	Each(objs, function(o, i){
		o.onmouseover = function(){
			o.className = "on";
			tv.Auto = false;
			tv.Index = i;
			tv.Start();
		}
		o.onmouseout = function(){
			o.className = "";
			tv.Auto = true;
			tv.Start();
		}
	})
}
var isIe=(document.all)?true:false;
function setSelectState(state) 
{ 
 var objl=document.getElementsByTagName('select'); 
 for(var i=0;i<objl.length;i++) 
 { 
 objl[i].style.visibility=state; 
 } 
} 
function mousePosition(ev) 
{ 
if(ev.pageX || ev.pageY) 
{ 
return {x:ev.pageX, y:ev.pageY}; 
} 
return { 
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop 
}; 
} 
//弹出方法 
function showMessageBox(wTitle,content,pos,wWidth) 
{ 	
closeWindow(); 
var bWidth=parseInt(document.documentElement.scrollWidth); 
var bHeight=parseInt(document.documentElement.scrollHeight); 
if(isIe){ 
	 setSelectState('hidden');} 
var back=document.createElement("div"); 
back.id="back"; 
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;"; 
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;"; 
back.style.cssText=styleStr; 
document.body.appendChild(back); 

showBackground(back,50); 

var mesW=document.createElement("div"); 
mesW.id="mesWindow"; 
mesW.className=""; 
if(pos!=0){
	mesW.innerHTML="<div class='tc_in2_1'><div style='width:446px; float:left;'><div style=' width:129px; height:25px; float:left; font-size:18px; border-bottom:#98a0b2 1px solid; padding-bottom:5px;'>"+wTitle+"</div> <div style=' width:317px; height:25px; text-align:right; float:left; border-bottom:#98a0b2 1px solid; padding-bottom:5px;'><a style='cursor:pointer' onclick='closeWindow();'>Close</a></div></div>"+content+"</div>";
	styleStr="left:"+(((pos.x-wWidth)>0)?(bWidth/2-wWidth/2):pos.x)+"px;top:"+(pos.y-140)+"px;position:absolute;width:"+wWidth+"px;";
}else{
	mesW.innerHTML="<div class='tc_in2_1'><div style='width:446px; float:left;'><div style='  height:25px; float:left; font-size:18px; border-bottom:#98a0b2 1px solid; padding-bottom:5px;'><B><font style='color:#ff0000'>"+wTitle+"</font></B></div> <div style=' width:70px; height:25px; text-align:right; float:left; border-bottom:#98a0b2 1px solid; padding-bottom:5px;'><a style='cursor:pointer' onclick='closeWindow();'>Close</a></div></div>"+content+"</div>";
	styleStr="left:"+(((bWidth-wWidth)>0)?(bWidth/2-wWidth/2):pos.x)+"px;top:140px;position:absolute;width:"+wWidth+"px;";
}
mesW.style.cssText=styleStr; 
document.body.appendChild(mesW); 
} 
//让背景渐渐变暗 
function showBackground(obj,endInt) 
{ 
if(isIe) 
{ 
obj.filters.alpha.opacity+=1; 
if(obj.filters.alpha.opacity<endInt) 
{ 
//setTimeout(function(){showBackground(obj,endInt)},5); 
	showBackground(obj,endInt);
} 
}else{ 
var al=parseFloat(obj.style.opacity);al+=0.01; 
obj.style.opacity=al; 
if(al<(endInt/100)) 
{//setTimeout(function(){showBackground(obj,endInt)},5);
	showBackground(obj,endInt)
} 
} 
} 
//关闭窗口 
function closeWindow() 
{ 
if(document.getElementById('back')!=null) 
{ 
  document.getElementById('back').parentNode.removeChild(document.getElementById('back')); 
} 
if(document.getElementById('mesWindow')!=null) 
{ 
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow')); 
} 
if(isIe){ 
	 setSelectState('');} 

} 
//测试弹出 
function testMessageBox(ev,status) 
{ 
var objPos = mousePosition(ev); 
if(status==1){
	messContent='<table class="tc_bg" width="446" border="0" cellspacing="0" cellpadding="0"><tr><td><br/>Please place larger orders early! Chinese New Year is coming soon, starting on February 13th and lasting for eight days. Chinese companies will not work during this time. Please be informed that our StoreGo will not work from 13th February to 20th February 2010. We will back to work on 21th February 2010. Any orders received on and after 13th February 2010 will be shipped on 21th February. However, our office will be open most of the time. Despite this, shipping time will be longer than usual. To avoid supply gaps, we suggest that our customers place bulk orders as soon as possible and find all the great wholesale discounts available on our site! Happy Chinese New Year! <br/><br/></td></tr></table>';
	showMessageBox('IMPORTANT CHINESE NEW YEAR NOTICE',messContent,0,400); 
}else{
messContent='<table class="tc_bg" width="446" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" width="129" style="padding-top:10px; border-top:#ffffff 1px solid;">Company Name*</td><td width="317" style="padding-top:10px; border-top:#ffffff 1px solid;"><label><input  name="company" id="company" type="text" class="tc_srk" size="30"/></label></td></tr><tr><td align="right">Contact Person*</td><td><input  name="uname" id="uname" type="text" class="tc_srk" size="30"/></td></tr><tr><td align="right">Email Address*</td><td><input name="email" id="email" type="text" class="tc_srk" size="30"/></td></tr><tr><td align="right">Phone Number*</td><td><input name="qq" id="qq" class="tc_srk"  size="30"/></td></tr><tr><td align="right">Fax Number*</td><td><input name="fax" id="fax" type="text" class="tc_srk" size="30"/></td></tr><tr><td align="right">Address*</td><td><input name="address" id="address" type="text" class="tc_srk" size="30"/></td></tr><tr><td align="right">Country</td><td><input name="country" id="country" type="text" class="tc_srk" size="30"/></td></tr><tr><td align="right">Member</td><td><input type="radio" name="member" value="1" />Yes&nbsp;&nbsp; <input type="radio" name="member"  value="0" />NO</td></tr><tr><td colspan="2" align="right"><div class="tc_in2_2">Inquiry or Comments*<br />(The more information you provide, the quicker response you will get)</div></td></tr><tr><td align="right" valign="top">Inquiry</td><td><label><textarea class="tc_srk1" name="msg" id="msg" cols="45" rows="5"></textarea></label></td></tr><tr><td colspan="2" align="right"><div class="tc_in2_2">Thank you, please click &quot;submit &quot;!</div></td></tr><tr><td colspan="2" align="center"><div align="center"><span id="subsubmit"><a style="cursor:pointer"  onclick="saveInquire();"><img src="includes/templates/easybtc/images/tc_13.gif" width="64" height="23"/></a></span><span id="rereset">&nbsp;<a style="cursor:pointer" onclick="resetInquire();"><img src="includes/templates/easybtc/images/tc_15.gif" width="64" height="23"/></a></span></div></td></tr></table>';
showMessageBox('Inquiry Now',messContent,objPos,400); 
}
} 
var xmlhttp;   
try   
{   
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");   
}   
catch (e)   
{   
  try   
  {   
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");   
  }   
  catch (e)   
  {    
  try   
  {   
xmlhttp=new XMLHttpRequest();   
  }   
  catch (e)   
  {   
  }   
  }   
} 
function saveInquire() {
	
	var companyObj = document.getElementById("company");
	var nameObj = document.getElementById("uname");
	var emailObj = document.getElementById("email");
	var memberObj= document.getElementsByName('member');
	var qqObj = document.getElementById("qq");
	var faxObj = document.getElementById("fax");
	var addressObj = document.getElementById("address");
	var countryObj = document.getElementById("country");
	var msgObj = document.getElementById("msg");
	
	if (companyObj.value == "") {
		alert("Please input Company Name!");
		companyObj.focus();
		return false;
	} else if (nameObj.value == "") {
		alert("Please input Contact Person!");
		nameObj.focus();
		return false;
	} else if (emailObj.value == "") {
		alert("Please input Email Address!");
		emailObj.focus();
		return false;
	} else if (emailObj.value != "") {
		 var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		if (!myreg.test(emailObj.value))
	    {
		alert("E-mail address format error or contains illegal characters!");
		emailObj.focus();
		return false;
	    }
	}else if (qqObj.value == "") {
		alert("Please input Phone Number!");
		qqObj.focus();
		return false;
	}  else if (faxObj.value == "") {
		alert("Please input Fax Number!");
		faxObj.focus();
		return false;
	}  else if (addressObj.value == "") {
		alert("Please input Address!");
		addressObj.focus();
		return false;
	}  else if (msgObj.value == "") {
		alert("Please input Inquiry or Comment!");
		msgObj.focus();
		return false;
	}
	
   document.getElementById('rereset').style.display='none';
   document.getElementById('subsubmit').innerHTML='Send Email,please waiting..';
   document.getElementById('subsubmit').disabled=true;
  for(i=0;i<memberObj.length;i++){
	  if(memberObj[i].checked==true){
		  memberObjvalue=memberObj[i].value;
	  }
	  
  }
	var url = "index.php?main_page=index&action=save";
	var postStr = "company=" + companyObj.value + "&uname=" + nameObj.value + "&email=" + emailObj.value + "&qq=" + qqObj.value + "&fax=" + faxObj.value + "&address=" + addressObj.value + "&country=" + countryObj.value+ "&msg=" + msgObj.value+"&member=" + memberObjvalue;
	xmlhttp.open("POST",url); 
	 xmlhttp.onreadystatechange=function(){  
		if(xmlhttp.readyState==4 && xmlhttp.status==200){   
		  alert(xmlhttp.responseText);
		  document.getElementById('company').value='';
		  document.getElementById('uname').value='';
		  document.getElementById('email').value='';
		  document.getElementById('qq').value='';
		  document.getElementById('fax').value='';
		  document.getElementById('address').value='';
		  document.getElementById('country').value='';
		  document.getElementById('msg').value='';
		  closeWindow();
		  }
		  
	}
     xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlhttp.send(postStr); 
	
}
function resetInquire(){
	document.getElementById('company').value='';
	  document.getElementById('uname').value='';
	  document.getElementById('email').value='';
	  document.getElementById('qq').value='';
	  document.getElementById('fax').value='';
	  document.getElementById('address').value='';
	  document.getElementById('country').value='';
	  document.getElementById('msg').value='';
	
}

