// JavaScript Document
function tellFriendsShow(){
	$('#in_tell_text').slideToggle('normal');	
}
function printPage(){
	window.print();	
}


function getDocument(){
	
	if(document.compatMode!="BackCompat"){
		return document.documentElement;
	}else{
		return document.body;
	}
	
}


var loadding = {
	show : function(){
		$('#loadding_mask').show();
		$('#loadding_mask').css('opacity',0);
		$('#loadding_mask').fadeTo('slow',0.66);
		$('#loadding_mask').css('height',getDocument().scrollHeight);
		$('#loadding_icon').show();
		$('#loadding_icon').css('top',getDocument().scrollTop + 200);
	},
	hide : function(){
		$('#loadding_mask').fadeOut('slow');
		$('#loadding_icon').hide();
	}
};

var alert_info = {
	show : function(msg,callback){
		$('#loadding_mask2').show();
		$('#loadding_mask2').css('opacity',0);
		$('#loadding_mask2').css('height',getDocument().scrollHeight);
		$('#loadding_mask2').fadeTo('slow',0.66);
		$('#alert_info').html(msg);
		
		$('#alert_mask').css('top',getDocument().scrollTop + 200);
		$('#alert_mask').show();
		$('#err_info').hide();
		$('.err_text').removeClass('err_text');
		if(typeof callback !== 'undefined' && typeof callback == 'function'){
			$('#alert_btn').bind('click',function(){					  
				alert_info.hide();
				window.setTimeout(function(){
					callback();								
				},1000);
				
			});
		}
	},
	hide : function(){
		$('#loadding_mask2').fadeOut('slow');
		$('#alert_mask').hide();
	}
}


var ajax = function(url,param,el,callback){
	
	var status;
	var info;
	var callback = callback;
	var url = url;
	var time = 10000;
	var timeout = 1000;
	var loading = '处理数据中，请稍等';
	var method = 'POST';
	
	if(typeof el != 'undefined' && el != '')
		var el = $('#'+el);
	else
		el = '';
	
	var param = param;
	
	if(el != '')
	el.hide();
	
	var result = function(data){

		//if(el != ''){
			
			if(typeof callback != 'undefined' && typeof callback == 'function'){
				window.setTimeout(function(){
					loadding.hide();
					callback(data.data,status,data.info);
				},timeout);
			};
			
			//el.html(info);
			
		//}
		//else{
//			
//			if(status != 9){
//				tool_layer({'info':info},function(){
//					
//					if(typeof callback != 'undefined' && typeof callback == 'function'){
//						window.setTimeout(function(){
//							callback(data.data,status);
//						},timeout);
//					};
//					
//				});
//			}else{
//				login_form(callback);
//			}
//			
//		}
		
		//window.setTimeout(function(){
//			
			if(el != '')
			el.fadeOut('slow');
//								
//		},time);
		
	};
	
	return {
		
		method		: function(m){
			method	= m;
			return this;
		},
		
		send		: function(){
			
			if(el != ''){
				el.fadeIn('slow');
			}
			loadding.show();
			
			$.ajax({
				
				url		:url,
				dataType:'json',
				timeout	:8000,
				type	:method,
				data	:param,
				success	:function(data,textStatus){
					
					status = data.status;
					info = data.info;
					
					result(data);
					
				},
				error	:function(){
					
					result('服务器繁忙,请求失败');
					
				}
				   
			});

		},
		
		sendform : function(fid){
			
			var form = $('#'+fid);
			
			
			if(form.get(0).tagName == 'form' || form.get(0).tagName == 'FORM'){
				
				var p = new Array();
				
				$('input,select,textarea',form).each(function(i){
					
					if(typeof $(this).attr('name') != 'undefined')
					p.push($(this).attr('name')+'='+ encodeURIComponent($(this).get(0).value));
					
				});
				
				param = p.join('&');
				
				this.send();
				
			}
			
			
			
		}
		
	}

}

//处理返回AJAX返回
function exeReturn(el,data,mapping){
	$('#'+el).show();
    $('#'+el).html('');
	
	if(data != ''){
		for(var i=0;i<data.length;i++){
			$('#'+el).append(data[i][1]+'<br/>');
			
			if(typeof mapping != 'undefined'){
				for(var j=0;j<mapping.length;j++){
					if(data[i][0] == mapping[j][0]){
						$('#'+mapping[j][1]).addClass('err_text');
					}	
				}
			}
		}
	}
	
}

function getInputChecked(){
	var val = new Array();
    $('input:checkbox').each(function(i){
      	if($(this).attr('checked')){
          	val.push($(this).get(0).value);
        }
    });
	return val;
}

(function($){
	
	$.fn.ajax_get = function(url,param,callback,loadding_img){
		
		var obj = $(this);
		if(typeof loadding_img !== 'undefined')
			obj.html('<img src="'+loadding_img+'" />');	
		
		$.get(url,param,function(data){
			
			obj.html(data);
			
			if(typeof callback != 'undefined' && typeof callback == 'function')
				callback();
			
		});
		
	};
			
	
})(jQuery);

$(document).ready(function(){
	document.body.oncontextmenu = function(){ self.event.returnValue=false; }
	document.body.onselectstart = function(){ return false; }					   
});

function fontChange(area_id,size){
	if(size=='normal')
	$('#'+area_id).css('font-size','11px');
	else if(size=='big')
	$('#'+area_id).css('font-size','12px');
	else if(size=='xbig')
	$('#'+area_id).css('font-size','14px');
}

$(document).ready(function(){
	$('a.fl_code').bind('click',function(){
		if($(this).get(0).href.indexOf('service/down')>0){
			var href = $(this).attr('href');
			var self = $(this);
			$(this).attr('href','javascript:void(0)'); 
			var k = $('<div style="position:absolute; width:200px; height:60px; background:#fff; border:1px solid #ccc; text-align:center"><div style="margin-top:10px;"><form style="margin:0;padding:0" action="'+href+'" method="post">code : <input name="code" type="text" class="inputtext" /><input type="submit" class="bgimg search_button" value=""  /></form></div></div>');
			var cl = $('<a href="javascript:" style="display:\"\";">[close]</a>');
			k.append(cl);
			cl.bind('click',function(){
				k.remove();	
				self.attr('href',href);
			});
			k.css('left',$(this).offset().left);
			k.css('top',$(this).offset().top);
			$($(this).parent()).append(k);
		}							 
	});					   
});