var usat = new clsUsat();
usat.init();

function clsUsat () {
    this.util = new clsUtil();
	this.page=new clsPage();
	this.cookie = new clsCookie();
	this.init = fxInit;
	
	function fxInit () {   // member of clsUsat
		this.util.init();
	}   // fxInit

	function clsUtil () {   // member of clsUsat
		this.init = fxInit;
		
		function fxInit () {   // member of clsUtil
			String.prototype.trim = fxTrim;
		}  // fxInit
		
		function fxTrim (strInput) {   // member of clsUtil
			/*
				Trim all leading and trailing whitespace using Regular Expressions
			*/
			var strResult = null;
			if (strInput == null)
				strInput = this;
			if (strInput){
				strResult = new String(strInput);
				strResult = strResult.replace(/^\s+/, "");
				strResult = strResult.replace(/\s+$/, "");
			}
			return(strResult);
		}   // fxTrim
	}   // clsUtil

	function clsCookie () {   // member of clsUsat
		this.set = fxSet;
		this.get = fxGet;
		this.remove = fxRemove;
		this.buildMatrix = fxBuildMatrix;
		
		function fxSet (strKey, strValue, dtExpires,
						strPath, strDomain, blnSecure) {   // member of clsCookie
			var strCookie = strKey + "=" + escape(strValue)+ ";";
			if (dtExpires){
				strCookie += "expires=" + dtExpires.toUTCString()+ ";";
			}   // if
			if ((strPath) && (strPath != "")){
				strCookie += "path=" + strPath+ ";";
			}   // if
			if ((strDomain) && (strDomain != "")){
				strCookie += "domain=" + strDomain + ";";
			}   // if
			if (blnSecure){
				strCookie += "secure";
			}   // if
			document.cookie = strCookie;
		}   // fxSet

		function fxGet (strKey) {   // member of clsCookie
			var strValue = null;
			var arrCookies = this.buildMatrix(new String(document.cookie));
			for (var intIndex=0;intIndex<arrCookies.length;intIndex++) {
				if (arrCookies[intIndex][0] == strKey){
					strValue = arrCookies[intIndex][1];
					break;
				}
			}   // for
			return strValue;
		}   // fxGet

		function fxBuildMatrix (strCookies) {   // member of clsCookie
			var arrCookie;
			var arrCookies = strCookies.split(";");
			for (var intIndex=0;intIndex<arrCookies.length;intIndex++){
				arrCookie = arrCookies[intIndex].trim().split("=");
				arrCookie[1] = unescape(arrCookie[1]);
				arrCookies[intIndex] = arrCookie;
			}   // for
			return arrCookies;
		}   // fxBuildMatrix

		function fxRemove (strKey, strPath, strDomain) {   // member of clsCookie
			var strCookie, dtYesterday;
			var strValue = this.get(strKey);
			if (strValue){   // the cookie exists so delete it.
				strCookie = strKey + "=;";
				if ((strPath) && (strPath != "")){
					strCookie += "path=" + strPath + ";";
				}   // if
				if ((strDomain) && (strDomain != "")){
					strCookie += "domain=" + strDomain + ";";
				}   // if
				dtYesterday = new Date();
				dtYesterday.setDate(dtYesterday.getDate() - 1);
				strCookie += "expires=" + dtYesterday.toGMTString() + ";";
				document.cookie = strCookie;
			}   // if
			return strValue;
		}   // fxRemove
	}   // clsCookie
	function clsPage(){
		this.writeObject=fxWriteObject;
		this.writeString=fxWriteString;

		function fxWriteObject(){
			document.write(usatGenerateObject("usatGenerateObject",true,arguments));
		}
		function fxWriteString(objectString){
			document.write(objectString);
		}
	}
}   // clsUsat

function usatAddAttribute(prefix,slotName,tagName){
	var value;
	value=gTagAttrs[prefix+slotName];
	if(null==value)
		value=gTagAttrs[slotName];
	if(null !=value){
		if(0==slotName.indexOf(prefix)&&(null==tagName))
			tagName=slotName.substring(prefix.length);
		if(null==tagName)
			tagName=slotName;
		return tagName+'="'+value+'" ';
	}
	else
	return "";
}
function usatAddObjectAttr(slotName,tagName){
	if(0==slotName.indexOf("emb#"))
		return "";
	if(0==slotName.indexOf("obj#")&&(null==tagName))
		tagName=slotName.substring(4);
		return usatAddAttribute("obj#",slotName,tagName);
}
function usatAddEmbedAttr(slotName,tagName){
	if(0==slotName.indexOf("obj#"))
		return "";
	if(0==slotName.indexOf("emb#")&&(null==tagName))
		tagName=slotName.substring(4);
		return usatAddAttribute("emb#",slotName,tagName);
}
function usatAddObjectParam(slotName,generateXHTML){
	var paramValue;
	var paramStr="";
	var endTagChar=(generateXHTML)?' />':'>';
	if(-1==slotName.indexOf("emb#")){
		paramValue=gTagAttrs["obj#"+slotName];
		if(null==paramValue)
			paramValue=gTagAttrs[slotName];
		if(0==slotName.indexOf("obj#"))
			slotName=slotName.substring(4);
		if(null !=paramValue)
		paramStr='  <param name="'+slotName+'" value="'+paramValue+'"'+endTagChar+'\n';
	}
	return paramStr;
}
function usatDeleteTagAttrs(){
	for(var ndx=0;ndx<arguments.length;ndx++){
		var attrName=arguments[ndx];
		delete gTagAttrs[attrName];
	delete gTagAttrs["emb#"+attrName];
	delete gTagAttrs["obj#"+attrName];
	}
}

function usatGenerateObject(callingFcnName,generateXHTML,args){
	if(args.length<4||(0!=(args.length%2))){
		usatComplain(callingFcnName,gArgCountErr);
		errMsg='The "%%" function requires an even number of arguments. Arguments should be in the form "atttributeName", "attributeValue", ...';
		errMsg=errMsg.replace("%%",callingFcnName);
		return "<!-- "+errMsg+" -->";
	}
	gTagAttrs=new Array();
	gTagAttrs["src"]=args[0];
	gTagAttrs["width"]=args[1];
	gTagAttrs["height"]=args[2];
	gTagAttrs["classid"]="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	gTagAttrs["pluginspage"]="http://www.macromedia.com/go/getflashplayer/";
	var activexVers=args[3]
	if((null==activexVers)||(""==activexVers))
		activexVers="8,0,24,0";
	gTagAttrs["codebase"]="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+activexVers;
	var	attrName,attrValue;
	for(var ndx=4;ndx<args.length;ndx+=2){
		attrName=args[ndx].toLowerCase();
		attrValue=args[ndx+1];
		if("name"==attrName||"id"==attrName)
			gTagAttrs["name"]=attrValue;
		else
			gTagAttrs[attrName]=attrValue;
	}
	var objTag='<object '+usatAddObjectAttr("classid")+usatAddObjectAttr("width")+usatAddObjectAttr("height")+usatAddObjectAttr("codebase")+usatAddObjectAttr("name","id")+usatAddObjectAttr("tabindex")+usatAddObjectAttr("hspace")+usatAddObjectAttr("vspace")+usatAddObjectAttr("border")+usatAddObjectAttr("align")+usatAddObjectAttr("class")+usatAddObjectAttr("title")+usatAddObjectAttr("accesskey")+usatAddObjectAttr("noexternaldata")+'>\n'+usatAddObjectParam("src",generateXHTML);
	var embedTag='  <embed '+usatAddEmbedAttr("src")+usatAddEmbedAttr("width")+usatAddEmbedAttr("height")+usatAddEmbedAttr("pluginspage")+usatAddEmbedAttr("name")+usatAddEmbedAttr("align")+usatAddEmbedAttr("tabindex");
	usatDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex","hspace","vspace","border","align","noexternaldata","class","title","accesskey");
	for(var attrName in gTagAttrs){
		attrValue=gTagAttrs[attrName];
		if(null !=attrValue){
			embedTag+=usatAddEmbedAttr(attrName);
			objTag+=usatAddObjectParam(attrName,generateXHTML);
		}
	}
	return objTag+embedTag+'> </em'+'bed>\n</ob'+'ject'+'>';
}
function renderQQ(qqID,qqSection,qqCount,qqDisplay) {
	switch (qqDisplay){
		case 'notch':
        qqOffset = 100;
        qqItemHeight = 45;
        qqWidth = 245;
        break;
		case 'default':
		qqOffset = 100;
		qqItemHeight = 46;
		break;
		case 'va':
		qqOffset = 85;
		qqItemHeight = 36;
		break;
		case 'front':
		qqOffset = 85;
		qqItemHeight = 36;
		break;
		default : 
		qqOffset = 100;
		qqItemHeight = 46;
	} 
        var qqHeight = (qqOffset + (qqCount * qqItemHeight)) +'px';  
        document.write('<div class="qqBox" style="height:' + qqHeight + '"><iframe id="qqFrame' + qqID + '" name="qqFrame' + qqID + '" class="qqFrame" src="http://content.usatoday.com/quickquestion/jquery/1.0.2.html?qqID=' + qqID + '&section=' + qqSection + '&display=' + qqDisplay + '" width="100%" height="100%" frameborder="0" border="0"></iframe></div>');  
}
