
dochref = document.location.href.substr(document.location.href.search('/')+2, 1000);

if(dochref.search('/') == -1){

	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref;

} else {

	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref.substr(0, dochref.search('/'));

}

$thisurl = $thisurl + '';



var xmlhttp

/*@cc_on @*/

/*@if (@_jscript_version >= 5)

  try {

  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")

 } catch (e) {

  try {

	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

  } catch (E) {

   xmlhttp=false

  }

 }

@else

 xmlhttp=false

@end @*/



if (!xmlhttp && typeof XMLHttpRequest != 'undefined')

{

  try {

	xmlhttp = new XMLHttpRequest ();

  }

  catch (e) {

  xmlhttp = false}

}



function myXMLHttpRequest ()

{

  var xmlhttplocal;

  try {

  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}

  catch (e) {

	try {

	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}

	catch (E) {

	  xmlhttplocal = false;

	}

  }



  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {

	try {

	  var xmlhttplocal = new XMLHttpRequest ();

	}

	catch (e) {

	  var xmlhttplocal = false;

	}

  }

  return (xmlhttplocal);

}



var mnmxmlhttp = Array ();

var xvotesString = Array ();

var mnmPrevColor = Array ();

var responsestring = Array ();

var myxmlhttp = Array ();

var responseString = new String;





function vote (user, id, htmlid, md5, value)

{

  	if (xmlhttp) {

		url = $thisurl + "/vote.php";

		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;

		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {

            window.location="http://www.mogultunes.com/login.php?return="+location.href;

        } else {

    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

    		if (mnmxmlhttp) {

    			mnmxmlhttp[htmlid].open ("POST", url, true);

    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',

    					   'application/x-www-form-urlencoded');

    

    			mnmxmlhttp[htmlid].send (mycontent);

    			errormatch = new RegExp ("^ERROR:");    

    			target1 = document.getElementById ('xvotes-' + htmlid);    

    			mnmPrevColor[htmlid] = target1.style.backgroundColor;

    			mnmxmlhttp[htmlid].onreadystatechange = function () {

    				if (mnmxmlhttp[htmlid].readyState == 4) {

    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;

    					if (xvotesString[htmlid].match (errormatch)) {

    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);

							changemnmvalues (htmlid, value, true);
    					} else {

							
							if (xvotesString[htmlid].substring (1, 6) == "ERROR") { alert(xvotesString[htmlid]);  } else {changemnmvalues (htmlid, value, false); } 
    					}

    				}

    			}

    		}

    	}

	}

}





function unvote (user, id, htmlid, md5, value)

{

  	if (xmlhttp) {

		url = $thisurl + "/vote.php";

		var mycontent = "unvote=true&id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;

		anonymous_vote = false;

        if (anonymous_vote == false && user == '0') {

            window.location="http://www.mogultunes.com/login.php?return="+location.href;

        } else {

    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

    		if (mnmxmlhttp) {

    			mnmxmlhttp[htmlid].open ("POST", url, true);

    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',

    					   'application/x-www-form-urlencoded');

    

    			mnmxmlhttp[htmlid].send (mycontent);

    			errormatch = new RegExp ("^ERROR:");    

				target1 = document.getElementById ('xvotes-' + htmlid);

  				target2 = document.getElementById ('xvote-' + htmlid);    

    			mnmPrevColor[htmlid] = target1.style.backgroundColor;

    			mnmxmlhttp[htmlid].onreadystatechange = function () {

    				if (mnmxmlhttp[htmlid].readyState == 4) {

    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;

    					if (xvotesString[htmlid].match (errormatch)) {

    						 xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);

							changemnmvalues (htmlid, value, true);target2.innerHTML = "<span>Vote</span>";
						} else {

							if (xvotesString[htmlid].substring (1, 6) == "ERROR") { alert(xvotesString[htmlid]);  } else {target2.innerHTML = "<span>Vote</span>";changemnmvalues (htmlid, value, false); }							

    					}

    				}

    			}

    		}

    	}

	}

}





function cvote (user, id, htmlid, md5, value)

{

	if (xmlhttp) {

		url = $thisurl + "/cvote.php";

		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;

		anonymous_vote = false;



        if (anonymous_vote == false && user == '0') {

            window.location="http://www.mogultunes.com/login.php?return="+location.href;

        } else {

    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

    		if (mnmxmlhttp) {

    			mnmxmlhttp[htmlid].open ("POST", url, true);

    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    

    			mnmxmlhttp[htmlid].send (mycontent);

    			errormatch = new RegExp ("^ERROR:");

    			target1 = document.getElementById ('cvote-' + htmlid);        

    			mnmPrevColor[htmlid] = target1.style.backgroundColor;

    			target1.style.backgroundColor = '#FFFFFF';

    			mnmxmlhttp[htmlid].onreadystatechange = function () {

    				if (mnmxmlhttp[htmlid].readyState == 4) {

    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;

    					if (xvotesString[htmlid].match (errormatch)) {

    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						

    						changecvotevalues (htmlid, true);							

    					} else {

							target1 = document.getElementById ('ratebuttons-' + id);

							target1.style.display = "none";

							target2 = document.getElementById ('ratetext-' + id);

							target2.innerHTML = "";

							changecvotevalues (htmlid, false);

    					}

    				}

    			}

    		}

    	}

	}

}



function changemnmvalues (id, value, error)

{

	split = new RegExp ("~--~");

	b = xvotesString[id].split (split);

	//alert(id);

	target1 = document.getElementById ('xvotes-' + id);

	target2 = document.getElementById ('xvote-' + id);

	target3 = document.getElementById ('xreport-' + id);

	target4 = document.getElementById ('xnews-' + id);

	if (error) {

		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }

		else if (value < 0) { target2.innerHTML = "<span>Buried</span> "; }

		return false;

	}

	if (b.length <= 3) {

		target1.innerHTML = b[0];

		target1.style.backgroundColor = mnmPrevColor[id];

		new Effect.Fade(target3);

		if (value > 0) { target2.innerHTML = "<span>Voted</span> "; }

		else if (value < 0 ) { target2.innerHTML = "<span>Buried</span> ";

													new Effect.Opacity(target4, {duration:0.8, from:1.0, to:0.3}); }

	}

	return false;

}



function changecvotevalues (id, error)

{

	split = new RegExp ("~--~");

	b = xvotesString[id].split (split);

	target1 = document.getElementById ('cvote-' + id);

	if (error) {

		return false;

	}

	if (b.length <= 3) {

		target1.innerHTML = b[0];

		target1.style.backgroundColor = mnmPrevColor[id];

	}

	return false;

}





function enablebutton (button, button2, target)

{    

	var string = target.value;

	button2.disabled = false;

	if (string.length > 0) {

		button.disabled = false;

	} else {

		button.disabled = true;

	}

}



function disablebutton (button, button2, target)

{    

	var string = target.value;

	button2.disabled = true;

	if (string.length > 0) {

		button.disabled = true;

	} else {

		button.disabled = false;

	}

}



function enablebuttonname ()

{    

	document.step1.checkbutton1.disabled = false;

}


function disablebuttonname ()

{    

	document.step1.checkbutton1.disabled = true;

}

function enablebuttoninvite ()

{    

	
        document.step1.checkbutton0.disabled = false;

}


function disablebuttoninvite ()

{    

	document.step1.checkbutton0.disabled = true;

}

function enablebuttonemail ()

{    

	document.step1.checkbutton2.disabled = false;

}





function enablesubmitbut1 ()

{

var invite_code=document.getElementById('invite_code').value;

var username=document.getElementById('username').value;

var passwd=document.getElementById('passwd').value;

var passwd2=document.getElementById('passwd2').value;

var email=document.getElementById('email').value;

var confirm_email=document.getElementById('confirm_email').value;

var username_check=document.getElementById('username_check').value;

var email_check=document.getElementById('email_check').value;



  if(invite_code !='' && username!='' && passwd!='' && passwd2!='' && email!='' && confirm_email !='' && username_check !='' && email_check !='')

   {

	document.step1.step1continue.disabled = false;

   }  

  else 

  {

	document.step1.step1continue.disabled = true;

  }

}



function enablesubmitbut2 ()

{

var how_heard=document.getElementById('how_heard').value;




	if(how_heard!='')

   {

	document.step2.step2continue.disabled = false;

	}

	else 

	  {

		document.step2.step2continue.disabled = true;

	  }

   

}

function dis_pgshowname()
{
if(document.step2.pd_hostshow_yn.value=='0')
{
document.getElementById('show_pdnm').style.display="none";
}
else
{
document.getElementById('show_pdnm').style.display="block";
}
}

function dis_showname()
{
if(document.step2.md_hostshow_yn.value=='0')
{
document.getElementById('show_nm').style.display="none";
}
else
{
document.getElementById('show_nm').style.display="block";
}
}



function enablesubmitbut3 ()

{

var first_name=document.getElementById('first_name').value;

var last_name=document.getElementById('last_name').value;

var birth_month=document.getElementById('birth_month').value;

var birth_day=document.getElementById('birth_day').value;

var birth_year=document.getElementById('birth_year').value;

var gender=document.getElementById('gender').value;



  if(first_name!='' &&  last_name!=''  &&  birth_month!='' && birth_day!='' && birth_year!='' && gender!='')

   {

	document.step3.step3continue.disabled = false;

   }  

  else 

  {

	document.step3.step3continue.disabled = true;

  }

}



function enablesubmitbut4 ()

{

var address1=document.getElementById('address1').value;

var country=document.getElementById('country').value;

var state=document.getElementById('state').value;

var city=document.getElementById('infocity').value;

var phone=document.getElementById('phone').value;

var preferred_contact=document.getElementById('preferred_contact').value;

var mobile_phone=document.getElementById('mobile_phone').value;

var mobile_provider=document.getElementById('mobile_provider').value;

var message_preference=document.getElementById('message_preference').value;



if(address1!='' && country!='' && state!='' && city!=''  && phone!='' && preferred_contact!='' && mobile_phone!='' && mobile_provider!='' && message_preference!='')

   {

	document.step4.step4continue.disabled = false;

   }  

  else 

  {

	document.step4.step4continue.disabled = true;

  }

}



function enablesubmitbut5 ()

{

var agree_terms=document.getElementById('agree_terms').value;



  if(agree_terms!='')

   {

	document.step5.step5continue.disabled = false;

   }  

  else 

  {

	document.step5.step5continue.disabled = true;

  }

}



function displaystate()

{

var country= document.step4.country.value;

var pars = "country1="+country+"&task=stateajax";

  new Ajax.Updater("state1",'http://www.mogultunes.com/registerdec2.php',

                        {

                        method: 'post',

						parameters: pars

						}

                );

if(country!='')

	{

	document.step4.state.disabled = false;

	}

}


function displayzip()
{
	if(document.step4.country.value==43 || document.step4.country.value==253 || document.step4.country.value==254)
	{
		document.getElementById('infozip').style.display="block";
	}
	else
	{
		document.getElementById('infozip').style.display="none";
	}
}

function displayclubstate()

{
                               
var clubcountry= document.getElementById('country').value;
var pars2 = "country2="+clubcountry+"&task=clubstateajax";
if(clubcountry!='')
{
  new Ajax.Updater("clubstate",'http://www.mogultunes.com/registerdec2.php',

                        {

                        method: 'post',

						parameters: pars2

						}

                );
	

	}

}

function displaycolstate()

{

var col_country= document.step2.col_country.value;

var col_pars = "col_country="+col_country+"&task=col_stateajax";
if(col_country!='')
{
  new Ajax.Updater("col_state1",'http://www.mogultunes.com/registerdec2.php',

                        {

                        method: 'post',

						parameters: col_pars

						}

                );

	document.step2.state.disabled = false;

	}

}


function showhideTextSelect(selectmenu,id)  

{ 

	var elm = document.getElementById(id)

	if (selectmenu.selectedIndex == "1" || selectmenu.selectedIndex == "2" || selectmenu.selectedIndex == "3" || selectmenu.selectedIndex == "7" || selectmenu.selectedIndex == "8" || selectmenu.selectedIndex == "9" || selectmenu.selectedIndex == "10" || selectmenu.selectedIndex == "12" || selectmenu.selectedIndex == "13" || selectmenu.selectedIndex == "15" || selectmenu.selectedIndex == "16") {

		elm.style.display = "inline";

	} else {

		elm.style.display = "none";

	}

}

function showhide(id)  

{ 

	var style = document.getElementById(id).style;

	if (style.display == "none")  

		style.display = "inline";  

	else  

		style.display = "none";  

}



function showhideText(box,id)  

{ 

	var elm = document.getElementById(id) 

	elm.style.display = box.checked? "inline":"none" 

}

function checkfield (type, form, field)

{

	url = $thisurl + '/checkfield.php?type='+type+'&name=' + field.value;

	checkitxmlhttp = new myXMLHttpRequest ();

	checkitxmlhttp.open ("GET", url, true);

	checkitxmlhttp.onreadystatechange = function () {

		if (checkitxmlhttp.readyState == 4) {

		responsestring = checkitxmlhttp.responseText;

			if (responsestring == 1) {

				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:#EA1156; font-weight: bold;">"' + field.value + 

						'" is GOOD!</span>';

				//document.step1.step1continue.disabled = '';
                                
                                if (type == 'invite_code') {
                                    
                                    unlock_registration_form();
									
                                }
                                
                                if (type == 'email') {
                                
                                    document.step1.checkbutton2.disabled = true;
                                    document.step1.email.readOnly = true;
                                    document.step1.email.className = 'input-grey validate-email';
                                    document.step1.email_check.value = 1;
                                
                                }
                                
                                if (type == 'username') {
                                
                                    document.step1.checkbutton1.disabled = true;
                                    document.step1.username.readOnly = true;
                                    document.step1.username.className = 'input-grey';
                                    document.step1.username_check.value = 1;
                                
                                }

			} else {

				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:#EA1156; font-weight: bold;">' + responsestring + '</span>';

				//document.step1.step1continue.disabled = '';
    

			}

		}

	}

  checkitxmlhttp.send (null);

  return false;

}



function emailto (original_id, htmlid, instpath, address_count)

{

	email_message = document.getElementById('email_message' + htmlid).value;

	email_address = document.getElementById('email_address_1_' + htmlid).value;

	if (address_count > 1){ 

		for ($i = 2; $i <= address_count; $i++) {

			if(document.getElementById('email_address_' + $i + '_' + htmlid).value != "") {

				email_address = email_address + ', ' + document.getElementById('email_address_' + $i + '_' + htmlid).value;

			}

		}

	}

	

	if (xmlhttp) {

		url = $thisurl + "/recommend.php";

		mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";

		target2 = document.getElementById ('emailto-' + htmlid);

		target2.innerHTML = "<br>Sending, please wait....";

		

		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

		if (mnmxmlhttp) {

			mnmxmlhttp[htmlid].open ("POST", url, true);

			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',

					   'application/x-www-form-urlencoded');



			mnmxmlhttp[htmlid].send (mycontent);

			errormatch = new RegExp ("^ERROR:");

			target1 = document.getElementById ('emailto-' + htmlid);

			mnmxmlhttp[htmlid].onreadystatechange = function () {

				if (mnmxmlhttp[htmlid].readyState == 4) {

					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;

			

					if (xvotesString[htmlid].match (errormatch)) {

						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						

						target2 = document.getElementById ('emailto-' + htmlid);

						target2.innerHTML = xvotesString[htmlid];						

					} else {

						target2 = document.getElementById ('emailto-' + htmlid);

						target2.innerHTML = xvotesString[htmlid];

					}

				}

			}

		}

	}

}



function show_recommend(htmlid, linkid, instpath)

{

	var emailtodisplay=document.getElementById('emailto-' + htmlid).style.display ? '' : 'none';

	document.getElementById('emailto-' + htmlid).style.display = emailtodisplay;



	if (xmlhttp) {

		url = $thisurl + "/recommend.php";

		mycontent = "draw=small&htmlid=" + htmlid + "&linkid=" + linkid;

		target2 = document.getElementById ('emailto-' + htmlid);

		target2.innerHTML = "<br>Loading, please wait....";		

		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

		

		if (mnmxmlhttp) {

			mnmxmlhttp[htmlid].open ("POST", url, true);

			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',

					   'application/x-www-form-urlencoded');



			mnmxmlhttp[htmlid].send (mycontent);

			errormatch = new RegExp ("^ERROR:");

			target1 = document.getElementById ('emailto-' + htmlid);

			mnmxmlhttp[htmlid].onreadystatechange = function () {

				if (mnmxmlhttp[htmlid].readyState == 4) {

					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;			

					if (xvotesString[htmlid].match (errormatch)) {

						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						

						target2 = document.getElementById ('emailto-' + htmlid);

						target2.innerHTML = xvotesString[htmlid];						

					} else {

						target2 = document.getElementById ('emailto-' + htmlid);

						target2.innerHTML = xvotesString[htmlid];

					}

				}

			}

		}

	}

	

}

function populate_statebox(str,target1,target2){
	if(str!=''){
				var url = 'get_country_states.php?id='+str+'&target1='+target1+'&target2='+target2;
				new Ajax.Request(url,   {   method:'get',
                                   onSuccess: function(transport){ 
                                   response = transport.responseText;
//										alert(response);
									   	document.getElementById(target1+'_box').innerHTML = response;
								  		
								
                                    },
                                   onFailure: function(){ alert('Something went wrong...') }   });
	}
}

function populate_citybox(strt,target){
	
			if(strt!=''){
			
			var url = 'get_state_cities.php?id='+strt+'&target='+target;
			new Ajax.Request(url,   {   method:'get',
                                   onSuccess: function(transport)
								   { 
                                    response = transport.responseText;
//									alert(response);
									document.getElementById(target+'_box').innerHTML = response;

                              	    },
                               	  onFailure: function(){ alert('Something went wrong...') 
									 }  
						 });
	   				}
}

function unlock_registration_form()  {
	// disable invite code fields
	document.step1.checkbutton0.disabled = true;
	document.step1.invite_code.readOnly = true;
	document.step1.invite_code.className = 'input-grey validate-alphanum';
	
	// enable the rest of the form entry fields
	document.step1.username.disabled = false;
	document.step1.username.className = 'input-blue validate-alphanum validate-username';
	
	document.step1.passwd.disabled = false;
	document.step1.passwd.className = 'input-blue required validate-password';
	
	document.step1.passwd2.disabled = false;
	document.step1.passwd2.className = 'input-blue required validate-password-confirm';
	
	document.step1.email.disabled = false;
	document.step1.email.className = 'input-blue required validate-email';
	
	document.step1.confirm_email.disabled = false;
	document.step1.confirm_email.className = 'input-blue required validate-email-compare';
	
	document.step1.step1continue.disabled = false;	
}
