﻿document.domain = 'popsheep.cn';
// 用来让一个元素在页面中显示出position:fixed的效果
var FixedPosition = function(objElement, iTop, iLeft)
{
	if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1 && navigator.userAgent.toLowerCase().indexOf('msie 8') == -1 && navigator.userAgent.toLowerCase().indexOf('msie 7') == -1)
	{
		objElement.style.position = "absolute";
		objElement.style.left = iLeft +"px";
	}
	else
	{
		objElement.style.position = "fixed";
		objElement.style.top = iTop +"px";
		objElement.style.left = iLeft +"px";
	}
}

// 弹出快速登录窗口
function LoginFirst()
{
	var objQuickLogin = new QuickLogin();
	var strPageUrl = parent.location.href;
	var strKey = strPageUrl.substring(0,strPageUrl.indexOf('.popsheep.cn'));
	objQuickLogin.Show(strKey.replace('http://',''));
}

function IsIE6()
{
	return navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
}

function IsIE7()
{
	navigator.userAgent.toLowerCase().indexOf('msie 7') != -1;
}

function IsIE8()
{
	navigator.userAgent.toLowerCase().indexOf('msie 8') != -1;
}

// 快速登陆窗口类
var QuickLogin = function()
{
	this.Show = function(strKey)
	{
		var objDocument;
		if(document.location.href == parent.location.href)
		{
			objDocument = document;
		}
		else
		{
			objDocument = parent.window.document;
		}
		
		var hdivIframeBack = objDocument.createElement('div');
		hdivIframeBack.id = 'hdivQuickLoginIframeBack';
		hdivIframeBack.className = 'IframeBack';
		hdivIframeBack.style.width = '100%';
		if (IsIE6() && !IsIE7()  && !IsIE8())
		{
			hdivIframeBack.style.height = objDocument.body.scrollHeight;
		}
		else
		{
			hdivIframeBack.style.height = '100%';
		}
		hdivIframeBack.style.zIndex = 100000000;
		hdivIframeBack.style.background = "#000000";
		if(document.all)
		{
			hdivIframeBack.style.filter = "alpha(opacity =30);opacity: 0.2;";
		}
		else
		{
			hdivIframeBack.style.opacity = 0.2;
		}
		
		objDocument.body.appendChild(hdivIframeBack);
		FixedPosition(hdivIframeBack, 0, 0);
	
		var hdivIframeWrap = objDocument.createElement('div');
		hdivIframeWrap.id = 'hdivQuickLoginIframeWrap';
		hdivIframeWrap.style.width = 244;
		hdivIframeWrap.style.height = 190;
		hdivIframeWrap.style.zIndex = 100000001;
		var thisIframe = objDocument.createElement('iframe');
		thisIframe.id = 'iframeQuickLogin';
		thisIframe.src = 'http://js.popsheep.cn/QuickLogin.aspx?CK=' + strKey;
		thisIframe.width = 244;
		thisIframe.height = 190;
		thisIframe.scrolling = 'no';
		thisIframe.frameBorder = 0;
		thisIframe.allowTransparency = 'true';
		hdivIframeWrap.appendChild(thisIframe);
		
		objDocument.body.appendChild(hdivIframeWrap);
		
		var iTop = objDocument.documentElement.clientHeight / 2 - 190 / 2;
		var iLeft = objDocument.body.clientWidth / 2 - 244 / 2;
		FixedPosition(hdivIframeWrap, iTop, iLeft);
	}
};

function CorrectSize(thisImg, iMaxWidth, iMaxHeight)
{
	thisImg.style.display = 'block';
	if(iMaxWidth > 0 && iMaxHeight > 0)
	{
		if(thisImg.width > iMaxWidth || thisImg.height > iMaxHeight)
		{
			var sourceRatio = thisImg.width / thisImg.height;
			var targetRatio = iMaxWidth / iMaxHeight;
			if(sourceRatio > targetRatio)
			{
				thisImg.width = iMaxWidth;
				thisImg.height = iMaxWidth / sourceRatio;
			}
			else if(sourceRatio > 0)
			{
				thisImg.height = iMaxHeight;
				thisImg.width = iMaxHeight * sourceRatio;
			}
		}
		thisImg.style.top = (iMaxHeight - thisImg.height) / 2 + 'px';
		thisImg.style.left = (iMaxWidth - thisImg.width) / 2 + 'px';
	}
	thisImg.parentNode.parentNode.className = thisImg.parentNode.parentNode.className.replace(' Loading','');
}

function ImageMissing(thisImg)
{
	thisImg.parentNode.parentNode.className = thisImg.parentNode.parentNode.className.replace(' Loading',' ImageMissing');
}

function RestoreItem(hdivItem, strKey)
{
	hdivItem.className = hdivItem.className.replace(strKey,'');
}

function ActiveItem(hdivItem, strKey)
{
	RestoreItem(hdivItem, strKey);
	hdivItem.className += strKey;
}

// 输入框编辑
function StartWrite(objInput, iMaxInputLength)
{
	objInput.parentNode.className = objInput.parentNode.className.replace(' WritingInput','');
	objInput.parentNode.className = objInput.parentNode.className.replace(' NoDataInput','');
	objInput.parentNode.className += ' WritingInput';
	if(objInput.value == objInput.title)
	{
		objInput.value = '';
	}
	objInput.name = objInput.value;
}

function EndWrite(objInput)
{
	objInput.parentNode.className = objInput.parentNode.className.replace(' WritingInput','');
	var strNewValue = objInput.value;
	if(objInput.value.replace(/(^\s*)|(\s*$)/g,"") == '')
	{
		objInput.value = objInput.title;
		objInput.parentNode.className += ' NoDataInput';
	}
	if(objInput.name == strNewValue)
	{
		return false;
	}
	return true;
}

function GetInputValue(objInput)
{
	var strInputValue = objInput.value.replace(/(^\s*)|(\s*$)/g,"");
	if(objInput.title == strInputValue)
	{
		return '';
	}
	return strInputValue;
}

function GetTextareaValue(objInput)
{
	var strInputValue = GetInputValue(objInput);
	if(strInputValue.length == 0)
	{
		return strInputValue;
	}
	strInputValue = "<p>" + strInputValue.replace(/\r\s/g,"</p><p>") + "</p>";
	return strInputValue;
}

function ResetInput(objInput)
{
	if(objInput.title != null)
	{
		objInput.value = objInput.title;
		objInput.parentNode.className = objInput.parentNode.className.replace(' NoDataInput','');
		objInput.parentNode.className += ' NoDataInput';
	}
	else
	{
		objInput.value = '';
	}
}
// 输入框编辑
