/**
 * @author Jay
 */
var jq = jQuery.noConflict();
jQuery.cookie = function(name, value, options,callback) {
    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('');
		if(callback){
			callback();
		}
    } 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]);
                
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



function setMenuOn(d){
	var par=d.attr('class');
/*
		thisUrl=d.attr('go');
*/
		
	jq.cookie('topMenuOn',par,{expires:1,path:'/',domain:'ndui1.com'});
	//setTimeout(window.location.href=thisUrl,500);
}
function getMenuOn(){
	var mON=jq.cookie('topMenuOn'),
		box=jq('.menu');
		url=window.location.href.split('/'),
		files=url[url.length-2],
		isIndex=files.indexOf('.com');

	if(isIndex>0){
		box.find('a').removeClass('on');
	}else{
		var thisMenu=box.find('a.'+mON);
		//thisMenu.siblings().removeClass('on');
		box.find('a').removeClass('on');
		thisMenu.addClass('on');
	}
}
function replaceUrl(){
	var link=jq('.menu').find('a');
	var thisLink;
	link.each(function(){
		thisLink=jq(this).attr('href');
		jq(this).attr({
			'href': 'javascript:void(0)',
			'go':thisLink
		});
	});
}

/*
================================
*/
jq(function(){
	var _menu=jq('.menu').find('a');
	getMenuOn();
	//replaceUrl();
	_menu.click(function(){
		jq.cookie('topMenuOn',null);
		setMenuOn(jq(this));
	});
});
/*
================================
*/
function trim(str) {
	return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}

function checkform(theform){
   if (theform.parentsname.value.length < 2){
      alert("请输入正确的家长姓名");
      theform.parentsname.focus();
      return (false);
   }
   var mobile = trim(theform.mobile.value);
   var illegalmobile = !(/(^13|^15|^18)\d{9}$/.test(mobile));
   if (illegalmobile) {
       alert('请您正确输入手机号码');
       theform.mobile.focus();
	   return false;
   }
   var email = theform.email.value;
   var reMail = /^(?:[a-z\d]+[_\-\+\.]?)*[a-z\d]+@(?:([a-z\d]+\-?)*[a-z\d]+\.)+([a-z]{2,})+$/i;   
   if(!reMail.test(email)) {
	   alert("请您输入正确邮箱地址");
	   theform.email.focus();
	   return false;
   }  
   if(theform.grade.value == ""){
	   alert("请选择年级");
	   theform.grade.focus();
	   return false;
   }   
   if(theform.schoolurl.value == ""){
	   alert("请选择您最方便的校区");
	   theform.schoolurl.focus();
	   return false;
   }
}


