/**
 * 公用JS函数
 */

/**
 * 信息提示框
 * @param {Object} msg
 * @author darkcloud.tan
 */
function showMsg(msg){
	$('pop_msg_content').innerHTML= msg;
	$('pop_msg').show();
	//alert($('pop_msg').offsetHeight);
//	alert(document.viewport.getHeight());
	$('pop_msg').style.top = ((document.viewport.getHeight() - $('pop_msg').offsetHeight)/2+(document.viewport.getScrollOffsets())[1])+'px';
	setTimeout(fleshMsg,3000);

}
/*刷新页面*/
function fleshMsg(){
	
	window.location.href=window.location.href;
	//window.event.returnValue=false;	
}
/**
 * 获取URL问号后的参数
 * @param {Object} key
 * @author darkcloud.tan
 */
function getParameter(key){
	var url = location.href.split("?");
	if(url[1]==null)return "";
	var par =url[1].split("#");
	var field = par[0].split("&");
	for(i=0;i<field.length;i++){
		var val = field[i].split("="); 
		if(val[0]==key){
			return val[1];
		}
	}
	return '';
}
/**
 * 获取URL井号后的参数
 * @param {Object} key
 * @author darkcloud.tan
 */
function getParameter2(key){
	var url = location.href.split("?");
	if(url[1]==null)return "";
	var par =url[1].split("#");
	if(!par[1]){
		return false;
	}
	var field = par[1].split("&");
	for(i=0;i<field.length;i++){
		var val = field[i].split("="); 
		if(val[0]==key){
	//alert('f');
			return val[1];
		}
	}
	return '';
}
//提交关于新闻的评论信息
function submitLeave(){			 
		//alert("fff");	
		
		if($('003').value==""){
			alert("留言主题不能为空");return false ;
		}
		if($('004').value==""){
			
			alert("留言内容不能为空");return false ;
			
		}
		if($('010').value==""){
			alert("EMail不能为空");return false ;
		}
		var form_news_info=Form.serialize('form_news');
		//alert(form_news_info);
		var myAjax=new Ajax.Request(
		'?act=ajax_insert_news_comment',
		{
			method:'post',
			onComplete:returnSubmitLeave,			//	指定请求完成需要执行的方法
			postBody:form_news_info
		}		
	)
		//alert(form_news_info);
		return false ;
					 
}
function returnSubmitLeave(response){
		rs = response.responseText;
		//alert(rs);
	
		if(rs==1){
			alert('发表评论成功，谢谢你的评论,管理员将在24小时给予回复！！');	
			window.location =window.location;
		}else if(rs==2){
			alert('你已经发表过了评论，请等待管理员回复~~~');	
			window.location =window.location;	
		}else{
			alert('评论失败，服务器忙~~~');	
		}
	
}

function showJournal(id){
	if($(id).style.display=='none'){
		$(id).style.display='block';	
	}else{
		$(id).style.display='none';	
	}
	
}
//处理游客订阅杂志的函数
function submitJournal(){			 
		//alert("fff");	
		var email=/^[\w]+(\.\w+){0,3}@[\w]+(\.\w+){1,3}$/i;
		if($F('user')==""){
			alert("留言者姓名不能为空");return false ;
		}
		if(!email.exec($F('email'))){
			
			alert("Email格式错误");return false ;
			
		}
	
		var form_journal=Form.serialize('form_journal');
			//alert(form_journal);
		var myAjax=new Ajax.Request(
		'?act=ajax_journal_subscription',
		{
			method:'post',
			onComplete:returnSubmitJournal,			//	指定请求完成需要执行的方法
			postBody:form_journal
		}		
	)
		//alert(form_news_info);
		return false ;
					 
}
function returnSubmitJournal(response){
		rs = response.responseText;
		//alert(rs);
	
		if(rs==1){
			alert('用户名不能为空');	
			
		}else if(rs==2){
			alert('Emial格式错误');	
				
		}else if(rs==3){
			alert('订阅成功');	
			window.location =window.location;
		}else if(rs==4){
			alert('你已经订阅过了');	
			window.location =window.location;
		}else{
			alert('订阅失败失败，服务器忙~~~');
			window.location =window.location;
		}
	
}
//处理用户订阅杂志
function userSubmitJournal(){
		var myAjax=new Ajax.Request(
		'?act=ajax_user_journal_subscription',
		{
			method:'post',
			onComplete:returnUserSubmitJournal,			//	指定请求完成需要执行的方法
			postBody:'sf'
		}		
	)
}
function returnUserSubmitJournal(response){
		rs = response.responseText;
		//alert(rs);
		if(rs==0){
			alert('你已经订阅杂志了');	
		}else if(rs==1){
			alert('订阅成功');	
			
		}else{
						

			alert('订阅失败，操作错误');	
				
		
		}	
}

function copyToClipBoard(input_id){
	var clipBoardContent=$F(input_id);
	window.clipboardData.setData("Text",clipBoardContent);
	alert("复制成功");
}

//引入另外的JS
$importjs = (
	function(){
	    var uid = 0;
	    var curr = 0;
	    var remove = function(id){
	        var head = document.getElementsByTagName('head')[0];
	        head.removeChild( document.getElementById('jsInclude_'+id) );
	    };
	
	    return function(file,callback){
	        var callback;
	        var id = ++uid;
	        var head = document.getElementsByTagName('head')[0];
	        var js = document.createElement('script');
	        js.setAttribute('type','text/javascript');
	        js.setAttribute('src',file);
	        js.setAttribute('id','jsInclude_'+id);
	        if( document.all ){
	            js.onreadystatechange = function(){
	                if(/(complete|loaded)/.test(this.readyState)){
	                    try
	                    {
	                        callback(id);remove(id);
	                    }catch(e){
	                        setTimeout(function(){remove(id);include_js(file,callback)},2000);
	                    }
	                }
	            };
	        } else{
	            js.onload = function(){callback(id); remove(id); };
	        }
	        head.appendChild(js);
	        return uid;
	    };
	}
)();

/**
 * 显示flash轮播图片。
 */
function show_flash()
{
    var button_pos=4; //按扭位置 1左 2右 3上 4下
    var stop_time=5000; //图片停留时间(1000为1秒钟)
    var show_text='1'; //是否显示文字标签 1显示 0不显示
    var txtcolor="000000"; //文字色
    var bgcolor="DDDDDD"; //背景色
    var text_height = 18;
    var focus_width = swf_width;
    var focus_height = swf_height - text_height;
    var total_height = focus_height + text_height;
//	alert('a');
	var flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	flash += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0"';
	flash += ' width="'+ focus_width +'" height="'+ total_height +'">';
	flash += ' <param name="movie" value="player/dynfocus.swf">';
//	alert('1');
	flash += ' <param name="quality" value="high"><param name="wmode" value="opaque">';
//	alert('3');
	flash += ' <param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+total_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">';
	flash += ' <embed src="player/dynfocus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+total_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ focus_width +'" height="'+ total_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/>';
	flash += ' </object>';
    document.getElementById('flash_cycle_image').innerHTML = flash;

}

function simplePreload(){ 
	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++){
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
} 
