var uri_shoppingcart=null;
var uri_home=null;
function getObject(id){
  if(document.getElementById) return document.getElementById(id);
  if(document.all) return document.all[id];
  return null;
}
function setShow(thiselt,id, parent, ofsx, ofsy, root){
	var tid=setTimeout(function(){
				show(id, parent, ofsx, ofsy, root);
			}, 500);
	
	thiselt.onmouseout=function(){
		clearTimeout(tid);
		hide(id);
	}	
}

function show(id, parent, ofsx, ofsy, root){
  var root_x=0, o;
  if(root){
    o=getObject(root);
    root_x=findPosX(o)
  }
  o=getObject(id);
  if(o==null)return;
  var s=o.style;
  if(s==null)return;
  s.left=findPosX(parent)+ofsx-root_x+'px';
  s.top=findPosY(parent)+ofsy+'px';
  s.display='block';
}
function hide(id){
  var o=getObject(id);
  if(o==null)return;
  o.style.display="none";
}
function findPosX(obj) {var curleft = 0;
  if (obj.offsetParent){
    while (obj.offsetParent){
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}
function findPosY(obj){
  var curtop = 0;
  if (obj.offsetParent){
    while (obj.offsetParent){
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  } else if (obj.y)
    curtop += obj.y;
  return curtop;
}
function goResults(){
  var destrination=document.fm.callTo.value;
  destrination=destrination.replace(" ", "_");
  destrination=destrination.replace(" ", "_");
  destrination=destrination.replace(" ", "_");
  document.fm.action=destrination+".calling-cards";
  //document.fm.action="search";
  document.fm.submit();
}
function goShoppingCart(){
  if(uri_shoppingcart==null)
  uri_shoppingcart="shoppingcart";
  document.fm.action=uri_shoppingcart;
  document.fm.submit();
}
function goHome(){
  if(uri_home==null)
  uri_home="/";
  document.fm.action=uri_home;
  document.fm.submit();
}
function goTerms(){
  document.fm.action="terms";
  document.fm.submit();
}
function goFAQ(){
  document.action="faq";
  document.fm.submit();
}
function goContactUs(){
  if(uri_contactus==null)
  uri_contactus="contactus";
  document.fm.action=uri_contactus;
  document.fm.submit();
}
function help(page){
  day = new Date();
  id = day.getTime();
  window.open(page, id, "height=350,width=500,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,top=100, left=100")
}
function showCard(card_id, location_from_id, location_id){
  document.fm.action="cardinfo";
  document.fm.card_id.value=card_id;
  document.fm.submit();
}
function showCardLnk(card_id){
  document.fm.action=card_id;
  document.fm.submit();
}
function addOne(card_id, denom){
  document.fm.fn.value="add";
  document.fm.card_id.value=card_id;
  document.fm.denom.value=denom;
  goShoppingCart();
  return false;
}
function addBookmark(url,title) {
  if (window.sidebar) {
	window.sidebar.addPanel(title,url,"");
  } else if( document.all ) {
    window.external.AddFavorite( url, title);
  } else if( window.opera && window.print ) {
    return true;
  }
}
function setSelectValue(obj, val){
	for(var i=0;i<obj.options.length;i++){
		if(obj.options[i].value==val){
			obj.selectedIndex=i;
			break;
		}
	}
}
function serachInSelect(obj, val){
	for(var i=0;i<obj.options.length;i++){
		if(obj.options[i].text.substr(0,val.length).toUpperCase()==val.toUpperCase()){
			obj.selectedIndex=i;
			return val;
			break;
		}
	}
	return val.substr(0, val.length-1);
}

function changecss(theClass,element,value) {
	 alert(5);
	 var cssRules;

	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){
     alert(document.styleSheets[S]['cssRules']);
     if (document.styleSheets[S]['rules']) {
	  cssRules = 'rules';
	 } else if (document.styleSheets[S]['cssRules']) {
	  cssRules = 'cssRules';
	 } else {
	  //no rules found... browser unknown 
	 }

	 for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	 }
	 if(!added){
	  try{
	  	document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);

	  } catch(err){
	  		try{document.styleSheets[S].addRule(theClass,element+': '+value+';');}catch(err){}

	  }

	 }
	 }
}
function tourl(gourl){
	document.location=gourl;
}

