// initiate the player popup window
var newWindow = new Object();

// Use this instead of div.innerHTML (Safari compatibility)
function changeInnerHTML(divId,html){
 if (document.getElementById) {
       document.getElementById(divId).innerHTML= html;
 }else{
     document.layers[divId].document.open();
     document.layers[divId].document.write(html);
     document.layers[divId].document.close();
 }
}

// Use this instead of div.innerHTML (Safari compatibility)
function changeValue(divId,html){
 if (document.getElementById) {
       document.getElementById(divId).value= html;
	   document.getElementById(divId).className = "textfield fivehundred noticethis";
	}
}

// Show more allows you to newegg customer review style hide a chunk of a content and expand it by swapping the divs with the dhtml hidden data
function showMore(divID1, divID2)
{
	a = document.getElementById(divID1).innerHTML;	
	b = document.getElementById(divID2).innerHTML;		
	
	changeInnerHTML(divID1, b);
	changeInnerHTML(divID2, a);	
}

function showImportArtist() {
    document.getElementById('importartist').style.display='block';
    document.getElementById('test123').style.display='none';
}

function refresh_com(args,logOut)
{	
	// create a new player popup window (if you are not currently logging out) in order to give it focus
	if (typeof(logOut)=="undefined" && newWindow){
		newWindow = open( "", "jba_player","status=0,menubar=0,toolbar=0,scrollbars=0,location=0,directories=0,width=425,height=355,top=60,left=60");
		newWindow.focus() 
	}	
	
	stuff = document.getElementById("flashcom");
	contents = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"1\" height=\"1\" id=\"timer_test\" align=\"middle\">	"
	contents = contents + "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
	contents = contents + "<param name=\"movie\" value=\"player/gateway.swf\" />";
	contents = contents + "<param name=\"quality\" value=\"high\" />";
	contents = contents + "<param name=\"bgcolor\" value=\"#333333\" />	";
	contents = contents + "<param name=\"flashvars\" value=\"" + args + "\">";
	contents = contents + "<embed src=\"player/gateway.swf\" FLASHVARS=\"" + args + "\"   quality=\"high\" bgcolor=\"#333333\" width=\"1\" height=\"1\" name=\"timer_test\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />	</object>"

	changeInnerHTML("flashcom", contents);
	
}


function formGen(module,method,target_monkey_id,url,instantiate) {
	contents = "<form action=" + url + " method='post' id ='blarg'>";
    contents = contents + "<input type='hidden' name='module' value=" + module + ">";
    contents = contents + "<input type='hidden' name='method' value=" + method + ">";
    //We need to decide if we want target_monkey_id or instantiate_id because some things
    //get deleted through HttpArgs::runMethods() which uses instantiate_id and other things 
    //just look for target_monkey_id in the args array and delete it directly
	if (instantiate === true) {
		contents = contents + "<input type='hidden' name='instantiate_id' value=" + target_monkey_id + ">";
	} else {	
		contents = contents + "<input type='hidden' name='target_monkey_id' value=" + target_monkey_id + ">";
	}
	contents = contents + "</form>";
	changeInnerHTML("flashcom", contents);
	document.getElementById("blarg").submit();
}


function popup_player(id, meth)
{		
	pop_url = 'player/player.php?' + id + '&method=' + meth;
	newWindow=window.open(pop_url,'jba_player','status=0,menubar=0,toolbar=0,scrollbars=0,location=0,directories=0,width=425,height=355,top=60,left=60');
//	alert(newwindow);
	if(window.focus){
		newWindow.focus()
	}
	
}
function showAutoComplete(form,field,module,div_id)
{
	val=document.forms[form][field].value;
	swap_module_template('AutoComplete', 'Display', div_id, '','',val,module);	
}
function hideAutoComplete(div_id)
{
	swap_module_template('AutoComplete', 'Display', div_id, '','','','');	
}
function setFormFocus(){
	for(i=0;i<document.forms.length;i++){
		for(j=0;j<document.forms[i].length;j++){
			var field=document.forms[i][j];
			var type=field.type;
			
			if(type=="text" || type=="textarea"){
					field.focus();
					break;
			}
		}	
	}	
}
function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid Email Address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid Email Address")
		  return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid Email Address")
		return false
		}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid Email Address")
		 return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid Email Address")
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid Email Address")
		return false
	}
		
	if (str.indexOf(" ")!=-1){
		alert("Invalid Email Address")
		return false
	}

 	return true					
}

function swap(showid, hideid, displaytype) { //Swap the visibility of two elements
	if(document.getElementById(showid).style.display == displaytype){
		document.getElementById(hideid).style.display = displaytype;
		document.getElementById(showid).style.display = "none";
	}
	else {
		document.getElementById(showid).style.display = displaytype;
		document.getElementById(hideid).style.display = "none";
	}
}

function setprofileimage(id) {
	document.getElementById('input').value = id;
	document.setprofileimage.submit();
}

function hide(id)
{
	document.getElementById(id).className = "hide";
}

function clearTextField(id,val)
{
	if(document.getElementById(id).value == val && document.getElementById(id).count == null)
	{
		document.getElementById(id).value = "";
		if(id == 'password') //Special conditions for the password box
		{
			//swap out the password box with a new password box so we can change the type (thanks IE, you rule)
			var passwordbox = document.createElement('input'); //Create a new input box
			passwordbox.type='password'; //Set up the attributes of the new password box
			passwordbox.name='password';
			passwordbox.className='textfield';
			passwordbox.id = 'password';
			passwordbox.value = "";
			document.login.password.parentNode.replaceChild(passwordbox, document.login.password); //swap out the elements
			document.login.password.focus(); //Set the focus twice to account for DOM slowness (doesn't work in IE if you only do it once.  thanks, again)
			document.login.password.focus();
		}
		
		if(id == 'tag') //If this is a tagbox
		{
			document.getElementById("tagsubmit").disabled = false;
			document.getElementById("tagsubmit").className = "submit";
		}
		
	}
	document.getElementById(id).count = 1;
}

// Module = class (comment/user/album/etc.)
// Template = template(display/add/fullview)
// div_id = Div ID (a unique ID for the particular target div we're swapping out the new content into)
// *optional* Instantiate_id = Monkey ID (the monkey ID you wish to instantiate the module with (Usually a Stored Module)) *optional*
// *optional* Choose to run a method call on a module before rendering it
// *optional* Arg1 = additional argument that can be used to pass into the module when you need more data to get there than just instantiate_id


// function swap_module_template (module, template, div_id, instantiate_id, methodcall, arg1, arg2)



//Toggle display of edit in place elements
//Hide box set not to display in css file
function show(id) {
	if (document.getElementById(id).style.display == "") {
		document.getElementById(id).style.display = "block";
	}
	else {
		document.getElementById(id).style.display = "";
	}
}


//show and hide track listing info box
function showtracklist(id,imgid) {
	if (document.getElementById(id).style.display == "") {
		document.getElementById(id).style.display = "block";
		document.getElementById(imgid).src = "images/tabloid/minus.gif";
	}
	else {
		document.getElementById(id).style.display = "";
		document.getElementById(imgid).src = "images/tabloid/plus.gif";
	}
}



//For the message center
function toggleAll(form){
	for(i=0;i<form.length;i++){
		if(form[i].name=="messages_to_delete[]"){
			form[i].checked=!form[i].checked;
		}
	}
}

//Used to prevent the user from double submitting a form.  Used in the checkout process
function stopDoubleSubmit(frm, btn){
   btn.disabled=true;
   btn.value='Please wait...';
}

function addInvitee(mid) {

mids = document.getElementById('mids');

mids_post = mids.value;

if ( mids_post.indexOf(mid) == -1 ) { // NOT IN STRING
    if (mids.value)
        mids.value = mids.value + ','+mid;
    else
        mids.value = mid;
}
else { // ALREADY THERE, TAKE IT OUT

if ( mids_post.indexOf(mid+',') == -1 ) // NOT FOLLOWED BY COMMA
    if ( mids_post.indexOf(','+mid) == -1 ) // NOT PRECEDED BY COMMA
       temp = mids_post.split(mid); // SO JUST REMOVE THE MID
    else
       temp = mids_post.split(','+mid); // IS PRECEDED BY COMMA SO REMOVE THAT TOO
else
    temp = mids_post.split(mid+','); // IS FOLLOWED BY COMMA SO REMOVE THAT TOO
    
mids.value = temp[0]+temp[1];

}
    
friend=document.getElementById(mid);
if (friend.className=="pixSelected" )
    friend.className="";
else
    friend.className="pixSelected";
// alert( mids.value );
}

function toggleVisible(toggle_id) {
    togglee = document.getElementById( toggle_id );
    
    if ( togglee.style.display=='block' )
        togglee.style.display='none';
    else
        togglee.style.display='block';
}

var reqMajor = 9;
var reqMinor = 0;
var reqRev = 0;
var flashRequirements = DetectFlashVer(reqMajor, reqMinor, reqRev);
if(!flashRequirements){
	// flash requirement has failed... express install?
	if (confirm('this site requires flash player '+reqMajor+'.'+reqMinor+'.'+reqRev+' Click ok to install.')) {
		window.location = 'http://www.adobe.com/go/getflash/';
	}
}
