function gId(obj)
{
	return document.getElementById(obj);
}
function $(obj)
{
	return document.getElementById(obj);
}

function $$(name)
{
	return document.getElementsByName(name);
}

function plusHeight()
{
	var bg = $("bg");
	var maxHeight = window.document.documentElement.clientHeight;
	if (bg.clientHeight < maxHeight)
	{
		bg.style.height = maxHeight + "px";
	}
}

function showParentTop(obj)
{
	var o = obj;
	var top = 0;
	while (o)
	{
		top += o.offsetTop;
		o = o.parentElement;
	}
	if (fullmenu) top -= 45;
	return top;
}


function showParentLeft(obj)
{
	var o = obj;
	var left = 0;
	while (o)
	{
		left += o.offsetLeft;
		o = o.parentElement;
	}
	return left;
}

function goUrl(url)
{
	window.location = url;
}

/*
function $()
function checkall(form, prefix, checkall)
function copycode(obj) 
function getcookie(name) 
function opensmiliewindow(width, height, editorid) 
function in_array(needle, haystack) 
function div_message(html)
function close_div_message()

function  selectAll()  
{  
   var  arrObj  =  document.all;  
   for(var  i  =  0;  i  <  arrObj.length;i++)  
	{   
        if(typeof  arrObj[i].type  !=  "undefined"  &&  arrObj[i].type=='checkbox')  arrObj[i].checked  =true;  
     }  
}  
 
function  unSelectAll()  
{  
    var  arrObj  =  document.all;  
    for(var  i  =  0;  i  <  arrObj.length;i++)  
    {  
        if(typeof  arrObj[i].type  !=  "undefined"  &&  arrObj[i].type=='checkbox')  arrObj[i].checked  =false;  
     }  
}

*/


/*
将str的值COPY到剪贴板
*/
function js_copy(str)
{
	if (document.all)
	{
		window.clipboardData.setData('Text', str);
	}
	else
	{
		alert('浏览器不支持!');
	}
}


/**
 * 正则判断是否为有效EMAIL
 * @param string $email_str
 * @return boolean
 */
function fun_check_email(email_str)
{
	var preg_email = /^[a-z0-9]+[\._a-z0-9-]*[a-z0-9]+@[a-z0-9]+[a-z0-9-]*[a-z0-9]+\.[a-z]+(\.[a-z]+)?$/;
	return preg_email.test(email_str);
}




/**
 * 正则判断是否为有效邮编
 * @param string $email_str
 * @return boolean
 */
function fun_check_postcode(postcode)
{
	var preg_email = /^\d\d\d\d\d\d$/;
	return preg_email.test(postcode);
}

/*
checkbox_name	被操作的checkbox的name[]
value		1:全选	0:不选	-1:反选
示例：<input type="button" name="Submit3" value="反选" onclick="check_checkbox('checkbox[]', 1);">
*/
function check_checkbox(checkbox_name, value)
{
	var obj = document.getElementsByName(checkbox_name);
	for(var i=0; i<obj.length; i++)
	{
		if (value == 1)
		{
			obj[i].checked = true; 
		}
		else if (value == 0)
		{
			obj[i].checked = false; 
		}
		else if (value == -1)
		{
			if (obj[i].checked == true)
			{
				obj[i].checked = false;
			}
			else
			{
				obj[i].checked = true;
			}
		}
	}
}



function checkall(form, prefix, checkall)
{
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) 
	{
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) 
		{
			e.checked = form.elements[checkall].checked;
		}
	}
}


function copycode(obj) 
{
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}


function getcookie(name) 
{
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}




function opensmiliewindow(width, height, editorid) 
{
	smiliewindow = window.open('post.php?action=smilies' + (editorid ? '&editorid=' + editorid : ''), 'Popup', 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes');
	window.onunload = closesmiliewindow;
}

function winopen(url,width,height) 
{
	window.open (url, "show_win", "height="+height+", width="+width+",toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}

function in_array(needle, haystack) 
{
	if(typeof needle == 'string') 
	{
		for(var i in haystack)
		 {
			if(haystack[i] == needle) 
			{
					return true;
			}
		}
	}
	return false;
}

//弹出一个DIV对话窗口
function div_message(html)
{
	//将不足一屏的页面加满一屏
//	if (document.body.clientHeight > document.body.scrollHeight)
//	{
//		var add_div_height = document.body.clientHeight - document.body.scrollHeight;
//		document.write('<div style="width:100%; height:' + add_div_height + 'px"><iframe style=" display:none; width:100%; height:' + add_div_height + 'px;" frameborder="0" scrolling="no"></iframe></div>');
//	}
	
	
	close_div_message();
	var p=40;
	var base = document.createElement('DIV');
	base.style.textAlign = "center";
	base.style.position = "absolute";
	base.style.filter = "alpha(opacity="+p+")";
	base.style.opacity = (p / 100);
	base.style.MozOpacity = (p / 100);
	base.style.KhtmlOpacity = (p / 100);
	base.style.width  = document.body.clientWidth + "px";
	base.style.height = document.body.clientHeight + "px";
	base.style.margin = "0px";
	base.style.backgroundColor = '#999999';
	base.style.top=0;
	base.style.left=0;
	base.setAttribute('id',"baseFloatDiv");
	
//	var base_iframe = document.createElement('IFRAME');
//	base_iframe.style.display= "none";
//	base_iframe.style.width  = "0px";
//	base_iframe.style.height = "0px";
//	base.appendChild(base_iframe);
	document.body.appendChild(base);

	var msg = document.createElement('DIV');
	msg.style.textAlign = "center";
	msg.style.position = "absolute";
	//msg.style.width  = '450px';
	//msg.style.height = '30px';
	msg.style.padding = "10px";
	//msg.style.backgroundColor = '#FFFFFF';
	//msg.style.border="1px solid #c1c1c1";
	msg.setAttribute('id', "msgFloatDiv");
	msg.innerHTML = html;
	document.body.appendChild(msg);
	msg.style.top = (document.documentElement.scrollTop + document.documentElement.clientHeight/2 - msg.clientHeight/2) + "px";
	msg.style.left = (document.documentElement.clientWidth/2 - msg.clientWidth/2) + "px";
}

//关闭弹出的DIV对话窗口
function close_div_message()
{
	if(document.getElementById("baseFloatDiv"))
	{
		document.body.removeChild(document.getElementById("baseFloatDiv"));
	}
	
	if(document.getElementById("msgFloatDiv"))
	{
		document.body.removeChild(document.getElementById("msgFloatDiv"));
	}
}



//缩放图片
function resize_img(imgObj, rectWidth, rectHeight, fixIeBug)
{
	try
	{
		if(!fixIeBug) fixIeBug = true;
		//修正在IE运行下的问题
		if( (imgObj.width==0 || imgObj.height==0) && fixIeBug ) {
			var timer = setInterval(function(){
										act_resize_img(imgObj, rectWidth, rectHeight, false);
										clearInterval(timer);
									}, 1000);	
			return;
		}
		var x = imgObj.width>rectWidth ? rectWidth : imgObj.width;
		var y = imgObj.height>rectHeight ? rectHeight : imgObj.height;
		var scale	= imgObj.width/imgObj.height;
	
		if( x>y*scale ) {
			imgObj.width	= Math.floor(y*scale);
			imgObj.height	= y;
		}else {
			imgObj.width	= x;
			imgObj.height	= Math.floor(x/scale);
		}
		imgObj.style.width = imgObj.width+"px";
		imgObj.style.height = imgObj.height+"px";

		if (typeof(imgObj.onload)!='undefined')
		{
			imgObj.onload=null;
		}
	}
	catch(err)
	{
	
	}
}

String.prototype.Trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.LTrim = function()
{
	return this.replace(/(^\s*)/g, "");
}

String.prototype.RTrim = function()
{
	return this.replace(/(\s*$)/g, "");
}

String.prototype.getQuery = function(name) 
{ 
　　var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
　　var r = this.substr(this.indexOf("\?")+1).match(reg); 
　　if (r!=null) return unescape(r[2]); return null; 
} 

function fun_alert(message)
{
	alert(message);
}

/**
 * 是否为正整数
 */
function fun_is_pint(tmp_val)
{
	var val = parseInt(tmp_val);
	if (fun_is_int(val))
	{
		if (val > 0)
		{
			return true;
		}
	}

	return false;
}


/**
 * 是否来数值型
 */
function fun_is_int(tmp_val)
{
	var val = parseInt(tmp_val);
	if (!isNaN(val))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function fun_set_selectobj_value(objName, value)
{
	var selectobj = $(objName);
	for (i=0; i < selectobj.options.length; i++)
	{
		if (selectobj.options[i].value == value)
		{
			selectobj.options[i].selected = true;
			break;
		}
	}
}
