/** share function global info **/
var gs_share_config = {
        url:"",
        title:"",
        titleSufix:"£º",
        content:"",
        charset:"",
        pics:"",
        language:"",
        appkey:"",
        title_suffix:"",
        content_suffix1:"",
        content_suffix2:""
}

/** init the parameter **/
function init(name, content, interceptLength){

        if(gs_share_config.url == ""){
            gs_share_config.url = location.href;
        }
	
        //title process
        gs_share_config.title = document.title.substring(0,document.title.length-interceptLength);
        if(gs_share_config.title.length > 40){
                gs_share_config.title = gs_share_config.title.substring(0, 40);
        }
        gs_share_config.title =  gs_share_config.title + gs_share_config.titleSufix;
        gs_share_config.content = content;
        gs_share_config.pics = "";
		
        //charset process
        if(gs_share_config.charset == ""){
            gs_share_config.charset = "utf-8";
        }
	
        //language process
        if(gs_share_config.language != ""){
            gs_share_config.language = "zh-CN";
        }
}

/** the enter for share info **/
function gsshare_sendto(name, content, interceptLength){
        var runFunction = "gsshare_sns_" + name + "()";
        init(name, content, interceptLength);
        setTimeout(runFunction ,0);
}

// share info to sina
function gsshare_sns_tsina(){
 
        var _url = encodeURIComponent(gs_share_config.url);
        var _title = encodeURIComponent(gs_share_config.title); 
        var _title_sufix = encodeURIComponent(gs_share_config.title_suffix ); 
        var _content = encodeURIComponent(gs_share_config.content);
        var _content_sufix1 = encodeURIComponent(gs_share_config.content_suffix1);
        var _content_sufix2 = encodeURIComponent(gs_share_config.content_suffix2);
        var _pics = '';
        if(gs_share_config.pics != ''){
            _pics = encodeURIComponent( gs_share_config.pics);
        }
        var _appkey = "1875138812";
        var _charset = gs_share_config.charset;
        var all_content = _title + _title_sufix + _content + _content_sufix1 + _url + _content_sufix2;
 
        var openUrl = "http://v.t.sina.com.cn/share/share.php?title=" + all_content + "&appkey=" + _appkey + '&pic=' + _pics
 			   + "&content=" + _charset;
 
        openNewPage(openUrl,"tsina", 500, 450);
}

// share info to weibo of 163 site
function gsshare_sns_t163(){
        var _url = encodeURIComponent(gs_share_config.url);
        var _title = encodeURIComponent(gs_share_config.title); 
        var _title_sufix = encodeURIComponent(gs_share_config.title_suffix ); 
        var _content = encodeURIComponent(gs_share_config.content);
        var _content_sufix1 = encodeURIComponent(gs_share_config.content_suffix1);
        var _content_sufix2 = encodeURIComponent(gs_share_config.content_suffix2);
        var _pics = encodeURIComponent( gs_share_config.pics);
        var _source = "GlobalSources"; //the name of web site
        var _togImg = "true"; // show the picture or not, true/false
        var all_content = _title + _title_sufix + _content + _content_sufix1 + _url + _content_sufix2;
        var openUrl = "http://t.163.com/article/user/checkLogin.do?link=" + _url + "&source=" + _source + "&info=" + all_content + "&images=" + _pics + "&togImg=" + _togImg;
        openNewPage(openUrl,"t163", 500, 300);
}

// share info to weibo of qq site
function gsshare_sns_tqq(){
        var _url = encodeURIComponent(gs_share_config.url);
        var _title = encodeURIComponent(gs_share_config.title); 
        var _title_sufix = encodeURIComponent(gs_share_config.title_suffix ); 
        var _content = encodeURIComponent(gs_share_config.content);
        var _content_sufix1 = encodeURIComponent(gs_share_config.content_suffix1);
        var _content_sufix2 = encodeURIComponent(gs_share_config.content_suffix2);
        var _pics = encodeURIComponent( gs_share_config.pics);
        var all_content = _title + _title_sufix + _content + _content_sufix1 + _url + _content_sufix2;
	    var _assname = "";//the user name of register,not nickname
        var _appkey = "";//the appkey for tencent assgin to us
        var openUrl = 'http://v.t.qq.com/share/share.php?url=' +_url + '&title=' + all_content + '&appkey=' + _appkey + '&site=' + _url + '&pic=' + _pics + "&&assname=" + _assname;
        openNewPage( openUrl,'tqq', 500, 450);
}


// share info to the weibo of sohu site.
function gsshare_sns_tsohu(){
        var _url = encodeURIComponent(gs_share_config.url);
        var _title = encodeURIComponent(gs_share_config.title); 
        var _title_sufix = encodeURIComponent(gs_share_config.title_suffix ); 
        var _content = encodeURIComponent(gs_share_config.content);
        var _content_sufix1 = encodeURIComponent(gs_share_config.content_suffix1);
        var _content_sufix2 = encodeURIComponent(gs_share_config.content_suffix2);
        var _pics = encodeURIComponent( gs_share_config.pics);
        var _appkey = "";
        var _charset = gs_share_config.charset;
        var all_content = _title + _title_sufix + _content + _content_sufix1 + _content_sufix2;
        var openUrl = "http://t.sohu.com/third/post.jsp?url=" + _url + "&title=" + all_content + "&appkey=" + _appkey + "&pic=" + _pics + "&content=" + _charset;
        openNewPage( openUrl,'tsohu', 650, 400);
}


function openNewPage(openUrl,appName, width, height){
        var oleft =  (screen.width-width)/2;
        var otop =  (screen.height-height)/2;
        window.open( openUrl,appName, 'width=' + width + ', height=' + height+ ',left=' + oleft + ',top=' + otop + ', toolbar=no, menubar=no, scrollbars=yes, location=yes, resizable=no, status=no');
}
