/**************************************************************************
*
*	Functions
*
*	setInfoBoxDefaultText	- Sets pages default info box text.
*	setInfoBoxText			- Sets temporary infobox text. For mouseovers.
*	returnInfoBox			- Return info box to default position and display
*							  default text. For mouseouts.
							  
*	openConfirmBox			- Open confirm box using link when user press ok.
*	openConfirmBoxForForm	- Open confirm box using form submit when user prsee ok.
*
***************************************************************************/

	function getStyleObject(objectId) {
	    // cross-browser function to get an object's style object given its
	    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
			return document.getElementById(objectId).style;
	    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
			return document.all(objectId).style;
	    } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
			return document.layers[objectId];
	    } else {
			return false;
		}
    }


/************************************************************************
*	Infobox
************************************************************************/
	
	var defaultInfoBoxText = '';
	
	function setInfoBoxDefaultText(txt) {
		defaultInfoBoxText = txt;
		setInfoBoxText(txt);
	}
	
	function alertWhere() {

			var tempScrollTop = 0;

			if (document.documentElement && document.documentElement.scrollTop) {
			// IE6 +4.01 and user has scrolled
				tempScrollTop = document.documentElement.scrollTop
			} else if (document.body && document.body.scrollTop) {
				// IE5 or DTD 3.2
				tempScrollTop = document.body.scrollTop;
			}		
			
			
			if (tempScrollTop > 350) { 
				
				var elem2 = document.getElementById('side_phone_bar');
				if (elem2 != null) {
					elem2.style.position = 'fixed';	
					elem2.style.visibility = "visible";
					elem2.style.right="180px";
					elem2.style.top="300px";
				}
				
			} else {
	
				var elem2 = document.getElementById('side_phone_bar');
				if (elem2 != null) {
					elem2.style.position = 'absolute';	
					elem2.style.right = '300px';
					elem2.style.top = '80px';
					elem2.style.visibility = "visible";
			}
		}
	}
	
	var infoBoxFloating = false;
	
	function setInfoBoxText(txt) {
		var elem = document.getElementById('info_box_text');
		if (elem != null) {
			elem.innerHTML  = txt;	
		}
		
			if (!infoBoxFloating) {
			var tempScrollTop = 0;
			if (document.documentElement && document.documentElement.scrollTop) {
			// IE6 +4.01 and user has scrolled
				tempScrollTop = document.documentElement.scrollTop
			} else if (document.body && document.body.scrollTop) {
				// IE5 or DTD 3.2
				tempScrollTop = document.body.scrollTop;
			}		
			
			if (tempScrollTop > 200) {
				infoBoxFloating = true;
				var elem2 = document.getElementById('infobox_location');
				if (elem2 != null) {
					elem2.style.position = 'fixed';	
					elem2.style.top = "2px";
					elem2.style.left = "2%";
					elem2.style.width =  "80%";
				}
			}
		}
	}
	
	function returnInfoBox() {
		var elem2 = document.getElementById('infobox_location');
		if (elem2 != null) {
			elem2.style.visibility = 'hidden';
			elem2.style.position = 'static';
			elem2.style.top = "0px";
			elem2.style.left = "0px";
			elem2.style.width =  "680px";
			elem2.style.visibility = 'visible';
			infoBoxFloating = false;
		}
	}
	
/************************************************************************
*	Message box. To show some basic message to user.
************************************************************************/	
	function closeMessageBox() {

		var elem = document.getElementById('base_messagebox');
		var elem2 = document.getElementById('base_messagebox_positioner');		
		if (elem != null) {
			elem.style.visibility='hidden';
			elem2.style.visibility='hidden';
			elem.style.zIndex=-1;
			elem2.style.zIndex=-1;						
		}
	}

/************************************************************************
*	Validation messages.
************************************************************************/	
	
	function openValidationMessage(msg) {
		var elem = document.getElementById('validation_message');
		var elemContent = document.getElementById('validation_message_content');		
		if (elem != null) {
			elem.style.visibility = "visible";
			elemContent.innerHTML = msg;
		}	
	}
	function closeValidationMessage() {
		var elem = document.getElementById('validation_message');	
		if (elem != null) {
			elem.style.visibility = "hidden";
		}	
	}
	function moveValidationMessageBox(x, y) {
		var elem = document.getElementById('validation_message');	
		if (elem != null) {
			elem.style.left = x +"px";
			elem.style.top = y +"px";			
		}	
	}

/***********************************************************************************
* Show / Hide elements
***********************************************************************************/	
	
	/*
		Number box (Small geen box with number, mouse over for different number bars).
	*/
	function showNumberBox(inputObj, num, parentObj) {
		var top = numberBox_getTopPos(inputObj, parentObj);
		var left = numberBox_getLeftPos(inputObj, parentObj);
		top-= 20;
		left += 27;
		
		var elem = getStyleObject('number_box');
		if (elem != null) {
			elem.visibility='visible';
			elem.zIndex="100";
			elem.top=top+"px";
			elem.left=left+"px";
			document.getElementById('number_box_text').innerHTML = ""+num;
		}
	}
	
	function hideNumberBox() {
		var elem = getStyleObject('number_box');
		if (elem != null) {
			elem.visibility='hidden';
			elem.zIndex="-10";
			elem.top="0px";
			elem.left="0px";

		}
	}

	/*
		Div with icon.
	*/
	
	function openBaseLoadingIconFromScrollTop(x,y) {
		
		var tempScrollTop = 0;

		if (document.documentElement && document.documentElement.scrollTop) {
		// IE6 +4.01 and user has scrolled
			tempScrollTop = document.documentElement.scrollTop
		} else if (document.body && document.body.scrollTop) {
			// IE5 or DTD 3.2
			tempScrollTop = document.body.scrollTop;
		}	
		
		var elem = getStyleObject('base_loading_icon');
		if (elem != null) {
			elem.visibility='visible';
			elem.zIndex="100";
			elem.top=(tempScrollTop+y)+"px";
			elem.left=x+"px";

		}
	}	

	/*
		Div with icon.
	*/
	
	function openBaseLoadingIcon(x, y) {
		var elem = getStyleObject('base_loading_icon');
		if (elem != null) {
			elem.visibility='visible';
			elem.zIndex="100";
			elem.top=y+"px";
			elem.left=x+"px";

		}
	}	
	
	function hideBaseLoadingIcon() {
		var elem = getStyleObject('base_loading_icon');
		if (elem != null) {
			elem.visibility='hidden';
			elem.zIndex="-10";
			elem.top="0px";
			elem.left="0px";

		}
	}	
	
	/* Pal Icon Mouse Over */
	var isPalIconMOVisible = false;
	var palIconMOPreviewImage = null;
	
	function showPalIconMO(inputObj, palImageURL, additionalText, parentObj) {
	
		var top = numberBox_getTopPos(inputObj, parentObj);
		var left = numberBox_getLeftPos(inputObj, parentObj);
		top-= 80;
		left += 40;
		
		if (palIconMOPreviewImage == null )
			palIconMOPreviewImage = document.images.pal_icon_mouse_over_img
		
		if (isPalIconMOVisible == false) {
			var elem = getStyleObject('pal_icon_mouse_over');
			palIconMOPreviewImage.src=palImageURL;
			if (elem != null) {
				isPalIconMOVisible = true;
				elem.visibility='visible';
				elem.zIndex=100;
				elem.top=top+"px";
				elem.left=left+"px";
				//document.getElementById('number_box_text').innerHTML = ""+num;
			}	
		}

		var elem2 = getStyleObject('pal_icon_additional_text');
		if (elem2 != null) {
			if (additionalText != null && additionalText.length > 0) {
				document.getElementById('pal_icon_additional_text').innerHTML= additionalText;
				elem2.visibility='visible';
				elem2.zIndex=101;
				elem2.top=(top+130)+"px";
				elem2.left=(left-120)+"px";				
			} else {
				elem2.zIndex=-10;
				elem2.visibility='hidden';			
			}
		} else {
			alert ("NULL: "+additionalText);
		}
	}
	
	function hidePalIconMO() {
		if (isPalIconMOVisible == true) {
			var elem = getStyleObject('pal_icon_mouse_over');
			if (elem != null) {
				elem.visibility='hidden';
				elem.zIndex=-10;
				elem.top="-1000px";
				elem.left="60px";
				//palIconMOPreviewImage.src="";
			}
			var elem2 = getStyleObject('pal_icon_additional_text');
			if (elem2 != null) {
				elem2.visibility='hidden';	
				elem2.zIndex=-10;
			}
			isPalIconMOVisible = false;
		}
	}	
	/* Number for stat bars */

	function numberBox_getTopPos(inputObj, parentObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	  if (parentObj != null) {
	  	//alert ("ScrollTop: "+parentObj.scrollTop);
	  	returnValue -= parentObj.scrollTop;
	  }
	  return returnValue;
	}
	
	function numberBox_getLeftPos(inputObj, parentObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	  return returnValue;
	}
	
/***********************************************************************************
* Confirm box
***********************************************************************************/

var confirmBoxLink = null;
var confirmBoxForm = null;


function openConfirmBox(header, message, link, x, y) {
	confirmBoxForm = null;
	var elemHeader = document.getElementById('confirm_box_header');
	if (elemHeader != null) {
		elemHeader.innerHTML = header;
	}


	var elemMsg = document.getElementById('confirm_box_message');
	if (elemMsg != null) {
		elemMsg.innerHTML = message;
	}
	
	//base_confirm_box_positioner
	var elem = document.getElementById('confirm_box');
	if (elem != null) {
		elem.style.visibility = 'visible';
		elem.style.position = 'relative';
		elem.style.top = y+"px";
		elem.style.left = x+"px";
		elem.style.zIndex=20;	

	}
	
	confirmBoxLink = link;
	
}

function openConfirmBoxForForm(header, message, formi, x, y) {
	confirmBoxLink = null;
	var elemHeader = document.getElementById('confirm_box_header');
	if (elemHeader != null) {
		elemHeader.innerHTML = header;
	}


	var elemMsg = document.getElementById('confirm_box_message');
	if (elemMsg != null) {
		elemMsg.innerHTML = message;
	}
	
	//base_confirm_box_positioner
	var elem = document.getElementById('confirm_box');
	if (elem != null) {
		elem.style.visibility = 'visible';
		elem.style.position = 'relative';
		elem.style.top = y+"px";
		elem.style.left = x+"px";
		elem.style.zIndex=20;	

	}
	
	confirmBoxForm = formi;
	
}

function closeConfirmBox() {

	var elem = document.getElementById('confirm_box');	
	if (elem != null) {
		elem.style.visibility='hidden';
		elem.style.zIndex=-1;				
	}

}

function execConfirmBoxOk()
{
	if (confirmBoxLink != null) {
		link = confirmBoxLink;
		confirmBoxLink = '';
		window.location = link;
		closeConfirmBox();
	} else if (confirmBoxForm != null){
		confirmBoxForm.submit();
		closeConfirmBox();		
	} else {
		alert("Error in confirm box. Cannot execute command.");
	}

	
}
	
/***********************************************************************************
* Buttons
***********************************************************************************/

function baseBlueButton_goLite(FRM,BTN){
   window.document.forms[FRM].elements[BTN].style.color = "#CCCCFF";
   window.document.forms[FRM].elements[BTN].style.backgroundColor = "#5587EE";
   window.document.forms[FRM].elements[BTN].style.borderStyle = "inset";
}

function baseBlueButton_goDim(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#FFFFFF";
   window.document.forms[FRM].elements[BTN].style.backgroundColor = "#7799FF";
   window.document.forms[FRM].elements[BTN].style.borderStyle = "outset";
}


/***********************************************************************************
* Mouse trail
***********************************************************************************/

var trailImageX = 50;
var trailImageY = 40;
var trailImageSrc = "http://ironstar.game-server.cc/pp_res/applet/release/res/item/qvga/arctic_fluffy_penguin.png";

var offsetFromMouseX= 2;
var offsetFromMouseY= 0;

var displayDuration=0 //duration in seconds image should remain visible. 0 for always.

if (document.getElementById || document.all) {
	//document.write('');
}

function getTrailObj(){
	if (document.getElementById) {
		return document.getElementById("mouse_trail_image_id").style
	} else if (document.all) {
		return document.all.trailimagid.style
	}
}

function trueBody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showTrail(paramTrailImageSrc) {
	var elem = getTrailObj();
	elem.visibility = "visible";
	elem.zIndex = 2000;
	document.images.mouse_trail_image_id_src.src=paramTrailImageSrc;

}

function hideTrail(){
	var elem = getTrailObj();
	elem.visibility = "hidden";
	elem.zIndex = -1;	
}

function followMouse(e) {
	var xcoord=offsetFromMouseX;
	var ycoord=offsetFromMouseY;
	if (typeof e != "undefined") {
		//alert("xcoord+=e.pageX;");
		xcoord+=e.pageX;
		ycoord+=e.pageY;
	} else if (typeof window.event !="undefined") {
		// In IE those coordinates are little different. Atleast IE 7.
		xcoord+=trueBody().scrollLeft+event.clientX -2;
		ycoord+=trueBody().scrollTop+event.clientY -2;
		xcoord+=1;
		ycoord+=1;
	}
	var docwidth=document.all? trueBody().scrollLeft+trueBody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.max(trueBody().scrollHeight, trueBody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	if (xcoord+trailImageX+3>docwidth || ycoord+trailImageY> docheight) {
		getTrailObj().display="none";
 	} else { 
		getTrailObj().display="";
	}
	getTrailObj().left=xcoord+"px";
	getTrailObj().top=ycoord+"px";
}

/***********************************************************************************
* Languages
***********************************************************************************/

var africaArray =  new Array("('Select country','',true,true)",
"('Ethiopia')",
"('Somalia')",
"('South Africa')",
"('Other')");
var middleeastArray =  new Array("('Select country','',true,true)",
"('Egypt')",
"('Iran')",
"('Israel')",
"('Kuwait')",
"('Lebanon')",
"('Morocco')",
"('Saudi Arabia')",
"('Syria')",
"('Turkey')",
"('U. A. Emirates')",
"('Other')");
var asiaArray =  new Array("('Select country','',true,true)",
"('Armenia')",
"('Bangladesh')",
"('Cambodia')",
"('China')",
"('India')",
"('Indonesia')",
"('Japan')",
"('Malaysia')",
"('Myanmar')",
"('Nepal')",
"('Pakistan')",
"('Philippines')",
"('Singapore')",
"('South Korea')",
"('Sri Lanka')",
"('Taiwan')",
"('Thailand')",
"('Uzbekistan')",
"('Vietnam')",
"('Other')");
var europeArray =  new Array("('Select country','',true,true)",
"('Albania')",
"('Austria')",
"('Belarus')",
"('Belgium')",
"('Bosnia')",
"('Bulgaria')",
"('Croatia')",
"('Cyprus')",
"('Czech Rep.')",
"('Denmark')",
"('Estonia')",
"('Finland')",
"('France')",
"('Germany')",
"('Greece')",
"('Hungary')",
"('Iceland')",
"('Ireland')",
"('Italy')",
"('Latvia')",
"('Liechtenstein')",
"('Lithuania')",
"('Luxembourg')",
"('Macedonia')",
"('Malta')",
"('Monaco')",
"('Netherlands')",
"('Norway')",
"('Poland')",
"('Portugal')",
"('Romania')",
"('Russia')",
"('Slovakia')",
"('Slovenia')",
"('Spain')",
"('Sweden')",
"('Switzerland')",
"('Ukraine')",
"('United Kingdom')",
"('Other')");
var australiaArray =  new Array("('Select country','',true,true)",
"('Australia')",
"('New Zealand')",
"('Other')");
var lamericaArray =  new Array("('Select country','',true,true)",
"('Costa Rica')",
"('Cuba')",
"('El Salvador')",
"('Guatemala')",
"('Haiti')",
"('Jamaica')",
"('Mexico')",
"('Panama')",
"('Other')");
var namericaArray =  new Array("('Select country','',true,true)",
"('Canada')",
"('USA')",
"('Other')");
var samericaArray =  new Array("('Select country','',true,true)",
"('Argentina')",
"('Bolivia')",
"('Brazil')",
"('Chile')",
"('Colombia')",
"('Ecuador')",
"('Paraguay')",
"('Peru')",
"('Suriname')",
"('Uruguay')",
"('Venezuela')",
"('Other')");
function populateCountry(inForm,selected) {
	var selectedArray = eval(selected + "Array");
	while (selectedArray.length < inForm.country.options.length) {
		inForm.country.options[(inForm.country.options.length - 1)] = null;
	}
	for (var i=0; i < selectedArray.length; i++) {
		eval("inForm.country.options[i]=" + "new Option" + selectedArray[i]);
	}
	if (inForm.region_selection.options[0].value == '') {
		inForm.region_selection.options[0]= null;
		if ( navigator.appName == 'Netscape') {
			if (parseInt(navigator.appVersion) < 4) {
				window.history.go(0);
			}
			else {   	
				if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
				window.history.go(0);
            }
         }
      }
   }
}
function populateUSstate(inForm,selected) {  
var stateArray =  new Array("('Select State','',true,true)",
	"('Alabama')",
	"('Alaska')",
	"('Arizona')",
	"('Arkansas')",
	"('California')",
	"('Colorado')",
	"('Connecticut')",
	"('Delaware')",
	"('Columbia')",
	"('Florida')",
	"('Georgia')",
	"('Hawaii')",
	"('Idaho')",
	"('Illinois')",
	"('Indiana')",
	"('Iowa')",
	"('Kansas')",
	"('Kentucky')",
	"('Louisiana')",
	"('Maine')",
	"('Maryland')",
	"('Massachusetts')",
	"('Michigan')",
	"('Minnesota')",
	"('Mississippi')",
	"('Missouri')",
	"('Montana')",
	"('Nebraska')",
	"('Nevada')",
	"('New Hampshire')",
	"('New Jersey')",
	"('New Mexico')",
	"('New York')",
	"('North Carolina')",
	"('North Dakota')",
	"('Ohio')",
	"('Oklahoma')",
	"('Oregon')",
	"('Pennsylvania')",
	"('Rhode Island')",
	"('South Carolina')",
	"('South Dakota')",
	"('Tennessee')",
	"('Texas')",
	"('Utah')",
	"('Vermont')",
	"('Virginia')",
	"('Washington')",
	"('West Virginia')",
	"('Wisconsin')",
	"('Wyoming')");
	if (selected == 'USA') {
	for (var i=0; i < stateArray.length; i++) {
	eval("inForm.country.options[i]=" + "new Option" + stateArray[i]);
	}
	if ( navigator.appName == 'Netscape') {
	if (parseInt(navigator.appVersion) < 4) {
	window.history.go(0)
	}
	else {    	
	if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
	window.history.go(0)
         }
      }
   }
}
else {
}  
	if (selected == 'Other') {
	newCountry = "";
	while (newCountry == ""){
	newCountry=prompt ("Please enter the name of your country.", "");
}
	if (newCountry != null) {
	inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
	inForm.country.options[inForm.country.options.length]=new Option('Other, not listed','Other');
   }
}
	if(inForm.country.options[0].text == 'Select country') {
	inForm.country.options[0]= null;
   }
}

function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
}

/* *******************************************
 *  Mail box
 *********************************************/

function glMail_writeMailCountLetters() {
	var msg = $('glMail_message').value;
	if (msg.length > 160) {
		msg=msg.substring(0,160);
		$('glMail_message').value = msg;
	}
	$('glMail_write_mail_word_count').innerHTML = msg.length;
}			

function glMail_showWriteMail(friendId, recipientName, x, y) {
	$('glMail_message').value='';
	$('glMail_recipient_id').value=friendId;
	var elem = getStyleObject("glMail_write_mail");
	elem.visibility="visible";
	elem.zIndex= '12';
	document.getElementById('glMail_recipient_name').innerHTML  = recipientName;
	elem.left =  x + "px";
	elem.top =  140 + y + "px";
	
	$('glMail_write_mail').setStyle({display:  'block'});
	$('glMail_write_mail_submit_button').setStyle({display:  'block'});	
    //$('write_mail_submit_button').value = buttonText;	
    $('glMail_message').value = '';		
    $('glMail_write_mail_word_count').innerHTML = '0';	
    $('glMail_message').setStyle({color: '#000000'});
}

function glMail_closeWriteMail() {
	$('glMail_recipient_id').value=-1;
	var elem = getStyleObject("glMail_write_mail");
	elem.visibility="hidden";
	elem.zIndex= '-1';
	elem.top = '20px';
	$('glMail_write_mail').setStyle({display:  'none'});
}

var glMail_timer;
var glMail_step = 0;

function glMail_startSlidePalMail() {
	if (glMail_step == 0) 
		timer=setInterval("glMail_moveImage1()",3500);	
	else 
		timer=setInterval("glMail_moveImage2()",1500);	
} 	
function glMail_moveImage1() {
    var response = 'Ok';
	$('glMail_message').value = ''+response;
	$('glMail_message').setStyle({color: '#555555'});
	$('glMail_write_mail_submit_button').setStyle({display:  'none'});				   
	$('glMail_write_mail_loader').setStyle({display:  'none'});
    clearInterval(glMail_timer);
    glMail_step = 1;
    glMail_startSlidePalMail();
}	
function glMail_moveImage2() {
    $('glMail_write_mail').setStyle({display:  'none'});
    glMail_step = 0;
    clearInterval(glMail_timer);
}	


function glMail_sendWriteMail(waitText) {
		var urli = './jsp/simple/input.jsp';
	var params = encodeURI(
		'cmd=44'+
		'&rid='+$('glMail_recipient_id').value+
		'&msg='+encodeURIComponent($('glMail_message').value));
	new Ajax.Request(urli, {
		asynchronous: true,
		method: "POST",
		parameters: params + '',
		onSuccess: function(transport){
			var response = transport.responseText;
			var friendAffectionValueAttr = $('friend_affection_value_attribute');
			if (friendAffectionValueAttr != null) {
				if (friendshipAffectionValue < 100) {
					friendshipAffectionValue++;
					friendAffectionValueAttr.innerHTML=friendshipAffectionValue;
				}
			}
		},
		onFailure: function(){ 
		}
	});	
	$('glMail_write_mail_submit_button').value = waitText;
	$('glMail_write_mail_loader').setStyle({display:  'block'});
	glMail_startSlidePalMail();
}

var timerPoints;
var yText=0;
var yStart=0;
var wPoints = 7;
var hPoints = 9;


function startPointsSlide(startY) {
	yStart = startY;
	timerPoints=setInterval("movePoints()",50);	

} 	
function movePoints() {
  yText++;
  if ($('helper_text_anim') && yStart > 0 ) {
  	$('helper_text_anim').setStyle({display:  'block'});				   
  	$('helper_text_anim').setStyle({top:  (yStart-yText)+'px'});
  }	
  if (yText>30) { 
	if ($('helper_text_anim') && yStart > 0) $('helper_text_anim').setStyle({display:  'none'});
  	for (var ii=0;ii<6;ii++) {
	  	$('points_img_'+ii).setStyle({width:  '14px'});	
	  	$('points_img_'+ii).setStyle({height:  '17px'});	
	  }
  	clearInterval(timerPoints);
  }
  if (yText<10) {
  	wPoints++;
  	hPoints++;
  	for (var ii=0;ii<6;ii++) {
	  	$('points_img_'+ii).setStyle({width:  wPoints+'px'});	
	  	$('points_img_'+ii).setStyle({height:  hPoints+'px'});	
	}
  }
  else if (yText<20) {
  	wPoints--;
  	if (wPoints < 14) wPoints = 14;
  	hPoints--;
  	if (hPoints < 17) hPoints = 17;
  	for (var ii=0;ii<6;ii++) {
	  	$('points_img_'+ii).setStyle({width:  wPoints+'px'});	
	  	$('points_img_'+ii).setStyle({height:  hPoints+'px'});	
		}
  }
}	

function showNewPoints(urli, params, startY) {
	params = encodeURI(params);
	new Ajax.Request(urli, {
		asynchronous: true,
		method: "get",
		parameters: params + '',
		onSuccess: function(transport){
  			var response = transport.responseText;
  			if (response.indexOf('LEVELUP') != -1) { 
  				location.href = 'index.jsp?State=100&levelup=1';
  			} 
  			else $('pal_points_text').innerHTML = ''+response;
  			startPointsSlide(startY);
		},
		onFailure: function(){ 
		}
		});
}

function ironAjaxRequestSimpleResponse( urli, params, responseDiv) {
	$(responseDiv).innerHTML = "...";
	new Ajax.Request(urli, {
		asynchronous: true,
		method: "get",
		parameters: params + '',
		onSuccess: function(transport){
  			var response = transport.responseText;
  			$(responseDiv).innerHTML = response;
  			
	},
		onFailure: function(){ 
			alert("failed");
		}
	});
}

function updateCollectionItem( collectionID, itemID) {
	var urli = './jsp/components/ajax_handler.jsp';
	var checked = $('cb_collection_'+collectionID+'_'+itemID);
	if ($('text_collection_priority_'+collectionID+'_'+itemID) != null) {
		if (checked.checked) {
			$('text_collection_priority_'+collectionID+'_'+itemID).disabled=false;
		}else {
			$('text_collection_priority_'+collectionID+'_'+itemID).disabled='disabled';
			$('text_collection_priority_'+collectionID+'_'+itemID).value='0';
		}	
	}
	var params = "cmd=update_collection_item&item_id="+itemID+
					"&collection_id="+collectionID+"&set_to="+checked.checked+
					"&r="+Math.random();
	ironAjaxRequestSimpleResponse(urli, params, 'item_collection_response_'+itemID);
}

function updateCollectionItemPriority( collectionID, itemID) {
	var urli = './jsp/components/ajax_handler.jsp';
	var value = $('text_collection_priority_'+collectionID+'_'+itemID).value;
	var params = "cmd=update_collection_priority&item_id="+itemID+
					"&collection_id="+collectionID+"&value="+value+
					"&r="+Math.random();
	ironAjaxRequestSimpleResponse(urli, params, 'item_collection_response_'+itemID);
}

function setOpenStorePanel(panelID) {
	var urli = './jsp/components/ajax_handler.jsp';
	var params = "cmd=set_open_store_panel&panel_id="+panelID+
					"&r="+Math.random();
	ironAjaxRequestSimpleResponse(urli, params, 'item_collection_response');
}

var wallURL = './jsp';

function showTenWallMsgs() {
	
   	var urli = wallURL+'/my_pal/profile_wall_see_ten.jsp';
	var params = encodeURI('');
	new Ajax.Request(urli, {
			asynchronous: true,
			method: "get",
			parameters: params + '',
			onSuccess: function(transport){
			   var response = transport.responseText;
			   $('pall_wall_content').innerHTML = ''+response;
			},
			onFailure: function(){ 
			}
	});	
	$('pall_wall_content').innerHTML = ''+
		'<center>'+
		'<table>'+
		'<tr>'+
		'<td style="vertical-align: top; text-align: center; border-bottom: 0px #cfcb86 solid; color: #71a134;">'+
		'<img src="http://www.moipal.com/mp_res/web/images/loader.gif" border="0" />'+
		'</td>'+
		'</tr>'+
		'</table>'+
		'</center>';	
}

function showWallMsgs() {

   	var urli = wallURL+'/my_pal/profile_wall_see_all.jsp';
	var params = encodeURI('');
	new Ajax.Request(urli, {
			asynchronous: true,
			method: "get",
			parameters: params + '',
			onSuccess: function(transport){
			   var response = transport.responseText;
			   $('pall_wall_content').innerHTML = ''+response;
			},
			onFailure: function(){ 
			}
	});	
	$('pall_wall_content').innerHTML = ''+
		'<center>'+
		'<table>'+
		'<tr>'+
		'<td style="vertical-align: top; text-align: center; border-bottom: 0px #cfcb86 solid; color: #71a134;">'+
		'<img src="http://www.moipal.com/mp_res/web/images/loader.gif" border="0" />'+
		'</td>'+
		'</tr>'+
		'</table>'+
		'</center>';	
}

var timerWall;

function startSlideWall() {
	timerWall=setInterval("moveImageWall()",3500);	
} 	

function moveImageWall() {
    clearInterval(timerWall);
    if (facebookUI > 0) {
    	parent.$('website_frame').src = './index.jsp?Command=31&pal_id='+wallInfoPalId;
    }
    else showTenWallMsgs();	    
}	

var facebookUI = 0;
var wallInfoPalId = 0;

function sendWallMsg(infoPalId) {
	   	var urli = wallURL+'/simple/input.jsp';
	   	wallInfoPalId = infoPalId;
		var params = encodeURI(
			'cmd=71'+
			'&wall_id='+infoPalId+
			'&msg='+encodeURIComponent($('wall_text').value));
		new Ajax.Request(urli, {
			asynchronous: true,
			method: "POST",
			parameters: params + '',
			onSuccess: function(transport){
			    var response = transport.responseText;
			},
			onFailure: function(){ 
				var response = transport.responseText;
				$('pall_wall_content').innerHTML = response;
			}
		});	
		$('pal_wall_submit').value = '...';
		$('pal_wall_loader').setStyle({display:  'block'});
		startSlideWall();
}	

var allMyAdvActions = [];
var allMyAdvActionNames = [];
var allMyAdvReports = [];
var allMyAdvShowing = [];
 
function changeReport(direction, adventure) {
	var advActionsArray = allMyAdvActions[adventure];
	var advActionNamesArray = allMyAdvActionNames[adventure];
	var advReportsArray = allMyAdvReports[adventure];
	xArrayLength = advActionsArray.length;
	if (allMyAdvShowing[adventure]+direction >= xArrayLength || allMyAdvShowing[adventure]+direction < 0) return;
	else allMyAdvShowing[adventure] += direction;
	for (i=0;i<xArrayLength;i++){
		$('report_img_'+advActionsArray[i]).style.display = 'none';
	}
	$('report_img_'+advActionsArray[allMyAdvShowing[adventure]]).style.display = 'block';
	$('report_text_'+adventure).innerHTML = ''+advReportsArray[advActionsArray[allMyAdvShowing[adventure]]];
	$('adventure_action_label_'+adventure).innerHTML = (allMyAdvShowing[adventure]+1)+'';
	$('action_name_'+adventure).innerHTML = ''+advActionNamesArray[advActionsArray[allMyAdvShowing[adventure]]];
}

function startParty(partyVariable, div, urli) {
	var urli = urli;
	var params = encodeURI('cmd=start_party&party_variable='+partyVariable);
	new Ajax.Request(urli, {
		asynchronous: true,
		method: "get",
		parameters: params + '',
		onSuccess: function(transport){
			var response = transport.responseText;
			$(div).innerHTML = ''+response;
		},
		onFailure: function(transport){
			var response = transport.responseText;
			$(div).innerHTML = 'ERROR:'+response;
		}
	});
}

function selectThisGift(giftw, tpalid, urli) {
	var urli = urli;
	var params = encodeURI('cmd=set_giftw&tpalid='+tpalid+'&giftw='+giftw);
	new Ajax.Request(urli, {
		asynchronous: true,
		method: "get",
		parameters: params + '',
		onSuccess: function(transport){
			var response = transport.responseText;
			$('helper_box').innerHTML = response;
		},
		onFailure: function(transport){
			var response = transport.responseText;
			$('helper_box').innerHTML = response;
		}
	});
}

function fbCloseBubble() {
	if ($('applet_moiphone_fb')) $('applet_moiphone_fb').style.width = '696px';
	if ($('bubble_notify_player')) $('bubble_notify_player').style.display = 'none';
	return false;
}
