﻿var defaultImageUrl,preImgId;

function showText(ele,off) {
  var tip=document.getElementById('tip');
  
  tip.innerHTML=ele.title;
  tip.style.marginLeft=off + 'px';
}

function resetText(){ document.getElementById('tip').innerHTML=''; }

function loginEnter(ele,txt) {
  if (ele.value==txt) {
    ele.value='';
    ele.style.color='#000';
  }
}

function loginLeave(ele,txt) {
  if (ele.value=='') {
    ele.value=txt;
    ele.style.color='#999';
  }
}

function MenuItemMouseOverHandler(e, info) {
  var segs=info.getItem().getPath().split('/');
  var img=document.getElementById(preImgId);

  if (segs.length>1) {
    if (segs[0]=='_i1'&&info.getItem().getValue()) {
      img.src='/images/categories/'+info.getItem().getValue()+'.jpg';
    } else {
      img.src=defaultImageUrl;
    }
  }
}

function MenuItemMouseOutHandler(e, info) {
  document.getElementById(preImgId).src=defaultImageUrl;
}

function swapMake(idx,mod) {
  var lst=document.getElementById(mod);
  var y;
  
  if (!lst) { return }
  lst.length=0;
  
  for (i=0;i<makes[idx].length;i++) {
    y=document.createElement('option');
    y.text=makes[idx][i];
    try {
      lst.add(y,null); // standards compliant
    } catch(ex) {
      lst.add(y); // IE only
    }
  }
}

function CheckValidCCNumber(sender,args) {
  args.IsValid=(ValidatorTrim(args.Value).length>=16);
}

function CheckAccountID(sender,args) {
  var cbo=document.getElementById(GetTagAttribute(sender,'rel'));

  args.IsValid=((cbo.selectedIndex!=1)||ValidatorTrim(args.Value).length>0);
}

function CheckValidExpiryDate(sender,args) {
  var today = new Date();
  var m=args.Value;
  var ycbo=document.getElementById(GetTagAttribute(sender,'rel'));
  var y=ycbo.options[ycbo.selectedIndex].value;
  var expiry = new Date(y, m);
  
  args.IsValid=(today<expiry);  
}

function GetTagAttribute(sender,name) {
  for (var i=0;i<sender.attributes.length;i++) {
    if (sender.attributes[i].name==name) { return sender.attributes[i].value }
  }
}

function PasteBullets(editorId) {
  var edt=$get(editorId);

  if (edt) {
    var sel=edt.GetSelection();
    
    if (sel) {
      if (sel.type) {
        var txt=sel.createRange();
        if (sel.type=='Text') {
          edt.PasteHTML('<ul><li>'+txt.htmlText+'</li></ul>');
        } else {
          edt.PasteHTML('<ul><li></li></ul>');
        }
      } else {
        edt.PasteHTML('<ul><li>'+sel+'</li></ul>');
      }
    } else {
      edt.PasteHTML('<ul><li> </li></ul>');
    }
  }
}