﻿/**
	Global Trim left & right Space function
*/  
String.prototype.Trim = function(){ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
}
/**
	Function for Add Page into MyFavorites
*/
function AddFavorite(sURL, sTitle){
    try{
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e){
        try{
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e){
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
/**
	Function for Set Page as Homepage
*/
function SetHome(obj,url){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
	}
	catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch(e){
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入 about:config 并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);
		 }
	}
}
/**
	Global function for getting Flash Object
*/ 
function getSWF(_name){
	if (window.document[_name]){
		//alert(window.document[_name]);
	   return window.document[_name];
	}else if (navigator.appName.indexOf("Microsoft Internet")==-1){
	   if (document.embeds && document.embeds[_name]){
		  // alert(document.embeds[_name]);
	   	return document.embeds[_name];
	   }
	}else{
		//alert(document.getElementById(_name));
	   return document.getElementById(_name);
	}
	
	/*var isIE = navigator.appName.indexOf("Microsoft") != -1;
	if(isIE) { alert(window[_name]);}
	return (isIE) ? window[_name] : document[_name];*/
}
//
//
$(function(){
	/**
		Top Logined Status Greeting words Scrolling
	*/
	var marquee = '<marquee width="165" height="19" direction="left" behavior="scroll" loop="-1" vspace="2" hspace="0" scrollamount="2" scrolldelay="5"></marquee>';
	var loginGreeting = $('.header .nav .rightBar .wrap .welcome');
	if(loginGreeting.text().Trim().replace(/&nbsp;/g,"*").replace(/[^\x00-\xff]/g,"*").length > 18){
		loginGreeting.wrapInner(marquee);
	}
	/**
		Global Tab function
	*/  
	
	/* Tab */
	$('.tab li:not([class="div"])').click(function(){
		if($(this).is('.now')) return false;
		var i = $(this).index();
		$(this).addClass('now').siblings().removeClass('now');
		var tabC =  $(this).parent().next('.tabC').children('.cont');
		tabC.hide().eq(i).show();							 
	});
	//
	/* *
		A function includes all staffs which need position fix:
	*/
	var header_top_lr = $('.header .top .l, .header .top .r');
	
	function global_staff_positionFix(){
		if(screen.availWidth<=1024){
			header_top_lr.hide();
		}
		else {
			header_top_lr.show();
		}
	}
	
	global_staff_positionFix();
	
	$(window).resize(function(){
		global_staff_positionFix();	
	});
	
	/* *
		Search Box Keywords onFocus / onBlur Events & onSubmit Event
	*/
	$('input.keywords').each(function(){
		$(this).data('defaultTxt',this.value);
	});
	
	$('input.keywords').bind('focus',function(){
		if(this.value.Trim()==$(this).data('defaultTxt')) {
			this.value = '';
			$(this).addClass('keywordsFocus');	
		}
	}).bind('blur',function(){
		if(this.value.Trim()=='') {
			this.value = $(this).data('defaultTxt');
			$(this).removeClass('keywordsFocus');	
		}
	});
	
	$('.btn_search').bind('click',function(){
		var keywords = $(this).parents('.form').find('input.keywords');
		if(keywords.val().Trim()==keywords.data('defaultTxt')){
			if($(this).parents('form').length!=0){
				$(this).parents('form')[0].onsubmit = function(){
					alert('请输入关正确的关键字！');	
					keywords[0].focus();
					return false;
				}
			}
			else{
				alert('请输入关正确的关键字！');	
				keywords[0].focus();	
			}
		}
		else {
			if($(this).parents('form').length==0) return false;
			$(this).parents('form')[0].onsubmit = function(){
				return true;
			}	
		}
	});
	
	/**
		Login Check
	*/
	
	$('.form input.input_text').each(function(){
		$(this).data('defaultTxt',this.value);
	}).bind('focus',function(){
		if(this.value.Trim()==$(this).data('defaultTxt')) {
			this.value = '';
			if($(this).hasClass('input_pw')){
				this.type = "password";	
			}
		}
	}).bind('blur',function(){
		if(this.value.Trim()=='') {
			this.value = $(this).data('defaultTxt');
			//$(this).removeClass('Focus');
			if($(this).hasClass('input_pw')){
				//this.type = "text";	
				//alert(this.type);
			}
		}
	});
	
	$('input[type=image]').bind('click',function(){
		var input = $(this).parents('.form').find('.input_text');
		input.each(function(){
			if(($(this).val().Trim()==$(this).data('defaultTxt'))||($(this).val().Trim()=='')){
				//alert('请输入您的用户名和密码后再点击登录！谢谢！');	
				this.focus();
				return false;
			}	
		})
	});
	
	/* *
	 	Fix outline appearing when click hyperlink in IEs 
	 */
	$('a').focus(function(){
		this.blur();						 
	});
	
})
