var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
if (Browser.isFirefox) {
extendEventObject();
}

var $ = function(dName){
return document.getElementById(dName);
};

function extendEventObject() {
Object.prototype.attachEvent = function(type, fc){
this.addEventListener(type.toLowerCase().replace(/^on/ig, ""), fc, false);
};

Object.prototype.detachEvent = function(type, fc){
this.removeEventListener(type.toLowerCase().replace(/^on/ig, ""), fc, false);
};

Event.prototype.__defineGetter__("srcElement", function () {
var node = this.target;
while (node.nodeType != 1) node = node.parentNode;
return node;
});

Event.prototype.__defineGetter__("fromElement", function () {
var node;
if (this.type == "mouseover")
node = this.relatedTarget;
else if (this.type == "mouseout")
node = this.target;
if (!node) return;
while (node.nodeType != 1) node = node.parentNode;
return node;
});

Event.prototype.__defineGetter__("toElement", function () {
var node;
if (this.type == "mouseout")
node = this.relatedTarget;
else if (this.type == "mouseover")
node = this.target;
if (!node) return;
while (node.nodeType != 1) node = node.parentNode;
return node;
});
}

//////////////////
// Helper Funcs //
//////////////////

// used to find the Automation object name
function getDomDocumentPrefix() {
if (getDomDocumentPrefix.prefix)
return getDomDocumentPrefix.prefix;

var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".DomDocument");
return getDomDocumentPrefix.prefix = prefixes[i];
}
catch (ex) {};
}

throw new Error("Could not find an installed XML parser");
}

function getXmlHttpPrefix() {
if (getXmlHttpPrefix.prefix)
return getXmlHttpPrefix.prefix;

var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".XmlHttp");
return getXmlHttpPrefix.prefix = prefixes[i];
}
catch (ex) {};
}

throw new Error("Could not find an installed XMLHttp object");
}


//////////////////////////
// Start the Real Funcs //
//////////////////////////

// XmlHttp factory
function XmlHttp() {}

XmlHttp.create = function () {
try {
// NS & MOZ
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();

// some versions of Moz do not support the readyState property
// and the onreadystate event so we patch it!
if (req.readyState == null) {
req.readyState = 1;
req.addEventListener("load", function () {
req.readyState = 4;
if (typeof req.onreadystatechange == "function")
req.onreadystatechange();
}, false);
}

return req;
}
// IE
if (window.ActiveXObject) {
return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
}
}
catch (ex) {}
// Fail
throw new Error("Your browser does not support XmlHttp objects");
};

// XmlDocument factory
function XmlDocument() {}

XmlDocument.create = function () {
try {
// DOM2, MOZ & NS
if (document.implementation && document.implementation.createDocument) {
var doc = document.implementation.createDocument("", "", null);

// some versions of Moz do not support the readyState property
// and the onreadystate event so we patch it!
if (doc.readyState == null) {
doc.readyState = 1;
doc.addEventListener("load", function () {
doc.readyState = 4;
if (typeof doc.onreadystatechange == "function")
doc.onreadystatechange();
}, false);
}

return doc;
}
if (window.ActiveXObject)
return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
}
catch (ex) {}
throw new Error("Your browser does not support XmlDocument objects");
};

// Create the loadXML method and xml getter for Mozilla
if (window.DOMParser &&
window.XMLSerializer &&
window.Node && Node.prototype && Node.prototype.__defineGetter__) {

// XMLDocument did not extend the Document interface in some versions
// of Mozilla. Extend both!
//XMLDocument.prototype.loadXML = 
Document.prototype.loadXML = function (s) {

// parse the string to a new doc	
var doc2 = (new DOMParser()).parseFromString(s, "text/xml");

// remove all initial children
while (this.hasChildNodes())
this.removeChild(this.lastChild);

// insert and import nodes
for (var i = 0; i < doc2.childNodes.length; i++) {
this.appendChild(this.importNode(doc2.childNodes[i], true));
}
};


/*
* xml getter
*
* This serializes the DOM tree to an XML String
*
* Usage: var sXml = oNode.xml
*
*/
Document.prototype.__defineGetter__("xml", function () {
return (new XMLSerializer()).serializeToString(this);
});
}

var  isIE = document.all?true:false;

if (!isIE){
var  ex;
XMLDocument.prototype.__defineGetter__( "xml" ,  function (){
try {
return   new  XMLSerializer().serializeToString( this );
} catch (ex){
var  d  =  document.createElement( "div" );
d.appendChild( this .cloneNode( true ));
return  d.innerHTML;
}
});
Element.prototype.__defineGetter__( "xml" ,  function (){
try {
return   new  XMLSerializer().serializeToString( this );
} catch (ex){
var  d  =  document.createElement( "div" );
d.appendChild( this .cloneNode( true ));
return  d.innerHTML;
}
});
XMLDocument.prototype.__defineGetter__( "text" ,  function (){
return   this .firstChild.textContent
});
Element.prototype.__defineGetter__( "text" ,  function (){
return   this .textContent
});




XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function (xpath){
var  x = this .selectNodes(xpath)
if ( ! x  ||  x.length < 1 ) return   null ;
return  x[ 0 ];
}
XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function (xpath){
var xpe = new XPathEvaluator();
var doc = (this.ownerDocument==null)?(this.documentElement):(this.ownerDocument.documentElement);
var nsResolver = xpe.createNSResolver(doc);
var result = xpe.evaluate(xpath,this,nsResolver,0,null);
var found = new Array();
var res;
while  (res  =  result.iterateNext())
found.push(res);
return  found;
}
}
//length 为中文字符长度  replaceMent 为截断字符串后，替换的字符
String.prototype.cutToString = function cutToString(length, replaceMent)
{
if(this.length > length)
{
length = length * 2;
var s = "",temp;
var count=0, i=0;
while(count<length)
{
temp = this.substr(i++, 1);
if(temp.charCodeAt(0) <= 127)
count += 1;
else
count += 2;
if(count <= length)
s += temp;
}
return s + replaceMent;
}
else
return this.toString();
}


function Cookie()
{
this.Success = false;
this.baseString = function(){
var s = ";path=/;domain=.qvodsou.com;";
if(this.expireHours > 0)
{
var d = new Date();
d.setTime(d.getTime()+this.expireHours*3600*1000);
s += "expires=" + d.toGMTString();
}
return s;
}
}

Cookie.prototype.SetCookie = function(sName, sValue, expireHours) {
this.expireHours = expireHours;
document.cookie = sName + "=" + escape(sValue) + this.baseString();
}

Cookie.prototype.GetCookie = function(sName) {

var arr = document.cookie.match(new RegExp("(^| )"+sName+"=([^;]*)(;|$)"));
if(arr != null){return unescape(arr[2])};
return "";

}

Cookie.prototype.DeleteCookie = function(sName) {
document.cookie = sName + "=;path=/;domain=.qvodsou.com;expires=Sun, 1 Nov 1970 06:52:02 UTC";
}

function setAdCookie(name, value) //cookies设置 
{ 
	var Then = new Date();
	Then.setTime(Then.getTime() + 6*60*60*1000 ); //秒分  设定1小时弹一次。
	document.cookie = name + "=" + escape (value)+ "; expires=" + Then.toGMTString() +";path=/;domain=.qvodsou.com";
} 

function setNoAd(){
	var cstring = "NOAD";
	var cname = "QVODSOUNOAD";
	setAdCookie(cname,cstring);
	alert("恭喜您，无广告体验设置成功，成功屏蔽弹窗、漂浮和部分广告!");
	window.location.reload();
}
function setYesAd(){
	var cstring = "YESAD";
	var cname = "QVODSOUNOAD";
	setAdCookie(cname,cstring);
	alert("您已经恢复到快播搜广告版，谢谢您对快播搜的支持！"); 
	window.location.reload();
}
function getAdCookie(name) 
{ 
　　var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 
　　if(arr !=null) return unescape(arr[2]); return null; 
}