// JavaScript Document
// 图片缓存开始
var searchhove = new Image() ;
	searchhove.src = "http://www.onlychild.cn/images/searchhove.gif";
var nav = new Image() ;
	nav.src = "http://www.onlychild.cn/images/nav.gif";
var bigok = new Image() ;
	bigok.src = "http://www.onlychild.cn/images/okbig.gif";
var err = new Image() ;
	err.src = "http://www.onlychild.cn/images/err.gif";
var bbsitemhovebg = new Image() ;
	bbsitemhovebg.src = "http://www.onlychild.cn/images/bbsitemhovebg.gif";
var ok = new Image() ;
	ok.src = "http://www.onlychild.cn/images/ok.gif";
var loading = new Image() ;
	loading.src = "http://www.onlychild.cn/images/ajax.gif";

var usernumbdata="";
var rcvname=/^[\u4e00-\u9fa5]+$/i;
var rcvmobile=/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var email= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


function changeContent(i,j){
		var div1 = document.getElementById(i);
		var div2 = document.getElementById(j);
		div1.style.display = "none";
		div2.style.display = "block";
	}
	function isMouseLeaveOrEnter(e, handler) {   
    if (e.type != 'mouseout' && e.type != 'mouseover') return false;   
    var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;   
    while (reltg && reltg != handler)   
        reltg = reltg.parentNode;   
    return (reltg != handler);   
}


// jquery 开始
////////////////*  竞赛专区 滚动字幕  */
$(function(){
        var $this = $("#righttop");
		var RaceTimer;
		$this.hover(function(){
			  clearInterval(RaceTimer);
		 },function(){
		   RaceTimer = setInterval(function(){
						 Racefun( $this );
					}, 1000 );
		}).trigger("mouseleave");
});

function Racefun(obj){
   var $self = obj.find("ul").eq(1);
   var lineHeight = $self.find("li:first").height(); //获取行高
   $self.animate({ "marginTop" : -lineHeight +"px" }, 10 , function(){
         $self.css({marginTop:0}).find("li:first").appendTo($self); //appendTo能直接移动元素
   })
}
////////////////*  在线报名课程滚动  */

$(function(){
if($("#courselist").length>0)
{
	var $this = $("#courselist");
	var KCTimer;
		$this.hover(function(){
			  clearInterval(KCTimer);
		 },function(){
		   KCTimer = setInterval(function(){
						 KCScroll( $this );
					}, 1500 );
		}).trigger("mouseleave");
}
if($("#onlyselect").length>0)
{
	var $only = $("#onlyselect");
	var onlyTimer;
		$only.hover(function(){
			  clearInterval(onlyTimer);
		 },function(){
		   onlyTimer = setInterval(function(){
						 OnlyScroll( $only );
					}, 1000 );
		}).trigger("mouseleave");
}
});

function TeaScroll(Teaobj){
   var $Teaself = Teaobj; 
   	    $Teaself.animate({ "left" : -100+"px" }, 1000 , function(){
        $Teaself.css({left:0}).find("li:first").appendTo($Teaself).show("slow"); //appendTo能直接移动元素
   })
}


function OnlyScroll(obj){
   var $onlyself = obj; 
   var lineHeight = $onlyself.find("li:first").height(); //获取行高
   	    $onlyself.animate({ "marginTop" : -lineHeight +"px" }, 200 , function(){
        $onlyself.css({marginTop:0}).find("li:first").appendTo($onlyself); //appendTo能直接移动元素
   })
}


function KCScroll(obj){
   var $self = obj; 
   var lineHeight = $self.find("li:first").height(); //获取行高
   	    $self.animate({ "marginTop" : -lineHeight +"px" }, 200 , function(){
        $self.css({marginTop:0}).find("li:first").appendTo($self); //appendTo能直接移动元素
   })
}


$(function(){
	$("#tabs1 li").click(function(){
								  		var ultitle=$(this).text();										
										$(this).addClass("tabs-select").siblings().removeClass("tabs-select");
										$("#righttop ul[title=" + ultitle + "]").fadeIn("slow").siblings(":not(:first)").hide();
						             });
	$("#tabs2 li").click(function(){
								  		var ultitle = $(this).text();										
										$(this).addClass("tabs-select").siblings().removeClass("tabs-select");
										$("#rightcentercontent ul[title=" + ultitle + "]").fadeIn("slow").siblings().hide();
										$("#rightcentercontent div[title=" + ultitle + "]").fadeIn("slow").siblings().hide();
						             });
	$("#bbsitem li a").click(function(){
											$("#bbsitem li a").removeClass("bbsitemselect");
											$(this).addClass("bbsitemselect");
											var atitle = $.trim($(this).text());										
											$("#bbscontent").html("<div class='ajaximg font12notb'>&nbsp;&nbsp;&nbsp;<img src='images/ajax.gif' alt='正在获取数据' /><br /><br />正在获取数据...</div>");
											$.ajax({
													  url: "bbsdata.asp",
													  type: "POST",
													  data: {url:"bbs.onlychild.cn/api/javascript.php",key:"昂立首页_"+atitle},
													  dataType: 'html', 
													  success: function(result){$("#bbscontent").html("<ul id='bbsdata'>"+result+"</ul>");}
												   });											
										});
	$("#nav li a,#logo a,#bbsitem li a").click(function(){$(this).blur();});
	$("#courselist li").hover(function(){$(this).css("background-color","#E5F9FA");}, function(){$(this).css("background-color","#FFF");});	
	$("#sbb:input").hover(function (){$(this).attr("src","images/searchhove.gif");},function (){$(this).attr("src","images/searchbtm.gif");});
	
	 $('#sbb').click(function(){
			if($("sbi").val()=="在此搜索您需要的信息..." || $("sbi").val()=="")
				return false;
	 });
	 $("#sbi").focus(function(){
				$(this).css({"fontSize":"16","color":"#01879F","fontWeight":"bold"}).val("");
	 });
	 
	 $("#sbi").blur(function(){
			if($(this).val()==this.defaultValue || $(this).val()=="")
				$(this).css({"fontSize":"14","color":"#cccccc","fontWeight":"normal"}).val(this.defaultValue);
  			this.blur();
	});
	 
	 
	if($("#contentpic").length>0)
	{
		/////// 处理首页图片滚动
		 var len  = $("#contentpic .num > li").length;
		 var index = 0;
		 var adTimer;
		 $("#contentpic .num li").mouseover(function(){
			index  =   $("#contentpic .num li").index(this);
			showImg(index);
		 }).eq(0).mouseover();	
		 //滑入 停止动画，滑出开始动画.
		 $("#contentpic").hover(function(){
				 clearInterval(adTimer);
			 },function(){
				 adTimer = setInterval(function(){
					showImg(index);
					index++;
					if(index==len){index=0;}
				  } , 3000);
		 }).trigger("mouseleave");
	}
	
	//////// 通过控制top ，来显示不同的幻灯片
	function showImg(index){
		var adHeight = $("#contentpic").height();
		$("#contentpic .slider").stop(true,false).animate({top : -adHeight*index},400);
		$("#contentpic .num li").removeClass("on").eq(index).addClass("on");
	}

	if($("#cjcx").length>0)
	{
		$("#usernumb").click(function(){
									  	$(this).val("");
									  });
		$("#getresults").click(function(){
			usernumbdata=$("#usernumb").val();
			if(usernumbdata=="" ||usernumbdata=="在此输入准考证号" )
			{
				$("#tab3 li p").css("margin-bottom","12px");
				$("#inputerr").addClass("red").fadeIn("slow");
				return false;
			}
			$("#cjcx").hide();
			$("#cjcxloading").fadeIn("slow");
		});
		$("#recove").click(function(){
			usernumbdata=$("#usernumb").val();
			//alert("usernumbdata="+usernumbdata);
			$("#cjcxloading").hide();
			$("#inputerr").addClass("center font12notb hide").hide();
			$("#cjcx").fadeIn("slow");
			$("#usernumb").val(usernumbdata);
		});
	}
	
	$("#comname,#comcontent").click(function(){if($(this).val()==this.defaultValue){$(this).val("");}});
	$("#okback").click(function(){$("#inquiry").show();});
	$("#submitinquiry").click(function(){
									   		  if($("#selectinquiry").val()=="点击选择")
											  {
												  $("#onlyinquiry div p").css("margin","24px 0px");
												  $("#inquiryerr").css("font-weight","normal").show();
												  return false;
											  }
									   	  	  
											  if($("#comname").val()=="" || !email.test($("#comname").val()))
											  {
												  $("#onlyinquiry div p").css("margin","24px 0px");
												  $("#inquiryerr,#emailerr,#contenterr").hide();
												  $("#emailerr").css("font-weight","normal").show();
												  return false;
											  }
											  
											  if($.trim($("#comcontent").val())=="" || $("#comcontent").val()=="在此输入您咨询内容")
											  {
												  $("#onlyinquiry div p").css("margin","24px 0px");
												  $("#emailerr").hide();
												  $("#contenterr").css("font-weight","normal").show();
												  return false;
											  }
											  else
											  {
												  	$("#inquiryerr,#emailerr,#contenterr,#inquiry").hide();
												  	$("#inquiryloading").show();
											  		$.ajax({
													  	url: "postcomment.asp",
													  	type: "POST",
													  	data: {id:$("#selectinquiry").val(),recuser:$("#selectinquiry").val(),comname:$("#comname").val(),comcontent:$("#comcontent").val()},
													  	dataType: 'html', 
													  	cache: false,
													 	success: function(data, textStatus){
																								if(data==$("#comname").val())
																								{
																									$("#inquiryloading").hide();
																									$("#inquiryok").show();
																								}
																								else
																								{
																									$("#inquiryloading").hide();
																									$("#inquiryok").addClass("red center").html("<br /><br /><br /><br /><br />发生异常，请您稍后再试!").show();
																								}
																							}
												    });
												//window.open ('postcomment.asp?id='+ escape($("#comname").val()) + '&recuser=' + escape($("#comname").val()) + '&comname='+ escape($("#comname").val()) +'&comcontent='+$("#comcontent").val()+ '&a=' +new Date().getTime(),'newwindow','top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');

											  }
									   	  });

	if($("#sendcomment").length>0)
	{
		$("#commentname").focus(function(){ 
												if($.trim($(this).val())==this.defaultValue)
													$(this).addClass("blackcolor").val("");
											});
		$("#commentcontent").focus(function(){ 
												if(($.trim($(this).val())=="" || $(this).val()==this.defaultValue) && $(this).height() <= 30 )
												{
													$(this).animate({ height : "+=60" },400);
													$(this).addClass("blackcolor").val("");
													$("#sendcomment").addClass("sendcommentok").css("font-weight","bold");
												}													
												});
		$("#commentname").blur(function(){ 
												if($.trim($(this).val())=="" || $(this).val()==this.defaultValue)
													$(this).removeClass("blackcolor").addClass("graycolor").val("input your Email address");
											});
		
		$("#commentcontent").blur(function(){ 
												if($.trim($(this).val())=="" || $(this).val()==this.defaultValue)
												{
													$(this).removeClass("blackcolor").addClass("graycolor").val("请在这里输入您要咨询的问题 ...");
													$("#senderr").hide();
													$("#sendcomment").removeClass("sendcommentok").css("font-weight","normal");
													if($(this).height() >= 90)
														$(this).animate({ height : "-=60" },400);
												}
												else
													$("#sendcomment").addClass("sendcommentok").css("font-weight","bold");
											});
			
	}
	
	
	if($("#bbscontent").length>0)
	{
		$.ajax({
  				url: "bbsdata.asp",
				type: "POST",
				data: {url:"bbs.onlychild.cn/api/javascript.php",key:"昂立首页_营养美食"},
				dataType: 'html', 
  				cache: false,
  				success: function(result){$("#bbscontent").html("<ul id='bbsdata'>"+result+"</ul>");}
			});
	}
	if($("#down").length>0)
	{
		$.ajax({
  				url: "bbsdata.asp",
				type: "POST",
				data: {url:"bbs.onlychild.cn/api/javascript.php",key:"昂立首页_教育资料下载"},
				dataType: 'html', 
  				cache: false,
  				success: function(result){$("#down").html("<ul id='downbbsdata'>"+result+"</ul>");}
			});
	}
	})

$(function(){
function Getcomment(thisid)
{
	var commentmainhtml="";
		$.ajax({
   			type: "POST",
				url: "http://www.onlychild.cn/getcomment.asp",
				data: {"id":thisid},
				cache: false,
				error: function(){$("#commentmain li div.comquestion").html('<img src="'+err.src+'" alt="参数错误" />&nbsp;&nbsp;发现错误: 错误发生在 jquery ajax JSON 中!');},
				success: function(json){
											var jsondata = eval('(' + json + ')');
											if(unescape(jsondata[0].id)=="err")
											{
												$("#commentmain li div.comquestion").html('<img src="'+err.src+'" alt="参数错误" />&nbsp;&nbsp;文章编号 或 校区名称 参数错误!');
												$("#commentnum").text("咨询0条");
											}
											else if(unescape(jsondata[0].id)=="datanull")
											{
												$("#commentmain li div.comquestion").addClass("font14b").html('<p class="right"><br />欢迎在线咨询我们的课程顾问 --- 请在下面输入您的E-mail地址以备答复您的咨询&nbsp;&nbsp;<br /><br /></p><p class="red right font14b">--- 上海昂立少儿教育&nbsp;&nbsp;<br /><br /></p>');
												$("#commentnum").text("咨询0条");
											}
											else
											{
												if(jsondata.length>3)
													$("#moreinfo").show();
												//构造 #commentmain li 内容开始
													 commentmainhtml="";
													 $("commentnum").text(jsondata.length);
													 for (var i = 0; i < jsondata.length; i++)
													 {
														commentmainhtml=commentmainhtml+'<li><div class="comuserinfo font12notb"><div class="userinfo">编号:' + unescape(jsondata[i].id) + ' - 家长:' + unescape(jsondata[i].email) + '</div><div class="sourceinfo">[ IP:' + unescape(jsondata[i].ip) + '   提交时间: ' + unescape(jsondata[i].comdate) + ' ]</div></div><div class="comquestion font14notb">' + unescape(jsondata[i].comquestion) + '</div>';
														if(unescape(jsondata[i].comanswer)=="datanull")
															commentmainhtml=commentmainhtml+'<div class="comanswer graycolor">本问题尚未得到答复，答复后您的邮箱将会收到答复邮件，请您注意查收</div></li>'; 
														else
															commentmainhtml=commentmainhtml+'<div class="comanswer font14notb">答复：' + unescape(jsondata[i].comanswer) + '</div></li>'; 
													 }
													 $("#commentmain").html("");
													 $("#commentmain").html(commentmainhtml);
													 $("#commentnum").text("咨询"+jsondata[0].comnum+"条");
											}
										}
			  });		
}

if($("#thisid").length>0)
{	
	Getcomment($("#thisid").attr("title")); //页面就绪后立即获取一次咨询数据
	setInterval(function(){Getcomment($("#thisid").attr("title"));},5000); //启动定时器函数每隔5秒自动获取数据
}

if($("#sendcomment").length>0)
{
	var oldcommentcontent="";
	$("#sendcomment").click(function(){
	 if($("#commentname").val()!="" && $("#commentname").val()!="input your Email address" && $("#commentcontent").val()!="" && $("#commentcontent").val()!="请在这里输入您要咨询的问题 ..." && email.test($("#commentname").val()) )
	 {
		if(oldcommentcontent==$.trim($("#commentcontent").val()))
		{
			$("#senderr").css("color","#ff0000").html('错误： 请勿发送重复的咨询数据!').show();
		}
		else
		{
		$("#senderr").removeClass("red").css("color","#006600").html('<img src="'+loading.src+'" alt="正在发送数据" />&nbsp;&nbsp;正在发送您的咨询 ...').show();
		$.ajax({
			url: "http://www.onlychild.cn/postcomment.asp",
			type: "POST",
			data: {id:$("#thisid").attr("title"),recuser:$("#adduser").attr("title"),comname:$("#commentname").val(),comcontent:$("#commentcontent").val()},
			dataType: 'html', 
			cache: false,
			success: function(data, textStatus){
													if(data==$("#commentname").val())
													{
														$("#senderr").css("color","#006600").html("您的咨询问题已成功提交，我们将在本页面以及您留下的电子邮箱答复您!").show();
														oldcommentcontent=$("#commentcontent").val();
														//alert($("#thisid").attr("title"));
														Getcomment($("#thisid").attr("title"));  //启动函数获取新数据
													}
													else
													{
														$("#senderr").css("color","#ff0000").html("错误： 服务器返回异常数据，请刷新重试 或 稍后再试！").show();
														alert(data);
														alert($("#thisid").attr("title"));														
													}
												}
		});
		}
	 }
	 else
	 {
		 $("#senderr").css("color","#ff0000").html("错误：请正确填写您的 邮件地址 和 咨询内容!").show();
		 return false;		
	 }
	 });
}
if($("#hitsnum").length>0)
{
			$.ajax({
			url: "counter.asp",
			type: "get",
			data: {id:$.trim(($("#thisid").attr("title")).replace(/\D/g,""))},
			dataType: 'html', 
			cache: false,
			success: function(data){
										$("#hitsnum").text("已被阅读"+ data +"次");
									 }
				   });	
}

if($("#showmain").height()>700)
	$("#startea").show();	
		
function Getmorekc(arraydata)
{
	var targedata="";
		targedata=arraydata.split(",");
		if(targedata[0]!="stop")
		{
			$("#tempinfo").html("正在载入新数据...");
			//location.href="#"
			$.ajax({
					url: "getmorekc.asp?"+escape(targedata[0])+"="+escape(targedata[1])+"&curpage="+targedata[2],
					type: "get",
					cache: false,
					success: function(data){
												$("#choose").html(data);
												if(targedata[1]=="rand")
													$("#tempinfo").text("当前随机显示所有课程");
												else												
													$("#tempinfo").text(targedata[1]);
											}
			   	   });
		}
		else
			return false;
}


$("#firstpage").live("click", function() {Getmorekc($(this).attr("name"));});
$("#prepage").live("click", function() {Getmorekc($(this).attr("name"));});
$("#nextpage").live("click", function() {Getmorekc($(this).attr("name"));});
$("#endpage").live("click", function() {Getmorekc($(this).attr("name"));});


$("#regetkc,#rechoose").live("click", function() {
									 		var randarray="rand,rand,1";
												Getmorekc(randarray); //页面就绪后理解获取一次课程数据
										 });


$("#choose li:not(.chooselititle,.chooselifoot) a").live("click", function() {
	if( $(this).attr("name")!=null && $(this).attr("name")!='undefined' &&  $(this).attr("name")!="" )
	{
		//alert($(this).attr("name"));
		$("#tempinfo").html("正在载入新数据...");
		//location.href="#"
		$.ajax({
				url: "getkc.asp?id="+$(this).attr("name")+"&a="+new Date().getTime(),
				type: "get",
				cache: false,
				success: function(data){$("#choose").html(data);}
			   });
		$("#tempinfo").html("当前课程编号为: <b>"+$(this).attr("name")+"</b>");
	}
});

$("#billform input[type=text]").live("focus", function() {
															if(($.trim($(this).val())=="" || $(this).val()==this.defaultValue) )
																$(this).val("").css("color","#333");														
															});
$("#billform input[type=text]").live("blur", function() {
													   		if($.trim($(this).val())=="" || $(this).val()==this.defaultValue)
													   		{
																$(this).val(this.defaultValue).css("color","#ccc");
																$(this).next("span").css("color","#f00").html('<img src="http://www.onlychild.cn/images/close.gif" /> '+$(this).attr("title")+'填写错误!');
															}	
															else
															{
																if( $(this).is('#v_rcvname'))
																{
																	if(this.value.length>=2 && rcvname.test($(this).val()))
																		$(this).next("span").css("color","#060").html('<img src="http://www.onlychild.cn/images/ok.gif" /> '+$(this).attr("title")+'填写正确');
																	else
																		$(this).next("span").css("color","#f00").html('<img src="http://www.onlychild.cn/images/close.gif" /> 学生姓名填写错误');
																}
																
																if( $(this).is('#v_rcvtel') )
																{
																	if(this.value.length>=7)
																		$(this).next("span").css("color","#060").html('<img src="http://www.onlychild.cn/images/ok.gif" /> '+$(this).attr("title")+'填写正确');
																	else
																		$(this).next("span").css("color","#f00").html('<img src="http://www.onlychild.cn/images/close.gif" /> 固定电话号码填写错误');
																}
																
																if( $(this).is('#v_rcvmobile'))
																{
																	if(this.value.length==11 && rcvmobile.test($(this).val()) )
																		$(this).next("span").css("color","#060").html('<img src="http://www.onlychild.cn/images/ok.gif" /> '+$(this).attr("title")+'填写正确');
																	else
																		$(this).next("span").css("color","#f00").html('<img src="http://www.onlychild.cn/images/close.gif" /> 手机号码填写错误');		
																}
																
																if( $(this).is('#v_rcvemail'))
																{
																	if(this.value.length>5 &&  email.test($(this).val()) )
																		$(this).next("span").css("color","#060").html('<img src="http://www.onlychild.cn/images/ok.gif" /> '+$(this).attr("title")+'填写正确');
																	else
																		$(this).next("span").css("color","#f00").html('<img src="http://www.onlychild.cn/images/close.gif" /> 邮箱地址填写错误');		
																}
																
																if( $(this).is('#v_rcvaddr'))
																{
																	if(this.value.length>4)
																		$(this).next("span").css("color","#060").html('<img src="http://www.onlychild.cn/images/ok.gif" /> '+$(this).attr("title")+'填写正确');
																	else
																		$(this).next("span").css("color","#f00").html('<img src="http://www.onlychild.cn/images/close.gif" /> 家庭地址填写错误');	
																}
															}
													  		});

$("#Submit").live("click", function() {
	if($("#v_rcvname").val()!="" && $("#v_rcvname").val()!="中文的汉字全称" && $("#v_rcvmobile").val()!="" && $("#v_rcvmobile").val()!="格式: 13944448888" && $("#v_rcvemail").val()!="" && $("#v_rcvemail").val()!="格式: xxx@email.com" && $("#v_rcvaddr").val()!="" && $("#v_rcvaddr").val()!="格式: xx区xx路xx号")
	{
		return true;
		document.billform.submit();
	}
	else
	{
		alert("\n请正确填写所有表单项目!");
		return false;
	}
});


$("#chooseindex li a").click(function(){
	Getmorekc($(this).attr("title"));
});

if( $("#choose").length>0 && $("#chooseid").attr("title")=="" )
{
var	randarray="rand,rand,1";
	Getmorekc(randarray);    //页面就绪后立即获取一次课程数据
}

if($("#division").length>0)
{
	$("div.onlyschoolname").hover(function(){$(this).css("border","1px solid #006600");}, function(){$(this).css("border","1px solid #E2FFC0");});
	$("div.onlyschoolname,div.onlyschoolname img").click(function(){
		$("#division ul[title=" + $(this).attr("title") + "]").fadeIn("slow").siblings(":not(div,p)").hide();												  
	});
}
	var object=$("#aboutonly");
	$("#aboutus div.tooltip").bind("mouseover",function(){
		object.show();
	}).bind("mouseleave",function(){
		object.hide();
	})

if($("#indexshowonlytea").length>0)
{	
    $("#indexshowonlytea").YlMarquee({
        visible:3,
        step:3
    });
}

});
