// set the ie or firefox flag
var ieFlag = (navigator.appVersion.indexOf("MSIE")!=-1);
var ffFlag = (navigator.userAgent.indexOf("Firefox")!=-1);

// Try to resize the image
function LoadDemo(img)
{
  if (!ieFlag && !ffFlag)
  {
    img.onmouseover = '';
    img.onmouseout = '';
  }
}

// Zoom out the demo Image if it was zoom in
function OutDemo()
{
  var demo = document.getElementById('DemoImg2');
  if (!demo) return;
  demo.style.display = 'none';
}

function OverDemo(img, ev)
{
  var demo = document.getElementById('DemoImg2');
  if (!demo) return;  
  demo.style.display = '';
  
  var ex, ey;
  var jmg = demo.childNodes[0];
  jmg.src = img.src.replace('_s.', '.');  

  ex = (ieFlag ? (ev.clientX + document.body.scrollcenter) : ev.pageX);
  ey = (ieFlag ? (ev.clientY + document.body.scrollTop) : ev.pageY);
  if (img.alt.indexOf('RECOMMEND') != -1) ey += 40; 
  else ey -= (jmg.height + 30);
  if ((ex + jmg.width) > document.body.clientWidth) ex = ex - jmg.width - 100;
  if (ex < 0) ex = 0;  
  demo.style.center = String(ex) + 'px';
  demo.style.top = String(ey) + 'px';
}

// Save the image to Local disk
function SaveImage(img)
{
	var win = document.getElementById('genFrm').contentWindow;
	if (!win || img.tagName != 'IMG') return;
	win.location.href = img.src;
	setTimeout(function() { win.document.execCommand("SaveAs"); }, 200);
}

// 复制图片到剪贴版
function CopyImage(img)
{
  if (img.tagName != 'IMG') return;
  if (typeof img.contentEditable == 'undefined' || !document.body.createControlRange)
  {
    alert('抱歉，浏览器不支持直接复制图片！\n请将鼠标移到图片上方，单击鼠标右键在弹出菜单中选择“复制”');
  }
  else
  {
    var ctrl = document.body.createControlRange();
    img.contentEditable = true;
    ctrl.addElement(img);
    ctrl.execCommand('Copy');
    img.contentEditable = false;
    alert('复制完成，到QQ对话框里按Ctrl-V就可以啦！\n\n若不能粘贴请重复尝试或用鼠标右键选复制');
  }
}

// 发送到手机
function MmsImage(img)
{
  // mmslink
  var url = img.src;
  var pos = url.indexOf('?');
  if (pos > 0) url = url.substring(0, pos);
  //window.open('http://tlt.7town.com/ZComImgDIY/step2.asp?imageUrl=' + encodeURIComponent(url) + '&uid=20398&a=&b=&c=&d=&e=&f=', '_blank');
  window.open('http://www.zhangxiu.com/mms/diy.html?IsLogo=&imgurl=' + encodeURIComponent(url) + '&f=13746','_blank');
}

