var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

function DateCheck(y,m,d){
	var  date =  new  Date(y, m-1, d);

	if (date.getFullYear() == y && ((date.getMonth()+1) == m) && date.getDate() == d){
		return true;
	}else{
		return false;
	}
}

function GetFileExt(name){
	return String(name.match(/\.\w{1,4}$/gi)).replace('.', '').toLowerCase();
}

function GetFilename(path){
	return path.match(/[^\/\\]+$/gi)[0];
}

String.prototype.sub = function(n){var r = /[^\x00-\xff]/g;if(this.replace(r, "mm").length <= n) return this;n = n - 3;var m = Math.floor(n/2);for(var i=m; i<this.length; i++){if(this.substr(0, i).replace(r, "mm").length>=n){return this.substr(0, i) +"...";}}return this;}

String.prototype.format = function(){var str = this;for(var i=0;i<arguments.length;i++){var re = new RegExp('\\{' + (i) + '\\}','gm');str = str.replace(re, arguments[i]);}return str;}

var msgwidth = 0;
function attachimg(obj, action) {
	if(action == 'load') {
	
			if(!msgwidth) {
				var re = /pbr|pbcontent/i;
				var testobj = obj;
				while((testobj = testobj.parentNode) != null) {
					var matches = re.exec(testobj.className);
					if(matches != null) {
						msgwidth = testobj.clientWidth - 20;
						break;
					}
				}
				if(msgwidth < 1) {
					msgwidth = window.screen.width;
				}
			}
		
		if(obj.width > msgwidth) {
			obj.resized = true;
			obj.width = msgwidth;
			//obj.style.cursor = 'pointer';
		} else {
			obj.onclick = null;
		}
	} else if(action == 'mouseover') {
		if(obj.resized) {
			//obj.style.cursor = 'pointer';
		}
	}
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}

function ShareDialog(html,callback){
	$('body').find('#mask').remove();
	$('body').find('.dialog').remove();

	$('body').append('<div id="mask"></div><div class="dialog"><div class="dialog_title">推荐</div><div class="block5"></div>'+html+'<div class="mf"><div class="mleft">评论：</div><div class="mright"><textarea id="share_description" style="width:300px;height:50px;"></textarea></div></div><div class="dialog_bottom"><input type="button" class="btn" id="dialog_ok" value="确定" /> <input type="button" class="btn" value="取消" onclick="UnDialog();" /></div></div>');

	$('#dialog_ok').click(callback);
}

function Dialog(title, html, callback){
	$('body').find('#mask').remove();
	$('body').find('.dialog').remove();

	$('body').append('<div id="mask"></div><div class="dialog"><div class="dialog_title">'+title+'</div><div class="block20"></div>'+html+'<div class="dialog_bottom"><input type="button" class="btn" id="dialog_ok" value="确定" /> <input type="button" class="btn" value="取消" onclick="UnDialog();" /></div>');

	$('#dialog_ok').click(callback);
}

function Loading(html){
	$('body').find('#mask').remove();
	$('body').find('.dialog').remove();

	$('body').append('<div id="mask"></div><div class="dialog"><div class="dialog_title">Loading...</div></div>');
}

function UnDialog(){
	$('body').find('#mask').remove();
	$('body').find('.dialog').remove();
}

function PointOut(obj,time){
	if (obj.length<1){
		return false;
	}
	var offset = obj.offset();
	var div = $('<div style="position:absolute;border:4px dashed #000;" id="__point_out"></div>');
	div.css('left',offset.left-4);
	div.css('top',offset.top-4);
	div.css('width',obj.width());
	div.css('height',obj.height());
	$('body').append(div);

	var htime = 800;
	if (time){
		var htime = time;
	}

	div.animate({opacity: 0.1}, htime, false, function(){div.remove();});
}

function UnPointOut(){
	$('#__point_out').append(div);
}


var SubStr=function(str,length){
    var a=str.match(/[^\x00-\xff]|\w{1,2}/g);
    return a.length<length?str:a.slice(0,length).join("")+"……";
}

$(document).ready(function(){
	$('form').submit(function(){
		if ($(this).find('input[@type="submit"][@ctl!="self"]').length>0){
			$(this).find('input[@type="submit"][@ctl!="self"]')[0].disabled = true;
		}
	});

	$('.alist dt').mouseover(function(){
		$(this).find('.tb').show();
	});

	$('.alist dt').mouseout(function(){
		$(this).find('.tb').hide();
	});

	$('.plist dt').mouseover(function(){
		$(this).find('.tb').show();
	});

	$('.plist dt').mouseout(function(){
		$(this).find('.tb').hide();
	});

	if( $('.layout_left_main').height() < $('.layout_right_side').height() )
	{
		$('.layout_left_main').height($('.layout_right_side').height());
	}
});

