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 vPicture(table,code) { //v3.0
  window.open('/Common/picviewer.php?table='+table+'&code='+code,'picview','width=470,height=300')
}
function addblog(userid){
	var userID;
	userID=getCookie("User_ID");
	if(userID!="null" && userID!="" && userID!=null){
		window.open('/nickspace/blog/addblog_popup.php?uid='+userid,'popup','width=400,height=245');
	}else{ 
			alert('Please log in to add this blog to your fovorites');
	}
}

function writepm(userid){
	var userID;
	userID=getCookie("User_ID");
	if(userID!="null" && userID!="" && userID!=null){
		Sendmessage(userid);
	}else{
		alert("Please log in to send message to this user");
	}
	
}

 var caution = false;

   // name - name of the cookie
   // value - value of the cookie
   // [expires] - expiration date of the cookie
   // (defaults to end of current session)
   // [path] - path for which the cookie is valid
   // (defaults to path of calling document)
   // [domain] - domain for which the cookie is valid
   // (defaults to domain of calling document)
   // [secure] - Boolean value indicating if
   // the cookie transmission requires a secure transmission
   // * an argument defaults when it is assigned null as a placeholder
   // * a null placeholder is not required for trailing omitted arguments
   function setCookie(name, value, expires, path, domain, secure) {
      var curCookie = name + "=" + escape(value) +
         ((expires) ? "; expires=" + expires.toGMTString() : "") +
         ((path) ? "; path=" + path : "") +
         ((domain) ? "; domain=" + domain : "") +
         ((secure) ? "; secure" : "");
      if (!caution || (name + "=" + escape(value)).length <= 4000)
         document.cookie = curCookie;
      else
         if (confirm("Cookie exceeds 4KB and will be cut!"))
            document.cookie = curCookie;
   }

function getCookie (name) {
    var dcookie = document.cookie; 
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
    var rvalue;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) { 
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            	rvalue = unescape(dcookie.substring(vbegin, vend));
            	if(rvalue=="deleted"||rvalue=="DELETED"){
            		return null;	
            	}else{
            		return rvalue;
            	
            	}
            }
        	cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
    return null;
}

//---added for new website----
	function pastTo(section,cdate){
		if(cdate!=""){
			location.href="/"+section+"/"+cdate+"/";
		}
	}

function Sendmessage(uid) {	
	window.open('/Myworld/Blog/Message/pmessage.php?receiver='+uid,'pmessage','width=500,height=300,scrollbars=1');
}
function Listmessage() {	
	window.open('/Myworld/Blog/Message/plist.php','pmessage','width=500,height=300,scrollbars=1');
}

function TrimAll(data)
	{
		var lszTrim = data;
		var j = 0;

		for(var i = 0; i < data.length; i++)
		{
			if(data.substring(i, i+1) == ' ')
			{
				if(i > 0)
					lszTrim = data.substring(0, i);
				else
					lszTrim = "";
				lszTrim = lszTrim + data.substring(i+1);
				i = i - 1;

				data = lszTrim;
			}
		}

		return lszTrim;
	}
function IsEmpty(data)
	{
		var nCount = 0;
		var lszTrim = TrimAll(data);
		
		if(lszTrim.length == 0)
			return true;
		else
			return false;
	}
function Guestbook_num(arg1){
	
	document.all["divmsg"].innerHTML="<a href=\"/Myworld/Blog/guestbook.php\"><blink><b> ("+arg1+")</b></blink></a>";
}
function Message_num(arg1,arg2){
	var sum;
		sum = arg1.valueOf()+arg2.valueOf();
	
		document.all["divmsg"].innerHTML="<a href=\"javascript:void(Listmessage())\" title=\""+arg1+" new messages\"><blink><b> "+sum+"("+arg1+")</b></blink></a>";
		if(document.all["divmsg2"]){
			document.all["divmsg2"].innerHTML="<a href=\"javascript:void(Listmessage())\" title=\""+arg1+" new messages\"><font color=\"8FC143\"><blink><b> "+sum+"("+arg1+")</b></blink></font></a>&nbsp;";			
		}
		
		if(document.all["divmsg3"]){
			document.all["divmsg3"].innerHTML="<a href=\"javascript:void(Listmessage())\" title=\""+arg1+" new messages\"><font color=\"ffffff\"><blink><b> "+sum+"("+arg1+")</b></blink></font></a>&nbsp;";			
		}
		
		
}

function launchFlipbook(path) {	
	gallery=window.open(path,'gallery','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=510');
}

function jumpTo(url){
		if(url!=""){
			location.href=url;
		}
}
function vFlipbook(code){
	
	window.open('/Flipbook/data/flipbook'+code+'/flip1.html','flip','width=420,height=468,scrollbars=yes');	
	
}

function wCopytoBlog(code){

	var userID;
	userID=getCookie("User_ID");
	if(userID!="null" && userID!="" && userID!=null){
		//window.open("/Myworld/Blog/copywhatsup_popup.php?code="+code,'copywhatsup','width=400,height=270');
		window.open("/nickspace/blog/copywhatsup_popup.php?code="+code,'copywhatsup','width=400,height=270');
	}else{
	 	alert("Please sign in to copy this to your blog");
	}
}

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 launchvideo(video_code) {
	path = "/common/video/player.php?refer="+window.location.href+"&path="+ 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=475,height=380');
}
function launchvideoFF(video_code) {
	path = "/common/video/playerFF.php?refer="+window.location.href+"&path="+ 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=475,height=380');
}
function launchvideoBCB(video_code) {
	path = "/common/video/playerBCB.php?refer="+window.location.href+"&path="+ 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=475,height=380');
}
function launchvideoSP(video_code,sp_player) { //sponsor 
	path = "/common/video/"+sp_player+".php?refer="+window.location.href+"&path="+ 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=475,height=380');
}
function launchvideoG(video_code) {//general
	path = "/common/video/playerG.php?refer="+window.location.href+"&path="+ 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=475,height=380');
}

function launchvideoNoBanner(video_code) {//general
	path = "/common/video/playerNoBanner.php?refer="+window.location.href+"&path="+ 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=475,height=380');
}

function launchvideoBanner(video_code) {//general
	path = "/common/video/playerBanner.php?refer="+window.location.href+"&path="+ 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=550,height=380');
}


function launchvideo_m(video_code,player_code) {//specific skin
	path = "/common/video/player"+player_code+".php?refer="+window.location.href+"&path="+ 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=475,height=380');
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


 function doVote(){
	var userID, artistCodeChecked;
	userID=getCookie("User_ID");
	if(userID!="null" && userID!="" && userID!=null){

		artistCodeChecked=false;
		for (i=0; i<document.voteForm.artistCode.length-1; i++) { // don't check last option, last option to check with artistText later
			if(document.voteForm.artistCode[i].checked){
					artistCodeChecked=true;				
			}
		}

		if(artistCodeChecked || (document.voteForm.artistCode[document.voteForm.artistCode.length-1].checked && (trim(document.voteForm.artistText.value)!="") )){
			document.voteForm.submit();
		}else{
			alert("Please choose your personal favourite!");
		}
	}else{
		alert("Please log in to cast your votes!");
//		location.href="/Myworld/Login/login.php?" + window.location.href;	
	}
}

 function doVoteBCB(){
	var userID, videoCodeChecked;
	userID=getCookie("User_ID");
	if(userID!="null" && userID!="" && userID!=null){
		videoCodeChecked=false;
		for (i=0; i<document.voteForm.videoCode.length; i++) { 
			if(document.voteForm.videoCode[i].checked){
				videoCodeChecked=true;				
			}
		}
		if(videoCodeChecked)
			document.voteForm.submit();
		else
			alert("Please choose the video you want to vote!");
	}else{
		alert("Please log in to cast your vote!");
//		location.href="/Myworld/Login/login.php?" + window.location.href;	
	}
 }

 function doVoteUPick(){
	var userID, showCodeChecked;
	userID=getCookie("User_ID");
	if(userID!="null" && userID!="" && userID!=null){
		showCodeChecked=false;
		for (i=0; i<document.voteForm.showCode.length; i++) { 
			if(document.voteForm.showCode[i].checked){
				showCodeChecked=true;				
			}
		}
		if(showCodeChecked)
			document.voteForm.submit();
		else
			alert("Please choose the show you want to vote!");
	}else{
		alert("Please log in to cast your vote!");
//		location.href="/Myworld/Login/login.php?" + window.location.href;	
	}
 }

function popup(path) {
	gallery=window.open(path,'gallery','directories=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0,hotkeys=0,titlebar=1,alwaysRaised=1,dependent=1,screenX=10,screenY=10,top=10,left=10,width=100,height=100');
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}