// JavaScript Document
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
        //**********************************************************************
        //destination:show & hide ask and question
        //filename:/templates/Original1_B2B/faq.tpl.php   /templates/Original1_B2B/information.tpl.php
        //**********************************************************************
        function showHide(id){
            var aswobj =  document.getElementById(id);
            if(aswobj.style.display == "block"){
                aswobj.style.display = "none";
            }else{
                aswobj.style.display = "block";
            }
        }
        //**********************************************************************
        //destination:price table change currency
        //filename:/templates/Original1_B2B/products_detail.tpl.php
        //**********************************************************************
        var showmua=false;
        function showmu(a){
            var bv = isIE();
            showmua=true;
            var offsetX = 14;              //268
            var offsetY = 0;              //80
            if(bv == "IE6"){
                offsetX = 14;
                offsetY = 0;
            }
            if(bv == "IE7"){
                offsetX = 16;
                offsetY = 0;
            }
            var e=$('#'+a);
            if (e.css("display")=="none"){
                var pos = getPos(document.getElementById(a).parentNode);
                var x = pos.x + offsetX;
                var y = pos.y + offsetY;
                e.css({left:x + "px",top:y + "px"});
                e.show('slow');
            }
        }
        function isIE(){
            if(navigator.userAgent.indexOf("MSIE 7.0") > 0){
                return "IE7";
            }else if(navigator.userAgent.indexOf("MSIE 6.0") > 0){
                return "IE6";
            }else{
                return "FF";
            }
        }
        function getPos(obj){
            if(typeof(obj) != "object") var obj = document.getElementById(obj);
            var pos = new Object();
            pos.x = obj.offsetLeft;
            pos.y = obj.offsetTop;
            while(obj = obj.offsetParent){
                pos.x += obj.offsetLeft;
                pos.y += obj.offsetTop;
            }
            return pos;
        }
        function hidmu(a){
            showmua=false;
            setTimeout('hid("'+a+'")',500);
        }
        function hid(a){
            var e=$('#'+a);
            if (e.css("display")=="block" && showmua==false){
                e.hide('slow');
            }
            showmua=true;
        }
        //**********************************************************************
        //destination:count price automatically
        //filename:/templates/Original1_B2B/products_detail.tpl.php
        //**********************************************************************
	function count_qty(count_type)
	{
    var tb = $('price_table');
    var tr = tb.getElementsByTagName('tr');
		var obj = $('cart_quantity');
    var cashObj = $("showCash");
    var totalSum = cashObj.innerHTML;
		if(count_type == '+')
		{
      obj.value = parseInt(obj.value) + 1;
    }
		if(count_type == '-' && parseInt(obj.value))
		{
      obj.value = parseInt(obj.value) - 1;
      if(parseInt(obj.value) <= 0) obj.value = 1;
    }
    var num_of_product = (parseInt(obj.value) > 0)?parseInt(obj.value):1;
    
    for(var i=1,len = tr.length; i < len;++i)
    {
      var td = tr[i].childNodes;
      var txt = '';
      for(k = 0,n = td.length; k < n;++k)
      {
        if(new RegExp(/^\d+(\s?\-\s?\d+)*$/).test(td[k].innerHTML) || new RegExp(/^\d+(\s?\-\s?Above)$/).test(td[k].innerHTML))
        {
        	txt = td[k].innerHTML;
        	break;
        }
      }
			var qty = txt.split(' - ');
			if(num_of_product >= parseInt(qty[0]) && (num_of_product <= parseInt(qty[1]) || qty[1] == "Above"))
			{
				for(m = 0,n = td.length; m < n;++m)
				{
	        if(new RegExp(/\d+\.\d{2}/).test(td[m].innerHTML))
	        {
	        	var product_price = td[m].innerHTML.replace(/[^\d\.]+/,'');
	          break;
	        }
        }
				break;
			}
    }

    var cash = formatFloat(product_price * num_of_product,2);
    cashObj.innerHTML = totalSum.replace(/[\d\.]+/,cash);
    obj.value = num_of_product;
 
	}
  
  function showTip(divId)
  {
    var obj = document.getElementById(divId);
    obj.style.display = 'block';
  }
  
  function formatFloat(src,pos) 
  {
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
	}
            //******************************************************************
            //destination:chang currency for head
            //filename:/templates/Original1_B2B/header.php
            //******************************************************************
            function changeCurrency(targetCurrency){
                var link_url = window.location.href;
                var regPattern = '';
                if(link_url.indexOf('?') > 0){
                    var newUrl = "";
                    if(link_url.indexOf('currency=') > 0){
                        if(link_url.indexOf('&currency=') > 0){
                            regPattern = /&currency=.+/ig;
                            newUrl = link_url.replace(new RegExp(regPattern),'') + '&currency=' + targetCurrency;
                        }
                        if(link_url.indexOf('?currency=') > 0){
                            regPattern = /\?currency=.+/ig;
                            newUrl = link_url.replace(new RegExp(regPattern),'') + '?currency=' + targetCurrency;
                        }
                    }else{
                        newUrl = link_url + '&currency=' + targetCurrency;
                    }
                }else{
                    newUrl = link_url + '?currency=' + targetCurrency;
                }
                window.location.href = newUrl;
            }

            function addToFavorites(){
                if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) ){
                        window.sidebar.addPanel(pageName, urlAddress, "");
                }else if ( document.all && "object" == typeof( window.external ) ){
                        window.external.addFavorite(urlAddress,pageName);
                }
            }
 
/* products list grid gallery */            
function changeSort(obj, sort_url){
	if(obj.value != '-1'){
		if(sort_url.indexOf('?') > -1){
			window.location.href= sort_url + "&sort=" + obj.value;
		}else{
			window.location.href= sort_url + "?sort=" + 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 g(o){return document.getElementById(o);}
function HoverLi(n)
{
	for(var i=1;i<=2;i++){g('tb_'+i).className='normaltab';g('tbc_0'+i).className='undis';}
	g('tbc_0'+n).className='dis';g('tb_'+n).className='hovertab';
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function ap_showHideLayers() { //v9.0
  var i,p,v,obj,args=ap_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function aps_showHideLayers() { //v9.0
  var i,p,v,obj,args=aps_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function aps_showHideLayers() { //v9.0
  var i,p,v,obj,args=aps_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function img_showHideLayers() { //v9.0
  var i,p,v,obj,args=img_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-

function chat_div_showHideLayers() { //v9.0 ------------- live -----------
  var i,p,v,obj,args=chat_div_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// copycode
function copycode(obj) {
	if(is_ie && obj.style.display != 'none') {
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
	}
}
var lang = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

function right_showHideLayers() { //v9.0
  var i,p,v,obj,args=right_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function fEvent(sType,oInput){
		switch (sType){
			case "focus" :
				oInput.isfocus = true;
			case "mouseover" :
				oInput.style.borderColor = '#333333';
				oInput.style.backgroundColor = '#ffffff';
				break;
			case "blur" :
				oInput.isfocus = false;
			case "mouseout" :
				if(!oInput.isfocus){
					oInput.style.borderColor='#dddddd';
					oInput.style.backgroundColor = '#f6f6f6';
				}
				break;
		}
}
