// JavaScript Document

//on esc close popup
document.onkeyup = function keyPress(event) {	
	if ( typeof event == "undefined" ) 
		event = window.event
	wkey = event.keyCode
	if ( document.layers ) 
		wkey = event.which;
	if (wkey==27 && document.getElementById('inline_popup') && document.getElementById('inline_popup').style.display=='block')
		hide_inline_popup();
}

function show_inline_popup(title,url,param,div_width,div_height,class_) {
	hide_all_info_box();
	black_wall(1,2);
	add_inline_popup(title,div_width,div_height,class_);
	if (url.length>0)
		document.getElementById('popup_loader').src=url+'?'+param;
}

function hide_inline_popup() {
	hide_all_info_box();
	black_wall(0);	
	if (document.getElementById('inline_popup'))
		document.getElementById('inline_popup').style.display='none';
	document.getElementById('inline_popup_inner').innerHTML='&nbsp;';
}

function add_inline_popup(title,div_width,div_height,class_) {
	var holder_id="inline_popup";
	
	if (class_!='white') 
		class_='';
	
	if (!document.getElementById(holder_id)) {
		var holder = document.createElement("div");	
		holder.id=holder_id;
		document.body.appendChild(holder);
	}
	
	var page_w=getPageSizeWithOutScroll('w');
	var page_h=getPageSizeWithOutScroll('h');
			
	document.getElementById(holder_id).style.width=div_width+'px'; 
	document.getElementById(holder_id).style.height=div_height+'px';
	document.getElementById(holder_id).style.position='absolute';
	document.getElementById(holder_id).style.display='block';	
	document.getElementById(holder_id).style.left=(page_w-div_width)/2+getScrollCoordinates('w')+'px';
	document.getElementById(holder_id).style.top=(page_h-div_height)/2+getScrollCoordinates('h')-15+'px';
	document.getElementById(holder_id).style.zIndex='10001';	
	
	document.getElementById(holder_id).innerHTML='<table class="popup" cellpadding=0 cellspacing=0><tr><td class="left_top">&nbsp;</td><td class="top" valign=bottom><table cellpadding=0 cellspacing=0><tr><td valign=middle class="title">'+title+'</td><td class="close" valign=middle><div class="close" onclick="hide_inline_popup()"></div></td></tr></table></td><td class="right_top">&nbsp;</td></tr><tr><td class="left_middle'+class_+'">&nbsp;</td><td class="middle'+class_+'" valign=top id="inline_popup_inner">&nbsp;</td><td class="right_middle'+class_+'">&nbsp;</td></tr><tr><td class="left_bottom'+class_+'">&nbsp;</td><td class="bottom'+class_+'" valign=top>&nbsp;</td><td class="right_bottom'+class_+'">&nbsp;</td></tr></table>';
	
	document.getElementById('inline_popup_inner').style.height=parseInt(div_height-115)+'px'; 
	
	Cufon.replace('TABLE.popup TD.top TABLE TD.title');
	Cufon.now();	
	
	add_loader('inline_popup_inner',class_);
}

function open_reg(title,get_temp) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_reg&get_temp='+parseInt(get_temp),500,429);
	if (parseInt(get_temp)==1)
		return false;
}

function open_privacy_statement(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_privacy_statement',600,447);
}

function open_contact(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_contact',380,300);
}

function open_message_to_artist(title,c,h) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_message_to_artist&c='+escape(c)+'&h='+escape(h),380,300);
}

function open_terms_conditions(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_terms_conditions',600,447);
}

function open_terms_conditions_wnd() {
	window.open(HOST+'/inline_popup.php?command=page_lang='+lang+'&command=show_terms_conditions_wnd','moozzix_terms_conditions','width=600,height=300,status=0,toolbar=0,resizable=1,scrollbars=1,location=0');
}

function open_disclaimer(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_disclaimer',600,447);
}

function open_faq(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_faq',500,447);
}

function open_ginst_video(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=ginst_video',420,340,'white');
}

function faq_item_show(i,j) {
	document.getElementById('faq_holder_'+i+'_'+j).style.display='';
	document.getElementById('faq_holder_'+i+'_'+j).style.height='0px';
	eval('faq_item_'+i+'_'+j+'_time = setInterval("faq_item_expand('+i+','+j+')",30);');
}

function faq_item_expand(i,j) {
	var height_=(parseInt(document.getElementById('faq_holder_'+i+'_'+j).offsetHeight)+15),
		offset_=parseInt(document.getElementById('faq_holder_'+i+'_'+j+'_height').value);
		
	if ( height_ >= offset_ ) {
		height_ = offset_;
		eval('clearInterval(faq_item_'+i+'_'+j+'_time);');
		document.getElementById('faq_sign_'+i+'_'+j).innerHTML='-';
	}
	update_black_wall(document.getElementById('inline_popup_inner').offsetHeight+145+getY(document.getElementById('inline_popup')),0);
	document.getElementById('faq_holder_'+i+'_'+j).style.height = height_+'px';
}

function faq_item_hide(i,j) {
	eval('clearInterval(faq_item_'+i+'_'+j+'_time)');
	eval('faq_item_'+i+'_'+j+'_time = setInterval("faq_item_collapse('+i+','+j+')",30);');
}

function faq_item_collapse(i,j) {
	var height_=(parseInt(document.getElementById('faq_holder_'+i+'_'+j).offsetHeight)-15);
	if ( height_ <= 0 ) {
		height_ = 0;
		eval('clearInterval(faq_item_'+i+'_'+j+'_time);');
		document.getElementById('faq_holder_'+i+'_'+j).style.display='none';
		document.getElementById('faq_sign_'+i+'_'+j).innerHTML='+';
	}
	document.getElementById('faq_holder_'+i+'_'+j).style.height = height_+'px';
}

function faq_calc_height() {
	for (var i=0;i<10;i++) {
		for (var j=0;j<15;j++) {
			if (document.getElementById('faq_holder_'+i+'_'+j)) {
				document.getElementById('faq_holder_'+i+'_'+j).style.display='';
				document.getElementById('faq_holder_'+i+'_'+j+'_height').value=document.getElementById('faq_holder_'+i+'_'+j).offsetHeight;
				document.getElementById('faq_holder_'+i+'_'+j).style.display='none';
			}
		}
	}
}

function show_faq_item(index,jndex) {
	for (var i=0;i<10;i++) {
		for (var j=0;j<15;j++) {
			if (i==index && j==jndex) {
				if (document.getElementById('faq_holder_'+i+'_'+j)) {
					if ( document.getElementById('faq_holder_'+i+'_'+j+'_sel').value==0 ) {
						faq_item_show(i,j);
						document.getElementById('faq_holder_'+i+'_'+j+'_sel').value=1;
					} else {
						faq_item_hide(i,j);
						document.getElementById('faq_holder_'+i+'_'+j+'_sel').value=0;
					}
				}				
			} else {
				if (document.getElementById('faq_holder_'+i+'_'+j)) {
					if ( document.getElementById('faq_holder_'+i+'_'+j+'_sel').value==1 )
						faq_item_hide(i,j);
					document.getElementById('faq_holder_'+i+'_'+j+'_sel').value=0;
				}
			}
		}
	}	

}

function contact() {
	document.contact_form.command.value='contact';
	document.getElementById('contact_form_error').style.display='none';
	document.getElementById('contact_form_error').style.width = document.getElementById('contact_form_holder').offsetWidth+'px';
	document.getElementById('contact_form_laoder').style.width = document.getElementById('contact_form_holder').offsetWidth+'px';
	document.getElementById('contact_form_laoder').style.height = document.getElementById('contact_form_holder').offsetHeight+'px';
	document.getElementById('contact_form_laoder').innerHTML='<table cellpadding="0" cellspacing="0" width="100%" style="height:100%;"><tr><td valign="middle" align="center"><img src="img/popup/_loader.gif" border="0" /></td></tr></table>';	
	document.getElementById('contact_form_laoder').style.display='';
	document.getElementById('contact_form_holder').style.display='none';	
}

function message_to_artist() {
	document.message_to_artist_form.command.value='message_to_artist';
	document.getElementById('message_to_artist_form_error').style.display='none';
	document.getElementById('message_to_artist_form_error').style.width = document.getElementById('message_to_artist_form_holder').offsetWidth+'px';		
	document.getElementById('message_to_artist_form_laoder').style.width = document.getElementById('message_to_artist_form_holder').offsetWidth+'px';
	document.getElementById('message_to_artist_form_laoder').style.height = document.getElementById('message_to_artist_form_holder').offsetHeight+'px';
	
	document.getElementById('message_to_artist_form_laoder').innerHTML='<table cellpadding="0" cellspacing="0" width="100%" style="height:100%;"><tr><td valign="middle" align="center"><img src="img/popup/_loader.gif" border="0" /></td></tr></table>';	
	document.getElementById('message_to_artist_form_laoder').style.display='';
	document.getElementById('message_to_artist_form_holder').style.display='none';
}

function reg() {
	document.reg_form.command.value='reg_user';
	document.getElementById('reg_form_error').style.display='none';
	document.getElementById('reg_form_error').style.width = document.getElementById('reg_form_holder').offsetWidth+'px';
	document.getElementById('reg_form_laoder').style.width = document.getElementById('reg_form_holder').offsetWidth+'px';
	document.getElementById('reg_form_laoder').style.height = document.getElementById('reg_form_holder').offsetHeight+'px';
	document.getElementById('reg_form_laoder').innerHTML='<table cellpadding="0" cellspacing="0" width="100%" style="height:100%;"><tr><td valign="middle" align="center"><img src="img/popup/_loader.gif" border="0" /></td></tr></table>';	
	document.getElementById('reg_form_laoder').style.display='';
	document.getElementById('reg_form_holder').style.display='none';
}

function open_password_recovery(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_password_recovery',420,200);	
}

function password_recovery() {
	document.precovery_form.command.value='password_recovery';
	document.getElementById('precovery_form_error').style.display='none';
	document.getElementById('precovery_form_error').style.width = document.getElementById('precovery_form_holder').offsetWidth+'px';
	document.getElementById('precovery_form_laoder').style.width = document.getElementById('precovery_form_holder').offsetWidth+'px';
	document.getElementById('precovery_form_laoder').style.height = document.getElementById('precovery_form_holder').offsetHeight+'px';
	document.getElementById('precovery_form_laoder').innerHTML='<table cellpadding="0" cellspacing="0" width="100%" style="height:100%;"><tr><td valign="middle" align="center"><img src="img/popup/_loader.gif" border="0" /></td></tr></table>';	
	document.getElementById('precovery_form_laoder').style.display='';
	document.getElementById('precovery_form_holder').style.display='none';
}

function open_login(title) {
	show_inline_popup(title,'','',280,200);	
}

function open_invite_your_friends(title) {
	show_inline_popup(title,'','',490,360,'white');	
}

function login() {
	document.login_form.command.value='login_user';
	document.getElementById('login_form_error').style.display='none';
	document.getElementById('login_form_error').style.width = document.getElementById('login_form_holder').offsetWidth+'px';
	document.getElementById('login_form_laoder').style.width = document.getElementById('login_form_holder').offsetWidth+'px';
	document.getElementById('login_form_laoder').style.height = document.getElementById('login_form_holder').offsetHeight+'px';
	document.getElementById('login_form_laoder').innerHTML='<table cellpadding="0" cellspacing="0" width="100%" style="height:100%;"><tr><td valign="middle" align="center"><img src="img/popup/_loader.gif" border="0" /></td></tr></table>';	
	document.getElementById('login_form_laoder').style.display='';
	document.getElementById('login_form_holder').style.display='none';	
	document.login_form.command.value='login_user';
}

function open_login(title) {
	show_inline_popup(title,HOST+'/inline_popup.php','page_lang='+lang+'&command=show_login',280,200);
}

//add_error_box
function hide_info_box(obj) {
	var id  = (obj.id == '' ? obj.name : obj.id)+'_info_box',
		id_arrow = id+'_arrow';
		
	if (document.getElementById(id)) {
		document.getElementById(id).style.display='none';	
		document.getElementById(id_arrow).style.display='none';
	}
}

var info_array=new Array();

function add_info_to_array(id,id_arrow) {
	for (var i=0;i<info_array.length;i++) {
		if (info_array[i][0]==id) {
			return;
		}		
	}
	info_array[info_array.length] = new Array(id,id_arrow);
}

function hide_all_info_box() {
	for(var i=0;i<info_array.length;i++) {
		if (document.getElementById(info_array[i][0]).style.display!='none') {
			document.getElementById(info_array[i][0]).style.display='none';
		}
		if (document.getElementById(info_array[i][1]).style.display!='none') {
			document.getElementById(info_array[i][1]).style.display='none';
		}
	}
}

function show_info_box(obj,msg,p1_,p2_,w_,h_,pw_,ph_) {
	var obj_x = getX(obj),
		obj_y = getY(obj),
		obj_height_ = obj.offsetHeight,
		obj_width_ = obj.offsetWidth,
		id  = (obj.id == '' ? obj.name : obj.id)+'_info_box',
		id_arrow = id+'_arrow'; 
	
	add_info_to_array(id,id_arrow);
	
	pw__ = parseInt(pw_)!=0 ? pw_ : 0;
	ph__ = parseInt(ph_)!=0 ? ph_ : 0;
	
	if (!document.getElementById(id)) {
		holder = document.createElement("div");	
		holder.id=id;		
		holder.className = 'info_box';
		document.body.appendChild(holder);		
	} else {
		document.getElementById(id).style.display='';	
		document.getElementById(id_arrow).style.display='';
	}
	
	if (!document.getElementById(id_arrow)) {
		arrow = document.createElement("div");	
		arrow.id=id_arrow;
		document.body.appendChild(arrow);		
	}
	
	switch (p1_) {
		case 'top':
				document.getElementById(id_arrow).className = 'top_info_box_arrow';		
				document.getElementById(id_arrow).style.top=(obj_y-16-5-ph__)+'px';
				switch (p2_) {
					case 'left':
						document.getElementById(id_arrow).style.left=obj_x+'px';
						break;
					case 'center':
						document.getElementById(id_arrow).style.left=parseInt(obj_x+(obj_width_+23)/2-23)+'px';
						break;
					case 'right':
						document.getElementById(id_arrow).style.left=(obj_x+obj_width_-23)+'px';
						break;
				}								
			break;
		case 'bottom':
				document.getElementById(id_arrow).className = 'bottom_info_box_arrow';		
				document.getElementById(id_arrow).style.top=(obj_y+obj_height_+5+ph__)+'px';
				switch (p2_) {
					case 'left':
						document.getElementById(id_arrow).style.left=obj_x+'px';
						break;
					case 'center':
						document.getElementById(id_arrow).style.left=parseInt(obj_x+(obj_width_+23)/2-23)+'px';
						break;
					case 'right':
						document.getElementById(id_arrow).style.left=(obj_x+obj_width_-23)+'px';
						break;
				}		
			break;
		case 'left':
				document.getElementById(id_arrow).className = 'left_info_box_arrow';				
				document.getElementById(id_arrow).style.left=(obj_x-16-5)+'px';
				switch (p2_) {
					case 'top':
						document.getElementById(id_arrow).style.top=(obj_y+ph__)+'px';
						break;
					case 'center':
						document.getElementById(id_arrow).style.top=parseInt(obj_y+obj_height_/2-12+ph__)+'px';
						break;
					case 'bottom':
						document.getElementById(id_arrow).style.top=(obj_y+obj_height_-23+ph__)+'px';
						break;
				}				
			break;
		case 'right':
				document.getElementById(id_arrow).className = 'right_info_box_arrow';
				document.getElementById(id_arrow).style.left=(obj_x+obj_width_+5)+'px';
				switch (p2_) {
					case 'top':
						document.getElementById(id_arrow).style.top=(obj_y+ph__)+'px';
						break;
					case 'center':
						document.getElementById(id_arrow).style.top=parseInt(obj_y+obj_height_/2-12+ph__)+'px';
						break;
					case 'bottom':
						document.getElementById(id_arrow).style.top=(obj_y+obj_height_-23+ph__)+'px';
						break;
				}
			break;		
	}
	
	
	switch (p1_) {
		case 'top':
			var arrow_x = getX(document.getElementById(id_arrow)),
				arrow_y = getY(document.getElementById(id_arrow));
				
			document.getElementById(id).style.width = w_>0 ? w_+'px' : 'auto';
			document.getElementById(id).style.height = h_>0 ? h_+'px' : 'auto';
			document.getElementById(id).innerHTML=msg;
			document.getElementById(id).style.left=parseInt(arrow_x-((document.getElementById(id).offsetWidth-23)/2))+'px';
			document.getElementById(id).style.top=(arrow_y-document.getElementById(id).offsetHeight+2)+'px';	
			break;
		case 'bottom':
			var arrow_x = getX(document.getElementById(id_arrow)),
				arrow_y = getY(document.getElementById(id_arrow));
				
			document.getElementById(id).style.width = w_>0 ? w_+'px' : 'auto';
			document.getElementById(id).style.height = h_>0 ? h_+'px' : 'auto';
			document.getElementById(id).innerHTML=msg;
			document.getElementById(id).style.left=parseInt(arrow_x-((document.getElementById(id).offsetWidth-23)/2))+'px';
			document.getElementById(id).style.top=(arrow_y+document.getElementById(id_arrow).offsetHeight-2)+'px';	
			break;
		case 'left':
			var arrow_x = getX(document.getElementById(id_arrow)),
				arrow_y = getY(document.getElementById(id_arrow));
				
			document.getElementById(id).style.width = w_>0 ? w_+'px' : 'auto';
			document.getElementById(id).style.height = h_>0 ? h_+'px' : 'auto';
			document.getElementById(id).innerHTML=msg;
			document.getElementById(id).style.top=parseInt(arrow_y-((document.getElementById(id).offsetHeight-23)/2))+'px';
			document.getElementById(id).style.left=(arrow_x-document.getElementById(id).offsetWidth+2)+'px';	
			break;
		case 'right':
			var arrow_x = getX(document.getElementById(id_arrow)),
				arrow_y = getY(document.getElementById(id_arrow));
				
			document.getElementById(id).style.width = w_>0 ? w_+'px' : 'auto';
			document.getElementById(id).style.height = h_>0 ? h_+'px' : 'auto';
			document.getElementById(id).innerHTML=msg;
			document.getElementById(id).style.top=parseInt(arrow_y-((document.getElementById(id).offsetHeight-23)/2))+'px';
			document.getElementById(id).style.left=(arrow_x+document.getElementById(id_arrow).offsetWidth-2)+'px';	
			break;
	}

	
}


//blackwall
function update_black_wall(h,w) {
	if ( h > document.getElementById('black_wall').offsetHeight )
		document.getElementById('black_wall').style.height=h+'px';
	if ( w > document.getElementById('black_wall').offsetWidth )
		document.getElementById('black_wall').style.width=w+'px';
}

function black_wall(visible,class_) {
	if (parseInt(visible)==1) {
		show_selects('hidden');	
		show_object('hidden');
		page_height=getPageSizeWithScroll('h');
		page_width=getPageSizeWithScroll('w');
		if (document.getElementById('black_wall')) {
			if (class_==2)
				document.getElementById('black_wall').className='black_wall_2';	
			else
				document.getElementById('black_wall').className='black_wall_1';	
			document.getElementById('black_wall').style.height=page_height+'px';
			document.getElementById('black_wall').style.width=page_width+'px';
		} else {
			var black_wall=document.createElement("div");
			black_wall.id='black_wall';
			document.body.appendChild(black_wall);
			if (class_==2)
				document.getElementById('black_wall').className='black_wall_2';	
			else
				document.getElementById('black_wall').className='black_wall_1';			
			document.getElementById('black_wall').style.height=page_height+'px';
			document.getElementById('black_wall').style.width=page_width+'px';			
		}		
		//iebody.style.overflow='hidden';		
	} else {		
		show_selects('visible');
		show_object('visible');
		if (document.getElementById('black_wall'))
			document.getElementById('black_wall').className='black_wall_0';						
		//iebody.style.overflow='auto';
	}		
}

function black_wall_top(visible,class_) {
	if (parseInt(visible)==1) {
		//show_selects('hidden');
		//show_object('hidden');
		page_height=getPageSizeWithScroll('h');
		page_width=getPageSizeWithScroll('w');
		if (document.getElementById('black_wall_top')) {
			if (class_==2)
				document.getElementById('black_wall_top').className='black_wall_top_2';	
			else
				document.getElementById('black_wall_top').className='black_wall_top_1';	
			document.getElementById('black_wall_top').style.height=page_height;
			document.getElementById('black_wall_top').style.width=page_width;
		} else {
			var black_wall=document.createElement("div");
			if (class_==2)
				black_wall.className='black_wall_top_2';	
			else
				black_wall.className='black_wall_top_1';			
			black_wall.id='black_wall_top';
			black_wall.style.height=page_height;
			black_wall.style.width=page_width;
			document.body.appendChild(black_wall);
		}		
		//iebody.style.overflow='hidden';		
	} else {		
		//show_selects('visible');
		//show_object('visible');
		if (document.getElementById('black_wall_top'))
			document.getElementById('black_wall_top').className='black_wall_0';						
		//iebody.style.overflow='auto';
	}		
}

//loader

function add_loader(id_,class_) {
	if (class_!='white') 
		class_='';
	if (document.getElementById(id_)) {		
		var width=document.getElementById(id_).offsetWidth;
		var height=document.getElementById(id_).offsetHeight;
		document.getElementById(id_).innerHTML="<table width='"+width+"' style='height: "+height+"px;'><tr><td align=center valign=middle><div class=\"pop_loader"+class_+"\"></div></td></tr></table>";
	}
}
