
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function preloadImages(){
    MM_preloadImages(
           js_images_path+'shared/btn_play_over.gif', 
		   js_images_path+'shared/bul_close.gif', 
		   js_images_path+'shared/bul_open.gif', 
		   js_images_path+'shared/counter.gif', 
		   js_images_path+'shared/counter_ok.gif', 
		   js_images_path+'shared/counter2.gif', 
		   js_images_path+'shared/cartPopUp_close.gif',
		   js_images_path+'shared/rstar1.gif',
		   js_images_path+'shared/rstar2.gif',
		   js_images_path+'shared/rstar3.gif',
		   js_images_path+'shared/transparent1.png', 
		   js_images_path+'shared/transparent2.png', 
		   js_images_path+'shared/dialog/shadow-l.png', 
		   js_images_path+'shared/dialog/shadow-r.png', 
		   js_images_path+'shared/dialog/shadow-t.png', 
		   js_images_path+'shared/dialog/shadow-b.png', 
		   js_images_path+'shared/dialog/shadow-lt.png', 
		   js_images_path+'shared/dialog/shadow-lb.png', 
		   js_images_path+'shared/dialog/shadow-rt.png', 
		   js_images_path+'shared/dialog/shadow-rb.png',		   
		   js_images_path+'shared/dialog/dlg-shadow-l-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-r-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-t-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-b-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-lt-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-lb-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-rt-rounded.png', 
		   js_images_path+'shared/dialog/dlg-shadow-rb-rounded.png',		   
		   js_images_path+'shared/modules/module_head_open.png', 
		   js_images_path+'shared/modules/module_head_closed.png', 
		   js_images_path+'shared/modules/module_left.png', 
		   js_images_path+'shared/modules/module_right.png',
		   js_images_path+'shared/modules/module_bottom.png',
		   js_images_path+'mod_default/start_search_here.gif',
		   js_images_path+'shared/forms/dropdown_bg_standard_over.gif',
		   js_images_path+'shared/links/link_bg.png',
		   js_images_path+'shared/header_menu/header_menu.jpg',
		   js_images_path+'shared/header_menu/header_menu_over.jpg');
}



function openPopUpWindow(url,x,y){
  window.open(url+"&popup_headers=yes","","scrollbars,resizable,width="+x+",height="+y);
}

window.onresize = function(){
  checkPlayerPosition('emptyRight','emptyTop'); //player.js
  resizeModalOverlay();
}


function addNeoEventHandler(element, type, func) {
	if(element.addEventListener) {
		element.addEventListener(type,func,false);
	}
	else if (element.attachEvent) {
		element.attachEvent('on'+type,func);
	}
}

function removeNeoEventHandler(element, type, func) {
	if(element.removeEventListener) {
		element.removeEventListener(type,func,false);
	}
	else if (element.attachEvent) {
		element.detachEvent('on'+type,func);
	}
}



var dialogTimeout = new Array();
var modalOverlays = new Array();
var openedDialogs = new Array();
var nextZIndex    = 0; 
bul_img_open      =  new Image();
bul_img_close     =  new Image();
bul_img_open.src  =  js_images_path+'shared/bul_open.gif';
bul_img_close.src =  js_images_path+'shared/bul_close.gif';




document.onkeydown = function(e) {
	e = e || window.event;
	if (e.keyCode == 27){
	    if(openedDialogs.length > 0){
			deleteDialog(openedDialogs[openedDialogs.length-1]); 
		}
	}
	return true;
}


//document.onclick = function(e) {
//	e = e || window.event;
//    var mouse_x  = parseInt(mouseX(e));
//	var mouse_y  = parseInt(mouseY(e));
//	if(document.getElementById('sign-in-dialog')){
//		if(mouse_x < getElementLeft(document.getElementById('sign-in-dialog')) || 
//		   mouse_x > getElementRight(document.getElementById('sign-in-dialog'))	|| 
//		   mouse_y > getElementTop(document.getElementById('sign-in-dialog')) + getElementHeight(document.getElementById('sign-in-dialog'))
//		   
//		 )
//		    deleteDialog('sign-in-dialog');		
//	}
//	return true;
//}


////////////////////////////// DIV MANIPULATION ///////////////////////////
function createDiv(id){
    var div = document.createElement('div');
    div.setAttribute('id',id);
    document.body.appendChild(div);
}

function deleteDiv(id){
	if(document.getElementById(id)){
       document.getElementById(id).innerHTML = '';
       document.getElementById(id).style.display = "none";
       document.body.removeChild(document.getElementById(id));
	   return true;
	}
	else 
	   return false;
}


function setDialogPosition(id,x,y){
	if(!document.getElementById(id))
	   return null;

    if(x == 'center')
	   moveElementToCenter(id);   
}


function createDialog(id,x,y,header_text,content,show_header,align,modal,width,height,buttons,conners){

	if(document.getElementById(id))
       deleteDialog(id);
    
    if(modal){
      var modalZ = getNextZIndex();
	      modalZ = getNextZIndex();
      createModalOverlay(modalZ, id);
	}

    zIndex = getNextZIndex();
	zIndex = getNextZIndex();
	if(align == '') align="center";
	createDiv(id);
	document.getElementById(id).display = "none";


    if(width == '' || width == 'undefined' || width == null)
        tblWidth = ' ';
    else {
        tblWidth = ' width="100%" ';
        document.getElementById(id).style.width = width+'px';
	}

    if(conners == "square")
	   conners = "";
    else if (conners == "rounded")
	   conners = "-rounded";
    else
	   conners = "-rounded";

	divHtml = '<'+'table border="0" align="left" width="100%" cellpadding="0" cellspacing="1" class="dialog_table'+conners+'"'+'>';


    if(show_header){
	divHtml += '<'+'tr'+'>'+
			     '<'+'td align="center"'+' nowrap="nowrap" width="100%">'+
				 '<'+'div id="'+id+'_handler" '+' style="cursor:move; margin:-5px -5px 0px -5px; position:relative;zoom:1;">'+
			       '<'+'table border="0" align="left" cellpadding="0" cellspacing="0" width="100%"'+'>'+
				     '<'+'tr'+'>'+
					    '<'+'td align="left" class="dialog_header_left" width="99%" nowrap="nowrap">'+header_text+'<'+'/'+'td'+'>'+							 
						'<'+'td align="right" width="1%"'+' class="dialog_header_right" valign="middle" nowrap="nowrap">'+
						  ' <'+'a href="javascript:deleteDialog(\''+id+'\')" class="dialog_close_icon"'+'>'+
						  '<'+'/'+'a'+'>'+ 
						'<'+'/'+'td'+'>'+
					  '<'+'/'+'tr'+'>'+
			       '<'+'/'+'table'+'>'+
                 '<'+'/'+'div'+'>'+
				 '<'+'/'+'td'+'>'+					  
			   '<'+'/'+'tr'+'>';
				  
	}

	divHtml += '<'+'tr'+'>'+
			     '<'+'td params="z-index:'+zIndex+'|id:'+id+'" align="'+align+'"'+'>'+'<'+'div id="'+id+'_content" class="dialog_content'+conners+'" align="'+align+'"'+' dialog="dialog">'+content+'<'+'/'+'div'+'>'+'<'+'/'+'td'+'>'+
			    '<'+'/'+'tr'+'>';


   if(!buttons == ''){
   divHtml += '<'+'tr'+'>'+
			    '<'+'td align="center"'+' nowrap="nowrap" class="dialog_content'+conners+'" style="padding:4px;">'+
				  '<img src="'+js_images_path+'shared/buttons/btn_s1_close.gif" border="0" alt="close" align="middle" onclick="deleteDialog(\''+id+'\');" class="dialog_buttons">'+
                '<'+'/'+'td'+'>'+
			  '<'+'/'+'tr'+'>';
   }
				  
   divHtml += '<'+'/'+'table'+'>';


 divContent = '<table border="0" cellspacing="0" cellpadding="0" class="shadowed" '+tblWidth+' >'+
              '  <tr>'+
              '    <td class="lt'+conners+'"></td>'+
              '    <td class="t'+conners+'"></td>'+
              '    <td class="rt'+conners+'"></td>'+
              '  </tr>'+

              '  <tr>'+
              '    <td class="l'+conners+'"></td>'+
              '    <td>'+divHtml+'</td>'+
              '    <td class="r'+conners+'"></td>'+
              '  </tr>'+

              '  <tr>'+
              '    <td class="lb'+conners+'"></td>'+
              '    <td class="b'+conners+'"></td>'+
              '    <td class="rb'+conners+'"></td>'+
              '  </tr>'+
              '</table>';



	document.getElementById(id).style.position = 'absolute';
    document.getElementById(id).style.zIndex   = zIndex;
	document.getElementById(id).innerHTML      = divContent;

    if(x == 'center')
	   x = getInnerWindowCenterX() - getElementWidth(id)/2;
    if(y == 'center')
	   y = getInnerWindowCenterY() - getElementHeight(id)/2 - 100;

	document.getElementById(id).style.top      = y+'px';
	document.getElementById(id).style.left     = x+'px';

	document.getElementById(id).display        = "";
	
    if(show_header){
       Drag.init(document.getElementById(id+"_handler"), document.getElementById(id),null,null,null,null);
	   openedDialogs.push(id);
	}
}


function getNextZIndex(){
   return nextZIndex++;
}
function decreaseZIndex(){
   return nextZIndex--;
}

function deleteDialog(id){
    deleteModalOverlay(id);
    if(dialogTimeout[id])
	   	clearTimeout(dialogTimeout[id]);
    deleteDiv(id)
	notice('');
	decreaseZIndex();
	decreaseZIndex();
	if(id == openedDialogs[openedDialogs.length-1])
       openedDialogs.pop();
}


function deleteAllDialogs(){
	var l=openedDialogs.length-1;
	for(var i=l; i>=0; i--)
		deleteDialog(openedDialogs[i]);
}


function getDialogParams(childId, paramName){
   if(!document.getElementById(childId))
      return;
   var obj = document.getElementById(childId);

   if(obj.offsetParent == 'undefined' || obj  == null)
      return;
   else if(!obj.offsetParent.attributes['params'])
      return;

   var params = new String(obj.offsetParent.attributes['params'].value);
   arr1 = new Array();
   arr2 = new Array();
   arr3 = new Array();
   arr1 = params.split("|");
   for(key1 in arr1){
      arr2 = arr1[key1].split(":");
	  if(arr2[0] == paramName)
	     return arr2[1];
   }
   return null;
}


function createModalOverlay(zIndex, openerId){
    var div = document.createElement('div');
    div.setAttribute('id','modal_overlay_'+openerId);
    document.body.appendChild(div);
    document.getElementById('modal_overlay_'+openerId).style.zIndex = zIndex;
    document.getElementById('modal_overlay_'+openerId).style.width  = getDocumentWidth()+'px';
    document.getElementById('modal_overlay_'+openerId).style.height = getDocumentHeight()+'px';
    document.getElementById('modal_overlay_'+openerId).className    = 'modal_overlay';
    document.getElementById('modal_overlay_'+openerId).onclick      = function(){deleteDialog(openerId); return true;};
    showHideIE6Selects('body', 'hidden');
    showHideFlashObjects('body', 'hidden');
	modalOverlays['modal_overlay_'+openerId] = 'modal_overlay_'+openerId;
}

function deleteModalOverlay(openerId){
    if(document.getElementById('modal_overlay_'+openerId)){
	   deleteDiv('modal_overlay_'+openerId);
       showHideIE6Selects('body', 'visible');
       showHideFlashObjects('body', 'visible');
	   delete modalOverlays['modal_overlay_'+openerId];
	   decreaseZIndex();
	   decreaseZIndex();
	}
}


function resizeModalOverlay(){
	for (key in modalOverlays){
	   if(document.getElementById(key)){
          document.getElementById(key).style.width  = getDocumentWidth()+'px';
          document.getElementById(key).style.height = getDocumentHeight()+'px';
	   }
	}
}

function showHideIE6Selects(objId, visibility){
   var obj;
   if(objId == '')
      return;

   if(objId == 'body')
      obj = document.body;
   else if(!document.getElementById(objId))
      return;
   else
     obj = document.getElementById(objId);
   
   detect = navigator.userAgent.toLowerCase();
   if(detect.indexOf('msie') + 1){
     selects = obj.getElementsByTagName('select');
     for(i = 0; i < selects.length; i++) {
        selects[i].style.visibility = visibility;
     }
   }
}


function showHideFlashObjects(objId, visibility){
   var obj;
   if(objId == '')
      return;

   if(objId == 'body')
      obj = document.body;
   else if(!document.getElementById(objId))
      return;
   else
     obj = document.getElementById(objId);
   
     flashObj = obj.getElementsByTagName('object');
     for(i = 0; i < flashObj.length; i++) {
		if(flashObj[i].id != 'neoplayer_swf')
        flashObj[i].style.visibility = visibility;
     }

}



////////////////////////////// COOKIES ///////////////////////////
function setCookie(name,value,lifetime){
	if (lifetime){
		var date = new Date();
		date.setTime(date.getTime()+(lifetime));
		var expires = "; expires="+date.toGMTString();
    }
	else
	    var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain="+js_cookie_domain;
}


function getCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ')
		   c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		   return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function deleteCookie(name){
	setCookie(name,"",-1);
}





function cookieArray(action,cookiename,key,value){
     var arr;
	 arr = getCookie(cookiename);
	 if(arr == null || arr == '')
	    arr = new Array();
	 else
	    arr = arr.split('|');
	 var cookieString = '';
	 var elem;

     if(action == 'update'){
		 if(arr.length == 0)
			 cookieString = key+':'+value;
		 else {
             cookieString = key+':'+value+'|';
			 for (arrkey in arr) {
				elem = arr[arrkey];
				elem = elem.split(':');
				if(elem[0] != key)
				   cookieString = cookieString+elem[0]+':'+elem[1]+'|';
			 }
			 cookieString = cookieString.substr(0,cookieString.length-1);
		 }
	 }
	 else if(action == 'delete'){
			 for (arrkey in arr) {
				elem = arr[arrkey];
				elem = elem.split(':');
				if(elem[0] != key)
				   cookieString = cookieString+elem[0]+':'+elem[1]+'|';
			 }
			 cookieString = cookieString.substr(0,cookieString.length-1);
	 }

	 if(cookieString == '')
        deleteCookie(cookiename);
	 else
	    setCookie(cookiename, cookieString, 365000*24*60*60);
}
 

function setCookieArray(cookiename,action,key,value){
	cookieArray(action,cookiename,key,value);
}


function toggleModule(obj,value){
   var module   = document.getElementById(obj);
   var modNodes = getChildNodes(module);
   var header   = modNodes[0];
   var box      = modNodes[1];
   if(value == 1){
	   box.className     = "box"; 
	   header.className  = "head";
       cookieArray('update','modules',module.id,1);
   }
   else if (value == 0){
	   box.className    = "box_closed";
	   header.className = "head_closed";
       cookieArray('update','modules',module.id,0);

   }
   else if(box.className == "box_closed"){
	   box.className     = "box"; 
	   header.className  = "head";
       cookieArray('update','modules',module.id,1);
   }
   else if (box.className == "box"){
	   box.className    = "box_closed";
	   header.className = "head_closed";
       cookieArray('update','modules',module.id,0);
   }
}



function initModules(){
   var elem;
   var modules = getCookie('modules');
   if(modules == null || modules == "" || modules == 'undefined')
     return;
		  
   modules = modules.split('|');
   if(modules == null || modules == "" || modules == 'undefined')
     return;
	 
   for (key in modules) {
	  elem = modules[key];
	  elem = elem.split(':');
      if(document.getElementById(elem[0]) && elem[1] == 1)
	     toggleModule(elem[0],1);
      else if(document.getElementById(elem[0]) && elem[1] == 0) 
	     toggleModule(elem[0],0);
   }
}

function getChildNodes(n){
  var x=n.childNodes;
  var i; var y; y=0;
  var nodes = new Array();
  for (i=0; i < x.length; i++){
	 if(x[i].nodeType == 1){
        nodes[y] = x[i];
		y++;
	 }
  }
  return nodes;
}


function openSelector(selector_type, selector_id, selector_name_id, header, width){
	if(width == '' || width == null || width == 'undefined')
	   width = 700;
   createDialog('selector','center',getBodyScrollTop()+20,header,'',true, 'center', true, width);
   loadContent('selector_content', js_domain+'?mod=royalty-free-music&modfile=search_criteria_selector&selector_type='+selector_type+'&selector_id='+selector_id+'&selector_name_id='+selector_name_id+'&ajax_load_content_to=selector_content', 'dynamic', true, false, '');
   return false;
}




function addToCart(url){
   createDialog('ajax_cart','center',getBodyScrollTop()+20,'SHOPPING CART','',true, 'center', true, 780);
   loadContent('ajax_cart_content', url+'&ajax_load_content_to=ajax_cart_content', 'dynamic', true, false, '');
}

function addToProject(url, elm_id){
	if((getElementLeft(elm_id)-310) <= 0)
	   dLeft = getElementLeft(elm_id) + getElementWidth(elm_id) + 10;
    else
	   dLeft = getElementLeft(elm_id)-310;

	if((getElementTop(elm_id)-getBodyScrollTop() - 25) <= 0)
	   dTop = getElementTop(elm_id);
    else
	   dTop = getElementTop(elm_id)-25;

    createDialog('add_to_project',dLeft ,dTop,'Add to PlayBox','',true,'center',false,300);
	//notice('-', document.getElementById(elm_id), 'left-middle', 'center', 300, 'add_to_project', true, 'Add to PlayBox', url+'&ajax_load_content_to=add_to_project_content');
    loadContent('add_to_project_content', url+'&ajax_load_content_to=add_to_project_content', 'dynamic', true, false, '');
}


function notice(txt, obj_id, align, content_align, width, custom_notice_id, isHeader, header_text, loadUrl, onComplete){
   if(custom_notice_id == '' || custom_notice_id == 'undefined' || custom_notice_id  == null)
      notice_id = 'notice';
   else
      notice_id = custom_notice_id;

   if(isHeader == '' || isHeader == 'undefined' || isHeader  == null)
      isHeader = false;


   if(document.getElementById(notice_id))
        deleteDialog(notice_id);

   if(!txt == '' || !loadUrl == ''){

     createDialog(notice_id, -1000, -1000, header_text, txt, isHeader, content_align, false, width);
	 
	 updateDialogPosition(obj_id, notice_id, align);
	 

	 if(!loadUrl == ''){
		 var container_id;
		 var is_remove_id = false;
		 if(obj_id.getAttribute('id') == '' || obj_id.getAttribute('id') == null || obj_id.getAttribute('id') == 'undefined'){
			  container_id = notice_id+'_loadcontainer';
			  obj_id.setAttribute('id', container_id);
			  is_remove_id = true;
		 }
		 else 
		      container_id = obj_id.getAttribute('id');
		
		 var callback = "updateDialogPosition('"+container_id+"','"+notice_id+"','"+align+"');"+
						  "if("+is_remove_id+"){document.getElementById('"+container_id+"').removeAttribute('id');}";
	     loadContent(notice_id+'_content', loadUrl, 'dynamic', true, false, '',(callback+onComplete));
         updateDialogPosition(obj_id, notice_id, align);		 
	 }
	 else{
		 if(!onComplete == ""){
		    eval(onComplete);
		 }
	 }
	
  }
}


function updateDialogPosition(obj_id, notice_id, align){
	 var obj_pos = getOffset(obj_id);
     if(align=='flags_pos_left'){
        x = obj_pos.left-getElementWidth(notice_id)+getElementWidth(obj_id)+12;
        y = obj_pos.top-12;
	 }
	 if(align=='flags_pos_right'){
        x = obj_pos.left-12;
        y = obj_pos.top-12;
	 }	 
	 
	 if(align=='center'){
        x = (obj_pos.left+getElementWidth(obj_id)/2)-getElementWidth(notice_id)/2;
        y = obj_pos.top-12;
	 }
     if(align=='top-left'){
        x = obj_pos.left-5;
        y = obj_pos.top-getElementHeight(notice_id); 
	 }  

     if(align=='top-center'){
        x = obj_pos.left+getElementWidth(obj_id)/2 - getElementWidth(notice_id)/2;
        y = obj_pos.top-getElementHeight(notice_id); 
	 }
     if(align=='top-right'){
        x = obj_pos.left+getElementWidth(obj_id)+5-getElementWidth(notice_id);
        y = obj_pos.top-getElementHeight(notice_id); 
	 }

	 if(align=='left' || align=='left-top'){
        x = obj_pos.left-getElementWidth(notice_id);
        y = obj_pos.top-10;
	 }
     if(align=='left-middle'){
        x = obj_pos.left-getElementWidth(notice_id);
        y = obj_pos.top+getElementHeight(obj_id)/2 - getElementHeight(notice_id)/2; 
	 }
	 if(align=='left-bottom'){
        x = obj_pos.left-getElementWidth(notice_id);
        y = obj_pos.top+getElementHeight(obj_id) - getElementHeight(notice_id) + 10; 
	 }

	 if(align=='right' || align=='right-top'){
        x = obj_pos.left+5+getElementWidth(obj_id);
        y = obj_pos.top-10;
	 }
     if(align=='right-middle'){
        x = obj_pos.left+getElementWidth(obj_id);
        y = obj_pos.top+getElementHeight(obj_id)/2 - getElementHeight(notice_id)/2; 
	 } 
     if(align=='right-bottom'){
        x = obj_pos.left+getElementWidth(obj_id);
        y = obj_pos.top+getElementHeight(obj_id) - getElementHeight(notice_id) + 10;
	 } 
	 if(align=='bottom' || align=='bottom-left'){
        x = obj_pos.left-5;
        y = obj_pos.top+getElementHeight(obj_id);
	 }
	 if(align=='bottom-center'){
        x = obj_pos.left+getElementWidth(obj_id)/2-getElementWidth(notice_id)/2;
        y = obj_pos.top+getElementHeight(obj_id);
	 }
	 if(align=='bottom-right'){
        x = obj_pos.left+getElementWidth(obj_id)+5-getElementWidth(notice_id);
        y = obj_pos.top+getElementHeight(obj_id);
	 }

     document.getElementById(notice_id).style.left = x+'px';
     document.getElementById(notice_id).style.top  = y+'px';

	 var out = new Array();
	 out['x'] = x;
	 out['y'] = y;
	 return out;

}


function downloadLRDemo(obj){
   notice(' ',obj, 'left', 'center', 200, 'dnldLRFile');
   loadContent('dnldLRFile_content', obj.href, 'dynamic', true, false, '');
}





////////////////////////////// RATINGS  ///////////////////////////
function ratingStars(starId, groupId){
	for(i=1; i<=5;i++){
       if(i <= starId)
	      document.getElementById('rstar_'+groupId+'_'+i).src=js_images_path+'shared/rstar2.gif';
       else
          document.getElementById('rstar_'+groupId+'_'+i).src=js_images_path+'shared/rstar1.gif';
	}
}


function restoreRating(score, groupId){
	for(i=1; i<=5;i++){
       if(i <= score)
          document.getElementById('rstar_'+groupId+'_'+i).src=js_images_path+'shared/rstar2.gif';
       else if((i-score)<=0.5)
          document.getElementById('rstar_'+groupId+'_'+i).src=js_images_path+'shared/rstar3.gif';
       else
          document.getElementById('rstar_'+groupId+'_'+i).src=js_images_path+'shared/rstar1.gif';
	}
}



function rateItem(itemType, itemId, score, itemName, action, x,y){
	var http_request = ajaxRequest(); // ajaxRequest(); //new JsHttpRequest();

         if(action == 'rate'){
		       message = '<'+'img src="'+js_images_path+'shared/counter.gif" border="0" align="middle"'+'>'+'<'+'br'+'>'+
						'&nbsp;&nbsp;Please wait...&nbsp;&nbsp;';
		 }
		 else {
			   message = '<'+'br'+'>'+
		                 ' <'+'b'+'>'+itemName+'<'+'/'+'b'+'>'+'<'+'br'+'>'+'<'+'br'+'> '+
						 'Score: <'+'b'+'>'+score+'<'+'/'+'b'+'>'+'<'+'br'+'>'+'<'+'br'+'>'+
						 '<'+'input type="button" value="RATE" class="form_button" '+
						 'onclick="rateItem(\''+itemType+'\',\''+itemId+'\',\''+score+'\',\''+escape(itemName)+'\',\'rate\','+x+','+y+')"'+'>';
		 }

          createDialog('rateDialog', x+60, y-40, 'Rate this song', '', true, 'center', false, 200);
		 document.getElementById('rateDialog_content').innerHTML = message;
			  
		 if(action == 'rate'){
			if(http_request){
			   http_request.onreadystatechange = function(){
					if (http_request.readyState == 4) {
					  if (http_request.status == 200){
						 if(dialogTimeout['rateDialog'])
						   clearTimeout(dialogTimeout['rateDialog']);
						   document.getElementById('rateDialog_content').innerHTML = '';
						   document.getElementById('rateDialog_content').innerHTML = http_request.responseText;
						   dialogTimeout['rateDialog'] = setTimeout('deleteDialog("rateDialog")', 10000);
					  }       
				   }
				};
			   http_request.open('GET', js_domain+'?mod=ratings&modfile=rate&item_id='+itemId+'&item_type='+itemType+'&score='+score+'&ajax=true', true);	   
			   http_request.send(null);
			 }
		 }
}


function addTag(id){
  text         = document.getElementById(id).innerHTML;
  var reg      = '<a[^>]*>([\u0001-\uFFFF]*?)</a>';
  var matchAll = new RegExp(reg, 'img');
  text         = text.match(matchAll,'');
  if(text == null || text == '') text = "";

  text         = text.toString();
  var reg      = '<a[^>]*>|</a>';
  var matchAll = new RegExp(reg, 'img');
  text         = text.replace(matchAll,'');
  text         = text.toString();
  


  document.getElementById(id+'_input').value = text;
  document.getElementById(id).style.display = (document.getElementById(id).style.display=="none") ? "":"none";  
  document.getElementById(id+'_edit').style.display = (document.getElementById(id+'_edit').style.display=="none") ? "":"none";  
}

function saveTag(musicProductId, divId){
	tag_data = encodeURIComponent(document.getElementById(divId+'_input').value);
    document.getElementById(divId+'_edit').style.display = "none";
    document.getElementById(divId).style.display = "";
	loadContent(divId, js_domain+'?mod=royalty-free-music&modfile=tag_edit&tag_data='+tag_data+'&music_product_id='+musicProductId,'dynamic', true,false,'');
}


function cancelTagEdit(id){
  document.getElementById(id+'_edit').style.display = "none";
  document.getElementById(id+'_input').value = "";
  document.getElementById(id).style.display = "";
}

function deleteTag(musicProductId, id){
   document.getElementById(id+'_input').value = "";
   saveTag(musicProductId, id);
}

function roundDecimals(number, decimals) {
    number = number*Math.pow(10, decimals);
    number = Math.round(number);
    number = number/Math.pow(10, decimals);
    return number;
}

function divStrReplace(div_id, srch, repl){
    if(document.getElementById(div_id)){
	   txt          = document.getElementById(div_id).innerHTML;
	   txt          = txt.toString();
	   var matchAll = new RegExp (srch, 'img');
	   txt          = txt.replace(matchAll, repl);
       document.getElementById(div_id).innerHTML = txt;
	}
}

function createChildMenu(parent_id, group_id, child_orientation, content, onmouseover_class, is_close_onclick){
	var child_id  = 'nsmenu_child_'+group_id;
	if(!document.getElementById(parent_id))
	    return;
	   
    var objParent = document.getElementById(parent_id);
	if(document.getElementById(child_id) == null || document.getElementById(child_id) == 'undefined' || !document.getElementById(child_id)) 
	     var objChild  = false;
    else 
	     var objChild  = document.getElementById(child_id);
		 
	 
	
    if(!objChild){

		objParent.setAttribute("original_class_name",objParent.className);
		
		if(!onmouseover_class == '')
		   objParent.className = onmouseover_class;
	
        objParent.setAttribute("onmouseout","parentMenuMouseOut('"+parent_id+"',event)");
		if((typeof objParent.onmouseout) == 'string')
		       objParent.onmouseout = (function(parent_id){return function(){parentMenuMouseOut(parent_id,event);}})(parent_id);
			   
		if(!content == ""){
		   if(content.substr(0,6) == '#load:'){
		      var loadUrl = content.replace('#load:','').toString();
			  content = '';
		   }
		   else {
		      var loadUrl = '';
		   }
			  
		   var objChild = document.createElement('div');
           objChild.setAttribute('id',child_id);
           objParent.appendChild(objChild);
		   objParent.setAttribute("child_id",child_id);
		   objChild.style.position = 'absolute';
		   objChild.setAttribute("child_orientation",child_orientation);
		   objChild.setAttribute("parent_id",parent_id);
		   objChild.setAttribute("onmouseout","childMenuMouseOut('"+child_id+"',event)");
		   if((typeof objChild.onmouseout) == 'string')
		       objChild.onmouseout = (function(child_id){return function(){childMenuMouseOut(child_id,event);}})(child_id);


		   var temp_id = parent_id+'_tmp';
     	   var doAfter = "if(document.getElementById('"+child_id+"').getAttribute('parent_id') == '"+parent_id+"'){"+
		                 "var child_tmp_pos         = getOffset('"+temp_id+"');"+
					     "var child_mrg_top         = child_tmp_pos.top;"+
						 "var child_mrg_left        = child_tmp_pos.left;"+
						 "   document.getElementById('"+child_id+"').innerHTML = document.getElementById('"+temp_id+"').innerHTML;"+
						 "   document.getElementById('"+child_id+"').style.zIndex = document.getElementById('"+temp_id+"').style.zIndex;"+
						 "   deleteDialog('"+temp_id+"');"+
						 "   var child_pos             = getOffset(document.getElementById('"+child_id+"'));"+
						 "   document.getElementById('"+child_id+"').style.marginTop  = (child_mrg_top  - child_pos.top)  +'px';"+
						 "   document.getElementById('"+child_id+"').style.marginLeft = (child_mrg_left - child_pos.left) +'px';"+
						 "}";
						  
			notice(content, objParent, child_orientation,'left','',temp_id,'','',loadUrl,doAfter);
			if(document.getElementById(temp_id)){
			    var objTemp = document.getElementById(temp_id);
		        objTemp.setAttribute("onmouseout","tempMenuMouseOut('"+temp_id+"',event)");
		        objTemp.setAttribute("parent_id",parent_id);
		        if((typeof objTemp.onmouseout) == 'string')
		           objTemp.onmouseout = (function(temp_id){return function(){tempMenuMouseOut(temp_id,event);}})(temp_id);
			}

		}
	}
	else if(objChild.getAttribute('parent_id') != parent_id){
		 previous_parent_id = objChild.getAttribute('parent_id');
		 document.getElementById(previous_parent_id).className = document.getElementById(previous_parent_id).getAttribute("original_class_name");
		 document.getElementById(previous_parent_id).removeAttribute("original_class_name");
		 document.getElementById(objChild.getAttribute('parent_id')).removeChild(objChild);
		 createChildMenu(parent_id, group_id, child_orientation, content, onmouseover_class);
	}
	   
}

function parentMenuMouseOut(parent_id,evt){
	if(!document.getElementById(parent_id) || parent_id == '' )
	    return;

    var objParent = document.getElementById(parent_id);
	var child_id  = objParent.getAttribute('child_id');
	if(child_id == '' || child_id == null || document.getElementById(child_id) == null || document.getElementById(child_id) == 'undefined') 
	    var objChild = false;
    else 
	    var objChild = document.getElementById(child_id);
	
    if(!objChild){
		   objParent.className = objParent.getAttribute("original_class_name");
		   objParent.removeAttribute("original_class_name");
		   return;
	}
    
    var p_coord  = getOffset(objParent);
	var c_coord  = getOffset(objChild);
	var p_left   = p_coord.left;
	var p_right  = p_coord.left  + getElementWidth(parent_id);
	var p_top    = p_coord.top;
    var p_bottom = p_coord.top   + getElementHeight(parent_id);
    var c_left   = c_coord.left;
    var c_right  = c_coord.left  + getElementWidth(child_id);
    var c_top    = c_coord.top;
    var c_bottom = c_coord.top   + getElementHeight(child_id);
    var mouse_x  = parseInt(mouseX(evt));
	var mouse_y  = parseInt(mouseY(evt));
	

    if(objChild.getAttribute('child_orientation') == 'left-top'
    || objChild.getAttribute('child_orientation') == 'left-middle'		
	|| objChild.getAttribute('child_orientation') == 'left-bottom'){
        if((mouse_x >= p_right-2 || mouse_y <= p_top+2 || mouse_y >= p_bottom-2) && 
			!(mouse_x <= c_right-2 && mouse_x >= c_left+2 && mouse_y >= c_top+2 && mouse_y <= c_bottom-2)){ 
		        menuRemoveMenu(objParent);
		}

	}
    else if(objChild.getAttribute('child_orientation') == 'bottom-left' 
         || objChild.getAttribute('child_orientation') == 'bottom-center' 
	     || objChild.getAttribute('child_orientation') == 'bottom-right'){  
         if((mouse_x >= p_right-2 || mouse_x <= p_left+2 || mouse_y <= p_top+2) && 
			!(mouse_x <= c_right-2 && mouse_x >= c_left+2 && mouse_y >= c_top+2 && mouse_y <= c_bottom-2)){ 
                menuRemoveMenu(objParent);
		 }
	}
}

function childMenuMouseOut(child_id, evt){
	if(!document.getElementById(child_id))
	    return;

    var objChild = document.getElementById(child_id);
	var parent_id = objChild.getAttribute('parent_id');
	if(!document.getElementById(parent_id))
	    return;

    var objParent = document.getElementById(parent_id);

    var p_coord  = getOffset(objParent);
	var c_coord  = getOffset(objChild);
	var p_left   = p_coord.left;
	var p_right  = p_coord.left  + getElementWidth(objParent);
	var p_top    = p_coord.top;
    var p_bottom = p_coord.top   + getElementHeight(objParent);
    var c_left   = c_coord.left;
    var c_right  = c_coord.left  + getElementWidth(objChild);
    var c_top    = c_coord.top;
    var c_bottom = c_coord.top   + getElementHeight(objChild);
    var mouse_x   = parseInt(mouseX(evt));
	var mouse_y   = parseInt(mouseY(evt));

    if(objChild.getAttribute('child_orientation') == 'left-top'
    || objChild.getAttribute('child_orientation') == 'left-middle'		
	|| objChild.getAttribute('child_orientation') == 'left-bottom'){
        if(    mouse_x <= c_left+2 || mouse_y <= c_top+2 || mouse_y >= c_bottom-2 
	       || (mouse_x >= c_right-2 && mouse_y >= p_bottom-2) 
		   || (mouse_x >= c_right-2 && mouse_y <= p_top+2)){
		       menuRemoveMenu(objParent);
		}
	}
    else if(objChild.getAttribute('child_orientation') == 'bottom-left'
         || objChild.getAttribute('child_orientation') == 'bottom-center'		
	     || objChild.getAttribute('child_orientation') == 'bottom-right'){
			if(    mouse_x <= c_left+2 || mouse_x >= c_right-2 || mouse_y >= c_bottom-2 
			   || (mouse_y <= c_top+2 && mouse_x <= p_left+2) 
			   || (mouse_y <= c_top+2 && mouse_x >= p_right-2)){
				   menuRemoveMenu(objParent);
			}
	}
}

function tempMenuMouseOut(temp_id, evt){
	if(!document.getElementById(temp_id))
	    return;

    var objTemp   = document.getElementById(temp_id);
    var objParent = document.getElementById(objTemp.getAttribute('parent_id'));

    var t_coord  = getOffset(objTemp);
	var t_left   = t_coord.left;
	var t_right  = t_coord.left + getElementWidth(objTemp);
	var t_top    = t_coord.top;
    var t_bottom = t_coord.top  + getElementHeight(objTemp);
    var mouse_x  = parseInt(mouseX(evt));
	var mouse_y  = parseInt(mouseY(evt));

    if(mouse_x <= t_left+2 || mouse_x >= t_right-2 || mouse_y <= t_top+2 || mouse_y >= t_bottom-2)
       menuRemoveMenu(objParent);
}



function menuRemoveMenu(objParent){
	var parent_id        = objParent.id;
	var child_id         = objParent.getAttribute('child_id');
	objParent.className  = objParent.getAttribute("original_class_name");
	if(document.getElementById(child_id))
       objParent.removeChild(document.getElementById(child_id));
	
	if(document.getElementById(parent_id+'_tmp'))
	   deleteDialog(parent_id+'_tmp'); 
}

function openFAQAnswer(url,section){
   createDialog('faq_answer','center',getBodyScrollTop()+20,'FAQ','',true,'center',true,550,'','close');
   loadContent('faq_answer_content', url+'&faq_mode=dialog&faq_section='+section, 'dynamic', true, false, '');
}


function trimStr(str) {
	var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
	for (var i = 0; i < str.length; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}
	for (i = str.length - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

