

$.extend({
		    
		    //create a pop window
			createPopWin:function(winName,winId,loadURL,Width,Height,keyValue,mode){
				    var browser=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
				    var winHeight=$(window).height();
                    var winWidth=$(window).width();
				    
			  		var popwinX=(winWidth-Width)/2;
			  		//var popwinY=(winHeight-Height)/2;
					var popwinY=browser.scrollTop+(winHeight-Height)/2;
		 			//get explore info
					var Sys = {};
        			var ua = navigator.userAgent.toLowerCase();
        			var s;
        			(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        			(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
        			(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
        			(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
        			(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;					
					
			  		// check if the popwin window existed 
					if($("#popwin").length==1){
					   $("#popwin").remove();
					   $("#maskdiv").remove();
					}
              		if($("#popwin").length==0){
			  		$("body").append("<div id='maskdiv'>&nbsp;</div><div id='popwin'><div id='winHeader'>"+winName+"<input type='hidden' name='loadurl' value='"+loadURL+"' title='"+winName+"' params='"+$.param(keyValue)+"'/></div><div id='closewin'>x</div><div id='winLoad'><iframe name='loader' frameborder='0' scrolling='yes' ></iframe></div></div>");
					$("#maskdiv").css({"position":"absolute","top":"0","left":"0","width":"1003px","height":$(document).height()+"px"});
			  		$("#popwin").css({"position":"absolute","top":popwinY,"left":popwinX-120,"width":Width+"px","height":Height+"px"});
					$("#winLoad").css({"height":Height-43+"px","position":"relative"});
					var loaderWidth=Width-14;
					if (Sys.ie=="6.0"){
						loaderWidth=Width-14;
						$("#winLoad iframe").css({"height":Height-43+"px","width":loaderWidth+"px","position":"relative","overflow":"auto"});
					}else{
					    $("#winLoad iframe").css({"height":Height-43+"px","width":loaderWidth+"px","position":"relative","overflow":"auto"});	
					}
					
			  		}else{
			  			$("#popwin").show();
						$("#maskdiv").show();
			  		}
					$.closewin();
					$.scrollWin(Width,Height);
					$.winloaddata(loadURL,keyValue,mode);
					
					
			 },

	
			//close the pop win
			closewin:function(){
					$("#closewin").click(function(){
								  	  $("#popwin").remove();
									  $("#maskdiv").remove();
									    			})				
			},
			scrollWin:function(Width,Height){
				$(window).scroll(function(){
										  
									var browser=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
									var winHeight=$(window).height();
                    				var winWidth=$(window).width();
				    
			  						var popwinX=(winWidth-Width)/2;
			  		                var popwinY=(winHeight-Height)/2;
					                
									$("#popwin").css({"filter":"Alpha(opacity=0)","-moz-opacity":"0","opacity":"0"})
									$("#popwin").css({"top":browser.scrollTop+popwinY,"filter":"Alpha(opacity=100)","-moz-opacity":"1","opacity":"1"},300)
										  
										  })
				
				
			},
			// load data into the pop win
			winloaddata:function(url,keyValue,mode){	
				var dtime=new Date();
               if(mode=="get"){
				$("iframe[name=loader]").attr("src",url+"?timesamp="+dtime.getTime()+"&"+keyValue);	
			   }
			   if(mode=="post"){
				$("#popwin #winLoad").load(url+"?timesamp="+dtime.getTime(),keyValue);	   
			   }
							
				
			},
			submitform:function(ob){
			$("select[@multiple][@selectall]").children("option").each(function(){
													$(this).attr("selected",true);				
																	})
			var samptime=new Date();
			  $.ajax({
			  	type:"POST",
			  	url:$(ob).attr("action")+"?"+samptime.getTime(),
			  	data:$(ob).serialize(),
			  	dataType:"json",
			  	success:function(result){
			  		if(result.num>0){
			  			alert(result.error);
			  	
			  		}
                    if(result.num==0){
                    	var confirmMsg="";
                    	if($("input[name=action]").val()=="add"){
                    		confirmMsg="¼ÌÐøÌí¼Ó?"
                    	}
                     	if($("input[name=action]").val()=="fix"){
                    		confirmMsg="¼ÌÐøÐÞ¸Ä?"
                    	}                   	
                    	if(confirm(confirmMsg)){
                    		$.reloadLoader()
                    		$("#popwin #winLoad").load($("#popwin input[name=loadurl]").val(),$.paramToObj($("#popwin input[name=loadurl]").attr("params")))
                    	}else{
                    		$.autoclosewin();
                    	}
                    }
			  		
			  	}
			  	
			   })
			 
				
			},
			paramToObj:function(param){
             var params=param.replace(/&/g,",").replace(/=/g,":");

             return "{"+params+"}";
             }
			
			
			
		 })
