
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_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_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 swaparrow (id)
  {
    var x = document.getElementById (id);
    var y = x.src.substring (x.src.lastIndexOf ('arrow'));
    if (y == 'arrow_right.jpg')
      {
        document.getElementById (id).src = '/files/pics/widget_black_arrow_down.jpg';
      }
    else
      {
        document.getElementById (id).src = '/files/pics/widget_black_arrow_right.jpg';
      }
  }
  
function showhide (s)
  {
    el = document.getElementById (s);
    el.style.display = (el.style.display == "block") ? "none" : "block";
  }
  
function hideshow (s)
  {
    el = document.getElementById (s);
    el.style.display = (el.style.display == "none") ? "block" : "none";
  }
  
function togglepopup (s)
  {
    if (s == "login")
      {
        document.getElementById ("registerwindow").style.display = "none";
        document.getElementById ("registerpopup").style.display = "none";
      }
    else if (s == "register")
      {
        document.getElementById ("loginwindow").style.display = "none";
        document.getElementById ("loginpopup").style.display = "none";
      }
    showhide (s + 'window');
    showhide (s + 'popup');
    //hideshow ('footer');
    showhide ('modalpage');
    showhide ('overlay');
    /*
    alert ('Login Popup: ' + document.getElementById ("loginpopup").style.display + ' Window: ' + 
           document.getElementById ("loginwindow").style.display + 'Register Popup: ' +
           document.getElementById ("registerpopup").style.display + ' Window: ' + 
           document.getElementById ("registerwindow").style.display);*/
  }
  
function sendcontest (n, c, t)
  {
    if (t != undefined)
      {
        document.getElementById ('senttofriend').value = 1;
        document.getElementById ('sendform').action = '';
      }
    else
      {
        document.getElementById ('sendform').action = document.getElementById ('sendform').action + c + '/' + n;
      }
    document.getElementById ('videoid').value = n;
    document.getElementById ('campaignfriend').value = c;
    togglepopup ('sendtofriend');
  }
  
function switchdisplay (n)
  {
    for (i = 0; i < 10; i++)
      {
        clist = document.getElementById ('clist' + i);
        carrow = document.getElementById ('carrow' + i);
        citem = document.getElementById ('citem' + i);
        
        if (carrow)
          {        
            carrow.style.display = 'none';
            citem.style.display = 'none';
            clist.style.cursor = 'pointer';
            clist.style.color = '#000';
            clist.style.backgroundColor = '#f3f3f5';
		        clist.style.borderColor = '#dcdcde';
          }
      }
      
    clist = document.getElementById ('clist' + n);
    carrow = document.getElementById ('carrow' + n);
    citem = document.getElementById ('citem' + n);
    
    carrow.style.display = 'block';
    citem.style.display = 'block';
    clist.style.cursor = 'default';
    clist.style.color = '#FFF';
    clist.style.backgroundColor = '#120E4D';
	clist.style.borderColor = '#120E4D';
  }
  
function bordershow (s)
  {
    el = document.getElementById (s);
    el.className = (el.className == "divlisting") ? "divlisting2" : "divlisting";
  }
  
function CreateHttpRequest ()
  {
    try { return new XMLHttpRequest () }  catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP") }     catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP") }  catch(e) {}
    throw new Error ("This browser does not support XMLHttpRequest or XMLHTTP.")
  }
   
function ajaxget (t, c, vid, ap, uri, start, sort, search, compact)
  {
    var http = CreateHttpRequest ();
    http.open ('get', '/ajaxget.php?type=' + t + '&campaign=' + c + '&vid=' + vid +
               '&ap=' + ap + '&uri=' + uri + '&start=' + start + '&sort=' + sort +
               '&search=' + search + '&compact=' + compact);
    http.onreadystatechange = function ()
      {
        if  (http.readyState == 4)
          { 
            top.document.getElementById('current' + t).innerHTML = http.responseText;
          }
      };
    http.send (null);
    delete http;
  }
  
function urlencode (text)
  {
    text = escape (text);
    text = text.replace ('+', '%2B');
    //text = text.replace ('%20', '+');
    //text = text.replace ('*', '%2A');
    text = text.replace ('/', '%2F');
    //text = text.replace ('@', '%40');
    return text;
  }

function changetext (id, text)
  {
    top.document.getElementById (id).innerHTML = text;
  }
  
function checktext (id)
  {
    return top.document.getElementById (id).innerHTML;
  }
  
function sendcommand (t, tvid, id, rate, uri, c, text, start)
  {
    var friends = '';
    if (tvid != undefined)
      {
        var vid = tvid;
      }
      
    if (t == 'sendfriend')
      {
        friends = urlencode (document.getElementById ('emails').value);
        vid = document.getElementById ('videoid').value;
      }
    else if (t == 'sitefriend')
      {
        friends = urlencode (document.getElementById ('tellemails').value);
      }
   
    var uri = '/sendcommand.php?type=' + t + '&vid=' + vid +
               '&rating=' + rate + '&id=' + id + '&text=' + urlencode (text) + '&friends=' + friends;
      
    var http = CreateHttpRequest ();
    http.open ('get', uri);
    http.onreadystatechange = function ()
      {
        if  (http.readyState == 4)
          { 
            if (id == 'favoriteheart')
              {
                ajaxget ('actions', c, vid, '', uri);
              }
            else if (t == 'sendfriend')
              {
                togglepopup ('sendtofriend');
                togglepopup ('thankfriend');
              }
            else if (t == 'sitefriend')
              {
                togglepopup ('tellfriend');
                togglepopup ('thankfriend');
              }
            else if (t == 'moderate')
              {
                changecomments (vid, start);
              }
            else if (t == 'comment')
              {
                ajaxget ('comments', '', vid, '', '', start);
                if (top.document.getElementById ('currentunapprovedcomments'))
                  {
                    ajaxget ('unapprovedcomments', '', vid, '', '', '0');
                  }
              }
            else if (t == 'fav')
              {
                var x = document.getElementById (id);
                var y = x.src.substring (x.src.lastIndexOf ('thumb'));
                if (y == 'thumb_add_alt.jpg')
                  {
                    document.getElementById (id).src = '/files/pics/player_thumb_sub_alt.jpg';
                    document.getElementById (id).oSrc = '/files/pics/player_thumb_sub.jpg';
                    document.getElementById (id).onmouseover = function ()
                      { MM_swapImage (id,'','/files/pics/player_thumb_sub_alt.jpg',1) };
                  }
                else if (y == 'thumb_sub_alt.jpg')
                  {
                    document.getElementById (id).src = '/files/pics/player_thumb_add_alt.jpg';
                    document.getElementById (id).oSrc = '/files/pics/player_thumb_add.jpg';
                    document.getElementById (id).onmouseover = function ()
                      { MM_swapImage (id,'','/files/pics/player_thumb_add_alt.jpg',1) };
                  }
              }
            else if (t == 'rate')
              {
                //setTimeout ("ajaxget ('rating', c, vid, '', uri);", 1500);
              }
          }
      };
    http.send (null);
    delete http;
  }
  
function changelist (c, list, start, sort, search, compact)
  {
    ajaxget (list, c, '', '', '', start, sort, search, compact);
  }
  
function changecomments (vid, start)
  {
    ajaxget ('comments', '', vid, '', '', start);
    if (top.document.getElementById ('currentunapprovedcomments'))
      {
        ajaxget ('unapprovedcomments', '', vid, '', '', '0');
      }
  }
  
function moderatecomment (vid, start, cid, type)
  {
    sendcommand ('moderate', vid, cid, '', '', '', type, start);
  }

function changecampaign (c, vid, ap, uri)
  {
    if (top.document.getElementById ('campaignname'))
      {
        top.document.getElementById ('campaignname').value = c;
        top.document.getElementById ('uploadvideocampaign').innerHTML = c;
      }
    if (top.document.getElementById ('currentcomments'))
      {
        changecomments (vid, 0);
      }    
    if (top.document.getElementById ('videoid'))
      {
        top.document.getElementById ('videoid').value = vid;
      }
    if (top.document.getElementById ('currentbanner'))
      {
        ajaxget ('banner', c, '', '', uri);
      }
    if (top.document.getElementById ('currentsubmitbar'))
      {
        ajaxget ('submitbar', c, '', '', uri);
      }
    if (top.document.getElementById ('currentcoupon'))
      {
        ajaxget ('coupon', c, '', '', uri);
      }
    if (top.document.getElementById ('currentrating'))
      {
        ajaxget ('rating', c, vid, '', uri);
      }
    if (top.document.getElementById ('currentinfo'))
      {
        ajaxget ('info', c, vid);
      }
    if (top.document.getElementById ('currentsocial'))
      {
        ajaxget ('social', c, vid);
      }
    if (top.document.getElementById ('currentactions'))
      {
        ajaxget ('actions', c, vid, '', uri);
      }
  }

function loadupload ()
  {
	  /*
    swfu = new SWFUpload({
				// Backend settings
				upload_url: "upload.php",
				file_post_name: "video_file",

				// Flash file settings
				file_size_limit : "101376",	// 99 MB
				file_types : "*.*",	// or you could use something like: "*.doc;*.wpd;*.pdf",
				file_types_description : "All Files",
				file_upload_limit : "0",
				file_queue_limit : "1",

				// Event handler settings
				swfupload_loaded_handler : swfUploadLoaded,
				
				//file_dialog_start_handler : fileDialogStart,	
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				
				//upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,

				// Flash Settings
				flash_url : "/swfupload_f9.swf",

				// UI settings
				swfupload_element_id : "flashUI",

				custom_settings : {
					progress_target : "fsUploadProgress",
					upload_successful : false
				},
				
				debug: false
			});
	*/
  }
  
function validate_submit ()
  {
    var t = document.getElementById ('termsaccepted').checked;
    if (document.getElementById ('btnBrowse').value.length > 0 && 
        document.getElementById ('videoname').value.length > 0 && 
        t == true)
      {
        document.getElementById ('btnSubmit').src = '/files/pics/Button_Video.jpg';
        document.getElementById ('btnSubmit').disabled = false;
      }
    else
      {
        document.getElementById ('btnSubmit').src = '/files/pics/Button_Video_grey.jpg';
        document.getElementById ('btnSubmit').disabled = true;
      }
  }
  
function getWindowHeight ()
  {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number')
      {
        windowHeight=window.innerHeight;
      }
    else
      {
        if (document.documentElement && document.documentElement.clientHeight)
          {
            windowHeight=document.documentElement.clientHeight;
          }
        else
          {
            if (document.body && document.body.clientHeight)
              {
                windowHeight = document.body.clientHeight;
              }
          }
      }
    return windowHeight;
  }
  
function setFooter ()
  {
    var ftop = getWindowHeight () - 30;
    document.getElementById ('footer').style.top = ftop;
  }
  
function validate_register ()
  {
    if (document.getElementById ('username').value.length > 1 && 
        document.getElementById ('email1').value.length > 1 && 
        document.getElementById ('email2').value == document.getElementById ('email1').value && 
        document.getElementById ('password').value.length > 1 && 
        document.getElementById ('password2').value == document.getElementById ('password').value)
      {
        //document.getElementById ('btnSubmit').src = '/files/pics/Button_Video.jpg'; bgColor 
        document.getElementById ('buttonregister').disabled = false;
        document.getElementById ('email2').style.background = '#FFFFFF';
        document.getElementById ('email1').style.background = '#FFFFFF';
        document.getElementById ('password2').style.background = '#FFFFFF';
        document.getElementById ('password').style.background = '#FFFFFF';
        document.getElementById ('username').style.background = '#FFFFFF';
      }
    else
      {
        //document.getElementById ('btnSubmit').src = '/files/pics/Button_Video_grey.jpg';
        document.getElementById ('buttonregister').disabled = true;
        if (document.getElementById ('username').value.length < 2)
          {
            document.getElementById ('username').style.background = '#FFCFCF';
          }
        else
          {
            document.getElementById ('username').style.background = '#FFFFFF';
          }
        if (document.getElementById ('email1').value.length < 2)
          {
            document.getElementById ('email1').style.background = '#FFCFCF';
          }
        else
          {
            document.getElementById ('email1').style.background = '#FFFFFF';
          }
        if (document.getElementById ('password').value.length < 2)
          {
            document.getElementById ('password').style.background = '#FFCFCF';
          }
        else
          {
            document.getElementById ('password').style.background = '#FFFFFF';
          }
        if (document.getElementById ('email1').value != document.getElementById ('email2').value)
          {
            document.getElementById ('email2').style.background = '#FFCFCF';
          }
        else
          {
            document.getElementById ('email2').style.background = '#FFFFFF';
          }
        if (document.getElementById ('password').value != document.getElementById ('password2').value)
          {
            document.getElementById ('password2').style.background = '#FFCFCF';
          }
        else
          {
            document.getElementById ('password2').style.background = '#FFFFFF';
          }
      }
  }