/*****************************************
	 Author:wq
	 last Modify:2008-07-15
	 Email:tellwangqing@gmail.com
	 Name:cool80 common javascript
*****************************************/

//flashobject
function InsertFlash(Flash,Width,Height,ID){
	document.write("<object id=\"FlashAD\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
	document.write(" ");
	document.write("width=\"" + Width + "\" height=\"" + Height + "\" id=\"" + ID + "\">");
	document.write("<param name=\"movie\" value=\"" + Flash + "\">");
	document.write("<param name=\"quality\" value=\"transparent\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
	document.write("<embed src=\"" + Flash + "\" quality=\"transparent\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"");
	document.write("type=\"application/x-shockwave-flash\" width=\"" + Width + "\" height=\"" + Height + "\"></embed>");
	document.write("</object>");
}
//<script type="text/javascript" language="javascript">InsertFlash("../images/s3/ad.swf",206,160,"top");

//ÔËÐÐ´úÂë¿ò
function runCode(obj)
{
    var winname = window.open("", "_blank","resizable=yes,scrollbars=yes,status=yes");
    winname.document.open("text/html", "replace");
    winname.document.writeln(obj.value);
    winname.document.close();
}

function saveCode(obj,filename)
{
    var winname = window.open("", "", "top=10000,left=10000");
    winname.document.open("text/html", "replace");
    winname.document.writeln(obj.value);
    winname.document.execCommand("saveas", "", filename + ".htm");
    winname.close();
}

function copyCode(obj)
{
    var rng = document.body.createTextRange();
    rng.moveToElementText(obj);
    rng.scrollIntoView();
    rng.select();
    rng.execCommand("Copy");
    rng.collapse(false);
}

// Smooth Scroll Back to Top
var scrollToTop = function(){ $('a[@href=#top]').click(function(){ backToTop(); return false;} ) };
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 35);
    }
}