function getElementTop(obj) {
  var ret_val = 0;
  ret_val = obj.offsetTop;
  objHTMLelement = obj.offsetParent;
  while (objHTMLelement != null) {
    ret_val += objHTMLelement.offsetTop;
    objHTMLelement = objHTMLelement.offsetParent;
  }
  return ret_val;
}

function answerShowHide(objId) {
  obj=document.getElementById(objId);
  if(obj) {
    if(obj.style.display == "block")
      obj.style.display="none";
    else
      obj.style.display="block";
  }
  return true;
}

function getElementLeft(obj) {
  var ret_val = 0;
  ret_val = obj.offsetLeft;
  objHTMLelement = obj.offsetParent;
  while (objHTMLelement != null) {
    ret_val += objHTMLelement.offsetLeft;
    objHTMLelement = objHTMLelement.offsetParent;
  }
  return ret_val;
}
function showHideLoginOrRegisterPopup(obj) {
  popup = document.getElementById('popuplr');

  if(popup.style.display == 'block') {
    popup.style.display = 'none';
  } else {
    objLeft = getElementLeft(obj)-125;

    if(objLeft > (document.body.clientWidth - 175))
      objLeft = (document.body.clientWidth - 175);

    popup.style.left = objLeft;
    popup.style.top = getElementTop(obj)+20;
    popup.style.display = 'block';
  }

  return true;
}

function showHideTelephonePopup(obj,id) {
  popup = document.getElementById('telpop'+id);

  if(popup.style.display == 'block') {
    popup.style.display = 'none';
  } else {
    objLeft = getElementLeft(obj)-125;

    if(objLeft > (document.body.clientWidth - 175))
      objLeft = (document.body.clientWidth - 175);

    popup.style.left = objLeft;
    popup.style.top = getElementTop(obj)+20;
    popup.style.display = 'block';
  }

  return true;
}


function showHideLoginPopup(obj) {

  popup = document.getElementById('popuplogin');

  if(popup.style.display == 'block') {
    popup.style.display = 'none';
  } else {
    objLeft = getElementLeft(obj);

    if(objLeft > (document.body.clientWidth - 195))
      objLeft = (document.body.clientWidth - 195);

    popup.style.left = objLeft;
    popup.style.top = getElementTop(obj)+13;
    popup.style.display = 'block';
  }

  return true;
}

var isOnPopup = false;
function hideLoginOrRegisterPopup(needToCheckIfOnPopup) {
  if(needToCheckIfOnPopup) {
    if(!isOnPopup) {
      document.getElementById('popuplr').style.display='none';
    }
  } else {
    document.getElementById('popuplr').style.display='none';
  }
  return true;
}
function hideLoginPopup(needToCheckIfOnPopup) {
  if(needToCheckIfOnPopup) {
    if(!isOnPopup) {
      document.getElementById('popuplogin').style.display='none';
    }
  } else {
    document.getElementById('popuplogin').style.display='none';
  }
  return true;
}

function setIsOnFlag(val) {
  isOnPopup = val;
  return true;
}



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
var curr_top = 0;
var curr_move = false;

function setScrollFlag(val) {
  curr_move = val;
  return(true);
}

function winScroll(e,obj) {
  if(curr_move) {
    //window.scroll(0,obj.clientHeight);
    //window.scroll(0,obj.event.y);
    if (!e)
      var e = window.event;

    window.scroll(0,Math.round(((e.clientY - 60) / obj.clientHeight) * document.height));

    //window.status=Math.round((e.clientY / obj.clientHeight) * document.height);

    //window.status=document.height;

  }
}

function recountCart() {
  document.forms.cartform.action='./?mode=cart&action=recount';
  document.forms.cartform.submit();
  return true;
}

function ow(url){
	if(!url)
	  return false;

	w = 650;
	h = 500;
	l = ( screen.width - w )/2;
	t = ( screen.height - h )/2;

	window.open( url, "_blank", "toolbar=0,scrollbars=1,resizable=1,left="+l+",top="+t+",width="+w+",height="+h );
}

function addDelivAddr() {
  delivAddrCount++;
  document.getElementById("delivAddrHandler").innerHTML += '<textarea class=\"form_content\" name=\"bank_deliveryaddress_' + delivAddrCount + '\"></textarea><br />';
  return(true);
}
