var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isIE=navigator.userAgent.indexOf("IE")>0;
var isIE5=navigator.userAgent.indexOf("IE 5.0")>0;
var isIE6=navigator.userAgent.indexOf("IE 6.0")>0;
var isNav=(navigator.appName.indexOf("Netscape")!=-1);
var element;
function $(obj){
	return typeof(obj) == "string" ? document.getElementById(obj) : obj;
}
String.prototype.trim=function(){
	return this.replace(/(^[\s]*)|([\s]*$)/g, "");
};
/********************

      UTILITIES
      
********************/
function findPos(obj) {
	var curleft = curtop = 0;
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return [curleft,curtop];
}
function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*#数组添加成员#*/
Array.prototype.add=function(key){
	this[this.length]=key;
};

/*#字符串是否为空 true 为空#*/
function isNone(str){
	return str==null||str.trim()=="" ? true:false;
};

/*#将焦点指定到对应的obj上#*/
function efocu(obj){
	try{$(obj).focus();}catch(e){}
};

/*#插入HTML代码#*/
function insHtm(obj,code,pos){
	obj=$(obj);
	if(isIE){
		obj.parentNode.insertAdjacentHTML(pos==null?"beforeend":"afterbegin",code);
	}
	else{
		var r=obj.ownerDocument.createRange();
		r.setStartBefore(obj);
		eval("obj.parentNode."+(pos==null?"appendChild":"insertBefore")+"(r.createContextualFragment(code),obj.parentNode.firstChild)");
	}
}


/*#查看k1是否在当前字符串中,k2为分割符默认为逗号#*/
String.prototype.inc=function(k1,k2){
	if(k2==null){k2=","};
	return (k2+this+k2).indexOf(k2+k1+k2) > -1 ? true:false;
};

/*#从字符串中截取k1字符串#*/
String.prototype.sub=function(k1,k2){
	if(k2==null){k2=","};
	var tmp = k2 + this + k2;
	var size = tmp.indexOf(k1);
	if(size ==-1){
		return 0;
	}
	var i = 0;
	while(tmp.charAt(size+3+i) != '/'){
		i++;
	}
	return tmp.substring(size+3,size+3+i);
};

function hide(el) {
	element = $(el);
	element.style.display = 'none';
}
function show(el) {
	element = $(el);
	element.style.display = '';
}
function remove(el){
	element = $(el);
	element.parentNode.removeChild(element);
}
function toggle(el) {
    el = $(el);
	if(el.style.display=="none"){
		el.style.display='block';
	}else{
		el.style.display='none';
	}
}
function menuToggle(element, eventName, handler){
	  element = $(element);
	  if (element.addEventListener) {
        element.addEventListener(eventName, handler, false);
      } else {
        element.attachEvent("on" + eventName, handler);
      }
}
/*==================================================*/
function setOpacity(opacity, theID) {
	var object = $(theID).style;
	if (navigator.userAgent.indexOf("Firefox") != -1) {
		if (opacity == 100) { opacity = 99.9999; } // This is majorly awkward
	}
	object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
	object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla
}

function getSize() {
	//var myWidth,myHeight,myScroll;
	if (self.innerHeight) { // Everyone but IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}
}

var str = '<div id=\"WWPopup\" style=\"height:56px;display:none;margin:-56px auto 0 auto;width:952px;background:#fff url('+baseURL+'/images/root/blue_bg.gif) repeat-x;\"><div id=\"WWPopupBody\" style=\"width:900px;height:50px;margin:0 auto;color:#333;padding-top:3px;font-weight:bold;font:12px Arial,Helvetica, sans-serif;position: relative;\">';
	str += '<span class="strongstyle black">Important Notice:</span> Dear Customers, Due to data migration, for customer who made order during PST 10:00PM May 31st to PST 9:00PM June 2nd, your order information and login information will be unavailable temporarily. We\'ll finish the data merge in the next 24 hours. Please note your order is being processed normally during the merge of data. If you have any questions please email to <a href="mailto:admin@admin.com" class="u b">admin@admin.com</a>. We apologize for any inconvenience.';
	str+='</div></div>';
//document.write(str);

function flashWrite( id, flashUri, vWidth, vHeight, winMode ) {
	var _obj_ = "";
	_obj_ = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + vWidth + '" height="' + vHeight + '" id="' + id + '" align="middle">';
	_obj_ += '<param name="movie" value="' + flashUri + '" />';
	_obj_ += '<param name="quality" value="high" />';
	_obj_ += '<param name="wmode" value="' + winMode + '" />';
	_obj_ += '<param name="bgcolor" value="#ffffff" />';
	_obj_ += '<embed src="' + flashUri + '" quality="high" wmode="' + winMode + '" bgcolor="#ffffff" width="' + vWidth +'" height="' + vHeight + '" id="' + id + '" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed>    ';
	_obj_ += '</object>';
	document.write( _obj_ );
}
/*××××××××××××××global××××××××××××××××××*/

function showWWPopup() {
	if (window != top||$('popuplargerimageBody')) {return false;}
	var wp = $('WWPopup');
	var n,tt;
	wp.style.display="";
    var anim = function(){
        n += 8;
        if(n >= 56){
            wp.style.marginTop = '0';
            window.clearInterval(tt);
        }else{
            wp.style.marginTop = "-"+(56 - n)+"px";
        }
    },n=0;
    var tt = window.setInterval(anim, 5);
}
//addEventSimple(window,"load",showWWPopup);

/*swich the layer*/
function layerswich(){	
	if($('boxswitch') === null ) {return;}
	var e, i = 0;
	var evtType = $('boxswitch').getAttribute('evt');	
	while (e = $('boxswitch').getElementsByTagName ('DIV') [i++]) {
		if (e.className == 'on' || e.className == 'off') {
			if(evtType=='click'){
				e.onclick = function () {
					var getEls = $('layer_switch').getElementsByTagName('DIV');
						for (var z=0; z<getEls.length; z++) {
						getEls[z].className=getEls[z].className.replace('show', 'hide');
						getEls[z].className=getEls[z].className.replace('on', 'off');
						}
					this.className = 'on';
					var max = this.getAttribute('title');
					$(max).className = "show";
				}
			}
			else{
				e.onmouseover = function () {
					var getEls = $('layer_switch').getElementsByTagName('DIV');
						for (var z=0; z<getEls.length; z++) {
						getEls[z].className=getEls[z].className.replace('show', 'hide');
						getEls[z].className=getEls[z].className.replace('on', 'off');
						}
					this.className = 'on';
					var max = this.getAttribute('title');
					$(max).className = "show";
				}
			}
		}	
	}

}
/*swich the layer*/
function clicklayerswich(){	
	if($('boxswitch') == null ) return;
	var e, i = 0;
	while (e = $('boxswitch').getElementsByTagName ('DIV') [i++]) {
		if (e.className == 'on' || e.className == 'off') {
		e.onclick = function () {
			var getEls = $('layer_switch').getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) {
				getEls[z].className=getEls[z].className.replace('show', 'hide');
				getEls[z].className=getEls[z].className.replace('on', 'off');
				}
			this.className = 'on';
			var max = this.getAttribute('title');
			$(max).className = "show";
			}
		}		
	}
}
/* marque => bof*/
function srcMarquee(){
	this.ID = $(arguments[0]);
	if(!this.ID){this.ID = -1;return;}
	this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.Correct = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
	this.Step = 1;
	this.Timer = 30;
	this.DirectionArray = {"top":0 , "bottom":1 , "left":2 , "right":3};
	if(typeof arguments[1] == "number")this.Direction = arguments[1];
	if(typeof arguments[2] == "number")this.Step = arguments[2];
	if(typeof arguments[3] == "number")this.Width = arguments[3];
	if(typeof arguments[4] == "number")this.Height = arguments[4];
	if(typeof arguments[5] == "number")this.Timer = arguments[5];
	if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
	if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
	if(typeof arguments[8] == "number")this.ScrollStep = arguments[8]
	this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
	this.ID.noWrap = false;
	this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
	if(arguments.length >= 7)this.Start();
}

srcMarquee.prototype.Start = function(){
	if(this.ID == -1)return;
	if(this.WaitTime < 800)this.WaitTime = 800;
	if(this.Timer < 20)this.Timer = 20;
	if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
	if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
	if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
	this.HalfWidth = Math.round(this.Width / 2);
	this.BakStep = this.Step;
	this.ID.style.width = this.Width;
	this.ID.style.height = this.Height;
	if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
	var msobj = this;
	var timer = this.Timer;
	var delaytime = this.DelayTime;
	var waittime = this.WaitTime;
	msobj.StartID = function(){msobj.Scroll()}
	msobj.Continue = function(){
		if(msobj.MouseOver == 1){
		setTimeout(msobj.Continue,delaytime);
     }
     else{ clearInterval(msobj.TimerID);
		msobj.CTL = msobj.Stop = 0;
		msobj.TimerID = setInterval(msobj.StartID,timer);
     }
    }
	msobj.Pause = function(){
		msobj.Stop = 1;
		clearInterval(msobj.TimerID);
		setTimeout(msobj.Continue,delaytime);
    }
	msobj.Begin = function(){
   msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth : msobj.ID.scrollHeight;
   if((msobj.Direction <= 1 && msobj.ClientScroll <msobj.Height) || (msobj.Direction > 1 && msobj.ClientScroll <msobj.Width))return;
   msobj.ID.innerHTML += msobj.ID.innerHTML;
   msobj.TimerID = setInterval(msobj.StartID,timer);
   if(msobj.ScrollStep < 0)return;
   msobj.ID.onmousemove = function(event){
       if(msobj.ScrollStep == 0 && msobj.Direction > 1){
			var event = event || window.event;
			if(window.event){
				if(msobj.IsNotOpera){msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : 

event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;}
				else{msobj.ScrollStep = null;return;}
			}
			else{msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;}
			msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
			msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
			msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
			}
		}
		msobj.ID.onmouseover = function(){
			if(msobj.ScrollStep == 0)return;
			msobj.MouseOver = 1;
			clearInterval(msobj.TimerID);
		}
		msobj.ID.onmouseout = function(){
		if(msobj.ScrollStep == 0){
			if(msobj.Step == 0)msobj.Step = 1;
			return;
		}
		msobj.MouseOver = 0;
		if(msobj.Stop == 0){
			clearInterval(msobj.TimerID);
			msobj.TimerID = setInterval(msobj.StartID,timer);
		}}}
		setTimeout(msobj.Begin,waittime);
}

srcMarquee.prototype.Scroll = function(){
	switch(this.Direction){
	case 0:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollTop >= this.ClientScroll){this.ID.scrollTop -= this.ClientScroll;}
		this.ID.scrollTop += this.Step;
	}
	break;

	case 1:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollTop <= 0){this.ID.scrollTop += this.ClientScroll;}
		this.ID.scrollTop -= this.Step;
	}
	break;

	case 2:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollLeft >= this.ClientScroll){this.ID.scrollLeft -= this.ClientScroll;}
		this.ID.scrollLeft += this.Step;
	}
	break;

	case 3:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollLeft <= 0){this.ID.scrollLeft += this.ClientScroll;}
	this.ID.scrollLeft -= this.Step;
	}
	break;
	}
} 
/* marque => eof*/
var timer;
function marquee(delay, liHeight, toAlign, lyorderID){	
	var o=$(lyorderID);
	var timer_bug;
	for(i=0;i<o.childNodes.length;i++){
		if(o.childNodes[i].tagName == null){
			o.removeChild(o.childNodes[i]);			
		}
	}
	if(o==null) return;
	
	function scrollup(o,h,d){	
		if(d==h){
		   var t = o.firstChild;
		   o.appendChild(t);
		   t.style.marginTop=o.firstChild.style.marginTop='0px';
		   d = 0;
		}
		else{
		   var s=3,d=d+s,l=(d>=h?d-h:0);
		   o.firstChild.style.marginTop=-d+l+'px';
		   timer_bug = setTimeout(function(){scrollup(o,h,d-l)},20);
		}
	}
	timer = setInterval(function(){clearTimeout(timer_bug);scrollup(o,liHeight,toAlign);},delay);
}


///////////////
function addListener(element, type, expression, bubbling)
{
  bubbling = bubbling || false;
  if(window.addEventListener)	{ // Standard
    element.addEventListener(type, expression, bubbling);
    return true;
  } else if(window.attachEvent) { // IE
    element.attachEvent('on' + type, expression);
    return true;
  } else return false;
}

var ImageLoader = function(url){
  this.url = url;
  this.image = null;
  this.loadEvent = null;
};

ImageLoader.prototype = {
  load:function(){
    this.image = document.createElement('img');
    var url = this.url;
    var image = this.image;
    var loadEvent = this.loadEvent;
    addListener(this.image, 'load', function(e){
      if(loadEvent != null){
        loadEvent(url, image);
      }
    }, false);
    this.image.src = this.url;
  },
  getImage:function(){
    return this.image;
  }
};

function loadImage(objId,urls){
var loader = new ImageLoader(urls);
loader.loadEvent = function(url){
 obj = $(objId);
 obj.src = url;
}
loader.load();
}

function rewrite_url(pname , pid){
	if(pid == null || pid == "undefined" ) {return ""};
	var re = /[^a-zA-Z0-9]/ig;
	var url = "";
	url = baseURL + pname.toLowerCase().replace(re,"-") + "_p" + pid + ".html";
	return url;
}
/////////////////
/*the li scroll*/
function page_go(id,num, c,t,cid){
	var Prev = id + "Prev";
	var Next = id + "Next";	
	var pageId = id + "Page";
	var Page = 0;
	var currentPage = 1;
	var PageNumber = Math.ceil(t/num);
	var activeClick = true;
	var gopage = 0;

	if(num>t){activeClick = false;}
	if(c >= num){
		if(t!=null){
			gopage = Math.ceil(c/num);
			if(c % num == 0) gopage++; 		
		}
		updateProduct('goto', gopage);
	}
	
	function updateProduct(type, gopage) {
		if(type=='pre') {Page -= parseInt(num);currentPage--};
		if(type=='next') {Page += parseInt(num);currentPage++};
		if(type=='goto' && gopage != null) {Page = (gopage-1) * num ; currentPage = gopage;}
		if(Page<0) {
			Page=num*(PageNumber-1);
			currentPage=PageNumber;
		}
		if(Page>=t) {
			Page=0;
			currentPage=1;
		}
		
		$(pageId).innerHTML = currentPage +'/'+PageNumber;
		
		for(i=0;i<num;i++){
			if(i >= productPrice.length){
				break;
			}
			n_page = i + Page;
			$('cell_price'+i).innerHTML=productPrice[n_page];
			$('cell_link'+i).href = rewrite_url(productName[n_page], productID[n_page]);
			$('cell_link'+i).title = productName[n_page];
			
			$('li'+i).style.display='block';
			if(productID[n_page] == null){
				$('li'+i).style.display='none';
				continue;
			}
			if(num==4)$('cell_img'+i).src=baseURL+"images/root/loading_img_b.gif";
			if(num==8)$('cell_img'+i).src=baseURL+"images/root/loading_img_s.gif";
			$('cell_img'+i).alt=productName[n_page];
			$('cell_img'+i).title=productName[n_page];
			loadImage('cell_img'+i,imgURL+productIMG[n_page]);
			if(cid != null){
				if(cid == productID[n_page]){
					$('cell_img'+i).className = 'allborder';
				}
				else{
					$('cell_img'+i).className = '';
				}
			}
		}
	}

	$(pageId).innerHTML = currentPage +'/'+PageNumber;
	$(Prev).onclick = function () {
		if(!activeClick) return false;
		updateProduct('pre');
	}
	$(Next).onclick = function () {
		if(!activeClick) return false;
		updateProduct('next');
	}	
}

function postAjax(url,content,onComplete){
	var options=new Object();
	options.method="post";
	options.asynchronous=true;
	options.parameters=content;
	options.onComplete=onComplete;
	return new Ajax.Request(url, options);
}

function checkWholesalNewsletter(id){
	if ($(id) == null) return;	
	if(checkEmail(id)){
		hide('wholesale_newsletter_text');
		show('wholesale_newsletter_loading');
			postAjax(window.location.pathname + '?main_page=wholesale_newsletter' , id + '=' + $(id).value, function(ajax){
			if(ajax.readyState==4&&ajax.status == 200){		
				$('wholesale_newsletter_text').innerHTML = ajax.responseText;
				hide('wholesale_newsletter_loading');
				show('wholesale_newsletter_text');
				if(ajax.responseText.indexOf('touch')>0){
					$(id).value = '';
				}
			}
		});	
	}
}

function checkEmail(id){
	var email = $(id) == null ? '' : $(id).value;
	if(!/(\,|^)([\w+._]+@\w+\.(\w+\.){0,3}\w{2,4})/.test(email.replace(/-|\//g,""))){
		$(id).focus();
		alert('Please check your email address.\nYour email addresses should look like "myname@gmail.com"');
		return false;
	}
	else{
		return true;	
	}
}

var openShow = false;
function show_chat_div(obj){
	if(openShow) {
		close_chat_div();
		return;
	}
	openShow = true;
	var name = obj.getAttribute("title");
	var msn = obj.getAttribute("msn");
	var skype = obj.getAttribute("skype");
	var email = obj.getAttribute("email");
	var yahoo = obj.getAttribute("yahoo");
	var aim = obj.getAttribute("aim");
	
	var str = "";
	    str += "<ul class='gray_trangle_list'>";
	    if(email!=null && email != ""){
	    	str += "<li><span class='big black b'>Email</span><BR/> <span class='pad_1em'>" + email + "</span></li>";
	    }
	    if(msn!=null && msn != ""){
	    	str += "<li><span class='big black b'>MSN</span><BR/> <span class='pad_1em'>" + msn + "</span></li>";
	    }
	    /*if(aim!=null && aim != ""){
	    	str += "<li><span class='big black b'>AIM</span><BR/> <span class='pad_1em'>" + aim + "</span></li>";
	    }*/
	    if(skype!=null && skype != ""){
	   		str += "<li><span class='big black b'>SKYPE</span><BR/> <span class='pad_1em'>" + skype + "</span></li>";
	    }
	    if(yahoo!=null && yahoo != ""){
	    	str += "<li><span class='big black b'>YAHOO</span><BR/> <span class='pad_1em'>" + yahoo + "</span></li>";
	    }
	    str += "</ul>";	
	$('chat_div_name').innerHTML = str;
	show('chat_div');
	clearInterval(timer);
	hide_select('in');
}

function close_chat_div(){
	hide('chat_div');
	marquee(3000, 15 ,0 ,'nav_chat_sales');
	hide_select("out");
	openShow = false;
}

function hide_select(what){	
  var anchors = document.getElementsByTagName("select");
  if (what=="in") {
 	 for (var i=0; i<anchors.length; i++) {
 	 	if(anchors[i].getAttribute("rel")=="dropdown"){
 			anchors[i].style.visibility="hidden";
 	 	}
 	 }
  } 
  else {
 	for (var i=0; i<anchors.length; i++) {
 		if(anchors[i].getAttribute("rel")=="dropdown"){
 	    	anchors[i].style.visibility="visible";
 		}
	}
  }
}

function back(num){
	history.go(num);
	return false;
}
function floatBox(posEL,element){
	var posX,posY,pos,offTop;
	var width = 339;
	var height = 328; 
	if(isIE){
		pos = $(posEL).childNodes[0];
		offTop = 120;
	}else{
		pos = $(posEL);
		offTop = 130;
	}
	posX = pos.offsetLeft-width;
	posY = pos.offsetTop-offTop;
	
	var box = $('pop_window');
    box.style.position = 'absolute';   
    box.style.zIndex = 999;
    box.style.top = posY + 'px';    
    box.style.left = posX + 'px';    
    box.style.width = width + 'px';    
    box.style.height = height + 'px';
	var str ="<img onclick='close_box(this)' src='"+baseURL+"images/root/close.gif' class='hand' title='close' alt='close' id='floatBox_img'/><div class='png'>";
	switch (element){
		case 'shipping_info':
		                     str += shipping_info;
		                     break;
        case 'payment_option':
                              str += payment_option;
                              break;
		case 'questions':
                              str += questions;
                              break;                              
		default : str += content;
		          break;
		
	}	
	str += "</div>";
	box.innerHTML = str;
	show('pop_window');
	return false;
}
function close_box(obj){	
	hide(obj.parentNode);
}

//tel toll 2010-10-13 James&Tiger

var marqueesHeight = 18; //height
var stopscroll     = false;
var scrollElem;
var preTop     = 0;
var currentTop = 0;
var stoptime   = 0;
var leftElem ;

function scrollUp(){
	if(stopscroll) return;
	currentTop += 1;
	if(currentTop == 19) { //roll distance
		stoptime += 1;
		currentTop -= 1;
		if(stoptime == 220) { //pause time
			currentTop = 0;
			stoptime = 0;
		}
	}
	else{
		preTop = scrollElem.scrollTop;
		scrollElem.scrollTop += 1;
		if(preTop == scrollElem.scrollTop){
			scrollElem.scrollTop = 0;
			scrollElem.scrollTop += 1;
		}
	}
}

function init_srolltext(){
	scrollElem.scrollTop = 0;
	setInterval('scrollUp()', 15); //roll speed
}

function init_tel(){
try
{
	var tel802 = document.getElementById("tel802");  
	tel802.innerHTML = "&nbsp;USA: 1-888-807-6588";
	var tel803 = document.getElementById("tel803");  
	tel803.innerHTML = "&nbsp;USA: 1-888-807-6588";	
	var tel804 = document.getElementById("tel804");  
	tel804.innerHTML = "&nbsp;USA: 1-888-807-6588";
	scrollElem =   document.getElementById("scrolllayer");
	leftElem =   document.getElementById("scrollmessage");
	with(scrollElem){
	style.width     = 500;//width
	style.height    = marqueesHeight;
	style.overflow  = 'hidden';
	noWrap          = true;
	}
	scrollElem.onmouseover = new   Function('stopscroll = true');
	scrollElem.onmouseout  = new   Function('stopscroll = false');
	
	scrollElem.appendChild(leftElem.cloneNode(true));
	init_srolltext();
}catch(e) {}

}

var FRIENDLY_URLS='true';
function sortFocus(obj){
	if(isIE){
		obj.value ='';
	}
	else{
		o=new Option('','-1');
	    obj.options.add(o);
		obj.value ='-1';
	}	
}
function sortBlur(obj, value){
	if(isIE){
		obj.value ='value';
	}
}
function changeSort(obj, sort_url){
if(obj.value != '-1'){
		if(sort_url.indexOf('?') > -1){
			window.location.href= sort_url + "&productsort=" + obj.value;
		}
		else{
			window.location.href= sort_url + "?productsort=" + obj.value;
		}
	}
}
function changePagesize(obj, sort_url){
	if(obj.value != '-1'){
		if(sort_url.indexOf('?') > -1){
			window.location.href= sort_url + "&pagesize=" + obj.value;
		}
		else{
			window.location.href= sort_url + "?pagesize=" + obj.value;
		}
	}
}
function changePage(obj, sort_url){
	if(obj.value != '-1'){
		if(sort_url.indexOf('?') > -1){
			window.location.href= sort_url + "&page=" + obj.value;
		}
		else{
			window.location.href= sort_url + "?page=" + obj.value;

	}
	}	
}
function getCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
  // a name/value pair (a crumb) is separated by an equal sign
  var aCrumb = aCookie[i].split("=");
  if (sName == aCrumb[0])
    return unescape(aCrumb[1]);
  }
    // a cookie with the requested name does not exist
    return null;
}
function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
  var expires = new Date();
  expires.setTime(expires.getTime() + seconds);
  document.cookie = escape(cookieName) + '=' + escape(cookieValue)
    + (expires ? '; expires=' + expires.toGMTString() : '')
    + (path ? '; path=' + path : '/')
    + (domain ? '; domain=' + domain : '')
    + (secure ? '; secure' : '');
}
addthis_url    = location.href;   
addthis_title  = document.title;  
addthis_pub    = 'nikemaxnow';  

if (typeof addthis_widget=="undefined"){
	var addthis_widget='addthis';
	var at12O='http://s7.addthis.com/'; 
	var at12o='http://s7.addthis.com/services/';
	function addthis( ){
		addthis_url=encodeURIComponent(addthis_url); addthis_title=encodeURIComponent(addthis_title); addthis_title=addthis_title.replace(/'/g,'\\\''); 
		var at12y='<a href="'+at12I('')+'\" onclick=\"return addthis_to()\">'; at12y+='<img src="'+baseURL+'images/bookmark.gif" width="125" height="16" border="0" style="border: none;padding:0px;position:absolute;left:385px;" alt="AddThis Social Bookmarking Widget" /></a>';
		document.write(at12y); 
	}
	function at12I(at12r){return 'http://www.addthis.com/bookmark.php?v=12&winname=addthis&pub='+addthis_pub+'&s='+at12r+'&url='+addthis_url+'&title='+addthis_title; }
	function addthis_to(at12r){if (at12r=='favorites'){addthis_url=decodeURIComponent(addthis_url); addthis_title=decodeURIComponent(addthis_title); if (document.all)window.external.AddFavorite(addthis_url,addthis_title); else window.sidebar.addPanel(addthis_title,addthis_url,''); return false; }window.open(at12I(at12r),'addthis','scrollbars=yes,menubar=no,width=620,height=400,resizable=yes,toolbar=no,location=no,status=no'); return false; }
}




function field_check(name, rule, field){
  	if(rule.indexOf("cpwd")>-1){
		strTmp = rule.split("#");
		if(strTmp[0].inc("cpwd","/") == true && field.value != $(strTmp[1]).value){
			return "The "+name+" must match your " +name.split(" Confirmation")[0];
		}
	}	
	if(rule.inc("eml","/")==true && !/(\,|^)([\w+._]+@\w+\.(\w+\.){0,3}\w{2,4})/.test(field.value.replace(/-|\//g,"")) && !isNone(field.value)){
		return "Is your " + name + " correct? Sorry, my system does not understand your email address.";
	}	
	if(rule.inc("tel","/")==true && !/(^[0-9+-]{3,30}$)/.test(field.value) && !isNone(field.value)){
		return "Is your "+name+" correct? Sorry, my system does not understand your telephone format.";
	}	
	size = rule.sub("min","/");
	if(size > 0 ){			
		if(field.value.trim().length < size && field.value.trim().length>0){
			return "Is your "+ name +" correct? Our system requires a minimum of "+size+" characters.";
		}
	}		
	size = rule.sub("max","/");		
	if(size > 0 ){
		if(field.value.trim().length > size){
			return "Is your "+ name +" correct? Our system requires a maximum of "+size+" characters."
		}
	}	
	if(rule.inc("nnull","/") == true && isNone(field.value)){
		return "Sorry, "+name+" information is required.";		
	}	
	if(rule.inc("ischeck","/") == true && ! field.checked ){
		return name;
	}
	if(rule.inc("isselect","/") == true && field.value == '-1' ){
		return 'Please Choose "' + name + '"';
	}	
	return "";
};

/*#表单验证#*/
function fmChk(fm){
	var name , rule , tmp , msgStr , size;
	if(fm == null || fm.tagName != "FORM"){
		alert("", null , "error");
	    return;
	}	
	for(i=0;i<fm.length;i++){		
		var msgStr = chkInput(fm[i]);				
		if(msgStr != "success"){
			efocu(fm[i]);
			msg(msgStr);
			return false;
		}
	}
	return true;
};

function chkInput(obj){
	var name , rule , msgStr;
	name=obj.getAttribute("chkName");
	rule=obj.getAttribute("chkRule");
	if(isNone(rule) || isNone(name))  return "success";	
	msgStr = field_check(name, rule, obj);
	
	if(msgStr != ""){
		return msgStr;
	}
	else{
		return "success";
	}
};

function msg(key){
	alert(key);
};

function initForm(el, func){	
	var img_path = baseURL + "includes/templates/doubleoranges/images/checkout";
	(new Image(10,10)).src = img_path + "/ico_F.gif";
	var error_bg = "#FEDFDF", blur_bg = "" , focus_bg = "#FFFEE1";
	var formId = $(el);
	if(formId == null || formId.tagName != "FORM"){
		alert("", null , "error");
	    return;
	}
	var addImage = '<img src="'+ img_path + "/ico_T.gif" +'" width="10" height="10" style="display:none;" class="pad_l"/>';
	var addDiv = '<div style="display:none;" class="red line_120"></div>';
	var elArr = formId.elements;
	var elLen = elArr.length;
	for(i=0; i<elLen; i++) {
		//insert the img and div
		var addHtml = elArr[i].getAttribute("chkRule");
		if(addHtml){
			insHtm(elArr[i],addImage);
			insHtm(elArr[i],addDiv);
			
			//add the mouse style have check;
			elArr[i].onfocus = function(){
					if((this.tagName === "INPUT" && (this.type === "text" || this.type === "password"))||this.tagName === "TEXTAREA")
					{this.style.backgroundColor = focus_bg;}
			}
			elArr[i].onblur = function(){
				this.style.backgroundColor = blur_bg;	
				var out_img = this.parentNode.getElementsByTagName("img")[0];
				var out_text = this.parentNode.getElementsByTagName("div")[0];
				var msg = chkInput(this);
				if(msg === "success") {
					out_img.src = img_path + "/ico_T.gif";
					out_img.style.display="inline";
					out_text.style.display="none";
				}else{
					out_img.src = img_path + "/ico_F.gif";						
					out_img.style.display="inline";
					out_text.innerHTML = msg;
					out_text.style.display="block";
					if((this.tagName === "INPUT" && (this.type === "text" || this.type === "password"))||this.tagName === "TEXTAREA"){
						this.style.backgroundColor = error_bg;
					}
				}
				if(func != null) {try{eval(func);}catch(e){}}						
			}
		}else{
				//add the mouse style not check;
			if((elArr[i].tagName === "INPUT" && (elArr[i].type === "text" || elArr[i].type === "password"))||elArr[i].tagName === "TEXTAREA"){
				elArr[i].onfocus = function(){this.style.backgroundColor = focus_bg;}
				elArr[i].onblur = function(){this.style.backgroundColor = blur_bg; if(func != null) {try{eval(func);}catch(e){}}}
			}
		}
	}
}
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}
function getRelatedTraget(event) {
  if (event.relatedTarget) {
    return event.relatedTarget;
  } else if (event.toElement) {
    return event.toElement;
  } else if (event.fromElement) {
    return event.fromElement;
  } else {
    return null;
  }
}

function init_search(){ 
	$('cont-search').onmouseover = function() {
	  $('homePopSearch').style.display = 'block';
	}
	$('cont-search').onmouseout = function(event) {
	  event = event ? event: window.event;
	  var relatedTarget = getRelatedTraget(event);
	  if (relatedTarget.id == 'homePopSearch') {
	    $('homePopSearch').style.display = 'block';
	  } else {
	    $('homePopSearch').style.display = 'none';
	  }
	}
	$('homePopSearch').onmouseout = function() {
	  $('homePopSearch').style.display = 'none';
	}		
}
function CustomSizeCheck(){
	var customSizeCheckBox = document.getElementsByName('customSizeCheckBox')[0].checked;
	if(customSizeCheckBox==true){ 
		document.getElementById("customSizePanel").style.display="";   
		document.getElementById('attrib-2').disabled=true;
	}else{
		document.getElementById("customSizePanel").style.display="none";  
		document.getElementById('attrib-2').disabled=false; 
	}
}
