﻿//IE6去除png灰色背景
$(document).ready(function () {
  $(document).pngFix();

  $(".menu").not(".left_cur").each(function (i) {
    $(this).hover(function () {
      $(this).removeClass("left_ot").addClass("left_cur");
    }, function () {
      $(this).removeClass("left_cur").addClass("left_ot");
    })
  })

  $(".menu").each(function (i) {
    $(this).mouseover(function () {
      if ($(".second_masterDiv:eq(" + i + ")").html() != "") {
        $(".second_masterDiv:eq(" + i + ")").slideDown("fast");
      }
    })
  })

  $(".left_second_ot").each(function () {
    $(this).hover(function () {
      $(this).removeClass("left_second_ot").addClass("left_second_cur");
    }, function () {
      $(this).removeClass("left_second_cur").addClass("left_second_ot");
    });
  });
})
//-------------------------------------=================================JQUERY Documnet=================---------------
var Tools = {
	isUndefined : function(variable) {
		return typeof variable == 'undefined' ? true : false;
	},
	lastFolderName : window.location.href.toLowerCase().replace(/.+\/(\w+)\/[^\/]*$/, '$1'),
	lastFileName : window.location.href.toLowerCase().replace(/.+\//g, ''),
	isArray : function(o) {
		return Object.prototype.toString.call(o) === '[object Array]';   
	},
	getExt : function(path) {
		return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
	},
	$ : function(obj) {
		return document.getElementById(obj);
	},
	getParameter : function(param) {
		var query = window.location.search;
		var iLen = param.length;
		var iStart = query.indexOf(param);
		if (iStart == -1)  return '';
		iStart += iLen + 1;
		var iEnd = query.indexOf('&', iStart);
		if (iEnd == -1) return query.substring(iStart);
		return query.substring(iStart, iEnd);
	},
	switchDiv : function(li, sltClass, otClass ,switchObj) {
		$(li).each(function(i) {
			$(this).click(function() {
			$(this).addClass(sltClass).siblings().removeClass(sltClass).addClass(otClass);
				$(switchObj).eq(i).show().siblings(switchObj).hide();
			});
		});
	},
	checkNull : function(id, str) {
		_temp = $('#'+ id).val().trim();
		if (_temp.length == 0) {
			alert('请输入' + str);
			$('#'+ id).focus();
			return false;
		}
		return true;
	},
	checkEmail : function(id, str) {
		_temp = $('#'+ id).val().trim();
		if (!/^[a-z0-9_]{1}[a-z0-9\-_]*(\.[a-z0-9\-_]+)*@[a-z0-9]{1}[a-z0-9\-_]*(\.[a-z0-9\-_]+)*\.[a-z]{2,4}$/.test(_temp)) {
			alert(str + '格式不正确');
			$('#'+ id).focus();
			return false;
		}
		return true;
	},
	comparePwd : function(str1, str2) {
	    if ($('#'+ str1).val().trim() != $('#'+ str2).val().trim()) {
			alert('前后密码不一致');
			$('#'+ str2).focus();
			return false;
	    }
		return true;
	},
	needChecked : function(id, str) {
	    if ($('#'+ id).attr('checked') == false) {
			alert(str);
			$('#'+ id).focus();
			return false;
	    }
		return true;
	},
	checkDigit : function(id, str) {
		_temp = $('#'+ id).val().trim();
		if (!/^[0-9]+$/.test(_temp)) {
			alert(str);
			$('#'+ id).focus();
			return false;
		}
		return true;
	},
	checkFixedLength : function(id, str, value, mode) {
		_temp = $('#'+ id).val().trim();
		if (mode == 'MIN') {
			if(value != null && _temp.length < value) {
				alert(str + ' 长度至少为 ' + value + '位');
				$('#'+ id).focus();
				return false;
			}
		}
		else if (mode == 'MAX') {
			if(value != null && _temp.length > value) {
				alert(str + ' 长度应小于 ' + value + '');
				$('#'+ id).focus();
				return false;
			}
		}
		else {
			if(value != null && _temp.length != value) {
				alert(str + ' 长度应当为 ' + value + '位');
				$('#'+ id).focus();
				return false;
			}
		}
		return true;
	},
	checkTel : function(id, str) {
		_temp = $('#'+ id).val().trim();
		if(/^[0-9\-,]+$/.test(_temp)) {
			return true;
		}
		else {
			alert(str + ' 格式不正确 ');
			$('#'+ id).focus();
			return false;
		}
	},
	checkMobile : function(id, str) {
		_temp = $('#'+ id).val().trim();
		if(/^1[35]\d{9}$/.test(_temp)) {
			return true;
		}
		else {
			alert(str + ' 格式不正确 ');
			$('#'+ id).focus();
			return false;
		}
	},
    checkUpLoadFile : function(obj, fileType, bool) {
	    var o = Tools.$(obj);
	    if (o.value.length > 0) {
		    var tempType = o.value.substring(o.value.lastIndexOf('.'), o.value.length);
		    if (fileType.toLowerCase().indexOf(tempType.toLowerCase()) == -1) {
			    alert('上传格式不对，请重新选择');
			    return false;
		    }
	    }
	    else {
		    if (!bool) {
		        alert('请选择图片后上传');
		        o.style.background = 'red';
		        return false;
		    }
	    }
	    return true;
    }
};
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, '');
}
String.prototype.isDigit = function() {
	return (this.trim().replace(/\d/g, '').length == 0);
}
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            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
        }
        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 = jQuery.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;
    }
};
    //-->

 
/**
*  左右上下的点击滚动，效果是卷动当前视野
*  up,down为上下 或者 左右的按钮，direction为移动方向 top,left两个值
*  2010-03-30 eric
*/
jQuery.fn.scrollMove = function (up, down, direction) {
var scroll = $(this);
var wh = direction == 'top' ? scroll.height() : (scroll.find('.item').length * scroll.find('.item').width());
var pwh = direction == 'top' ? scroll.parent().height() : scroll.parent().width();
var numTotal = wh == pwh ? 0 : Math.floor(wh / pwh); //总页数
var _local = function () {
  return parseInt(scroll.css(direction));
}
var _num = function () {
  var local = _local();
  return Math.floor(Math.abs(local) / pwh);
}
var checkButtonColor = function () {
  var num = _num();

  if (numTotal <= num)
    $(up).addClass('transparent');
  else
    $(up).removeClass('transparent');

  if (0 == num)
    $(down).addClass('transparent');
  else
    $(down).removeClass('transparent');
}
checkButtonColor();
$(up).click(function () {
  var local = _local();
  var num = _num();
  if (numTotal > num) {
    direction == 'top'
	? scroll.animate({ top: local - pwh + 'px' }, checkButtonColor)
	: scroll.animate({ left: local - pwh + 'px' }, checkButtonColor);
  }
});
$(down).click(function () {
  var local = _local();
  var num = _num();
  if (0 < num) {
    direction == 'top'
	? scroll.animate({ top: local + pwh + 'px' }, checkButtonColor)
	: scroll.animate({ left: local + pwh + 'px' }, checkButtonColor);
  }
});
};
//-->
