function hl_cvt(hs) {
	var s = "";
	if (hs.length % 2) {
		return;
	}
	for (var i = 0; i < hs.length; i += 2) {
		s = s + unescape("%" + hs.slice(i, i+2));
	}
	return s;
}

function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1) return false;
	else return true;
}

function confirmBox(msg, redirect) {
	var con;
	con=confirm(msg);
	if (con) {
		window.location=redirect;
	}
}

function checkConfirmSubmit() {
	var con;
	if (document.phoneComment.success[1].checked && document.phoneComment.email.value.length==0) {
		con=confirm('Thank you for taking the time to send us your feedback! However, without your email address we will be unable to diagnose this issue further. Click Cancel to enter your email address, or click OK to send your feedback without your email address.');
		return con;
	} else {
		return true;
	}
}

function dateChange(form) {
	var t3=0;
	var cur_select=form.birth_day.selectedIndex;
	if (form.birth_month.options[1].selected) {
		if (form.birth_year.options[form.birth_year.selectedIndex].value%4==0) t3=29;
		else t3=28;
	}
	else if(form.birth_month.options[8].selected || form.birth_month.options[3].selected || form.birth_month.options[5].selected || form.birth_month.options[10].selected)
	t3=30;
	else
	t3=31;
	for(i=0; i<31; i++) {
	form.birth_day.options[i]=null;
	}
	for (var i=0; i < t3 ; i++) {
		var x=String(i + 1);
		if (i < 9) x=String(0) + x;
		form.birth_day.options[i] = new Option(x);
	}
	if (cur_select > t3) cur_select=t3 -1;
	form.birth_day.selectedIndex=cur_select;
}

function leapYear(dayobj, monthobj, yearobj) {
	var t3=0;
	var cur_select=dayobj.selectedIndex;
	if (monthobj.options[1].selected) {
		if (yearobj.options[yearobj.selectedIndex].value%4==0) t3=29;
		else t3=28;
	} else if(monthobj.options[8].selected || monthobj.options[3].selected || monthobj.options[5].selected || monthobj.options[10].selected) t3=30;
	else t3=31;
	for(i=0; i<dayobj.options.length; i++) {
		dayobj.options[i]=null;
	}
	for (var i=0; i < t3 ; i++) {
		var x=String(i + 1);
		if (i < 9) x=String(0) + x;
		dayobj.options[i] = new Option(x);
	}
	if (cur_select > t3) cur_select=t3 -1;
	dayobj.selectedIndex=cur_select;
}

function textLimit (field, maxlength, strID) {
	var objSpan=document.getElementById(strID);
	var len=field.value.length;
	if (len  > maxlength) {
			field.value=field.value.substring(0, maxlength);
	}
	var left=maxlength-field.value.length;
	if (left == 1) objSpan.innerHTML = String(left) + " character left.";
	else objSpan.innerHTML = String(left) + " characters left.";
}

var _lastImg=0;

function img2Field (field_id, img, id) {
	var avatar_id_field;
	avatar_id_field=document.getElementById(field_id);
	avatar_id_field.value=id;
	img.style.borderStyle="solid";
	img.style.borderColor="#D55C00";
	if (_lastImg != 0 && _lastImg != img) { 
		_lastImg.style.borderStyle="solid";
		_lastImg.style.borderColor="#F5E9CF";
	}
	_lastImg=img;
}

function isFilled(elm) {
    if (elm.value == "" ||
        elm.value == null)
    return false;
    else return true;
}
/*
function remove(option) {
        to = document.getElementById("to");
        options = to.getElementsByTagName("option");
        for(var i=0;i<options.length;i++) {
                if (options[i].selected) {
                        if (option=='edit') {
                                rec = options[i].value;
                                name = rec.substring(0,rec.indexOf(":~#|:"));
                                address = rec.substring(rec.indexOf(":~#|:")+5,rec.length);
                                to_input = document.getElementById("to_input");
                                eto_input = document.getElementById("eto_input");
                                if(isFilled(to_input)&&isFilled(eto_input)) {
                                        add(to_input.value,eto_input.value);
                                }
                                to_input.value = name;
                                eto_input.value = address;
                        }
                        to.removeChild(options[i]); 
                }
        }
}

function add(name,address) {
        new_option = document.createElement("option");
        new_option.innerHTML = "&quot;"+name+"&quot;"+", "+address;
        new_option.value = name+":~#|:"+address;
        document.getElementById("to").appendChild(new_option);
}

function call_add() {
        to_input = document.getElementById("to_input");
        eto_input = document.getElementById("eto_input");
        if (isFilled(to_input)&&isFilled(eto_input)) {
                add(to_input.value,eto_input.value);
                to_input.value = '';
                eto_input.value = '';
        } else {
                alert("Please enter both a name and email address.");
                return false;
        }
}

function select_all() {
        to = document.getElementById("to");
        options = to.getElementsByTagName("option");
        for(var i=0;i<options.length;i++) {
                options[i].selected=true;
        }
}
*/

function openpopup(popurl, width, height, name){
	if (width==null) width=635;
	if (height==null) height=510;
	if (name==null) name='';
	var winpops=window.open(popurl,name,"width="+width+",height="+height);
}

function openpopup_news(popurl){
var winpops=window.open(popurl,"","width=470,height=600");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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_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 MM_showHideLayers() { //v6.0
	var i,p,v,o,z,obj,len,args=MM_showHideLayers.arguments;
	
	len=args.length;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
		v=args[i+2];
		if (obj.style) { 
			obj=obj.style; 
			if (v=='show') {
				v='visible';
				z=len;
				len=len-3;
			} else if (v=='show-auto') {
				v='visible';
				z=len;
				len=len-3;
				obj.overflow='auto';
			} else {
				v='hidden';
				obj.overflow='hidden';
				z=-1;
			}
			obj.visibility=v; 
			obj.zIndex=z;
		}
	}
}

function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// ajax functions
function AjaxClass() {
	var tagId='';
	var httpRequest=false;
	var url='';
	this.makeRequest=MakeRequest;
	this.setUrl=SetUrl;
	this.getResponse=GetResponse;
	this.postResponse=PostResponse;
	this.postSubmit=PostSubmit;
	this.setInnerHtml=SetInnerHtml;
	this.handleResponse=HandleResponse;
	this.abort=Abort;

	function MakeRequest(argurl) {
		url=argurl;
		if (!httpRequest) {
			if (window.XMLHttpRequest) { // Mozilla, Safari,...
				httpRequest = new XMLHttpRequest();
				if (httpRequest.overrideMimeType) {
					httpRequest.overrideMimeType('text/xml');
				}
			} else if (window.ActiveXObject) { // IE
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
				}
			}
		}
		return httpRequest;
	}
	
	function SetUrl(argurl) {
		url=argurl;
	}
	
	function GetResponse(param) {
		if (param != '') {
			if (url.indexOf('?')== -1) {
				url=url + '?' + param;
			} else {
				url=url + '&' + param;
			}
		}
		httpRequest.open('GET', url, true);
		httpRequest.send(null);
	}
	
	function PostResponse(param) {
		httpRequest.open('POST', url, true);
		// httpRequest.setRequestHeader('Host', 'localhost');
		httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpRequest.setRequestHeader("Content-length", param.length);
		httpRequest.setRequestHeader("X-Referer", document.location);
		httpRequest.setRequestHeader("Connection", "close");
		httpRequest.send(param);
	}
	
	function PostSubmit(formObj) {
		var postarr, poststr, elem, name, value;
		postarr=new Array();
		for(i=0; i<formObj.elements.length; i++) {
			value='';
			elem=formObj.elements[i];
			name=elem.name;
			if (elem.type=='radio') {
				if (elem.checked) {
					value=encodeURIComponent(elem.value);
					postarr[postarr.length] = name + "=" + value;
				}
			} else if (elem.type=='select-multiple') {
				for(j=0; j<elem.options.length; j++) {
					if (elem.options[j].selected) {
						value=encodeURIComponent(elem.options[j].value);
						postarr[postarr.length] = name + "=" + value;
					}
				} 
			} else if (elem.type=='select') {
				value=encodeURIComponent(elem.options[elem.selectedIndex].value);
				postarr[postarr.length] = name + "=" + value;
			} else if (elem.type=='checkbox') {
				if (elem.checked) {
					postarr[postarr.length] = name + "=" + encodeURIComponent(elem.value);
				}
			} else if (elem.value) {
				value=encodeURIComponent(elem.value);
				postarr[postarr.length] = name + "=" + value;
			}
		}
		poststr=postarr.join('&');
		this.postResponse(poststr);
	}
	
	function SetInnerHtml(tag) {
		var target, timeup=false;
		tagId=tag;
		// tim=setTimeout('timeup=true;', _small_timeout);
		httpRequest.onreadystatechange = function() {
			target=document.getElementById(tagId);
			if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					target.innerHTML=httpRequest.responseText;
					// clearInterval(tim);
					return true;
				} else {
					target.innerHTML='Server not responding - please try again.';
				}
				httpRequest=null;
			}
		}
	}
	
	function HandleResponse(func) {
		var tim, timeup=false;
		// tim=setTimeout('timeup=true;', _small_timeout);
		httpRequest.onreadystatechange = function() {
			if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					func(httpRequest.responseText);
					// clearInterval(tim);
				} else if (timeup) {
					func('');
					// alert('Server not responding - please try again');
				}
			}
		}
	}
	
	function Abort() {
		if (httpRequest && httpRequest.readyState > 0 && httpRequest.readyState < 4) {
			httpRequest.abort();
		}
	}
}

function simpleAjaxText(url, name) {
	var ao=new AjaxClass();
	ao.makeRequest(url);
	ao.setInnerHtml(name);
	ao.getResponse('');
}

function loginRefresh(win) {
	var ao, req, rep;
	ao=new AjaxClass();
	req=ao.makeRequest('/login_periodic.php');
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				if (req.responseText=='Login') {
					window.location.reload(true);
				} else {
					rep=setTimeout('loginRefresh()', 15055);
				}
			} else {
				rep=setTimeout('loginRefresh()', 15055);
			}
			req=null;
			ao=null;
		}
	}
	ao.getResponse();
}

// update array for looping 0=comments, 1=recent_uploads, 2=volatiles, 3=online, 4=dummy
_loop_indexes=new Array(0, 0, null, 0, 0);

function loopAjaxText(url, name, time, loop_index) {
	var ao, httpRequest, result, target, queryChar;
	ao=new AjaxClass();
	if (url.indexOf('?')== -1) {
		queryChar='?';
	} else {
		queryChar='&';
	}
	fullurl=url + queryChar + 'last_id=' + encodeURI(_loop_indexes[loop_index]);
	target=document.getElementById(name);
	httpRequest=ao.makeRequest('');
	httpRequest.onreadystatechange = function() {
		if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				if (httpRequest.responseText != '') {
					result=httpRequest.responseText.split('~|@');
					target.innerHTML=result[0];
					_loop_indexes[loop_index]=result[1];
				}
			}
			httpRequest=null;
			ao=null;
		}
	}
	httpRequest.open('GET', fullurl, true);
	httpRequest.send(null);
	setTimeout("loopAjaxText('" + url + "', '" + name + "', '" + time + "', '" + loop_index + "')", time);
}

function contentRefresh(url, name, startId) {
	this.url=url;
	this.name=name;
	this.lastId=startId;
	this.getContent=getContent;
	
	function getContent() {
		var ao, httpRequest, result, target, obj, queryChar;
		ao=new AjaxClass();
		if (this.url.indexOf('?')== -1) {
			queryChar='?';
		} else {
			queryChar='&';
		}
		fullurl=this.url + queryChar + 'last_id=' + encodeURI(this.lastId);
		target=document.getElementById(this.name);
		obj=this;
		httpRequest=ao.makeRequest('');
		httpRequest.onreadystatechange = function() {
			if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					if (httpRequest.responseText != '') {
						result=httpRequest.responseText.split('~|@');
						target.innerHTML=result[0];
						obj.lastId=result[1];
					}
				} 
				httpRequest=null;
				ao=null;
			}
		}
		httpRequest.open('GET', fullurl, true);
		httpRequest.send(null);
	}	
}


/* function toggleMsg(name, string, full) {
	var target=document.getElementById(name);
	var decode_string=unescape(string);
	if (full) {
		target.innerHTML='<img src="/layout_images/i_close.gif" border="0" onMouseUp="toggleMsg(\'' + name + '\', \'' + string + '\', false)"><br />' + decode_string;
	} else {
		target.innerHTML='<img src="/layout_images/i_open.gif" border="0" align="left" onMouseUp="toggleMsg(\'' + name + '\', \'' + string + '\', true)">';
	}
} */

function toggleMsg(message_id, full) {
	var target, ao, httpReq;
	target=document.getElementById('message_' + message_id);
	if (full) {
		target.innerHTML='<img src="/layout_images/loading_circle.gif">';
		ao=new AjaxClass();
		httpReq=ao.makeRequest('');
		httpReq.onreadystatechange = function() {
			if (httpReq.readyState == 4) {
				if (httpReq.status == 200) {
					target.innerHTML=httpReq.responseText;
				}
				httpReq=null;
				ao=null;
			}
		}
		httpReq.open('POST', '/ringtones/get_message.php', true);
		httpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpReq.setRequestHeader("Content-length", "1");
		httpReq.setRequestHeader("X-Referer", document.location);
		httpReq.send('message_id=' + message_id);
	} else {
		target.innerHTML='<img src="/layout_images/i_open.gif" border="0" align="left" onMouseUp="toggleMsg(\'' + message_id + '\', true)">';
	}
} 

function Chat(form_id, span_id, div_id, getUrl, postUrl) {
	this.form_id=form_id;
	this.span_id=span_id;
	this.div_id=div_id;
	this.getUrl=getUrl;
	this.postUrl=postUrl;
	this.init=initChat;
	this.submit=chatSubmit;
	this.refresh=chatRefresh;
	this.abort=abort;
	
	function initChat() {
		this.getUrl=(this.getUrl==null)?'/ringtones/chat/getChatMessages.php':this.getUrl;
		this.postUrl=(this.postUrl==null)?'/ringtones/chat/putChatMessage.php':this.postUrl;
		this.lastScrollTop= -1;
		this.last_id=0;
		this.isPosting=false;
		this.isGetting=false;
		this.blocked=0;
		this.chatAO=new AjaxClass();
		this.chatRequest=this.chatAO.makeRequest('');
		this.divarr=new Array();
		this.refresh();
		if (document.forms[this.form_id].elements['msg']) {
			document.forms[this.form_id].elements['msg'].setAttribute('autocomplete','off');
		}
	}
	
	function abort() {
		this.chatRequest=null;
		this.chatAO=null;
		this.divarr=null;
	}
	
	function chatSubmit() {
		var msg, submit;
		var url=this.postUrl;
		var chatObj=this;
		var targ=document.getElementById(this.span_id);
		var box=document.getElementById(this.div_id);
		var req=this.chatRequest;
		var lastScrollTop=this.lastScrollTop;
		url=url + '?last_id=' + this.last_id;
		msg=document.forms[this.form_id].elements['msg'];
		if (msg.value=='') {
			return false
		}
		submit=document.forms[this.form_id].elements['Submit'];
		submit.disabled=true;
		this.chatAO.setUrl(url);
		this.chatAO.postSubmit(document.forms[this.form_id]);
		if (!this.isGetting) {
			this.isPosting=true;
			this.chatRequest.onreadystatechange = function() {
				var results, text;
				if (req.readyState==4) {
					try {
						req.status;
					}
					catch(e) {
						return;
					}
					if (!chatObj.isGetting) {
						if (req.status==200) {
							chatObj.isPosting=false;
							text=req.responseText;
							if (text != '') {
								results='';
								results=text.split('~|@');
								if (results.length > 1) {
									targ.innerHTML=targ.innerHTML + results[1];
									box.scrollTop=box.scrollHeight;
									chatObj.lastScrollTop=box.scrollTop;
									chatObj.last_id=results[0];
								} 
							}
						}
					}
				}
			}
		} else {
			if (this.blocked > 3) {
				this.blocked=0;
				this.isGetting=false;
			}
			this.blocked=this.blocked + 1;
		}
		msg.value='';
		submit.disabled=false;
		return false;
	}
	
	function chatRefresh(url) {
		var url=this.getUrl;
		var chatObj=this;
		var targ=document.getElementById(this.span_id);
		var box=document.getElementById(this.div_id);
		var req=this.chatRequest;
		if (!this.isPosting) {
			this.isGetting=true;
			this.chatAO.setUrl(url);
			this.chatAO.getResponse('last_id=' + this.last_id);
			req.onreadystatechange = function() {
				var results, updateBox, text;
				if (req.readyState==4) {
					try {
						req.status;
					}
					catch(e) {
						return;
					}
					if (!chatObj.isPosting) {
						if (req.status==200) {
							chatObj.isGetting=false;
							text=req.responseText;
							if (text != '') {
								results='';
								results=text.split('~|@');
								if (results.length > 1) {
									targ.innerHTML=targ.innerHTML + results[1];
									if (box.scrollTop < chatObj.lastScrollTop) {
										updateBox=false;
									} else {
										updateBox=true;
									}
									if (updateBox) {
										box.scrollTop=box.scrollHeight;
										chatObj.lastScrollTop=box.scrollTop;
									}
									chatObj.last_id=results[0];
								} 
							}
						}
					}
				}
			}
		} else {
			if (this.blocked > 3) {
				this.blocked=0;
				this.isPosting=false;
			}
			this.blocked=this.blocked + 1;
		}
	}
}	

//phone pictures
_phone_image_disable=false;

function getPhoneModel(limit) {
	var manfield, manid, content, word, req, ao, url;
	ao=new AjaxClass();
	manfield=document.getElementById('manufacturer');
	manid=manfield.options[manfield.selectedIndex].value;
	content=document.getElementById('mod_sel');
	word=document.getElementById('modWord');
	if (limit == 1) {
		lim='&limit';
	} else {
		lim=''
	}
	req=ao.makeRequest('/ringtones/s2p_models.php');
	req.onreadystatechange=function() {
		if (req.readyState==4) {
			if (req.status==200) {
				content.innerHTML=req.responseText; 
				getPhoneImage();
				word.innerHTML='Model: [<a href="javascript:phoneWindow(' + limit + ');">Not sure?  View images</a>]';
				getPhoneImage();
				req=null;
			}
		}
	}
	ao.getResponse('man_id=' + manid + lim);
	word.innerHTML='Fetching Models';
}

function getPhoneImage() {
	var modfield, modid, content, ao;
	if (!_phone_image_disable) {
		ao=new AjaxClass();
		modfield=document.getElementById('model');
		modid=modfield.options[modfield.selectedIndex].value;
		if (modid != '') {
			content=document.getElementById('phone_image');
			content.innerHTML='<img src="/images/default_phone_loading.gif" height="150">';
			ao.makeRequest('/ringtones/s2p_photos.php');	
			ao.setInnerHtml('phone_image');
			ao.getResponse('mod_id=' + modid);
		}	
	}
}

function phoneWindow(limit) {
	var popupWin, manu, manvalue;
	manu=document.getElementById('manufacturer');
	manvalue=manu.options[manu.selectedIndex].value;
	if (limit == 1) {
		lim='&limit';
	} else {
		lim='';
	}
	if (manvalue=='')  {
		alert('Please select a manufacturer');
	} else {
	popupWin = window.open('/ringtones/hyperplayer_phones.php?man_id=' + manvalue + lim,'phones','scrollbars,width=860,height=680,left=50,top=50');
		popupWin.focus();
	}
}

function selectPhone(model, name, man) {
	if (window.opener) {
		var modmen = window.opener.document.getElementById('model');
		var models = modmen.options;
		var im = window.opener.document.getElementById('phone_image');
		for (i=0; i<models.length; i++) {
			if (model == models[i].value) {
				im.innerHTML='<img src="/ringtones/getPhoneImage.php?man_id=' + man + '&phone_name=' + name + '" border="0">';
				modmen.selectedIndex=i;
				window.close();
				break;
			}
		}
	}
}

function updateCarrierList() {
	var countlist, carmess, carfield;
	carmess=document.getElementById('phone_image');
	countlist=document.getElementById('country_id');
	if (countlist.options[countlist.selectedIndex].value != "US") {
		carmess.innerHTML='<font color="#000000">Currently, no carriers are<br>supported in this country.<br>Check back with us soon.</font>';
		_phone_image_disable=true;
	} else {
		_phone_image_disable=false;
		getPhoneImage();
	}
}

function carrierAlert(verizon, skype, skype_page, player) {
	var carsel, carid, carmess;
	carsel=document.getElementById('carrier');
	carid=carsel.options[carsel.selectedIndex].value;
	carmess=document.getElementById('carriers');
	if (carid==verizon) {
		carmess.innerHTML='<br><i>Verizon phones with Pix and Flix enabled <br>(see <a href="http://www.vzwpix.com" target="_blank">vzwpix.com</a>) are supported presently.</i>';
	} else if (carid==skype) {
		var theForm=document.forms['sendToPhone'];
		var payment;
		for(i=0; i<theForm.elements.length; i++) {
			if (theForm.elements[i].checked) {
				payment=theForm.elements[i].value;
				break;
			}
		}
		if (payment==null) {
			payment='full';
		} 
		if (player==1) {
			playerWindow(skype_page, 'payment=' + encodeURI(payment));
		} else {
			var qchar;
			if (skype_page.indexOf('?') != -1) {
				qchar='&';
			} else {
				qchar='?';
			}
			window.location=skype_page + qchar + 'payment=' + payment;
		}
	} else {
		carmess.innerHTML='';
	}
}

// tabbed top ten
/*
_last_tab="bestsellers";
function getTabList(linkid) {
	var list, link, loading, tab, tao, req, url;
	tao=new AjaxClass();
	if (linkid != _last_tab) {
		link=document.getElementById(linkid);
		switch (linkid) {
			case 'showtopten':	
			link.innerHTML='<img src="/layout_images/tab_byrank2.gif" name="tab_byrank" width="61" height="18" border="0">';
			url='/ringtones/topTenList.php';
			break;
			case 'showbycomments':
			link.innerHTML='<img src="/layout_images/tab_bycomments2.gif" name="tab_bycomments" width="92" height="18" border="0">';
			url='/ringtones/commentOnList.php';
			break;
			case 'bestsellers':
			link.innerHTML='<img src="/layout_images/tab_bestsellers2.gif" name="Image23" width="81" height="18" border="0">';
			url='/ringtones/bestSellerList.php';
			break;
			case 'mostplayed':
			link.innerHTML='<img src="/layout_images/tab_mostplayed2.gif" name="tab_mostplayed" width="82" height="18" border="0">';
			url='/ringtones/timesPlayedList.php';
			break;
			case 'stafffav':
			link.innerHTML='<img src="/layout_images/tab_stafffavorites2.gif" name="tab_stafffavorites" width="94" height="18" border="0">';
			url='/ringtones/staffFavList.php';
			break;
		}
		tab=document.getElementById(_last_tab);
		switch (_last_tab) {
			case 'showtopten':	
			tab.innerHTML='<a href="javascript:getTabList(\'showtopten\')" id="toptenlink" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'tab_byrank\',\'\',\'/layout_images/tab_byrank2.gif\',1)"><img src="/layout_images/tab_byrank.gif" name="tab_byrank" width="61" height="18" border="0"></a>';
			break;
			case 'showbycomments':
			tab.innerHTML='<a href="javascript:getTabList(\'showbycomments\')" id="commentonlink" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'tab_bycomments\',\'\',\'/layout_images/tab_bycomments2.gif\',1)"><img src="/layout_images/tab_bycomments.gif" name="tab_bycomments" width="92" height="18" border="0"></a>';
			break;
			case 'bestsellers':
			tab.innerHTML='<a href="javascript:getTabList(\'bestsellers\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image23\',\'\',\'/layout_images/tab_bestsellers2.gif\',1)"><img src="/layout_images/tab_bestsellers.gif" name="Image23" width="81" height="18" border="0"></a>';
			break;
			case 'mostplayed':
			tab.innerHTML='<a href="javascript:getTabList(\'mostplayed\')"onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'tab_mostplayed\',\'\',\'/layout_images/tab_mostplayed2.gif\',1)"><img src="/layout_images/tab_mostplayed.gif" name="tab_mostplayed" width="82" height="18" border="0"></a>';
			break;
			case 'stafffav':
			tab.innerHTML='<a href="javascript:getTabList(\'stafffav\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'tab_stafffavorites\',\'\',\'/layout_images/tab_stafffavorites2.gif\',1)"><img src="/layout_images/tab_stafffavorites.gif" name="tab_stafffavorites" width="94" height="18" border="0"></a>';
			break;
		}
		_last_tab=linkid;
		loading=document.getElementById('loadingCircle');
		loading.innerHTML='<img src="/layout_images/loading_circle.gif">';
		list=document.getElementById('showlist');
		req=tao.makeRequest(url);
		req.onreadystatechange=function() {
			if (req.readyState==4) {
				if (req.status==200) {
					list.innerHTML=req.responseText;
					loading.innerHTML='';
				} else {
					list.innerHTML='Server not responding.  Please try again.';
					loading.innerHTML='';
				}
				req=null;
				tao=null;
			}
		}
		tao.getResponse('');
	}
}
*/

_cur_rating=0;
_user_rating=0;

function ratingRollover(rating, refresh) {
	var field, star, starid;
	if (rating != _cur_rating) {
		_cur_rating=rating;
		field=document.getElementById('rating');
		field.value=rating;
		if (refresh != null && refresh) {
			starname='star';
		} else {
			starname='star_red';
		}
		for(i=0; i<rating; i++) {
			starid='star'+String(i+1);
			star=document.getElementById(starid);
			star.src="/layout_images/"+starname+".gif";
		}
		for(i=0; i<(5-rating); i++) {
			starid='star'+String(5-i);
			star=document.getElementById(starid);
			star.src="/layout_images/star_empty.gif";
		}
	}
}

/*
function customUrchin(domain, page) {
	// check for domain
	urchinTracker(page);
}

function topListSel() {
	var sel;
	sel=document.getElementById('type_sel');
	sel=sel.options[sel.selectedIndex].value;
	if (sel=='user') {
		window.location='top10.php?type=user';
	} else {
		window.location='top10.php?type=music';
	}
}
*/

function contentToggle(open, img, id, url, pref) {
	var image=document.getElementById(img);
	var zone=document.getElementById(id);
	if (open < 1) {
		userPref(pref, 0);
		zone.innerHTML='';
		image.innerHTML='<img src="/layout_images/tt_box_open.gif" onmouseup="contentToggle(1, \'' + img + '\', \'' + id + '\', \'' + url + '\', \'' + pref + '\')">';
		return true;
	}
	image.innerHTML='<img src="/layout_images/loading_circle.gif" height="20" width="20">';
	userPref(pref, 1);
	var ao=new AjaxClass();
	var httpReq=ao.makeRequest('');
	httpReq.onreadystatechange = function() {
		if (httpReq.readyState == 4) {
			if (httpReq.status == 200) {
				image.innerHTML='<img src="/layout_images/tt_box_close.gif" onmouseup="contentToggle(0, \'' + img + '\', \'' + id + '\', \'' + url + '\', \'' + pref + '\')">';
				zone.innerHTML=httpReq.responseText;
			}
			httpReq=null;
			ao=null;
		}
	}
	httpReq.open('GET', url, true);
	httpReq.send('');
	return true;
}

function loopToggle(open, img, id, url, pref, looper, chatObj) {
	var image=document.getElementById(img);
	var zone=document.getElementById(id);
	var loop=eval(looper);
	var chatStr='';
	if (chatObj != null) {
		chatStr=", '" + chatObj + "'";
	}
	if (open < 1) {
		userPref(pref, 0);
		clearInterval(loop);
		zone.innerHTML='';
		if (chatObj != null) {
			var chatter=eval(chatObj);
			chatter.abort();
		}
		image.innerHTML='<img src="/layout_images/tt_box_open.gif" onmouseup="loopToggle(1, \'' + img + '\', \'' + id + '\', \'' + url + '\', \'' + pref + '\', \'' + looper + '\'' + chatStr + ')">';
		return true;
	}
	image.innerHTML='<img src="/layout_images/loading_circle.gif" height="20" width="20">';
	userPref(pref, 1);
	var ao=new AjaxClass();
	var httpReq=ao.makeRequest('');
	httpReq.onreadystatechange = function() {
		if (httpReq.readyState == 4) {
			if (httpReq.status == 200) {
				image.innerHTML='<img src="/layout_images/tt_box_close.gif" onmouseup="loopToggle(0, \'' + img + '\', \'' + id + '\', \'' + url + '\', \'' + pref + '\', \'' + looper + '\'' + chatStr + ')">';
				zone.innerHTML=httpReq.responseText;
			}
			httpReq=null;
			ao=null;
		}
	}
	httpReq.open('GET', url, true);
	httpReq.send('');
	return true;
}

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" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return dc.substring(begin + prefix.length, end);
}

function parseCookieString(query) {
	var vars=query.split(escape("&"));
	var arr=new Array();
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split(escape("="));
		arr[pair[0]]=pair[1];
	}
	return arr;
}

function createCookieString(arr) {
	var outarr=new Array();
	var j=0;
	for(i in arr) {
		outarr[j]=i + '=' + arr[i];
		j++;
	}
	return outarr.join("&");
}

function userPref(prefname, prefval) {
	var cookie=getCookie('userprefs');
	var date=new Date();
	date.setTime(date.getTime() + 1000 * 60 * 60 * 24 * 365)
	if (cookie==null) {
		setCookie('userprefs', prefname + '=' + prefval, date, '/');
	} else {
		var prefs=parseCookieString(cookie);
		prefs[prefname]=prefval;
		var prefstring=createCookieString(prefs);
		setCookie('userprefs', prefstring, date, '/');
	}
}

function MM_goToURL() { 
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function findUser() {
	var screen_name=document.getElementById('screen_name').value;
	var ao=new AjaxClass();
	var httpReq=ao.makeRequest('/ringtones/search_screen_name.php');
	httpReq.onreadystatechange=function() {
		if (httpReq.readyState==4) {
			if (httpReq.status==200) {
				var resparr=httpReq.responseText.split('~|@');
				document.getElementById('recipient').innerHTML=resparr[0];
				document.getElementById('confirmation').innerHTML=resparr[1];
				document.getElementById('screen_name').value=resparr[2];
			}
			httpReq=null;
			ao=null;
		}
	}
	httpReq.open('GET', '/ringtones/search_screen_name.php?name=' + encodeURI(screen_name), true);
	httpReq.send('');
}

function changeSsn() {
	var ssn_elem;
	ssn_elem=document.getElementById('ssn');
	ssn_elem.innerHTML='<input type="text" name="ssn" id="ssn" size="9" maxchar="11"> Retype: <input type="text" name="ssn_retype" id="ssn_retype" size="9" maxchar="11">';
}

function limit30() {
	var start_min_obj, start_sec_obj, end_min_obj, end_sec_obj;
	var start_min, start_sec, start_time, end_min, end_sec, end_time;
	start_min_obj=document.getElementById('start_min');
	start_sec_obj=document.getElementById('start_sec');
	end_min_obj=document.getElementById('end_min');
	end_sec_obj=document.getElementById('end_sec');
	start_min=parseInt(start_min_obj.value);
	start_sec=parseFloat(start_sec_obj.value);
	end_min=parseInt(end_min_obj.value);
	end_sec=parseFloat(end_sec_obj.value);
	start_time=start_min * 60 + start_sec;
	end_time=end_min * 60 + end_sec;
	if (end_time > start_time + 30) {
		alert('Your ringtone clip can only be 30 seconds long.  Please adjust your start and end times.');
		return false;
	} else if (end_time <= start_time) {
		alert('Your ringtone clip needs to be at least one second long.  Please adjust your start and end times.');
		return false;
	}
	return true;
}

function swapPlay(elem_id, music_id, c_root, f_strat, swap, full) {
	var playobj, bg;
	playobj=document.getElementById(elem_id);
	if (full==null) {
		full=1;
	}
	if (swap==1) {
		if (f_strat=='H') {
			bg='#4D0602';
		} else {
			bg='#000033';
		}
		playobj.innerHTML='<embed src="/ringtones/play_small.swf?musicID=' + music_id + '&baseURL=' + c_root + '&strategy=' + f_strat + '&elem_id=' + elem_id + '&full=' + full + '" bgcolor="' + bg + '" width="13.2" height="14.35" type="application/x-shockwave-flash" />';
	} else {
		if (f_strat=='H') {
			im='tt_play.gif';
		} else {
			im='tt_play_mp3.gif';
		}
		playobj.innerHTML='<img src="/layout_images/' + im + '" border="0" style="cursor: pointer;"  onclick="javascript:swapPlay(\'' + elem_id + '\', \'' + music_id + '\', \'' + c_root +  '\', \'' + f_strat +  '\', 1, ' + full + ')" />';
	}
}