// ====================== Cookies functions =========================== //
var PlayerExpDays = 1; // number of days the cookie should last 

var PlayerExp = new Date(); 
PlayerExp.setTime(PlayerExp.getTime() + (PlayerExpDays*24*60*60*1000));


function GetCookie (name) 
{ 
    var arg = name + "="; 
    var alen = arg.length; 
    var clen = document.cookie.length; 
    var i = 0; 
    while (i < clen) 
    { 
        var j = i + alen; 
        if (document.cookie.substring(i, j) == arg) 
            return getCookieVal (j);
             
        i = document.cookie.indexOf(" ", i) + 1; 
        if (i == 0) 
            break; 
    } 
    return null; 
}
 
function SetCookie (name, value) 
{ 
    var argv = SetCookie.arguments; 
    var argc = SetCookie.arguments.length; 
    var expires = (argc > 2) ? argv[2] : null; 
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null; 
    var secure = (argc > 5) ? argv[5] : false; 
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) + 
    ((domain == null) ? "" : ("; domain=" + domain)) + 
    ((secure == true) ? "; secure" : ""); 
}
 
function DeleteCookie (name) 
{ 
    var exp = new Date(); 
    exp.setTime (exp.getTime() - 1); 
    var cval = GetCookie (name); 

//alert(name + "=" + cval + "; expires=" + exp.toGMTString());
//alert(document.cookie);
    
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
     
} 
 
function amt()
{ 
    var count = GetCookie('count') 
    if(count == null) 
    { 
        SetCookie('count','1') 
        return 1 
    } 
    else 
    { 
        var newcount = parseInt(count) + 1; 
        DeleteCookie('count') 
        SetCookie('count',newcount,PlayerExp) 
        return count 
    } 
}
 
function getCookieVal(offset) 
{ 
    var endstr = document.cookie.indexOf (";", offset); 
    if (endstr == -1) 
        endstr = document.cookie.length; 
    return unescape(document.cookie.substring(offset, endstr)); 
} 

function checkCount() 
{ 
    var count = GetCookie('MediaPlayerPopupCount'); 
    if (count == null) 
    { 
        count=1; 
        SetCookie('MediaPlayerPopupCount', count, PlayerExp); 
        window.open(page1, "", windowprops); 
    } 
/*
    else 
    { 
        count++; 
        SetCookie('count', count, PlayerExp); 
    }
*/     
} 

// END ====================== Cookies functions =========================== //




//Custom (The Messanger) Audio Player Top-Flash button handler function
function flashBtnCustomAudioPlayerClick(sRootUrl, isAuthorized, CustomPlayilstID)
{
    if(isAuthorized)
    {
        var count = GetCookie('CustomMediaPlayerPopupCount');
        if (count == null) 
        { 
            count=1; 
            SetCookie('CustomMediaPlayerPopupCount', count, PlayerExp);
            
            playlistWindow = window.open(sRootUrl + 'custom_playlistplayer.php?id=' + CustomPlayilstID, '', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=300, height=420, left=0, top=0'); 
        } 
        else
        {
            if(typeof(playlistWindow) != 'undefined')
                playlistWindow.focus();
            else
                alert('You already have this music player window open.');
        }
    }
    else
    {
        document.location.href = sRootUrl + 'login.php';
    }
}




//My Audio Player Top-Flash button handler function
function flashBtnAudioPlayerClick(sRootUrl, isAuthorized, haveTracks)
{
    if(isAuthorized)
    {
        if (haveTracks)
        {
            
            var count = GetCookie('MediaPlayerPopupCount');
            if (count == null) 
            { 
                count=1; 
                SetCookie('MediaPlayerPopupCount', count, PlayerExp);
                
                playlistWindow = window.open(sRootUrl + 'playlistplayer.php?action=play', '', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=300, height=420, left=0, top=0'); 
            } 
            else
            {
                if(typeof(playlistWindow) != 'undefined')
                    playlistWindow.focus();
                else
                    alert('Your music player window is already opened.\nPlease use it to control the playback.');
            }
            
/*            
            if (typeof(playlistWindow) == 'undefined' || playlistWindow.closed)
            {
                playlistWindow = window.open(sRootUrl + 'playlistplayer.php?action=play', '', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=300, height=420, left=0, top=0');
            }
            else
            {
                playlistWindow.focus();
            }
*/            
        }
        else
        {
             //alert('You have no playlists. You need to create at least one playlist\nand add some songs before you can use My Audio Player feature.\nPlease browse to Manage Profile - > Toolkit -> My playlists\nto create your playlists.');
             document.location.href = sRootUrl + 'page.php?id=96';
        }
    }
    else
    {
        document.location.href = sRootUrl + 'login.php';
    }
}

//select elements from collection with specific id
function MiniPlayerAllShowHide(colMiniPlayerDiv, state, elName)
{
	var elName = new String(elName);
	for (i = 0; i < colMiniPlayerDiv.length; i++)
	{
        //alert(colMiniPlayerDiv[i].id);
        if(colMiniPlayerDiv[i].id.indexOf(elName, 0) == 0)
        {
            
            colMiniPlayerDiv[i].style.visibility = state;
            
        }
	}
}

function round(Money) 
{
    Money = new Number(Money);
    

/*
  if(!isNaN(Money))
  {
        Money = Math.round(Money*100)/100;

        if (String(Money).split(".")[1])
        {
			if (String(Money).split(".")[1].length==1)
				Money = Money + "0";
        }
        else Money = Money + ".00";
  }
  else
  {
	   alert('Incorrect money format!');
	   return 0;
  }
  
*/

    return Money.toFixed(2);
}

function showProperties(obj, objName) 
{
  var result = "The properties for the " + objName + " object:" + "\n";
  
  for (var i in obj) {result += i + " = " + obj[i] + "\n";}
  
  return result;
}

function isValidEmail (email)
{
     return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function textareaCurLineNum(obj)
{
  var rowHeight = obj.clientHeight/obj.rows;
  var curHeight = obj.createTextRange().boundingHeight;

  return parseInt(curHeight/rowHeight)+(obj.value!=''?1:0);
}


function getCaretPos(obj)
{
  obj.focus();
  
  if(obj.selectionStart) return obj.selectionStart;//Gecko
  else if (document.selection)//IE
  {
    var sel = document.selection.createRange();
    var clone = sel.duplicate();
    sel.collapse(true);
    clone.moveToElementText(obj);
    clone.setEndPoint('EndToEnd', sel);
    return clone.text.length;
  }
  
  return 0;
}

function addslashes(str) 
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	//str=str.replace(/\\/g,'\\\\');
	//str=str.replace(/\0/g,'\\0');
	return str;
}

function stripslashes(str) 
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function showHide(id){
	if (!document.getElementById(id))
		return;

	if (document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display = '';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}


function eventsGridFrame_LoadContent(profileId, date)
{
	var iFrame = document.getElementById('eventsGridFrame');
	iFrame.src = '/frame/events_grid.php?pid=' + profileId + '&date=' + date;
//    alert(iFrame.src);
}


function setEventBandList(mode)
{
	document.getElementById("BandsDataTable").innerHTML = bandFrame.document.getElementById('BandsDataTable').innerHTML;
    if(mode == 'all')
    {
        checklist1 = document.mainForm['UserSelect'];
        if(checklist1.length == null)
        {
        	checklist1.checked = true;
        }
        else
        {
	        theLength = checklist1.length;
	    	for (var i=0; i < theLength; i++)
	    	    checklist1[i].checked = true;
        }
    }
    else
    {
        checkTwoChecklist(bandFrame.document.frameForm['UserSelect'], document.mainForm['UserSelect']);    
    }
}


// ---------- check all elements of checklist2 which selected in checklist1 ------------------ //
function checkTwoChecklist(checklist1, checklist2)
{
	if (!checklist1.length) 
	{
        checklist2.checked = checklist1.checked; 
	}
	else 
	{
    	theLength = checklist1.length;
    	for (var i=0; i < theLength; i++)
    	{
    		if(checklist1[i].checked)
    		{
    			checklist2[i].checked = true;
    		}
    		else
    		{
    			checklist2[i].checked = false;
    		}
    	}
    }
}

function checkTwoChecklistFixedFirefox(checklist1, checklist2)
{
	if (!checklist1.length) 
	{
        checklist2.checked = checklist1.checked; 
	}
	else 
	{
    	for (var i=0; i < checklist1.length; i++)
    	{
    		checklist2[i].checked = checklist1[i].checked;
    	}
    }
}

// ---------- select item in select list by item value (not by id which is 0,1,2,3...n) ------------------ //
function checkSelectListByValue(sel, val)
{
	for (var i=sel.options.length-1; i >= 0; i--)
	{
		if(sel.options[i].value == val)
		{
			sel.options[i].selected=true;
		}
	}
}

// -------- Mailing List Functions ----------------------- //
function setUserMailingList()
{
	var doc = parent.document;
	doc.getElementById('DataTable').innerHTML     = document.getElementById("DataTable").innerHTML;
	checkTwoChecklist(document.frameFrom['UserSelect'], doc.mainForm['UserSelect']);
}

function ProfileMailingList_MakeSearchByLetters(Letters)
{
	searchFrame.document.getElementById("txtSearchLetters").value = Letters;
	searchFrame.document.getElementById("hiddenForm").submit();
}

function ProfileMailingList_MakeSearch()
{

	searchFrame.document.getElementById("txtSearchKeyword").value = document.getElementById("txtSearchKeyword").value;
	searchFrame.document.getElementById("txtSearchZip").value = document.getElementById("txtSearchZip").value;
	searchFrame.document.getElementById("txtSearchState").value = document.getElementById("ddlSearchState").options[document.getElementById("ddlSearchState").selectedIndex].value;
	searchFrame.document.getElementById("txtSearchWithin").value = document.getElementById("ddlSearchWithin").options[document.getElementById("ddlSearchWithin").selectedIndex].value;
	searchFrame.document.getElementById("txtSearchType").value = 'Search';

	searchFrame.document.getElementById("hiddenForm").submit();
}
// END -------- Mailing List Functions ----------------------- //



// -------- Add Event Functions ----------------------- //

function check_Country_event_business(doc)
{
	var USA_ID = 201;
	
	if(doc.getElementById('ddlVenueCountry').value == 201)
	{
		doc.getElementById('blockPostalCode1').className = 'block';
		doc.getElementById('blockPostalCode2').className = 'block';
	}
	else
	{
		doc.getElementById('blockPostalCode1').className = 'none';
		doc.getElementById('blockPostalCode2').className = 'none';
	}
}


function setVenueFieldsForBusinessEvents(venueID)
{
	var doc = parent.document;
	doc.getElementById('txtVenueName').value     = document.getElementById('VenueName_'+venueID).value;
	doc.getElementById('txtVenueAddress1').value = document.getElementById('VenueAddress1_'+venueID).value;
	doc.getElementById('txtVenueAddress2').value = document.getElementById('VenueAddress2_'+venueID).value;
	doc.getElementById('txtVenuePhone').value    = document.getElementById('VenuePhone_'+venueID).value;
	doc.getElementById('txtVenueCity').value    = document.getElementById('VenueCity_'+venueID).value;
	doc.getElementById('txtVenueZip').value    = document.getElementById('VenueZip_'+venueID).value;

	var sel = doc.getElementById('ddlVenueState');
	for (var i=sel.options.length-1; i >= 0; i--)
	{
		if(sel.options[i].value == document.getElementById('VenueState_'+venueID).value)
		{
			sel.options[i].selected=true;
		}
	}

	var sel = doc.getElementById('ddlVenueCountry');
	for (var i=sel.options.length-1; i >= 0; i--)
	{
		if(sel.options[i].value == document.getElementById('VenueCountry_'+venueID).value)
		{
			sel.options[i].selected=true;
		}
	}
	check_Country_event_business(doc);
}


function setVenueFields(venueID)
{
	var doc = parent.document;
	doc.getElementById('txtVenueName').value     = document.getElementById('VenueName_'+venueID).value;
	doc.getElementById('txtVenueAddress1').value = document.getElementById('VenueAddress1_'+venueID).value;
	doc.getElementById('txtVenueAddress2').value = document.getElementById('VenueAddress2_'+venueID).value;
	doc.getElementById('txtVenuePhone').value    = document.getElementById('VenuePhone_'+venueID).value;
	doc.getElementById('txtVenueCity').value    = document.getElementById('VenueCity_'+venueID).value;
	doc.getElementById('txtVenueZip').value    = document.getElementById('VenueZip_'+venueID).value;
	doc.getElementById('ddlVenueState').selectedIndex    = document.getElementById('VenueState_'+venueID).value;
}

function ProfileEvents_MakeSearch()
{

    

	venuesGridFrame.document.getElementById("txtSearchName").value = document.getElementById("txtSearchName").value;
    
	venuesGridFrame.document.getElementById("txtSearchAddress").value = document.getElementById("txtSearchAddress").value;
	
    venuesGridFrame.document.getElementById("txtSearchCity").value = document.getElementById("txtSearchCity").value;
	venuesGridFrame.document.getElementById("txtSearchState").value = document.getElementById("ddlSearchState").options[document.getElementById("ddlSearchState").selectedIndex].value
	venuesGridFrame.document.getElementById("txtSearchZip").value = document.getElementById("txtSearchZip").value;
//    venuesGridFrame.document.getElementById("txtSearchWithin").value = document.getElementById("ddlSearchWithin").options[document.getElementById("ddlSearchWithin").selectedIndex].value;
	venuesGridFrame.document.getElementById("txtSearchPhone").value = document.getElementById("txtSearchPhone").value;
	venuesGridFrame.document.getElementById("txtSearchType").value = 'Search';

    

	venuesGridFrame.document.getElementById("hiddenForm").submit();
}
// END -------- Add Event Functions ----------------------- //

function empty_func()
{
    i = 1;
}


function eventsGridFrame_LoadContent(profileId, date)
{
	var iFrame = document.getElementById('eventsGridFrame');
	iFrame.src = '/frame/events_grid.php?pid=' + profileId + '&date=' + date;
//    alert(iFrame.src);
}





function breakoutOfFrameset(){
	if (window.top!=window.self){
		window.top.location=url;
	}
}


function IEBrowser(){
	var browser=navigator.appName;
	if (browser=="Microsoft Internet Explorer") {
		return true;
	}
	else{
		return false;
	}

}


function layerswap(layername){
	if(document.getElementById(layername)){
		if (document.getElementById(layername).style.visibility=='visible'){
			document.getElementById(layername).style.visibility='hidden';
			document.getElementById(layername).style.display='none';
		}else{
			document.getElementById(layername).style.visibility='visible';
			document.getElementById(layername).style.display='block';
		}
	}
}

function loadScript(url){
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = url;
	document.getElementsByTagName('head')[0].appendChild(script);
}




function runFlashHeader(url, queryString){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="422" height="140">');
	document.write('<param name="movie" value="'+url+'flash/siteHeader.swf?'+queryString+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+url+'flash/siteHeader.swf?'+queryString+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="422" height="140" wmode="transparent"></embed>');
	document.write('</object>');
}

function runFlashGalleryPlayer(url, profileID){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="250" height="297">');
	document.write('<param name="movie" value="'+url+'gPlayer.swf?pid='+profileID+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+url+'gPlayer.swf?pid='+profileID+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="250" height="297" wmode="transparent"></embed>');
	document.write('</object>');
}

function runFlashTrackPlayer(url, profileID, loggedIn){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="210" height="222">');
	document.write('<param name="movie" value="'+url+'Profiles/tPlayer.swf?profileID='+profileID+loggedIn+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+url+'Profiles/tPlayer.swf?profileID='+profileID+loggedIn+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="210" height="222" wmode="transparent"></embed>');
	document.write('</object>');
}


function runFlashBandRater(url, curRating){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="profilerater" width="210" height="115" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+url+'Profiles/profilerater.swf?curRating='+curRating+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="'+url+'Profiles/profilerater.swf?curRating='+curRating+'" quality="high" bgcolor="#ffffff" width="210" height="115" swLiveConnect=true id="profilerater" name="profilerater" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function Invisible(elem)
{
	var obj = document.getElementById(elem);
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		obj.style.setAttribute('cssText', 'display:none', 0);
	}
	else
	{
		obj.setAttribute('style', 'display:none');
	}
}

function checkAll(state, theName, theFormName) 
{
	if (!document.getElementById(theFormName).length) 
	{
		if (state)
			document.getElementById(theFormName).checked = true;
		else
			document.getElementById(theFormName).checked = false;
	}
	else 
	{
		theLength = document.getElementById(theFormName).length;
		if (state) 
		{
			for (i=0; i < theLength; i++) 
			{
				document.getElementById(theFormName)[i].checked = true;
			}
		} else 
		{
			for (i=0; i < theLength; i++) 
			{
				document.getElementById(theFormName)[i].checked = false;
			}
		}
	}
}

function checkAllByNameAndFormName(state, theName, theFormName) 
{
	if (document.getElementById(theFormName).length) 
	{
		theLength = document.getElementById(theFormName).length;
		if (state) 
		{
			for (i=0; i < theLength; i++) 
			{
				if(document.getElementById(theFormName)[i].name == theName)
                    document.getElementById(theFormName)[i].checked = true;
			}
		} 
        else 
		{
			for (i=0; i < theLength; i++) 
			{
				if(document.getElementById(theFormName)[i].name == theName)
                    document.getElementById(theFormName)[i].checked = false;
			}
		}
	}
}


function checkAllByNameAndFormNameInFrame(state, theName, objForm) 
{
    //document.getElementById(theFormName).length
	if (objForm.length) 
	{
		theLength = objForm.length;
		if (state) 
		{
			for (i=0; i < theLength; i++) 
			{
				if(objForm[i].name == theName)
                    objForm[i].checked = true;
			}
		} 
        else 
		{
			for (i=0; i < theLength; i++) 
			{
				if(objForm[i].name == theName)
                    objForm[i].checked = false;
			}
		}
	}
}

function checkAllByNameInFrame(state, theName, frameName) 
{
	elements = frameName.document.getElementsByName(theName);	
	
	for (i = 0; i < elements.length; i++)
	{
		if (state) 
		{
            elements[i].checked = true;
		} 
        else 
		{
            elements[i].checked = false;
		}	    
	}
}


function bookmarkPage(urlAddress, pageName) {

		if(window.sidebar){
			window.sidebar.addPanel(pageName, urlAddress, '');
		}
		else if (window.external) {
				window.external.AddFavorite(urlAddress,pageName)
		}
		else {
			alert("Sorry! Your browser doesn't support this function.  You can bookmark this page us using 'CRTL' and 'D'");
		}
}

function setPng24(obj) {
var Src, Width, Height;
Src = obj.src;
Width = obj.width;
Height = obj.height;
    obj.width=Width;
    obj.height=Height;
    obj.className=obj.className.replace(/\bpng24\b/i,'');
    obj.style.filter =
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
    obj.src='images/1x1.gif'; 
    return '';
} 



function OpenQuizGame(sRootUrl, GameID)
{
     var count = GetCookie('QuizGameOpened');
     if (!count) 
     { 
         count=1; 
         SetCookie('QuizGameOpened', count, PlayerExp, '/game/');
		         
         gameWindow = window.open(sRootUrl + 'game/playgame.php?action=play&GameID='+GameID, '', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=960, height=800, left='+((screen.Width/2)-480)+', top='+((screen.Height/2)-400));
          
     } 
     else
     {
         if(typeof(gameWindow) != 'undefined')
             gameWindow.focus();
         else
             alert('Game window is already opened.\nPlease use it to control the game.');
     }
}





