// JavaScript Document
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
    if (obj.style) {obj=obj.style;}
	v=args[i+2];
	if(v){v=(v=='show')?'visible':(v=='hide')?'hidden':v;}
	else {v=obj.visibility; v=(v=='hidden')?'visible':(v=='visible')?'hidden':v;}
    obj.visibility=v; }
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

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 s_login(){
	var eSrc=(document.all)?window.event.srcElement:arguments[1];
	var shield = document.createElement("DIV");
	shield.id = "shield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
	shield.style.background = "#333";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	shield.style.opacity = 0;

	document.body.appendChild(shield);
	document.getElementById("login_form").style.display='block';
	this.setOpacity = function(obj,opacity){
		if(opacity>=1)opacity=opacity/100;
		try{ obj.style.opacity=opacity; }catch(e){}
		try{ 
			if(obj.filters.length>0&&obj.filters("alpha")){
				obj.filters("alpha").opacity=opacity*100;
			}else{
				obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
			}
		}catch(e){}
	}
	var c = 0;
	this.doAlpha = function(){
		c = c+5;
		if (c > 20){clearInterval(ad);return 0;}
		setOpacity(shield,c);
	}
	var ad = setInterval("doAlpha()",1);
	this.doOk = function(){
		//alertFram.style.display = "none";
		//shield.style.display = "none";
		//document.body.removeChild(alertFram);
		document.getElementById("login_form").style.display='none';
		document.body.removeChild(shield);
		//eSrc.focus();
		document.body.onselectstart = function(){return true;}
		document.body.oncontextmenu = function(){return true;}
	}
	//document.getElementById("do_OK").focus();
	//eSrc.blur();
	document.body.onselectstart = function(){return false;}
	document.body.oncontextmenu = function(){return false;}
	return false;
}

function s_friend(){
	var eSrc=(document.all)?window.event.srcElement:arguments[1];
	var shield = document.createElement("DIV");
	shield.id = "shield";
	shield.style.position = "absolute";
	shield.style.left = "0px";
	shield.style.top = "0px";
	shield.style.width = "100%";
	shield.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
	shield.style.background = "#333";
	shield.style.textAlign = "center";
	shield.style.zIndex = "10000";
	shield.style.filter = "alpha(opacity=0)";
	shield.style.opacity = 0;

	document.body.appendChild(shield);
	document.getElementById("send_form").style.display='block';
	this.setOpacity = function(obj,opacity){
		if(opacity>=1)opacity=opacity/100;
		try{ obj.style.opacity=opacity; }catch(e){}
		try{ 
			if(obj.filters.length>0&&obj.filters("alpha")){
				obj.filters("alpha").opacity=opacity*100;
			}else{
				obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
			}
		}catch(e){}
	}
	var c = 0;
	this.doAlpha = function(){
		c = c+5;
		if (c > 20){clearInterval(ad);return 0;}
		setOpacity(shield,c);
	}
	var ad = setInterval("doAlpha()",1);
	this.doOk1 = function(){
		//alertFram.style.display = "none";
		//shield.style.display = "none";
		//document.body.removeChild(alertFram);
		document.getElementById("send_form").style.display='none';
		document.body.removeChild(shield);
		//eSrc.focus();
		document.body.onselectstart = function(){return true;}
		document.body.oncontextmenu = function(){return true;}
	}
	//document.getElementById("do_OK").focus();
	//eSrc.blur();
	document.body.onselectstart = function(){return false;}
	document.body.oncontextmenu = function(){return false;}
	return false;
}

function lay_signup(){
	var pid = document.getElementById('picid').value;
	var mid = document.getElementById('mp3id').value;
	//window.location='signup.php?mid='+mid+'&pid='+pid;
	ajax_get('lay_signup.php?mid='+mid+'&pid='+pid+'&t='+Math.random(),'login_form');
}

function lay_login(){
	doValidate('lay_login_form');
	var  lay_username  =  document.getElementById('lay_username').value;
	var  lay_password  =  document.getElementById('lay_password').value;
	
	if(lay_username==""){
		
		return false;
	}
	
	if(lay_password==""){
		
		return false;
	}
	
	document.getElementById('lay_image_name').value = document.getElementById('image_name').value;
	document.getElementById('lay_artist_name').value = document.getElementById('artist_name').value;
	document.getElementById('lay_song_name').value = document.getElementById('song_name').value;
	
	//f = window.document.lay_login_form;
	//f.submit();
	
	url = 'lay_login.php?mod=login';
	var q;
	q='username='+lay_username+'&pass='+lay_password
	ajax_login (url,q, 'comment');
	
	
}

function lay_signup_post(){
	if(!doValidate('lay_signup')) return false;

	var  lay_username  =  document.getElementById('username').value;
	var  lay_email  =  document.getElementById('email').value;
	var  lay_num1  =  document.getElementById('num1').value;
	var  lay_num2  =  document.getElementById('num2').value;
	var  lay_num3  =  document.getElementById('num3').value;
	
	var  lay_carrier_id  =  document.getElementById('carrier_id').value;
	
	var  lay_password  =  document.getElementById('pass').value;
	var  lay_confirm_pass  =  document.getElementById('confirm_pass').value;
	
	if(lay_username==""){
		//MM_setTextOfLayer('lay_username_msg','','Error!');
		document.getElementById('username').style.border='1px solid #800000';
		return false;
	}
	
	if(lay_email==""){
		//MM_setTextOfLayer('lay_username_msg','','Error!');
		document.getElementById('email').style.border='1px solid #800000';
		return false;
	}
	
	if(lay_password==""){
		//MM_setTextOfLayer('lay_password_msg','','Error!');
		document.getElementById('pass').style.border='1px solid #800000';
		return false;
	}
	if(lay_confirm_pass==""){
		//MM_setTextOfLayer('lay_password_msg','','Error!');
		document.getElementById('confirm_pass').style.border='1px solid #800000';
		return false;
	}
	
	//document.getElementById('lay_image_name').value = document.getElementById('image_name').value;
	//document.getElementById('lay_artist_name').value = document.getElementById('artist_name').value;
	//document.getElementById('lay_song_name').value = document.getElementById('song_name').value;
	
	//f = window.document.lay_login_form;
	//f.submit();
	
	url = 'lay_sign_post.php';
	var q;
	q='username='+lay_username+'&pass='+lay_password+'&confirm_pass='+lay_confirm_pass+'&email='+lay_email+'&carrier_id='+lay_carrier_id+'&num1='+lay_num1+'&num2='+lay_num2+'&num3='+lay_num3;
	//alert(q);
	ajax_signup (url,q, 'comment');
	
	
}

function ajax_login(url,q,div)
{
	//var q = generate_post_query(form);
	var ajax = new myAjax(); 
	var ajax_o = new login_callback_object();
	ajax_o.div = div;
	ajax.post(url,q,ajax_o);
}

function login_callback_object(){
	var t;
	this.div = '';
	this.callback = show_div;
	
	function show_div(response){
		//alert(response);
		if(response=="1"){
			doOk();
			//window.document.frmMain.onSubmit = 'return make_image()';
			ajax_get('lay_login_check.php?'+Math.random(),'login_mod');
			if(document.getElementById('mk_btn1')){
				/*
				if(document.getElementById('song_name').value){
					t = "mp3";
				}
				if(document.getElementById('image_name').value){
					t = "pic";
				}*/
				t = document.getElementById('ct').value;
				//alert(t);
				ajax_get('replace_btn.php?t='+t+'&tmp='+Math.random(),'mk_btn1');
			}else{
				send_mp3id = document.getElementById('send_mp3id').value;
				send_picid = document.getElementById('send_picid').value;
				ajax_get('replace_btn.php?m=send&send_mp3id='+send_mp3id+'&send_picid='+send_picid+'&t='+Math.random(),'send_btn');
			}
		}else{
			MM_setTextOfLayer('lay_log','','Username or Password Error!');
		}
	}
}


function ajax_signup(url,q,div)
{
	//var q = generate_post_query(form);
	var ajax = new myAjax(); 
	var ajax_o = new signup_callback_object();
	ajax_o.div = div;
	ajax.post(url,q,ajax_o);
}

function signup_callback_object(){
	
	this.div = '';
	this.callback = show_div;
	
	function show_div(response){
		//alert(response);
		var ret = parseInt(response);
		//alert(ret);
		if(ret==1){
			doOk();
			//window.document.frmMain.onSubmit = 'return make_image()';
			ajax_get('lay_login_check.php?'+Math.random(),'login_mod');
			if(document.getElementById('mk_btn1')){
				if(document.getElementById('song_name').value){
					t = "mp3";
				}
				if(document.getElementById('image_name').value){
					t = "pic";
				}
				ajax_get('replace_btn.php?t='+t+'&tmp='+Math.random(),'mk_btn1');
			}else{
				send_mp3id = document.getElementById('send_mp3id').value;
				send_picid = document.getElementById('send_picid').value;
				ajax_get('replace_btn.php?m=send&send_mp3id='+send_mp3id+'&send_picid='+send_picid+'&t='+Math.random(),'send_btn');
			}
		}else{
			MM_setTextOfLayer('lay_log','','Sign Up Error!');
		}
	}
}

function ajax_post_send(url,q,div)
{
	//var q = generate_post_query(form);
	var ajax = new myAjax(); 
	var ajax_o = new send_callback_object();
	ajax_o.div = div;
	ajax.post(url,q,ajax_o);
}

function send_callback_object(){
	
	this.div = '';
	this.callback = show_div;
	
	function show_div(response){
		//alert(response);
		var ret = parseInt(response);
		//alert(ret);
		if(ret==1){
			//doOk();
			//window.document.frmMain.onSubmit = 'return make_image()';
			//ajax_get('lay_login_check.php?'+Math.random(),'login_mod');
			//ajax_get('replace_btn.php?'+Math.random(),'mk_btn1');
			window.location.href='sent_success.php';
		}else{
			//MM_setTextOfLayer('lay_log','','Sign Up Error!');
		}
	}
}

function send_pic(pid){
	var q;
	ajax_post_send('send.php?mod=pic&pid='+pid,q,'send_msg');
}

function send_slide(pid){
	var q;
	ajax_post_send('send.php?mod=slide&pid='+pid,q,'send_msg');
}


function send_song(mid){
	var q;
	ajax_post_send('send.php?mod=song&mid='+mid,q,'send_msg');
}

function sendtofriend(){
	if(!doValidate('lay_sendtofriend')) return false;
	var carrier_id = document.getElementById('carrier_id').value;
	if(carrier_id==''){
		alert('please select a Carrier!');
		return false;
	}
	var send_mp3id = document.getElementById('send_mp3id').value;
	var send_picid = document.getElementById('send_picid').value;
	var send_slideid = document.getElementById('send_slideid').value;
	var pn = document.getElementById('num1').value+document.getElementById('num2').value+document.getElementById('num3').value;
	
	if(pn==''){
		alert('please give me a Mobile number!');
		return false;
	}
	
	url = 'send.php?mod=sendtofriend';
	var q;
	q='carrier='+carrier_id+'&send_mp3id='+send_mp3id+'&send_picid='+send_picid+'&send_slideid='+send_slideid+'&pn='+pn;
	//alert(q);
	ajax_post_send (url,q, 'send_table');
}

function onSelectChange(selectObj) {
       var val = selectObj.options[selectObj.selectedIndex].value;
       document.getElementById('carrier_id').value = val;
}


function check_num(obj,n){
  if(obj.value.length>n){
	  obj.value = obj.value.substr(0,n);
  }else{
  	  obj.value = obj.value.replace(/[^\d]/g,'');
  }	
}