﻿function readCookie(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 locateElement(pString) {
	if (document.getElementById(pString))
		return document.getElementById(pString);
	else
		return false;
}

function crash_get(objName){
  return document.getElementById(objName);
}

function headerLinks(){

    var pName = 'Edit Profile';
    var eSignIn = document.getElementById("divSignIn");
    var sHTML = '';
    
    if (eSignIn != 'undefined') {
        if (readCookie('.ASPXAUTH')) {    
            sHTML = '<strong>';
            //sHTML = sHTML + '<a href="/account/editDetails.html" rel="nofollow">' + pName + '</a> | ';
            //sHTML = sHTML + '<a href="/account/newsletters.html" rel="nofollow">Newsletters</a> | ';
            sHTML = sHTML + '&nbsp;<a href="/account/mycrash.html" rel="nofollow">MY CRASH</a> | ';
            sHTML = sHTML + '<a href="/logOut.html" rel="nofollow">LOG-OUT</a>';
            sHTML = sHTML + '</strong>';
            eSignIn.innerHTML = sHTML;
        }
        eSignIn.style.display = 'block';
    }
}

function crash_addEvent(objName, eventName, functionRef){
  var obj = evo_get(objName);
  if (obj.addEventListener)
    obj.addEventListener(eventName, functionRef, false);
  else if(obj.attachEvent)
    obj.attachEvent('on' + eventName, functionRef);
}
function openRadio(pID) {
	if (pID == '0')
		window.open('http://audio.crash.net/radioplayer.asp', 'crashRadio', 'status=1,location=0,directories=0,menubar=0,scrollbars=0');
	else
		window.open('http://audio.crash.net/radioplayer.asp?radioURL='+pID+'.wma', 'crashRadio', 'status=1,location=0,directories=0,menubar=0,scrollbars=0');
}
function itemDisplayChange(drpNewsCount){
var totalList = drpNewsCount.options.length; // total currently set to 3
var selectedCount = drpNewsCount.options.length;
var i = 0;
for (i=0; i<(totalList); i++)
{
    if(drpNewsCount.options[i].selected)
        selectedCount = drpNewsCount.options[i].value;  //get no. of items to display
}

//set display
for (i=0; i<(totalList); i++)
{
    if(i <= (selectedCount -1)) {
        document.getElementById('listItem' + i).style.visibility = 'visible';
    }else{
        document.getElementById('listItem' + i).style.visibility = 'hidden';
    }
}
}
function showMenu()
{
var menuStyle = document.getElementById('divMenuSiteMap').className;

if(menuStyle == "showMenuSiteMap")
{
   document.getElementById('divMenuSiteMap').className = 'hideMenuSiteMap';
}else{
    document.getElementById('divMenuSiteMap').className = 'showMenuSiteMap';
}
}
function showPicturePanel1()
{
var picturePanelStyle = document.getElementById('divPicturePanel1').className;

if(picturePanelStyle == "hideItem")
{
   document.getElementById('divPicturePanel1').className = '';
   document.getElementById('divPicturePanel2').className = 'hideItem';
   document.getElementById('divPicturePanelBabes').className = 'hideItem';
}
}
function showPicturePanel2()
{
var picturePanelStyle = document.getElementById('divPicturePanel2').className;

if(picturePanelStyle == "hideItem")
{
   document.getElementById('divPicturePanel1').className = 'hideItem';
   document.getElementById('divPicturePanel2').className = '';
   document.getElementById('divPicturePanelBabes').className = 'hideItem';
}
}
function showPicturePanelBabes()
{
var picturePanelStyle = document.getElementById('divPicturePanelBabes').className;

if(picturePanelStyle == "hideItem")
{
   document.getElementById('divPicturePanel1').className = 'hideItem';
   document.getElementById('divPicturePanel2').className = 'hideItem';
   document.getElementById('divPicturePanelBabes').className = 'showPicturePanel';
}
}
function hideLoginErrorMessage()
{
    document.getElementById('divUserNotFound').className = 'hideItem';
}
function setCaret (textObj) {
if (textObj.createTextRange) {
textObj.caretPos = document.selection.createRange().duplicate();
}
}

//add comment - check length of comment and display character count
function calcLength() {
	var chars = locateElement('ctl00_ctl00_masterContent_pageContent_txtComment').value.length;
	if (chars > 700)
		locateElement('ctl00_ctl00_masterContent_pageContent_txtComment').value = locateElement('ctl00_ctl00_masterContent_pageContent_txtComment').value.substring(0,699);
	locateElement('charAvail').firstChild.data = 700 - chars;
}

//add smilies into comment text
function insertTextCursor (pElementName, pText) {
//textObj = locateElement(pElementName);
textObj = locateElement('ctl00_ctl00_masterContent_pageContent_txtComment');
textValue = ' ' + pText;
if(document.all){ 
if (textObj.createTextRange && textObj.caretPos) {
var caretPos = textObj.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?textValue + ' ' : textValue;
}else{
textObj.value = textValue;
}
}else{
if(textObj.setSelectionRange){
var rangeStart = textObj.selectionStart;
var rangeEnd = textObj.selectionEnd;
var tempStr1 = textObj.value.substring(0,rangeStart);
var tempStr2 = textObj.value.substring(rangeEnd);
textObj.value = tempStr1 + textValue + tempStr2;
}else{
textObj.value = textObj.value + textValue;
}
}
calcLength();
}

function clearTip() {
	// Trigger to remove tooltips
	bTipVisible = false;
	setTimeout('hideTip()', 1500);
}

function hideTip() {
	// Make tooltip invisible
	if (!bTipVisible) {
		if (locateElement('tipHelp')) {
			locateElement('tipHelp').style.visibility = 'hidden';
			bTipVisible = false;
		}
	}
}

function showTip (pTipText) {
	// Show tooltip
	bTipVisible = true;
 	if (!locateElement('tipHelp')) {
		locateElement('tempArea').innerHTML = "<div class='tipHelp' id='tipHelp' style=\"position:absolute\"></div>";
	}
 	if (locateElement('tipHelp')) {
		locateElement('tipHelp').innerHTML = pTipText;
		locateElement('tipHelp').style.top = getPosition(e).y + 20;
		locateElement('tipHelp').style.left = getPosition(e).x - 60;
		if (getPosition(e).x > 0)
			locateElement('tipHelp').style.visibility = 'visible';		
	}
	
}
function showTipGallery (pTipText) {
	// Show tooltip
	bTipVisible = true;
 	if (!locateElement('tipHelp')) {
		locateElement('tempArea').innerHTML = "<div class='tipHelp' id='tipHelp' style=\"position:absolute\"></div>";
	}
 	if (locateElement('tipHelp')) {
		locateElement('tipHelp').innerHTML = pTipText;
		locateElement('tipHelp').style.top = getPosition(e).y + 20;
		locateElement('tipHelp').style.left = getPosition(e).x - 60;
		if (getPosition(e).x > 0)
			locateElement('tipHelp').style.visibility = 'visible';		
	}
	
}

var currentSnapPanelId = 0;

function SwapSnaps(sender, eventArgs) 
{
  if (eventArgs.get_elementId() == null || eventArgs.get_index() < 0) return; // Ignore
  var swapToPanel = document.getElementById(eventArgs.get_elementId());
  var swapFromPanel = document.getElementById(currentSnapPanelId);
  var fromSnapId = 0;
  var toSnapId = 0;
   
  
    if((swapFromPanel.childNodes.length == 0) || ((swapFromPanel.childNodes.length == 1) && (swapFromPanel.childNodes[0].nodeType == 3)))
    {        
          // Grab the last node that is an element and move it to the next panel
          for(var n = swapToPanel.lastChild; n != null; n = n.previousSibling)
          {            
            if (n.nodeType == 1) { 
                fromSnapId = n.previousSibling.id;
                swapFromPanel.appendChild(n); 
                toSnapId = n.id;
            break; 
            }
          }
          setCookie(fromSnapId,swapToPanel.id);
          setCookie(toSnapId,swapFromPanel.id);
  }
}


function setCookie(panelName,dockingPanel)
{
var myDate = new Date();
myDate.setFullYear(myDate.getFullYear() + 12);

//alert(myDate.toGMTString());
//document.cookie="http://"+location.host+"/default.aspx."+panelName+ "=0px,,487,297,"+dockingPanel+",0,0,0;expires=" + myDate.toGMTString();

document.cookie=panelName + "=docking="+dockingPanel+";expires=" + myDate.toGMTString();
}

function openCustomisePage(){
    window.open('/CustomiseHomePage.aspx','CustomiseHomePage','width=335,height=375');
    return false;
}

//masthead tabs
	function setTab1(){
	
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel1').className = 'mastheadTabLabelOn';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel2').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel3').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel4').className = 'mastheadTabLabelOff';
    	
	    document.getElementById('panelsTab1').style.display = 'block';
	    document.getElementById('panelsTab2').style.display = 'none';
	    document.getElementById('panelsTab3').style.display = 'none';
	    document.getElementById('panelsTab4').style.display = 'none';
	}
	
	function setTab2(){
	
		document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel1').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel2').className = 'mastheadTabLabelOn';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel3').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel4').className = 'mastheadTabLabelOff';
		
		document.getElementById('panelsTab1').style.display = 'none';
	    document.getElementById('panelsTab2').style.display = 'block';
	    document.getElementById('panelsTab3').style.display = 'none';
	    document.getElementById('panelsTab4').style.display = 'none';
	}
	
	function setTab3(){
			
		document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel1').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel2').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel3').className = 'mastheadTabLabelOn';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel4').className = 'mastheadTabLabelOff';
			
		document.getElementById('panelsTab1').style.display = 'none';
	    document.getElementById('panelsTab2').style.display = 'none';
	    document.getElementById('panelsTab3').style.display = 'block';
	    document.getElementById('panelsTab4').style.display = 'none';
	}
	
	function setTab4(){
	
		document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel1').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel2').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel3').className = 'mastheadTabLabelOff';
	    document.getElementById('ctl00_ctl00_masterContent_mastheadContent_adRotate_pnlTabLabel4').className = 'mastheadTabLabelOn';
		
		document.getElementById('panelsTab1').style.display = 'none';
	    document.getElementById('panelsTab2').style.display = 'none';
	    document.getElementById('panelsTab3').style.display = 'none';
	    document.getElementById('panelsTab4').style.display = 'block';
	}

function checkSearchBox(pElement, pEvent) {
	if (pEvent == 'b') {
	    if (pElement.value == '') {
			pElement.value = 'Search... ';
			pElement.style.color = '#999999';
		}
	}	
	if (pEvent == 'f') {
	    if (pElement.value == 'Search... ') {
			pElement.value = '';
			pElement.style.color = '#000000';
		}
	}
}