try {
    document.execCommand("BackgroundImageCache", false, true);
} catch(ignored) {}


// flashWrite(url, width, height, id, bg, window)
function flashWrite(url,w,h,id,bg,win){

	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='menu' value='false' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";

	document.write(flashStr);

}

// SubLeftMenu //
function ContMenu(num){
	var viewLayer = document.getElementById("Togmenu"+num);
	var viewm = document.getElementById("Menu"+num);

	if (viewLayer.style.display=="block"){
		viewLayer.style.display="none";
		viewm.className = viewm.className.replace("menu", "menu_active");

		}else{
		viewLayer.style.display="block";
		viewm.className = viewm.className.replace("menu_active", "menu");
	}
}


// Top Navi //
/*   removed by sean 20090217
hideElements = new Array();
function findForm() {
	for (var f=0; f<window.document.forms.length; f++) {
		var theForm = window.document.forms[f];
		for (var e=0; e<theForm.elements.length; e++) {
			var theElem = theForm.elements[e];
			if (theElem.type.substr(0,6) == "select") {
				hideElements.push(theElem);
			}
		}
	}
}
*/

function initnav(obj) {
	var av = navigator.appVersion.toLowerCase();
	var platform;
	if (av.indexOf("mac") != -1) {
		platform = "mac";
	} else if (av.indexOf("windows") != -1) {
		platform = "win";
	}
	var isIE = (navigator.appName == "Microsoft Internet Explorer");
	if (document.getElementById && document.getElementById(obj)) {
		navRoot = document.getElementById(obj);
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.offsetLeft > 1004) {
				var adjust = 1004-node.offsetLeft;
				for (var j=0; j<node.childNodes.length; j++) {
					if (node.childNodes[j].nodeName.toUpperCase() == 'UL') {
						node.childNodes[j].style.left = adjust+'px';
					}
				}
			}
			node.onmouseover = function() {
				if (this.className.indexOf('onmenu') != -1) {
					if (this.className.indexOf('solid') != -1) {
						this.className = 'onmenu_off solid';
					} else {
						this.className = 'onmenu_off';
					}
					if (isIE) {
						for (e=0; e<hideElements.length; e++) {
							var formElem = document.getElementById(hideElements[e].id);
							if (formElem != null) {
								formElem.style.visibility = 'hidden';
							}
						}
					}
				}
			}
			node.onmouseout = function() {
				if (this.className.indexOf('onmenu_off') != -1) {
					if (this.className.indexOf('solid') != -1) {
						this.className = 'onmenu solid';
					} else {
						this.className = 'onmenu'
					}
					if (isIE) {
						for (e=0; e<hideElements.length; e++) {
							var formElem = document.getElementById(hideElements[e].id);
							if (formElem != null) {
								formElem.style.visibility = 'visible';
							}
						}
					}
				}
			}
		}
	}

	if (navigator.appName == "Microsoft Internet Explorer" && platform != "mac") {
		isIE = true;
		//window.attachEvent("onload", findForm);		//removed by sean 20090217
		//window.onload = findForm;
	}
}
// Top Navi //


// tab //
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;
	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "over_tab")
			thismenu = tabAnchor.item(i);
		else
			continue;
		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return false;
			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				currentmenu.className = currentmenu.className.replace("over_tab_on", "over_tab");
			}
			this.targetEl.style.display = "";
			this.className = this.className.replace("over_tab", "over_tab_on");
			this.container.current = this;
			return false;
		};
		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
	if (tabContainer.first)
		tabContainer.first.onclick();
}

function initTabMenu2(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;
	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "over_tab2")
			thismenu = tabAnchor.item(i);
		else
			continue;
		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return false;
			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				currentmenu.className = currentmenu.className.replace("over_tab2_on", "over_tab2");
			}
			this.targetEl.style.display = "";
			this.className = this.className.replace("over_tab2", "over_tab2_on");
			this.container.current = this;
			return false;
		};
		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
	if (tabContainer.first)
		tabContainer.first.onclick();
}

// guide-beginners //
function listChange(name){
	var obj = (document.getElementById(name).nodeName!="DL") ? document.getElementById(name).getElementsByTagName("dl")[0] : document.getElementById(name) ;
	var objTitle = obj.getElementsByTagName("dt");
	var objCont = obj.getElementsByTagName("dd");
	for( i=0; i < objTitle.length; i++ ){
		objCont[i].style.display = "none";
		objTitle[i].onclick = function(){ listView(name,this,obj,objTitle,objCont) }
	}
}
function listView(name,item,obj,objTitle,objCont){
	for( i=0; i < objTitle.length; i++ ){
		objTitle[i].className = (objTitle[i]==item&&objTitle[i].className!="quick-on") ? "quick-on" : "" ;
		objCont[i].style.display = (objTitle[i]==item&&objTitle[i].className=="quick-on") ? "block" : "none" ;
	}
}

function downClick(loggedIn,dntype){
	if(loggedIn){
		window.open('/support/download_file/?dntype='+dntype);
	}else{
		loc = location.href;
		Set_Cookie('origin',loc,0,'/','.outspark.com',0);
		location.href='https://login.outspark.com/?redirect='+encodeURIComponent(loc);
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


function goto_byselect(sel)
{
	var index = sel.selectedIndex;
	if (sel.options[index].value != '') {
		location.href = './?'+sel.id+'='+sel.options[index].value;
	}
}

function ChoiceChar(sel) {
	var index = sel.selectedIndex;
    var cnt = sel.options.length;
    for(var i=0;i<cnt;i++) {
        var charLayer = document.getElementById(sel.id+i);
        charLayer.style.display="none"
    }
	if (sel.options[index].value != '') {
        var viewLayer = document.getElementById(sel.id+sel.options[index].value);
        viewLayer.style.display="block"
	}
}

function defaultChar(divName){
    var viewLayer = document.getElementById(divName);
    if(viewLayer)viewLayer.style.display="block";
}


// added 5/23 by vchoy

function pachinkoPlusActionHandler(action, game, variant) {
	switch (action) { 
		case 'back' : 
			location.href = '/' + game + '/' + variant;
			break;
		case 'charge' :
			location.href = 'https://payment.outspark.com';
	}
}

function changeDisplay(id){
	var element = document.getElementById(id);
	var dis = element.style.display;
	if (dis =='block'){
		element.style.display = 'none';
	}else{
		element.style.display = 'block';
	}
}

function delWish(game,itemid){
	var ingamePath = chkIngame();
	if(game && itemid)location.href=ingamePath+'/'+game+'/wish/rm/'+itemid;
}

function checkSearch(){
	var sForm = document.forms['searchForm'];
	var q = sForm.q.value;
	if (q == '' || q =='Enter search value'){
		alert('Please, enter search value');
		sForm.q.value = '';
		sForm.q.focus();
	}else{
		sForm.submit();
	}
}

/*create a thickbox for our form submittal*/
//when the document is ready
$(document).ready(function() {
	
	//check popup;
	//modalPopup();			//remove welcome popup of potal store -- sean 20090720
	
	// find friends auto-complete function
	$("#recieverName").autocomplete("/common/search_friends", {
		width: 260,
		selectFirst: false
	});
	
	//wrap form#comparison in an ajaxForm object
	$('#buyItemFrm').ajaxForm({
		//intercept the submit event with a callback
		beforeSubmit:  function(formData, jqForm, options) {
			//serialize form data; append to the form action; tack on Thickbox params
			var URL = jqForm[0].action + "?" + $.param(formData);
			if (OSK.inGame) {
				URL += "&KeepThis=true&height=550&width=515&modal=true";
			} else {
				URL += "&KeepThis=true&height=370&width=865&modal=true";
			}
			
			var itemId = $("#ItemID").val();
			var userid = $("#userid").val();
			if(!itemId){alert('Item id is not defined');return false;}
			if(!userid){$("#output1").show().html('Please <a href="http://login.outspark.com">log in</a> to make a purchase.');return false;}	
			
			//call Thickbox directly
			var caption = null;
			var imageGroup = false
			tb_show(caption,URL,imageGroup);
			//cancel the form submission by returning false
			return false;
		}
	});	
	
	
	//wrap form#comparison in an ajaxForm object
	$('#comparison').ajaxForm({
		//intercept the submit event with a callback
		beforeSubmit:  function(formData, jqForm, options) {
			//serialize form data; append to the form action; tack on Thickbox params
			var URL = jqForm[0].action + "?" + $.param(formData);
			 if (OSK.inGame) {
                URL += "&KeepThis=true&height=550&width=515&modal=true";
            } else {
                URL += "&KeepThis=true&height=370&width=865&modal=true";
            }	
			/*URL += "&KeepThis=true&height=370&width=865&modal=true";*/
			
			var queryString = $("#recieverName").val();
			var userid = $("#userid").val();
			if(!userid){$("#output1").show().html('Please <a href="http://login.outspark.com">log in</a> to make a purchase.');return false;}	
			if(!queryString){
				alert('Please, enter the SparkID');
				return false;
			}
			// check gift message length - sean 20090722 
			var form = jqForm[0];
			var maxCommentLen = 500;
			var commentLen = form.giftMessage.value.length;
			if (commentLen > maxCommentLen) {             
				$("#output1").show().html('Comments cannot exceed ' + maxCommentLen + ' characters in length.'+'(Now:'+commentLen+')');return false;
			}  
			
			//call Thickbox directly
			var caption = null;
			var imageGroup = false
			tb_show(caption,URL,imageGroup);
			//cancel the form submission by returning false
			return false;
		}
	});


	var options = { 
        target:        '#output1',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback
         // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
         // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };
    // bind form using 'ajaxForm' 
    $('#sendwish').ajaxForm(options);
});


// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString);
	rtn = true;
	var queryString = $("#storeWishSendTo > option:selected").val();
	if (queryString==''){
		alert('Please, choose your friend ');
		rtn = false;
	}	
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return rtn; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  {}

// fiesta rarefinds button actions
function fiesta_btn(act){
	var ingamePath = chkIngame();
	switch (act){
		case 'back':
		location.href = ingamePath + '/fiesta/minigames/rarefinds';
		break;
		case 'buy':
		window.open('https://payment.outspark.com/charge');
		break;
		case 'ok_fiesta':
		window.open('http://store.outspark.com'+ingamePath+'/fiesta');
		break;
		default:
		alert('not defined');
	}
}

function chkIngame(){
	var rtn = '';
	var path = jQuery.url.segment(0);
	if (path=='game')rtn = '/game';			//adding ingame url
	return rtn;
}


function modalPopup(){
  var caption = null;
  var popupUrl = "/html/welcome_profile_gift.html?keepThis=true&amp;width=692&amp;height=500&amp;modal=true";
  var imageGroup = false
  var cooK = Get_Cookie('giftwelcome');

  var path = jQuery.url.attr("path");
  if (!cooK && path=='/portal'){		
	tb_show(caption,popupUrl,imageGroup);
  }	
} 

function selfSolsticeClose(){
	if(navigator.appVersion.indexOf("MSIE 7") > 0 ) {
	  window.open("about:blank","_self").close(); //for IE 7.0
	}
	else {
	  self.opener=self;
	  self.close();
	}
}

function selfClose(){
	if(navigator.appVersion.indexOf("MSIE 7") > 0 ) {
	  window.open("about:blank","_self").close(); //for IE 7.0
	}
	else {
	  self.opener=self;
	  self.close();
	}
}

function sortItems() {
	var sortBy = document.getElementById('sortCategories');
	var selected = sortBy.options[sortBy.selectedIndex].value;
	document.location.href=selected;
}

var gamenavi = {
	contain : null,obj : null, itemList : [], subMr : 6, repeat : null,
	set : function(contain){
		gamenavi.contain = contain;
		for(d1=0,i=0;i<gamenavi.contain.childNodes.length;i++){
			if(gamenavi.contain.childNodes[i].nodeType==1){
				gamenavi.itemList[d1] = gamenavi.contain.childNodes[i];
				gamenavi.itemList[d1].d1a = gamenavi.itemList[d1].getElementsByTagName("a")[0];
				gamenavi.itemList[d1].onmouseover = gamenavi.view;
				gamenavi.itemList[d1].onmouseout = function(){ this.className=""; if(this.d2!=null) this.d2.style.display="none" }
				gamenavi.itemList[d1].d2 = (gamenavi.itemList[d1].getElementsByTagName("div").length > 0) ? gamenavi.itemList[d1].getElementsByTagName("div")[0] : null;
				if(gamenavi.itemList[d1].d2!=null){
					gamenavi.itemList[d1].d2.w = gamenavi.itemList[d1].d2.offsetWidth;
					gamenavi.itemList[d1].d2.style.display = "none";
				}

				d1++;
			}
		}
	},
	view : function(obj){
		this.className="this";
		if(this.d2!=null){ 
			this.d2.style.display="block";
			this.d2.style.top = getDoffset(gamenavi.contain)[1]+gamenavi.contain.offsetHeight+"px";
			this.d2.style.left = getDoffset(this)[0]+(this.offsetWidth/2)-(this.d2.w/2)+"px";
		}
	}
}


function initMenu() {
	
}
