﻿var title = "Music Choice Show Off";
function ShowLoading()
{
    document.getElementById("lblLoading").style.display = "block";
}
function HideLoading()
{
    document.getElementById("lblLoading").style.display = "none";
}
function AddSubTitle(subTitle)
{
    document.title = title + " - " + subTitle;
}

function FileAttachCriteria(imgfilePath,msg)
{
    //msg = "The format of the photo you selected is incorrect.  Please attach a photo in the .jpg, .jpeg, .gif, or .png format."
    if(document.getElementById(imgfilePath).value == "")
    {
        alert(msg);
        return false;
    }
    else
    {
        var str =document.getElementById(imgfilePath).value;
        var index = str.lastIndexOf(".");
        
        if(index!=-1)
        {
            var ext;
            ext = str.substr(index + 1);
            if(ext.length > 0)
            {
                ext = ext.toLowerCase();
                if(ext ==  "jpg" || ext == "png" || ext == "gif" || ext == "jpeg")
                {
                    ShowLoading();
                    return true;
                }
                else
                {
                    HideLoading();
                    alert(msg );
                    return false;
                }
            }
            else
            {  
                alert(msg);
                return false;
            }
        }
        else
        {
            alert(msg);
            return false;
        }
        
       
    }
    return false;
}


function GetCorrectID(controlId)
{
    controlId=controlId.replace("$","_");
    controlId=controlId.replace("$","_");
    return controlId;
}

/*
function CharacterCount(txtid,lblCount,MaxChar,flag,event)
{

    var x = event.keyCode;
    
        if(x>37 && x<=40)
            return;

    txtid=GetCorrectID(txtid);

    str = document.getElementById(txtid).value;

    strlen = str.length;
    var val;

    if (strlen >= MaxChar)
    {
        str =  str.substring(0,MaxChar);
        document.getElementById(txtid).value = str;
        strlen = str.length;
    }

    val = strlen + "/" +  MaxChar;

    document.getElementById(lblCount).innerHTML = val;
    if (flag == true)
        document.getElementById("hdn" + lblCount).value = val;		              
     		 
}
*/

function CharacterCount(txtid, lblCount, hiddencountcontrolname, MaxChar, flag, event) {
    var x = event.keyCode;
    if (x > 37 && x <= 40)
        return;

    txtid = GetCorrectID(txtid);
    str = document.getElementById(txtid).value;
    strlen = str.length;
    var val;
    if (strlen >= MaxChar) {
        str = str.substring(0, MaxChar);
        document.getElementById(txtid).value = str;
        strlen = str.length;
    }

    val = strlen + "/" + MaxChar;

    document.getElementById(lblCount).innerHTML = val;
    if (flag == true)
        document.getElementById(hiddencountcontrolname).value = val;

}

		
function IsAnswerProvided()
{
    var InputArray = new Array();
    InputArray = document.getElementsByTagName("textarea");	

    for ( i = 0; i < InputArray.length; i++ ) { // loop through and find <input>
        if(InputArray[i].value.length > 0)               
            return true;
    }

    return false;
}

/*
function ClearTextBox(txtid,lblCount,MaxChar,flag,event){			
    document.getElementById(txtid).value="";	
    if(flag==true)		
        document.getElementById("hdn" + lblCount).value = "";	
    return CharacterCount(txtid,lblCount,MaxChar,flag,event);
}
*/

function ClearTextBox(txtid, lblCount, hiddencountcontrolname, MaxChar, flag, event) {
    document.getElementById(txtid).value = "";
    if (flag == true)
        document.getElementById(hiddencountcontrolname).value = "";
    return CharacterCount(txtid, lblCount, hiddencountcontrolname, MaxChar, flag, event);
}
		 

function DetectBrowser()
{
//var browser=navigator.appName;
//alert("Browser name: "+ browser);

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
  return ieversion;
}
else
  return -1;
}

function ReplaceExtension(ImagePath)
{        
        if (ImagePath != "" && ImagePath != "[path to image]")
        {
            var xVersion;
            xVersion= DetectBrowser();
            
            if((xVersion < 7) && (xVersion != -1))  
            {
                var index = 0;                
                index = ImagePath.lastIndexOf(".");

                 if (ImagePath.substring(index).toLowerCase() == ".png")
                    {
                        if (index > 0)
                        {
                            ImagePath = ImagePath.substring(0, index);
                            ImagePath = ImagePath + ".gif";
                        }
                        return ImagePath;
                    }
                    else
                        return ImagePath;
            }
            else
              return ImagePath;
        }
        else
            return ImagePath;
}


function GetAbsoluteLeft(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (1)
        {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            else
                obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;

    return curleft + "px";
}


function GetAbsoluteTop(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (1)
        {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            else
                obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;

    return curtop + "px"; ;
   }

   /* Show Schedule */


   var ShowSchedule = {

   	SetUpTabs: function () {

   		// get active tab
   		var activeIndex = 0;
   		var currentClass = 'current';

   		// first check url hash
   		var $dayLinkByHash = $('a[href=' + window.location.hash + ']', 'ul#dayNav');
   		if ($dayLinkByHash.length == 1) {
   			activeIndex = $dayLinkByHash.parent().prevAll('li').length;
   		}
   		else {
   			var jsDayIndex = new Date().getDay();
   			var dayIndexShifted = jsDayIndex - 1;

   			activeIndex = (dayIndexShifted < 0) ? dayIndexShifted + 7 : dayIndexShifted;
   		}


   		$('ul#dayNav li', 'div#showSchedule').eq(activeIndex).addClass(currentClass);
   		ShowSchedule.DisplayScheduleForDay(activeIndex);

   		// attach click
   		$('ul#dayNav > li > a', 'div#showSchedule').click(function (evt) {
   			evt.preventDefault();
   			window.location.hash = $(this).attr('href');

   			$parentLi = $(this).parent('li');
   			// set current class on tab
   			$parentLi.siblings('li').removeClass(currentClass);
   			$parentLi.addClass(currentClass);

   			// hide tables/show correct one
   			ShowSchedule.DisplayScheduleForDay($parentLi.prevAll().length);

   		});
   	},
   	DisplayScheduleForDay: function (index) {
   		$context = $('div#showSchedule');

   		$context.children('table.schedule').hide().eq(index).show();
   	},
   	ApplyStriping: function () {
   		$('table.schedule', 'div#showSchedule').find('tr:even').addClass('alt');
   	}

   };

/* Mobile Screens */
   var SwrvMobile = {
   	SetUpScreens: function () {
   		// initialize
   		$('li:not(:first)', '#largescreenshots').hide();
   		$('li:first', '#thumbnails').addClass('selected');

   		// attach mouseover
   		$('a', '#screens > #thumbnails > li').mouseover(function (evt) {
   			// cache $(this)
   			var $this = $(this);
   			var targetId = $this.attr('href');

   			// remove all 'selected' classes from <li>s, then add 'selected' to parent of clicked <a>
   			$('ul#thumbnails li').removeClass('selected');
   			$this.parent('li').addClass('selected');

   			// hide all scrrenshot <li>s, then show the one corresponding to the anchor clicked
   			$('ul#largescreenshots li').hide();
   			$(targetId).show();

   		})
   		// prevent default click behavior (chained)
   		.click(function (evt) {evt.preventDefault();});
   	}
   };
