var td_read = false;
var td_ws = new Array();

var thunderpid = 0;
var thundertype = 0;
var thunderpara1 = '';
var thunderpara2 = '';
var thunderpara3 = 0;

function _src()
{	
	/*
	r = "";	
	try {		
		r = top.document.referrer;	
	}	
	catch (e) {		
		try {			
			r = parent.document.referrer;		
		}		
		catch (e) {			
			try {				
				r = document.referrer;			
			}			
			catch (e) {				
				r = "";					
			}		
		}	
	}	
	p = r.indexOf("?");	
	if(-1 == p)		
	p = r.indexOf("&");	
	if(-1 == p)		
		return r;	
	else 		
		return r.substring(0,p);
	*/
	return document.location;
}

function loadcop(sid) {
	var dtype = sid % 100;
	var copjs = '<script language="JavaScript" src="http://un.so.gougou.com/socop/' + dtype + '/' + sid + 'a.js"><\/script>' 
		+ '<script language="JavaScript" src="http://un.so.gougou.com/socop/' + dtype + '/' + sid + 'b.js"><\/script>' 
		+ '<script language="JavaScript" src="http://un.so.gougou.com/js/SearchWord.js"><\/script>';
	document.write(copjs);
}


function xcontent(sid,stype,spara1,spara2,spara3) {	

	var btype = Math.floor(parseInt(stype, 10)/100);
	if(btype == 4 || btype == 6 ) {
		sid = parseInt(sid, 10) + btype*1000000;
		preContent = '<a href="http://www.gougou.com/search?search=' + spara1 + '&id=' + sid + '&pattern=' + stype + '" target="_blank">' + spara2 + '</a>';
	} else {
		preContent = '<iframe id="gougouframe" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="no" width="' + spara1 + '" height="' + spara2 + '" src="http://un.so.gougou.com/gougou' + stype + '.htm#id=' + sid + '"></iframe>';
	}
	return preContent;
}

/* 
 *spara1 - width, keyword
 *spara2 - height, title
 */
function xprint(sid,stype,spara1,spara2,spara3) {
	var btype = Math.floor(parseInt(stype, 10)/100);
	if(btype == 4 || btype == 6 ) {
		thunderpid = sid;
		thundertype = stype;
		thunderpara1 = spara1;
		thunderpara2 = spara2;
		if(spara3)
			thunderpara3 = parseInt(spara3,10);
		if(!td_read) {
			//loadcop(1);
			loadcop(sid);
			td_read = true;
		}
		document.write('<script language="JavaScript" src="http://un.so.gougou.com/js/WordPrint.js"><\/script>');
	} else if(stype == 103) {
		document.write(advxcontent(arguments));
	} else if(parseInt(stype) >=110 && parseInt(stype) <120) {
		document.write(advxcontent2(arguments));
	}else {
		document.write(xcontent(sid,stype,spara1,spara2,spara3));
	}
}

function advxcontent(args) {
	arguments = args;
	var sid = arguments[0];
	var stype = arguments[1];
	var frameWidth = parseInt(arguments[2]);
	var typeList = getArgumentValue(arguments[3]);
	var defaultType = getArgumentValue(arguments[4]);
	var searchInputWidth = getArgumentValue(arguments[5]);
	var searchKeyword = getArgumentValue(arguments[6]);
	var gbColor = getArgumentValue(arguments[7]);
	var tagColor = getArgumentValue(arguments[8]);
	var tagFontColor = getArgumentValue(arguments[9]);
	var anchorColor = getArgumentValue(arguments[10]);		
	if(isNaN(frameWidth)) {
		frameWidth = 508;
	}

	//var iframeSrc = "http://localhost:8080/summary/gougou103.htm?id=" + sid 
	var iframeSrc = "http://un.so.gougou.com/gougou103.htm?id=" + sid 
		+ "&typeList=" + typeList
		+ "&defaultType=" + defaultType
		+ "&inputWidth=" + searchInputWidth
		+ "&defaultKey=" + searchKeyword
		+ "&bgColor=" + gbColor
		+ "&tagColor=" + tagColor
		+ "&tagFontColor=" + tagFontColor
		+ "&anchorColor=" + anchorColor;
		
	return '<iframe id="gougouframe" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" '
		+ 'scrolling="no" width="' + frameWidth + '" height="86" src="' + iframeSrc + '"></iframe>';
}
function advxcontent2(args) {
	arguments = args;
	var sid = arguments[0];
	var stype = arguments[1];
	var frameWidth = parseInt(arguments[2]);
	var frameHeight = parseInt(arguments[3]);
	var searchInputWidth = getArgumentValue(parseInt(arguments[4]));
	//var iframeSrc = "http://localhost:8080/summary/gougou103.htm?id=" + sid 
	var iframeSrc = "http://un.so.gougou.com/gougou"+stype+".htm?id=" + sid 
	+ "&inputWidth=" + searchInputWidth
	return '<iframe id="gougouframe" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" '
	+ 'scrolling="no" width="' + frameWidth + '" height="'+frameHeight+'" src="' + iframeSrc + '"></iframe>';
}

function getArgumentValue(arg) {
	return arg ? encodeURIComponent(arg) : "";
}