﻿/**
调用格式
<script language="javascript">var webonwerId=10009,minw=50,minh=50,maxw=300,maxh=200,showrightmenu=false;</script>
<script language="JavaScript" type="text/javascript" src="sendpic.js"></script>
**/
var wid=(typeof(webonwerId)=='undefined')?null:webonwerId;
var cid=(typeof(childid)=='undefined')?null:childid;
var refurl = "http://"+location.host+location.pathname;
var url = "http://"+location.host+location.pathname;
var XCMenu = null;
var XCTimerID = -1;
var XCCuteCheckImgSrc = false;

//for topmenu
var XCMinWidth = 160;
var XCMinHeight = 160;
//for rightmenu
var XCMaxWidth = 300;
var XCMaxHeight = 200;
var ShowRightMenu = true;

if(typeof(minw) == "number") XCMinWidth = minw;
if(typeof(minh) == "number") XCMinHeight = minh;
if(typeof(maxw) == "number") XCMaxWidth = maxw;
if(typeof(maxh) == "number") XCMaxHeight = maxh;
if(typeof(showrightmenu) == "boolean") ShowRightMenu = showrightmenu;

function openSendWindow(picUrl,picTitle) {
	var httpindex = picUrl.lastIndexOf("http://");
	var rurl = picUrl;
	if (httpindex != -1) {
		rurl = rurl.substring(httpindex, rurl.length);
	}
	window.open("http://www.okring.net/mmsi/?title="+picTitle+"&imgurl="+rurl+"&resurl="+rurl+"&webownerId="+wid+"&childid="+cid+"&siteurl="+url,"","width=550,height=440,top=100,left=200");
}

document.onreadystatechange = function()
{
	if(document.readyState=="complete")
	{
		XCSetupMenu(document);
	}
}

function XCSetupMenu(doc)
{
	try{
		if(typeof(doc.XCMenu)=="undefined")
		{
			doc.XCMenu = null;
			doc.XCMinWidth = XCMinWidth;
			doc.XCMinHeight = XCMinHeight;
			doc.XCMaxWidth = XCMaxWidth;
			doc.XCMaxHeight = XCMaxHeight;	
			doc.XCCuteCheckImgSrc = XCCuteCheckImgSrc;
		}
			
		for(var i = 0; i<doc.images.length; ++i)
		{
			var img = doc.images[i];
			if( img.width>doc.XCMinWidth && img.height>doc.XCMinHeight) {
			
				if( typeof(img.orig_onmouseover)=="undefined" ) {
					img.orig_onmouseover = img.onmouseover;
					img.orig_onmouseout = img.onmouseout;
				}			
	
				img.onmouseover = XCRollOver;
				img.onmouseout = XCRollOut;				
			}					
			
			
			if( img.width>=doc.XCMaxWidth && img.height>=doc.XCMaxHeight && ShowRightMenu )
			{
			    XCSetupImgMenu(img);
			}
		}
	}catch(e) {
	} 
}

function XCSetupImgMenu(img){
	if(typeof(img.XCMenu)=="undefined")
	{
		img.XCMenu = document.createElement("DIV");
		img.XCMenu.style.zIndex = 5000;
		img.XCMenu.style.color = "black";
		img.XCMenu.style.fontFamily = "宋体";
		img.XCMenu.style.fontSize  = "9pt";
		img.XCMenu.style.border = "solid 1px black";
		img.XCMenu.style.backgroundColor = "yellow";
		img.XCMenu.innerHTML = "";
		img.XCMenu.style.padding = "3px";
		img.XCMenu.target = "_blank";
		img.XCMenu.style.position = "absolute";
		img.XCMenu.style.visibility = "hidden";
		
		img.XCMenu.SendPic = document.createElement("A");
		//img.XCMenu.SendPic.id = "XCSendPic";
		img.XCMenu.SendPic.style.color = "black";
		img.XCMenu.SendPic.style.fontFamily = "宋体";
		img.XCMenu.SendPic.style.fontSize  = "9pt";
		img.XCMenu.SendPic.style.backgroundColor = "yellow";
		img.XCMenu.SendPic.style.textDecoration="none";
		img.XCMenu.SendPic.innerHTML = "←-<br>&nbsp;发&nbsp;<br>&nbsp;送&nbsp;<br>&nbsp;此&nbsp;<br>&nbsp;图&nbsp;<br>&nbsp;片&nbsp;<br>&nbsp;到&nbsp;<br>&nbsp;手&nbsp;<br>&nbsp;机&nbsp;";
		img.XCMenu.SendPic.target = "_blank";
		
		img.XCMenu.appendChild(img.XCMenu.SendPic);

		document.body.insertAdjacentElement("afterBegin", img.XCMenu);
	}
	picUrl=	ValueEncode(XCCalcSrc(img,document.XCCuteCheckImgSrc));
	picTitle=img.alt?img.alt:"本图片";

	var x = 0, y = 0;
	for(var obj = img; obj; obj = obj.offsetParent)
	{
		x += parseInt(obj.offsetLeft);
		y += parseInt(obj.offsetTop);
	}	
	img.XCMenu.SendPic.href = "JavaScript:openSendWindow('"+picUrl+"','"+picTitle+"');";
	img.XCMenu.SendPic.target = "_self";

	img.XCMenu.style.left = x+img.width;
	img.XCMenu.style.top = y+img.height/2;
	img.XCMenu.style.visibility = "";
}
function XCRollOver()
{
	if(this.orig_onmouseover)
	{
		this.orig_onmouseover();
	}
	var doc = this.document;
	if(!doc.XCMenu)
	{
		doc.XCMenu = doc.createElement("A");
		doc.XCMenu.id = "XCSendIMG";
		doc.XCMenu.style.color = "black";
		doc.XCMenu.style.fontFamily = "宋体";
		doc.XCMenu.style.fontSize  = "9pt";
		doc.XCMenu.style.border = "solid 1px black";
		doc.XCMenu.style.backgroundColor = "yellow";
		doc.XCMenu.innerHTML = "发送此图片到手机";
		doc.XCMenu.style.padding = "3px";
		doc.XCMenu.target = "_blank";
		doc.XCMenu.style.position = "absolute";
		doc.XCMenu.style.visibility = "hidden";
		doc.XCMenu.onmouseout = function()
		{
			this.style.visibility = "hidden";
		}
	}
	doc.body.insertAdjacentElement("BeforeEnd", doc.XCMenu);
	
	picUrl=	ValueEncode(XCCalcSrc(this,doc.XCCuteCheckImgSrc));
	picTitle=this.alt?this.alt:"本图片";
	
	var x = 0, y = 0;
	for(var obj = this; obj; obj = obj.offsetParent)
	{
		x += parseInt(obj.offsetLeft);
		y += parseInt(obj.offsetTop);
	}	
	doc.XCMenu.href = "JavaScript:openSendWindow('"+picUrl+"','"+picTitle+"');";
	doc.XCMenu.target = "_self";
	doc.XCMenu.style.left = x; //Math.max(x, stgcl(doc));
	doc.XCMenu.style.top = y; //Math.max(y, stgct(doc));
	doc.XCMenu.style.visibility = "";
	return;
}
function XCRollOut()
{
	var doc = this.document;
	if(doc.XCMenu)
	{
		if(this.orig_onmouseout)
		{
			this.orig_onmouseout();
		}
		var e = this.document.parentWindow.event;
		if(e.toElement&&e.toElement.id == "XCSendIMG")
		{
			return ;
		}
		doc.XCMenu.style.visibility = "hidden";
	}
}
function XCCalcSrc(img,CuteCheckImgSrc)
{
	var ext = "";
	var href = "";
	for(var obj=img; obj&&CuteCheckImgSrc; obj = obj.parentElement)
	{
		if(obj.tagName=="A")
		{
			href = obj.href;
			ext = getextension(href).toLowerCase();
			break;
		}
	}
	return ext==".jpg"||ext==".jpeg"||ext==".jpe"||ext==".gif"||ext==".png" ? href : img.src;
}
function getextension(s)
{
	var n=s.lastIndexOf('.');
	return n<0 ? "" : s.substring(n,s.length);
}
function ValueEncode(s)
{
	var r =s;
	r = r.replace(/%/gi, "%25");
	r = r.replace(/ /gi, "%20");
	r = r.replace(/\t/gi, "%09");
	r = r.replace(/#/gi, "%23");
	r = r.replace(/\{/gi, "%7B");
	r = r.replace(/\}/gi, "%7D");
	r = r.replace(/\^/gi, "%5E");
	r = r.replace(/~/gi, "%7E");
	r = r.replace(/\[/gi, "%5B");
	r = r.replace(/\]/gi, "%5D");
	r = r.replace(/;/gi, "%3B");
	r = r.replace(/@/gi, "%40");
	r = r.replace(/=/gi, "%3D");
	r = r.replace(/&/gi, "%26");
	r = r.replace(/`/gi, "%60");
	return r;
}
function stgcl(doc)
{
	if (doc == null)
		return 0;
	if (doc.body == null)
		return 0;

	//if (typeof(doc.documentElement) == 'undefined' || doc.documentElement == null)

	return doc.body.scrollLeft;
	return doc.documentElement.scrollLeft;
}
function stgct(doc)
{
	if (doc == null)
		return 0;
	if (doc.body == null)
		return 0;
	//if (typeof(doc.documentElement) == 'undefined' || doc.documentElement == null)
	return doc.body.scrollTop;
	return doc.documentElement.scrollTop;
}
//-->
