//QQ在线客服漂浮效果

lastScrollY = 0;
function FloatScroll() {
    var diffY;
    if (document.documentElement && document.documentElement.scrollTop){
    	diffY = document.documentElement.scrollTop;
	}
    else if (document.body){
    	diffY = document.body.scrollTop;
	}
    else
    {}
    percent = .1 * (diffY - lastScrollY);
    if (percent > 0){
		percent = Math.ceil(percent);
	}
    else{
		percent = Math.floor(percent);
	}
    document.getElementById("OnlineService").style.top = parseInt(document.getElementById("OnlineService").style.top) + percent + "px";
    lastScrollY = lastScrollY + percent;
}

//QQ在线客服折叠效果
jQuery(function(){
	var Height = jQuery("#OSMain").height()+ 13 + 'px';
	jQuery(".OSBox").attr("style","height:" + Height);
	jQuery('#OSIcon').click(function(){
		jQuery('#OSMain').animate({
			right: '0',
			width: '126px'
		},500);
		jQuery('.OSBox').animate({
			width: '126px'
		},500);
		jQuery(this).animate({
			left: '35px'
		},500);
		jQuery('#OnlineService').animate({
			width:"126px"
		},400);
		jQuery('#OsValiCodeImg').append('<img title="看不清？点击换一个" alt="验证码" onclick="this.src=\'/valiCode.php?rand=\'+(new Date()).getMilliseconds()" src="/valiCode.php">');
		jQuery('#OsValiCodeImg').find("img").attr("src","/valiCode.php?rand="+(new Date()).getMilliseconds());
	});
	jQuery('#OSMain .close').click(function(){
		jQuery('#OSMain').animate({
			right: '-126px',
			width: '0'
		},500);
		jQuery('.OSBox').animate({
			width: '34px'
		},500);
		jQuery("#OSIcon").animate({
			left: '0'
		},500);
		jQuery('#OnlineService').animate({
			width:'34px'
		},400);
		jQuery('#OsValiCodeImg img').remove();
	});
});

//QQ在线留言
jQuery(function(){
    var OsBox = jQuery("#OsForm");
    var fields = jQuery("input[type=text],textarea",OsBox);
                
    fields.each(function(){
        var node  = jQuery(this);
        node.attr("data",node.val());
    });
    fields.focus(function(){
        var node  = jQuery(this);
        var val = node.val();
        if (val == node.attr("data")){
            node.val("");
        }
    });
    fields.blur(function(){
        var node  = jQuery(this);
        var val = node.val();
        if(val == null || val.length == 0){
            node.val(node.attr("data"));
        }
    });
                
    var OsForm = jQuery("#OsForm");
    var valiCode = jQuery("input[name=guestbookValiCode]",OsForm);
    var valiCodeImg = jQuery("#OsValiCodeImg",OsForm);
    var valiCodeChange = jQuery("#valiCodeChange",OsForm);
    valiCodeChange.click(function(){
        valiCodeImg.find("img").attr("src","/valiCode.php?rand="+(new Date()).getMilliseconds());
    });
    OsForm.submit(function(data){
        fields.each(function(){
            if (fields.val() == fields.attr("data")){
                fields.val("");
            }
        });
        jQuery("input[name=guestbookTitle]",OsForm).val(jQuery("input[name=guestbookName]",OsForm).val()+" \u7684\u7559\u8a00");
        jQuery.post(OsForm.attr("action"),OsForm.serializeArray(),function(data){
            if (data.indexOf("\u6210\u529f") > 0){
                alert("\u7559\u8a00\u6210\u529f");
                jQuery("#OSMain .close").click();
                fields.val("");
                fields.blur();
            }else{
                alert(jQuery(".Message",data).text());
            }
        });
        return false;
    });
});
