//var json_config = eval('('+config+')');
//var type_configs = json_config.all;
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);

var all_configs = false;
$.LoadJson = function(url){ $.ajax({ 	type: "GET", url: url, async:false, dataType: "json", cache: true, success:function(json){all_configs = json;} }); };  //js文件载入
$(document).ready(function() { 
	$("select").each(function(){
		$(this).show();
	})
	$(".html_options").each(function(){
		html_options($(this));
	})
	
	$(".html_options_thin").each(function(){
		html_options_thin($(this));
	})
	
	//日期选择器
	$(function() {
		$.extend(DateInput.DEFAULT_OPTS, {
		  month_names: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
		  short_month_names: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"],
		  short_day_names: ["一", "二", "三", "四", "五", "六", "日"]
		});

		$.extend(DateInput.DEFAULT_OPTS, {
		  stringToDate: function(string) {
		    var matches;
		    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
		      return new Date(matches[1], matches[2] - 1, matches[3]);
		    } else {
		      return null;
		    };
		  },
		
		  dateToString: function(date) {
		    var month = date.getMonth() + 1;
		    var dom = date.getDate();
		    if (month.length == 1) month = "0" + month;
		    if (dom.length == 1) dom = "0" + dom;
		    return date.getFullYear() + "-" + month + "-" + dom;
		  }
		});

  		$(".date_input").date_input();
	});	
	
	$(function() {
		$.extend(DateInput.DEFAULT_OPTS, {
		  month_names: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
		  short_month_names: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"],
		  short_day_names: ["一", "二", "三", "四", "五", "六", "日"]
		});

		$.extend(DateInput.DEFAULT_OPTS, {
		  stringToDate: function(string) {
		    var matches;
		    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
		      return new Date(matches[1], matches[2] - 1, matches[3]);
		    } else {
		      return null;
		    };
		  },
		
		  dateToString: function(date) {
		    var month = date.getMonth() + 1;
		    var dom = date.getDate();
		    //alert(month);
		    if (month.length == 1) month = "0" + month;
		    if (dom.length == 1) dom = "0" + dom;
		    return date.getFullYear() + "-" + month;
		  }
		});

  		$(".date_input_noday").date_input();
	});	
})


//自动生成选择框
function html_options(obj){
	var json_config = eval('('+config+')');
	var type_configs = json_config.all;
	//$("#"+$(obj).attr('id')).append("<option value=''>  </option>");
	$.each(eval("type_configs."+$(obj).attr('config_type')),function(idx,item){
		if(item.id == $(obj).attr('parent_selected')){
			$("#"+$(obj).attr('id')).append("<option value='"+item.id+"' selected>"+item.title+"</option>");
		}else{
			$("#"+$(obj).attr('id')).append("<option value='"+item.id+"'>"+item.title+"</option>");
		}
	})
	if($(obj).attr('hasChild') == 'yes'){
		sub_html_options(obj,'auto');
	}
	//$("#"+$(obj).attr('id')+"_child").empty();
}

function html_options_thin(obj){
	var json_config = eval('('+config+')');
	var type_configs = json_config.all;
	
	if($(obj).attr('hasChild') == 'yes'){
		sub_html_options(obj,'auto');
	}	
}


function sub_html_options(obj,type){
	var json_config = eval('('+config+')');
	var type_configs = json_config.all;
	$("#"+$(obj).attr('id')+"_child").empty();
	
	if(type == 'auto'){
		var parent_id = $(obj).attr('parent_selected');
	}else{
		var parent_id = $(obj).val();
	}

	
	$.each(eval("type_configs."+$(obj).attr('config_type')),function(idx,item){
		if(item.id == parent_id){
			$.each(item.Child, function(idx2,item2){	
				if(type == 'auto' && item2.id == $(obj).attr('child_selected')){
					$("#"+$(obj).attr("id")+"_child").append("<option value='"+item2.id+"' selected>"+item2.title+"</option>");
				}else{
					$("#"+$(obj).attr("id")+"_child").append("<option value='"+item2.id+"'>"+item2.title+"</option>");
				}
			})
		}
	})
}

function sub_third_html_options(obj,type){
	$("#"+$(obj).attr('id')+"_third").show();
	var json_config = eval('('+config+')');
	var type_configs = json_config.all;
	$("#"+$(obj).attr('id')+"_third").empty();
	
	if(type == 'auto'){
		var parent_id = $(obj).attr('child_selected');
	}else{
		var parent_id = $(obj).val();
	}

	
	$.each(eval("type_configs."+$(obj).attr('config_type')),function(idx,item){
		if(item.id == parent_id){
			$.each(item.Child, function(idx2,item2){	
				if(type == 'auto' && item2.id == $(obj).attr('third_selected')){
					$("#"+$(obj).attr("id")+"_third").append("<option value='"+item2.id+"' selected>"+item2.title+"</option>");
				}else{
					$("#"+$(obj).attr("id")+"_third").append("<option value='"+item2.id+"'>"+item2.title+"</option>");
				}
			})
		}
	})
}


//定义当前分类
var configs_single = {};
/**
 **用法示例：<input type="button" name="button" value="行业选择" class="btn" configs="config_regions" output_value_block="output_value_block" output_id_block="output_id_block" selected_block="selecteds" hasMulti="yes" hasChild="yes" maxselects="3" configs_mark="地区类别" style="cousor:pointer;" onclick="SelectCategories(this);">
 减少.each的使用，极大提高IE下性能
 */


function SelectCategories(obj){
	//同步获取配置信息
	$.ajax({
		url:"/Cache/js/config/"+$(obj).attr('configs')+".js",
		dataType:"json",
		async:false,		
		success:function(json){
			configs_single = json; 
		}
	})


	//隐藏所有select
	$("select").each(function(){
		$(this).hide();
	})

	if($(obj).attr('hasMulti') == 'yes'){
		var input_type = "checkbox";
	}else{
		var input_type = "radio";
	}
	
	$("#selector_message").empty();
	$("#selector_container").remove();
	
	$("body").append(
		'<div id="selector_mask">'+
		'</div>'
	);
	 
	$("#selector_mask").css({
		height:$(document).height()
	})
	
	$("body").append(
	  '<div id="selector_container">' +
	  	'<div class="selector_top_title">'+
	    '<div id="selector_title"><span class="selector_operate_type"><a href="javascript://" class="selector_selectok" style="font-size:12px;font-weight:normal;">关闭</a></span>'+$(obj).attr("configs_mark")+'</div>' +
	    '<div class="selector_operation_block"><span id="selector_errorbox"></span><span class="selector_operate_type_btn">' +
	    		'<input type="button" class="btn selector_selectok" value="确定">&nbsp;' +
	    		'<input type="button" class="btn emptyok" name="" value="清空"></span>您所选的'+$(obj).attr("configs_mark")+'是：' +
	    	'</div></div>' +
	    '<div id="selector_selected_block"></div>' +
	    '<div id="selector_content">' +
	      '<div id="selector_message"></div>' +
	      '<div id="selector_message_child"></div>' +
	      '<div id="selector_message_third_child"></div>' +
		'</div>' +
	  '</div>');

	var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
	//var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2))  - 75;
	var scrolltop = $(document).scrollTop() + 5;
	
	var top = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? scrolltop : 10;
	
	//var top = 10;
	$("#selector_container").css({
		display:'block',
		top:top,
		left:$("body").width()/2 -400,
		position:pos,
		zIndex:9999
	});		

	if($.browser.msie && parseInt($.browser.version) <= 6){
		$("#selector_title").css({
			width:800
		});
	}
	
	$("#selector_message").append("<div class='selector_categories'><ul id='selector_all_categories'>");
//	var all_configs = eval('('+config+')');
//	var all_configs_all = eval("all_configs.all."+$(obj).attr('configs'));
//	var all_configs_kv = eval("all_configs.kv."+$(obj).attr('configs'));	
	var all_configs_all = configs_single.all;
	var all_configs_kv = configs_single.kv;
	
	//eval("all_configs_eval."+$(obj).attr('configs'))

	//获取已经选择
	var has_selected_ids = $("#"+$(obj).attr("output_id_block")).val();
	if(has_selected_ids != ''  && has_selected_ids != '0'){
		var s = new Array();
		s = has_selected_ids.split(",");
		for(i=0;i<s.length;i++){
			if(isInteger(s[i]) && s[i] != '0' && all_configs_kv[s[i]] != undefined){
				$("#selector_selected_block").append("<li id='checkedids_"+s[i]+"'><input type='"+input_type+"' name='checkedids' cvalue='"+all_configs_kv[s[i]].title+"' value="+s[i]+" style='display:none;'>"+all_configs_kv[s[i]].title+" <a href='javascript://' onclick='deleteCheckedOne(\""+s[i]+"\")'><img src='/Public/images/lay_delete.gif' align='absmiddle'></a></li>");
			}
		}
	}

	$.ajax({
		url:"/Index/ajaxCategories/outid/"+$(obj).attr('id')+"/check/"+input_type+"/type/"+$(obj).attr('configs')+"/hasChild/"+$(obj).attr('hasChild')+"/mustchild/"+$(obj).attr('mustchild'),
		type:"GET",
		dataType:"json",
		async:false,
		success:function(json){
			$("#selector_all_categories").append(json.data._parent);
//			$("#selector_message_child").append(json.data._child);
//			$("#selector_message_third_child").append(json.data._third_child);
		}
	})
	
	movePopBox("selector_title","selector_container");
	
	//选择已经选择的
	$("#selector_selected_block input").each(function(){
		$("#all_"+$(this).val()).attr('checked',true);
		$("#childitem_"+$(this).val()).attr('checked',true);
	})

	$(document).ready(function() { 
		//确定选项
		$(".selector_selectok").click(function(){
			$("#"+$(obj).attr("selected_block")).empty();
			var output_values_block = "";
			var output_ids_block = "";
			$("#selector_selected_block input").each(function(){
				if(output_values_block == ''){
					output_values_block = $(this).attr('cvalue');
				}else{
					output_values_block = output_values_block+"+"+$(this).attr('cvalue');
				}
				
				if(output_ids_block == ''){
					output_ids_block = $(this).val();
				}else{
					output_ids_block = output_ids_block+","+$(this).val();
				}				
			})

			if(output_values_block != "" || $("#"+$(obj).attr("output_id_block")).val() != ''){
				$("#"+$(obj).attr("output_value_block")).val(output_values_block);
			}
				
			$("#"+$(obj).attr("output_id_block")).val(output_ids_block);

			
			$('#selector_container').remove();
			$('#selector_sub_container').remove();
			$('#selector_mask').remove();
			$("select").each(function(){
				$(this).show();
			})			
		})
		
		//清空选择
		$(".emptyok").click(function(){
			$("#selector_selected_block").empty();
			
			$(".selector_categories_selected").attr("checked",false);
			$(".selector_categories_selected").attr("disabled",false);
		})
		
		//显示子分类  点击事件
//		$(".selector_categories_selected_title").click(function(){
//			if($(this).attr('hasThird') == 'yes'){
//				setTimeout("showThirdChild("+$(this).attr('cuid')+")",100);				
//			}else{
//				setTimeout("showChild("+$(this).attr('cuid')+")",100);	
//			}
//		})
	})
}

/**  选择已经选择的 **/
function select_one(obj,obj_this,blocks){
	if($(obj).attr('hasMulti') == 'yes'){
		var input_type = "checkbox";
	}else{
		var input_type = "radio";
	}	
	
	if($(obj_this).attr('type') != ''){
		if($(obj_this).attr('checked') == true){
			if($("#selector_selected_block input").length >= $(obj).attr('maxselects') && $(obj).attr('hasmulti') == 'yes' ){
				alert('对不起,您的已选项已经达到了'+$(obj).attr('maxselects')+'项. 请减少已选项,再继续选择.');
				$(obj_this).attr("checked",false);
			}else{
				if($(obj).attr('hasmulti') == 'no'){
					$("#selector_selected_block").empty();
				}
				
				$("#selector_selected_block").append("<li id='checkedids_"+$(obj_this).val()+"'><input type=checkbox name='checkedids' value="+$(obj_this).val()+" cvalue='"+$(obj_this).attr('cvalue')+"' style='display:none;'>"+$(obj_this).attr('cvalue')+" <a href='javascript://' onclick='deleteCheckedOne(\""+$(obj_this).val()+"\")'><img src='/Public/images/lay_delete.gif' align='absmiddle'></a></li>");
				
			}
		}else{
			$("#checkedids_"+$(obj_this).attr('cuid')).remove();
		}
	}else{
		if($(obj).attr('hasMulti') == 'yes'){
			$.ajax({
				url:"/Index/ajaxChildCategories/outid/"+$(obj).attr('id')+"/type/"+$(obj).attr('configs')+"/pid/"+$(obj_this).attr("cuid")+"/check/"+input_type,
				type:"GET",
				async:false,
				success:function(json){
					if(json != 'failed'){
						if(blocks == 'third'){
							$("#selector_message_third_child").empty();
							$("#selector_message_third_child").show();						
							$("#selector_message_third_child").html(json);
							$(document).ready(function() { 
								$("#selector_selected_block input").each(function(){
									$("#childitem_"+$(this).val()).attr('checked',true);
								})
							})
						}else{
							$("#selector_message_third_child").empty();
							$("#selector_message_child").show();						
							$("#selector_message_child").html(json);
							$(document).ready(function() { 
								$("#selector_selected_block input").each(function(){
									$("#childitem_"+$(this).val()).attr('checked',true);
								})
							})					
						}
					}
				}
			})		
		}
	}
	
	return;
	
	
	//计算选择数目
	if($(":checkbox[name='ids[]']:checked").length > $(obj).attr('maxselects') && $(obj).attr('maxselects') > 1){
		alert('对不起,您的已选项已经达到了'+$(obj).attr('maxselects')+'项. 请减少已选项,再继续选择.');
		//$("#selector_errorbox").html();
		$(obj_this).attr("checked",false);
	}
	
	//子有选择，则父置为false，子无选择，则父置为true
	if($(obj_this).attr('parent_id') > 0){
		if($("#child_"+$(obj_this).attr('parent_id')+" :checkbox[name='ids[]']:checked").length > 0){
			$("#all_"+$(obj_this).attr('parent_id')).attr('checked',false);	
			//$("#checkedids_".$(this).attr('parent_id')).remove();
			deleteCheckedOne($(obj_this).attr('parent_id'));
			$("#all_"+$(obj_this).attr('parent_id')).attr('disabled',true);
		}else{
			$("#all_"+$(obj_this).attr('parent_id')).attr('disabled',false);
		}
	}
	
	if($(obj_this).attr('checked') == true){
		if($(obj).attr('hasmulti') == 'no' || $(obj).attr('maxselects')  == '1'){
			$("#selector_selected_block").empty();
			
			$(".selector_categories_selected").attr('checked',false);
			$(".selector_categories_selected").attr('disabled',false);
			
			$(obj_this).attr("checked",true);
		}
		
		$("#selector_selected_block").append("<li id='checkedids_"+$(obj_this).val()+"'><input type=checkbox name='checkedids' value="+$(obj_this).val()+" style='display:none;'>"+$(obj_this).attr('cvalue')+" <a href='javascript://' onclick='deleteCheckedOne(\""+$(obj_this).val()+"\")'><img src='/Public/images/lay_delete.gif' align='absmiddle'></a></li>");

		//如果父选择，则子全部不能选择
		if($(obj).attr('maxselects')  != '1'){
			$("#child_"+$(obj_this).val()+" .selector_categories_selected").attr('disabled',true);
		}
	}else{
		$("#selector_selected_block #checkedids_"+$(obj_this).val()).remove();
	}
}

/**  选择已经选择的 **/
function select_third_one(obj,obj_this){

		if(congfigs_single == null){
			$.ajax({
				url:"/Cache/js/config/"+$(obj).attr('configs')+".js",
				dataType:"json",
				async:false,		
				success:function(json){
					configs_single = json; 
				}
			})		
		}
		//计算选择数目
		if($(":checkbox[name='ids[]']:checked").length > $(obj).attr('maxselects') && $(obj).attr('maxselects') > 1){
			alert('对不起,您的已选项已经达到了'+$(obj).attr('maxselects')+'项. 请减少已选项,再继续选择.');
			//$("#selector_errorbox").html();
			$(obj_this).attr("checked",false);
		}
		
		//子有选择，则父置为false，子无选择，则父置为true
		if($(obj_this).attr('parent_id') > 0){
			if($("#third_child_"+$(obj_this).attr('parent_id')+" :checkbox[name='ids[]']:checked").length > 0){
				$("#child_"+$(obj_this).attr('parent_id')).attr('checked',false);	
				//$("#checkedids_".$(this).attr('parent_id')).remove();
				deleteCheckedOne($(obj_this).attr('parent_id'));
				$("#childitem_"+$(obj_this).attr('parent_id')).attr('disabled',true);
			}else{
				$("#child__"+$(obj_this).attr('parent_id')).attr('disabled',false);
			}
		}
		
		if($(obj_this).attr('checked') == true){
			if($(obj).attr('hasmulti') == 'no' || $(obj).attr('maxselects')  == '1'){
				$("#selector_selected_block").empty();
				
				$(".selector_categories_selected").attr('checked',false);
				$(".selector_categories_selected").attr('disabled',false);
				
				$(obj_this).attr("checked",true);
			}
			
			$("#selector_selected_block").append("<li id='checkedids_"+$(obj_this).val()+"'><input type=checkbox name='checkedids' value="+$(obj_this).val()+" style='display:none;'>"+$(obj_this).attr('cvalue')+" <a href='javascript://' onclick='deleteCheckedOne(\""+$(obj_this).val()+"\")'><img src='/Public/images/lay_delete.gif' align='absmiddle'></a></li>");

			//如果父选择，则子全部不能选择
//			if($(obj).attr('maxselects')  != '1'){
//				$("#third_child_"+$(obj_this).val()+" .selector_categories_selected").attr('disabled',true);
//			}
		}else{
			$("#selector_selected_block #checkedids_"+$(obj_this).val()).remove();
		}
}

function showChild(cuid){
	$(".selector_child_ul").hide();
	$(".selector_third_child_ul").hide();	
	$("#child_"+cuid).show();			
	if($("#all_"+cuid).attr('checked') == true){
		$("#child_"+cuid+" .selector_categories_selected").attr('checked',false);
		$("#child_"+cuid+" .selector_categories_selected").attr('disabled',false);		
	}
}

function showThirdChild(cuid){
	$(".selector_third_child_ul").hide();
	$("#third_child_"+cuid).show();			
	if($("#child_"+cuid).attr('checked') == true){
		$("#third_child_"+cuid+" .selector_categories_selected").attr('checked',false);
		$("#third_child_"+cuid+" .selector_categories_selected").attr('disabled',false);		
	}	
}

function showError(msg){
	$("#selector_errorbox").show();
}

function deleteCheckedOne(ids){
	$("#checkedids_"+ids).remove();
	$("#all_"+ids).attr('checked',false);
	$("#childitem_"+ids).attr('checked',false);	
}

/**判断是否为整数*/
function isInteger(num) {
   var patrn=/^[0-9]*[1-9][0-9]*$/;  
  
   if (!patrn.exec(num))
    return false
   else
    return true
} 

function doAction(geturl)
{
	$.ajax({
		url:geturl,
		type:"POST",
		data:$("form").serialize(),
		dataType:"json",
	  	cache: true,
	  	success:function(data)
		{
	  		jAlert(data.info);
	  		if(data.status == '1')
			{
	  			location.reload();
	  		}
	  	}
	})
}

function doAjax(geturl,method,returnurl,refresh_block,failurl)
{
	$.ajax(
	{
		url:geturl,
		type:method,
		dataType:"json",
	  	success:function(data)
		{
			jAlert(data.info);
			if (returnurl != '' || failurl != '')
			{
				var ret_url;
		  		if(data.status == '1' && returnurl != '')
				{
					ret_url = returnurl;
		  		}
				else if (data.status == '0' && failurl != '')
				{
					ret_url = failurl;
				}
				$.ajax(
				{
					url:ret_url,
					type:"GET",
					success:function(data2)
					{
						$("#"+refresh_block).html(data2);
					}
				});
			}
			else
			{
				location.href=returnurl;
			}
	  	}
	});
	return false;
}

function doPostAjax(geturl,refresh_block,form,succ_url,fail_url)
{
	$.ajax(
	{
		url:geturl,
		type:"POST",
		dataType:"json",
		data:$('#'+form).serialize(),
	  	success:function(data)
		{
			alert(data.info);
			if (data.status == 1)
				location.href = succ_url;
			else
				location.href = fail_url;
	  	}
	});
	return false;
}
function checkAll(obj,type){
	//jQuery("input[name='"+obj+"[]']").attr('checked',true);
	if(type == 'all'){
		 $("input[name='"+obj+"[]']").each(function() {
		 	$(this).attr("checked", true); 
		 });
	}
	
	if(type == 'reverse'){
		 $("input[name='"+obj+"[]']").each(function() {
		 	if($(this).attr("checked") === true){
		 		$(this).attr("checked", ''); 
		 	}else{
		 		$(this).attr("checked", true); 
		 	}
		 });		
	}
}
$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = $.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function turnpage(geturl,blocks){
	//$("#messagebox").show();
	$.ajax({
	   type: "GET",
	   url: geturl,
	   cache: false,
   	   async:false,
	   success: function(msg){
	   	 //$("#messagebox").hide('slow');
	   	 $('#'+blocks).ScrollTo(800);	 
	   	 $("#"+blocks).html(msg);
		 //bindThickBoxEvents();
	   } 
	});
}




//////////////////// scroll ////////////////////////////////////////////////////////////////////////////
$.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = $.intval($.css(e,'width'));
	var h = $.intval($.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?$.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?$.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?$.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?$.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
$.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
$.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};

$.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

$.fn.ScrollTo = function(s) {
	o = $.speed(s);
	return this.each(function(){
		new $.fx.ScrollTo(this, o);
	});
};

$.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = $.getPos(e);
	z.s = $.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

function movePopBox(menubar,popbox)
{
	var startdrag = false;
	var mx = 0;
	var my = 0;
	var moffsetTop = 0;
	var moffsetLeft = 0;
	
	$("#"+menubar).css({
		cursor:"move"
	})
	
	$("#"+menubar).mousedown(function(e)
	{
		startdrag = true;
		if(is_ie)
		{	
			mx = event.x; 
			my = event.y;
		 }
		 else
		 {
		    mx = e.pageX ; 
			my = e.pageY;
		 }
		 moffsetTop = $("#"+popbox).offset().top; 
		 moffsetLeft = $("#"+popbox).offset().left; 
	})
	$(document).mousemove(function(e)
	{ 
		if(startdrag == true) 
		{
			if(is_ie)
			{ 
		    	$("#"+popbox).css('left',moffsetLeft+event.x-mx+'px');
				$("#"+popbox).css('top', moffsetTop+event.y-my+'px'); 
			}
			else
			{
				$("#"+popbox).css('left',moffsetLeft+e.pageX-mx+'px'); 
				$("#"+popbox).css('top', moffsetTop+e.pageY-my+'px');
			}
		}
	});
	$(document).mouseup(function()
	{ 
		startdrag = false; 
	});
		    
}

