﻿var IE = document.all ? true : false
var mouseX;
var mouseY;

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 popMusic( tapeid ){
	window.open( "http://www.datpiff.com/pop-mixtape-player.php?id=" + tapeid , "playMixtape", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=550,height=250,left=250,top=50");
	return false;
}

function Maximum(obj, maxlen, fieldname) {
    if (obj.length > maxlen) {
        alert('Maximum characters for ' + fieldname + ' is ' + maxlen);
        document.chars.tests.value = obj.substring(0, maxlen);
    }
}

function Minimum(obj, minlen, fieldname) {
    if (obj.value.length < minlen) 
        alert('Minimum characters for ' + fieldname + ' is ' + minlen);
}

function popupDJs(audioid, questionid, answer, submissionid) {
    if (audioid > 0)
        popup = window.open("djlist.aspx?audioid=" + audioid + "&questionid=" + questionid + "&answer=" + answer, "DJ", "left=100,top=100,width=600,height=600,resizable,scrollbars=yes,status=1,toolbar=yes");
    else
        popup = window.open("djlist.aspx?submissionid=" + submissionid + "&questionid=" + questionid + "&answer=" + answer, "DJ", "left=100,top=100,width=600,height=600,resizable,scrollbars=yes,status=1,toolbar=yes");
}

function toggleDiv(divElement) {
    var elm = document.getElementById(divElement);
    elm.style.display = elm.style.display == 'block' ? 'none' : 'block';
}

function captureMouseMoves() {
    if (!IE) 
        document.captureEvents(Event.MOUSEMOVE)
    document.onmousemove = getMouseXY;
}

function calendarPicker(strField, doSubmit) {
    //position window just below current field
    datewindow = window.open('/controls/DatePicker.aspx?field=' + strField + '&dosubmit=' + doSubmit, 'calendarPopup',
        'left=' + mouseX + ',top=' + (mouseY + 200) + ',width=250,height=190,resizable=0,status=0,toolbar=0,menubar=0,scrollbars=0');
}

function getMouseXY(e) {
    if (IE) { // Grab the x-y pos.s if browser is IE.
        mouseX = event.clientX + document.body.scrollLeft;
        mouseY = event.clientY + document.body.scrollTop;
    }
    else {  // Grab the x-y pos.s if browser isn't IE.
        mouseX = e.pageX;
        mouseY = e.pageY;
    }
    if (mouseX < 0) { mouseX = 0; };
    if (mouseY < 0) { mouseY = 0; };

    if (targetIsBody(e)) {
        document.body.style.cursor = 'pointer';
    }
    else
        document.body.style.cursor = 'auto';

    return true;
}

//Add a javascript file include after a particular tag (head, body,etc.)
function addJavascript(jsname, pos) {
    var th = document.getElementsByTagName(pos)[0];
    var s = document.createElement('script');
    s.setAttribute('type', 'text/javascript');
    s.setAttribute('src', jsname);
    th.appendChild(s);
}

function fblogin(message) {
    window.location.reload(true);
}
function fblogout(message) {
    FB.logout();
    window.location.reload(true);
}

function includeCSS(p_file) {
    var v_css = document.createElement('link');
    v_css.rel = 'stylesheet'
    v_css.type = 'text/css';
    v_css.href = p_file;
    document.getElementsByTagName('head')[0].appendChild(v_css);
}

function clickBg(e, targetUrl) {
    if (targetIsBody(e)) {
        window.location = targetUrl;
        return false;
    }
    return true;
}

function targetIsBody(e)
{
    evt = e || window.event;
    if (e.target)
        targ = e.target;
    else
        if (e.srcElement)
            targ = e.srcElement;
    if (targ.nodeType == 3) // Safari bug
        targ = targ.parentNode;

    return (targ.id == 'body');
}

captureMouseMoves();
