function CheckBrowser()
	{
	if (navigator.appName == "Microsoft Internet Explorer")		
		return true;
	else		
		return false;
	
	}

function setBackground(element, color, tcolor)
	{
	var obj=document.getElementById(element);
	obj.style.backgroundColor=color;
	if(tcolor!='')
		{
		setTextColor(element, tcolor);
		}
	}
	
function setTextColor(element, tcolor)
	{
	var obj=document.getElementById(element);
	obj.style.color=tcolor;	
	}

function doConfirm(msg, url)
	{
	if(url!='')
		{
		var check = confirm(msg);
		if(check==true)
			window.location=url;
		else
			return false;
		}
	return false;
	}
	
function MenuAction($elementId, $state)
	{
	if($('openedmenu').value != '')
		{
		
		$($('openedmenu').value).style.display ='none';
		}
	
	var $element = document.getElementById($elementId);	
	$element.style.display = $state;
	
	$('openedmenu').value = $elementId;	
	}

function ChangeClass($elementId, $class)
	{
	
	var $element=document.getElementById($elementId);
		$element.className = $class;		
	}
function ChangeTabClass($elementId, $class)
	{
	if($('activestatetab').value != '')
		{		
		$($('activestatetab').value).className ='tabSubButton';
		}
	$($elementId).className = $class;
	$('activestatetab').value = $elementId;
	}


function ChangeRoundedClass($elementId, $class, $normalclass)
	{
	if($('activestatetab').value != '')
		{		
		$($('activestatetab').value).className = $normalclass;
		$($('activestatetab').value + 'left').className = $normalclass + 'left';
		$($('activestatetab').value + 'right').className = $normalclass + 'right';
		}
	$($elementId).className = $class;
	$($elementId + 'left').className = $class + 'left';
	$($elementId + 'right').className = $class + 'right';
	$('activestatetab').value = $elementId;
	}
	
/*::::::::::::::: IMAGE CHECKBOX  ::::::::::::::::*/
function ChangeCheckbox(elementid, chboxid)
	{	
	if(document.getElementById(chboxid).checked == false)
		{
		document.getElementById(chboxid).checked = true;
		document.getElementById(elementid).src = 'images/buttonimage/checked.gif';			
		}
	else
		{
		document.getElementById(chboxid).checked = false;
		document.getElementById(elementid).src = 'images/buttonimage/uncheck.gif';		
		}
	}
	
function ChangeRadio(rdId, imgname, rdname, durn)
	{	
	if(document.getElementById(rdId).checked == true)		
		return false;		
	else				
		document.getElementById(rdId).checked = true;
		
	for(var i=1; i<=durn; i++)
		{		
		if(document.getElementById(rdname + i).checked == false)						
			document.getElementById(imgname + i).src = 'images/buttonimage/uncheck.gif';
		else
			document.getElementById(imgname + i).src = 'images/buttonimage/checked.gif';
		}
		
	}
/*::::::::::::::: STRING :::::::::::::::*/

function SubStr(str, length)
	{	
	if(str.length > length)
		{
		cutted_str = str.substr(0, length);	
		str = cutted_str + '...';
		}
	document.write(str);	
	}
	
/*::  ::*/
function CheckVal(el_id, state, defaultValue)
	{
		if(state=="blur")
			{
			if(document.getElementById(el_id).value == "")
				document.getElementById(el_id).value = defaultValue;
			}
		else
			{
			if(document.getElementById(el_id).value == defaultValue)
			document.getElementById(el_id).value = "";
			}
			
	}
	
function toPage(url)
	{
	window.location = url;
	}
function $(id)
	{
	return document.getElementById(id);
	}
/* IMAGE PREVIEW PANEL*/
function contentPreviewDivShow(url, container)
	{
	$(container).style.display = '';
	makeRequest(url, container);
	}
var opened, fm_shift_x, fm_shift_y;
function contentPreviewOpen(myEvent, container, url ,elemHeight ,elemWidth)
	{
	ScrolledPosition();
	opened = setTimeout("contentPreviewDivShow('"+url+"', '"+container+"')", 500);
	
	var left;	
	left = myEvent.clientX + 15 - fm_shift_x;
	if(document.body.offsetWidth < left + elemWidth)
		left = document.body.offsetWidth - elemWidth;
	var top;	
	top = myEvent.clientY + 15 + fm_shift_y;
	var contentbottom = parseInt(top + elemHeight);
	var scrolledY = parseInt(document.documentElement.scrollTop + document.documentElement.clientHeight);
	var minus = 0;
	if(contentbottom > scrolledY)
		{
		minus = contentbottom - scrolledY;		
		}
	top = top - minus;
	$(container).style.left = left + 'px';
	$(container).style.top  = top + 'px';	
	}
function contentPreviewMove(myEvent, container ,elemHeight ,elemWidth)
	{
	ScrolledPosition();
	var left;	
	left = myEvent.clientX + 15 - fm_shift_x;
	if(document.body.offsetWidth < left + elemWidth)
		left = document.body.offsetWidth - elemWidth;
	var top;	
	top = myEvent.clientY + 15 + fm_shift_y;
	var contentbottom = parseInt(top + elemHeight);
	var scrolledY = parseInt(document.documentElement.scrollTop + document.documentElement.clientHeight);
	var minus = 0;
	if(contentbottom > scrolledY)
		{
		minus = contentbottom - scrolledY;		
		}
	top = top - minus;
	$(container).style.left = left + 'px';
	$(container).style.top  = top + 'px';
	}
function contentPreviewClose(container)
	{
	clearTimeout(opened);
	$(container).innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="contentpreview" style="border:1px solid #DDDDDD;"><tr><td align="center"><img src="images/previewloader.gif" align="absmiddle" vspace="100"/></td></tr></table>';
	$(container).style.display = 'none';
	
	}
function ScrolledPosition()
	{
	var target_x = 1;
	var target_y = 1;
	
	var has_inner = typeof(window.innerWidth) == 'number';
	var has_element = document.documentElement && document.documentElement.clientWidth;
	fm_shift_x = has_inner
        ? pageXOffset
        : has_element
          ? document.documentElement.scrollLeft
          : document.body.scrollLeft;
    if (target_x < 0)
        fm_shift_x += has_inner
            ? window.innerWidth
            : has_element
              ? document.documentElement.clientWidth
              : document.body.clientWidth;

    fm_shift_y = has_inner
        ? pageYOffset
        : has_element
          ? document.documentElement.scrollTop
          : document.body.scrollTop;
    if (target_y < 0)
        fm_shift_y += has_inner
            ? window.innerHeight
            : has_element
              ? document.documentElement.clientHeight
              : document.body.clientHeight;	
	}
/*
::::::::::::::::::::::::::::::::::::::::::
:::::::::::::AJAX FUNCTION  ::::::::::::::
::::::::::::::::::::::::::::::::::::::::::
*/
function makeRequest(url, container, imagename)
		{
		if(!imagename){ var imagename = 'images/ajax-loader.gif'; }
		var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { alertContents(http_request, container, imagename) };
		url = url + '&rand = ' + parseInt(Math.random()*999999999999999);
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function alertContents(http_request, container, imagename) {
		if (http_request.readyState == 4)
			{
            if (http_request.status == 200)
				{
				$(container).innerHTML = http_request.responseText;
				if($('videoLoader'))
					$('videoLoader').style.display = 'none';
            	}
			 else 
				{
				alert("Problem");
           		}
        	}
		else
			{
			switch(container){
				case 'contentpreview':
					$(container).innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="contentpreview" style="border:1px solid #DDDDDD;"><tr><td align="center"><img src="images/previewloader.gif" align="absmiddle" vspace="100"/></td></tr></table>';
					break;
				case 'melodypreview':
					$(container).innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="contentpreview" style="border:1px solid #DDDDDD;"><tr><td align="center"><img src="images/previewloader.gif" align="absmiddle"/></td></tr></table>';
					break;
				case 'newsfilters':
					$(container).innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="contentpreview" style="border:1px solid #DDDDDD;"><tr><td align="center"><img src="images/previewloader.gif" align="absmiddle"/></td></tr></table>';
				break;
				case 'ratingContainer': 				
					{
					$(container).innerHTML = '<div align="center"><img src="siteimages/ajax-loader.gif" align="absmiddle"/></div>';	
					}
				break;
				
				case 'gamepreview':
					$(container).innerHTML = '<img src="siteimages/ajax-loader-game.gif" align="absmiddle" vspace="100"/>';
					break;
			default:
				{
				if($('videoLoader'))
					{
					$('videoLoader').style.display = '';
					}
				else
					{
					$(container).innerHTML = '<img src="'+imagename+'" align="absmiddle" vspace="100"/>';	
					}
				}
				break;
			}
			}
    }	
/*
::::::::::::::::::::::::::::::::::::::::::
:::::::::::::AJAX FUNCTION  ::::::::::::::
::::::::::::::::::::::::::::::::::::::::::
*/


function numbersonly(e, decimal) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if (decimal && (keychar == ".")) { 
  return true;
}
else
   return false;
}

/* MP3 PLAY PANEL*/
function mp3PlayOpen(myEvent, container, url ,elemHeight ,elemWidth)
	{
	ScrolledPosition();
	opened = setTimeout("mp3PlayShow('"+url+"', '"+container+"')", 500);
	
	var left;	
	left = myEvent.clientX - fm_shift_x;	
	var top;	
	top = myEvent.clientY + fm_shift_y;
	$(container).style.left = left - elemWidth - 20 + 'px';
	$(container).style.top  = top - elemHeight - 20 + 'px';	
	}
function mp3PlayShow(url, container)
	{
	$(container).style.display = '';
	makeRequest(url, container);
	}
	
/* LIMIT LENGHT */
function MaxLength(e, len, str)
	{
	if (window.event) {
	   key = window.event.keyCode;
	}
	else if (e) {
	   key = e.which;
	}
	else {
	   return true;
	}
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	   return true;
	}
	else
	{
	if(str.length >= len)
		{
		alert("Контентийн код хамгийн ихдээ "+len+" тэмдэгт агуулна.");
		return false;
		}
	else
		return true;
	}
}
/* SET HELP CONTENT */
function setHelp(container)
	{
	ScrolledPosition();
	$(container).style.left = document.documentElement.clientWidth / 2 - 300 + fm_shift_x + 'px';
	$(container).style.top  = document.documentElement.clientHeight / 2 - 130 + fm_shift_y + 'px';
	$(container).style.display = '';
	makeRequest('imagehelp.php?df=df', container);
	}



/// new center functions
function GetWindowHeight()
	{
	if( typeof( window.innerWidth ) == 'number' )
		{
    	//Non-IE
    	myHeight = window.innerHeight;
  	} 
	else 
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
			{
    		//IE 6+ in 'standards compliant mode'
   			myHeight = document.documentElement.clientHeight;
  			} 
		else
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
			{
			//IE 4 compatible
			myHeight = document.body.clientHeight;
		  	}
	return myHeight;
	}
	
function GetWindowWidth()
	{
	if( typeof( window.innerWidth ) == 'number' )
		{
    	//Non-IE
    	myWidth = window.innerWidth;
  	} 
	else 
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
			{
    		//IE 6+ in 'standards compliant mode'
   			myWidth = document.documentElement.clientWidth;
    		} 
		else
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
			{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			}
	return myWidth;
	}

function SetCenter(elemId)
    {
    var objElement 	= document.getElementById(elemId);
    
	winHeight	= GetWindowHeight();
    winWidth	= GetWindowWidth();

    var elemHeight 	= parseInt(objElement.style.height.substr(0, objElement.style.width.length-2));
    var elemWidth 	= parseInt(objElement.style.width.substr(0, objElement.style.width.length-2));
	
	$('disabledScreen').style.width = "100%";
	$('disabledScreen').style.height = document.documentElement.scrollHeight + "px";
	$('disabledScreen').style.display = '';
	
	objElement.style.left 	= parseInt(winWidth/2 - elemWidth/2) + "px"; 
    objElement.style.top 	= parseInt(winHeight/2 - elemHeight/2) + document.documentElement.scrollTop + "px";	
    }

function gamePreview(container, contentid)
	{	
	SetCenter(container);
	$(container).style.display = '';
	makeRequest('gamepreview.php?contentid=' + contentid,  container);
	}


/* CHANGE STAR ICON */
function ChangeStar(id, image)
	{
	$(id).src = image;	
	}

function ChangeAllStar(start, prefix, image)
	{
	for(var i = 1; i <= start; i++)
		$(prefix + i).src = image;
	}
	
function ChangeAllStarClear(prefix)
	{
	for(var i = 1; i <= 5; i++)
		$(prefix + i).src = $(prefix + i).lang;
	}