
function writeHTML(strtext, id) {
      var tmp = document.getElementById(id);

      if (tmp)
      {
        tmp.innerHTML = strtext;
      }
}

function GetXmlHttpObject()
{
  var xmlHttp=null;try
   {
   // Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
   }
  catch (e)
   {
   // Internet Explorer
   try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
   catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
   }
  return xmlHttp;
}
function ajaxContent(strLocation, strDivID)
{
    xmlHttp=new GetXmlHttpObject();
    xmlHttp.onreadystatechange= function() {
        if(xmlHttp.readyState < 4)
             writeHTML('<div id="ajaxloader"><img src="/images/indicator.gif"></div>', strDivID);

        if (xmlHttp.readyState==4)
            if (xmlHttp.status==200)
                writeHTML(xmlHttp.responseText, strDivID);
    }

    xmlHttp.open("GET",strLocation+"&sid="+Math.random(),true);
    xmlHttp.send(null);

}
      function launchvideo(video_code,video_title,video_artist) {
        //path = "http://www.mtvasia.com/cgi-bin/players/playvid2.pl?"+ video_code+'&title='+video_title+'&artist='+video_artist;
        path = "http://www.mtvasia.com/cgi-bin/players/playvid2.pl?"+ video_code;
        gallery=window.open(path,"video",'directories=0,location=0,menubar=0,resizable=0,scrollbars=0,scrolling=no,status=0,toolbar=0,hotkeys=0,titlebar=1,alwaysRaised=1,dependent=1,screenX=100,screenY=100,top=100,left=100,width=500,height=450');
      }
      function launchflipbook(path) {
          gallery=window.open(path,"flipbook",'directories=0,location=0,menubar=0,resizable=0,scrollbars=0,scrolling=no,status=0,toolbar=0,hotkeys=0,titlebar=1,alwaysRaised=1,dependent=1,screenX=100,screenY=100,top=100,left=100,width=475,height=400');
      }
      function vFlipbook(path) {
          window.open('/Flipbook/data/flipbook'+path+'/flip1.html','flip','width=477,height=468')
      }
      function changeScrollbarColor(SC,AC) {
        if (document.all) {
          document.body.style.scrollbarBaseColor = SC;
          document.body.style.scrollbarArrowColor = AC;
        }
      }

    var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function ClickNpop(){
  var GlobalNavURL = document.GlobalNav.site.options[document.GlobalNav.site.selectedIndex].value;
  if (GlobalNavURL != '.'){
    window.open(GlobalNavURL,'GlobalNavPop');
    }
}
function launchPlayer() {
  window.open("/Video/VOD/player.php?playlistId=http://www.mtvasia.com/vod/playlist_music.xml","Player","menubar=no,width=944,height=630,titlebar=no,status=no,toolbar=no,left=100,top=100");
}

function mtvJumper(target) {
  window.open(target,"TargetWin");
}

function emailFriends() {
    var sUrl = '/sendtofriends.php';
    sUrl += ('?url=' + window.location.href);
    sUrl += ('&title=' + document.title);
    remoteWindow = window.open(sUrl,'remoteWindow','width=450,height=450,resizable');
    remoteWindow.focus();
}

//Search
function submitSearch(formRef){
    var trimed = formRef.searchterm.value.replace(/^\s*|\s(?=\s)|\s*$/g, "").toLowerCase();
    formRef.searchterm.value = trimed;

    if (trimed.length == 0)
    {
        return;
    }
    else {
        formRef.submit();
    }
}

function catchEnter(formRef) {
  if (window.event && window.event.keyCode == 13)
    submitSearch(formRef);
  else
    return true;
}

function blogSearch(formRef){
    var trimed = formRef.searchterm.value.replace(/^\s*|\s(?=\s)|\s*$/g, "").toLowerCase();
    formRef.searchterm.value = trimed;

    if (trimed.length == 0)
    {
        return;
    }
    else {
        formRef.submit();
    }
}

function catchEnter(formRef) {
  if (window.event && window.event.keyCode == 13)
    blogSearch(formRef);
  else
    return true;
}


//Expanding Menu
var persisteduls=new Object()
var ddtreemenu=new Object()

ddtreemenu.closefolder="/images/tree/closed.gif" //set image path to "closed" folder image
ddtreemenu.openfolder="/images/tree/open.gif" //set image path to "open" folder image

//////////No need to edit beyond here///////////////////////////

ddtreemenu.createTree=function(treeid, enablepersist, persistdays){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
if (typeof persisteduls[treeid]=="undefined")
persisteduls[treeid]=(enablepersist==true && ddtreemenu.getCookie(treeid)!="")? ddtreemenu.getCookie(treeid).split(",") : ""
for (var i=0; i<ultags.length; i++)
ddtreemenu.buildSubTree(treeid, ultags[i], i)
if (enablepersist==true){ //if enable persist feature
var durationdays=(typeof persistdays=="undefined")? 1 : parseInt(persistdays)
ddtreemenu.dotask(window, function(){ddtreemenu.rememberstate(treeid, durationdays)}, "unload") //save opened UL indexes on body unload
}
}

ddtreemenu.buildSubTree=function(treeid, ulelement, index){
ulelement.parentNode.className="submenu"
if (typeof persisteduls[treeid]=="object"){ //if cookie exists (persisteduls[treeid] is an array versus "" string)
if (ddtreemenu.searcharray(persisteduls[treeid], index)){
ulelement.setAttribute("rel", "open")
ulelement.style.display="block"
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else
ulelement.setAttribute("rel", "closed")
} //end cookie persist code
else if (ulelement.getAttribute("rel")==null || ulelement.getAttribute("rel")==false) //if no cookie and UL has NO rel attribute explicted added by user
ulelement.setAttribute("rel", "closed")
else if (ulelement.getAttribute("rel")=="open") //else if no cookie and this UL has an explicit rel value of "open"
ddtreemenu.expandSubTree(treeid, ulelement) //expand this UL plus all parent ULs (so the most inner UL is revealed!)
ulelement.parentNode.onclick=function(e){
var submenu=this.getElementsByTagName("ul")[0]
if (submenu.getAttribute("rel")=="closed"){
submenu.style.display="block"
submenu.setAttribute("rel", "open")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else if (submenu.getAttribute("rel")=="open"){
submenu.style.display="none"
submenu.setAttribute("rel", "closed")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")"
}
ddtreemenu.preventpropagate(e)
}
ulelement.onclick=function(e){
ddtreemenu.preventpropagate(e)
}
}

ddtreemenu.expandSubTree=function(treeid, ulelement){ //expand a UL element and any of its parent ULs
var rootnode=document.getElementById(treeid)
var currentnode=ulelement
currentnode.style.display="block"
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
while (currentnode!=rootnode){
if (currentnode.tagName=="UL"){ //if parent node is a UL, expand it too
currentnode.style.display="block"
currentnode.setAttribute("rel", "open") //indicate it's open
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
currentnode=currentnode.parentNode
}
}

ddtreemenu.flatten=function(treeid, action){ //expand or contract all UL elements
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
for (var i=0; i<ultags.length; i++){
ultags[i].style.display=(action=="expand")? "block" : "none"
var relvalue=(action=="expand")? "open" : "closed"
ultags[i].setAttribute("rel", relvalue)
ultags[i].parentNode.style.backgroundImage=(action=="expand")? "url("+ddtreemenu.openfolder+")" : "url("+ddtreemenu.closefolder+")"
}
}

ddtreemenu.rememberstate=function(treeid, durationdays){ //store index of opened ULs relative to other ULs in Tree into cookie
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
var openuls=new Array()
for (var i=0; i<ultags.length; i++){
if (ultags[i].getAttribute("rel")=="open")
openuls[openuls.length]=i //save the index of the opened UL (relative to the entire list of ULs) as an array element
}
if (openuls.length==0) //if there are no opened ULs to save/persist
openuls[0]="none open" //set array value to string to simply indicate all ULs should persist with state being closed
ddtreemenu.setCookie(treeid, openuls.join(","), durationdays) //populate cookie with value treeid=1,2,3 etc (where 1,2... are the indexes of the opened ULs)
}

////A few utility functions below//////////////////////

ddtreemenu.getCookie=function(Name){ //get cookie value
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

ddtreemenu.setCookie=function(name, value, days){ //set cookei value
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

ddtreemenu.searcharray=function(thearray, value){ //searches an array for the entered value. If found, delete value from array
var isfound=false
for (var i=0; i<thearray.length; i++){
if (thearray[i]==value){
isfound=true
thearray.shift() //delete this element from array for efficiency sake
break
}
}
return isfound
}

ddtreemenu.preventpropagate=function(e){ //prevent action from bubbling upwards
if (typeof e!="undefined")
e.stopPropagation()
else
event.cancelBubble=true
}

ddtreemenu.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}
//End Expanding Menu

function initJumpMenus() {
// Turns all <select> elements with the 'jumpmenu' class into jump menus
var selectElements = document.getElementsByTagName("select");
for( i = 0; i < selectElements.length; i++ ) {
    // Check for the class and make sure the element has an ID
    if( selectElements[i].className == "jumpmenu" && document.getElementById(selectElements[i].id) != "" ) {
        jumpmenu = document.getElementById(selectElements[i].id);
        jumpmenu.onchange = function() {
            if( this.options[this.selectedIndex].value != '' ) {
                // Redirect
                window.open(this.options[this.selectedIndex].value,'NavigationPop');
            }
        }
    }
}
}

window.onload = function() {
  initJumpMenus();
}

function textCounter(field, divcounter, maxlimit) {
  if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
  else
    //divcounter.value = maxlimit - field.value.length;
    MM_findObj(divcounter).innerHTML = maxlimit - field.value.length;
}
function trim(value)
{
var strValue = value.replace(/^\s+|\s+$/,'');
return strValue;
}

var xmlHttp2;

function showNcomment(str,str2){
 xmlHttp2=GetXmlHttpObject1();
 if (xmlHttp2==null) {
 alert ("Your browser does not support AJAX!");
 return;
 }
 var url="/Common/News/getcomment.php";
 url=url+"?page="+str;
 url=url+"&newsid="+str2;
 url=url+"&sid="+Math.random();
 xmlHttp2.onreadystatechange=newsstateChanged;
 xmlHttp2.open("GET",url,true);
 xmlHttp2.send(null);
}

function newsstateChanged() {
 if(xmlHttp2.readyState < 4)
 document.getElementById("commentarea").innerHTML='<div style="width:100%;margin:auto;"><img src="/images/ajax-loader.gif"></div>';
 if (xmlHttp2.readyState == 4 && (xmlHttp2.status==200 || window.location.href.indexOf("http")==-1))
 {
 document.getElementById("commentarea").innerHTML=xmlHttp2.responseText;
 }
}

function GetXmlHttpObject1()
{
var xmlHttp2=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp2=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
 {
 xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
 }
 catch (e)
 {
 xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
 }
 }
return xmlHttp2;
}
//-->

var xmlHttp3;

function showArtistcomment(str,str2){
 xmlHttp3=GetXmlHttpObject2();
 if (xmlHttp3==null) {
 alert ("Your browser does not support AJAX!");
 return;
 }
 var url="/Common/Artist/getcomment.php";
 url=url+"?page="+str;
 url=url+"&reviewname="+str2;
 url=url+"&sid="+Math.random();
 xmlHttp3.onreadystatechange=artiststateChanged;
 xmlHttp3.open("GET",url,true);
 xmlHttp3.send(null);
}

function artiststateChanged() {
 if(xmlHttp3.readyState < 4)
 document.getElementById("commentarea").innerHTML='<div style="width:100%;margin:auto;"><img src="/images/ajax-loader.gif"></div>';
 if (xmlHttp3.readyState == 4 && (xmlHttp3.status==200 || window.location.href.indexOf("http")==-1))
 {
 document.getElementById("commentarea").innerHTML=xmlHttp3.responseText;
 }
}

function GetXmlHttpObject2()
{
var xmlHttp3=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp3=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
 {
 xmlHttp3=new ActiveXObject("Msxml2.XMLHTTP");
 }
 catch (e)
 {
 xmlHttp3=new ActiveXObject("Microsoft.XMLHTTP");
 }
 }
return xmlHttp3;
}
//-->

var xmlHttp4;

function showArtistcomment2(str,str2){
 xmlHttp4=GetXmlHttpObject3();
 if (xmlHttp4==null) {
 alert ("Your browser does not support AJAX!");
 return;
 }
 var url="/Common/Artist2/getcomment.php";
 url=url+"?page="+str;
 url=url+"&reviewname="+str2;
 url=url+"&sid="+Math.random();
 xmlHttp4.onreadystatechange=artiststateChanged2;
 xmlHttp4.open("GET",url,true);
 xmlHttp4.send(null);
}

function artiststateChanged2() {
 if(xmlHttp4.readyState < 4)
 document.getElementById("commentarea").innerHTML='<div style="width:100%;margin:auto;"><img src="/images/ajax-loader.gif"></div>';
 if (xmlHttp4.readyState == 4 && (xmlHttp4.status==200 || window.location.href.indexOf("http")==-1))
 {
 document.getElementById("commentarea").innerHTML=xmlHttp4.responseText;
 }
}

function GetXmlHttpObject3()
{
var xmlHttp4=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp4=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
 {
 xmlHttp4=new ActiveXObject("Msxml2.XMLHTTP");
 }
 catch (e)
 {
 xmlHttp4=new ActiveXObject("Microsoft.XMLHTTP");
 }
 }
return xmlHttp4;
}
//-->

var xmlHttp5;

function showNcomment2(str,str2){
 xmlHttp5=GetXmlHttpObject4();
 if (xmlHttp5==null) {
 alert ("Your browser does not support AJAX!");
 return;
 }
 var url="/Common/News2/getcomment.php";
 url=url+"?page="+str;
 url=url+"&newsid="+str2;
 url=url+"&sid="+Math.random();
 xmlHttp5.onreadystatechange=newsstateChanged2;
 xmlHttp5.open("GET",url,true);
 xmlHttp5.send(null);
}

function newsstateChanged2() {
 if(xmlHttp5.readyState < 4)
 document.getElementById("commentarea").innerHTML='<div style="width:100%;margin:auto;"><img src="/images/ajax-loader.gif"></div>';
 if (xmlHttp5.readyState == 4 && (xmlHttp5.status==200 || window.location.href.indexOf("http")==-1))
 {
 document.getElementById("commentarea").innerHTML=xmlHttp5.responseText;
 }
}

function GetXmlHttpObject4()
{
var xmlHttp5=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp5=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
 {
 xmlHttp5=new ActiveXObject("Msxml2.XMLHTTP");
 }
 catch (e)
 {
 xmlHttp5=new ActiveXObject("Microsoft.XMLHTTP");
 }
 }
return xmlHttp5;
}
//-->

function ncommentsubmit(){
 var userID;
 var matched=false;
 userID=getCookie("w3t_username");
 if(userID!="null" && userID!="" && userID!=null && userID!="deleted"){
 if(trim(document.getElementById("comment").value)!="" && trim(document.getElementById("comment").value)!="Enter Your Comment"){
 matched=true;
 document.commentform.submit();
 }
 if (matched==false) {
 alert("Please enter your comment.");
 }
 }	else{
 alert("Please sign in to post your comment!");
 }
}

// mimicks li:hover for IE, which doesn't support it
var hoverDebug = Array();
sfHover = function() {
	try
	{

		var sfEls = document.getElementById("header").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	catch(err)
	{
		hoverDebug[0] = err;
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

// mimicks li:hover for IE, which doesn't support it
var hover2Debug = Array();
sfHover2 = function() {
	try
	{

		var sfEls = document.getElementById("boxOffice-menu").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover2";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover2\\b"), "");
			}
		}
	}
	catch(err)
	{
		hover2Debug[0] = err;
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover2);