/*
* ---------------------------
* functions for the examples
* ---------------------------
*/

/*Toggles divs between open and close*/
function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
      document.getElementById(divid).style.display = 'block';
    }else{
      document.getElementById(divid).style.display = 'none';
    }
}

/*Pop up window - enter distance & description*/
function mycallbackfunc(v,m){
$.prompt('i clicked ' + v);
}

function mycallbackform(v,m){
$.prompt(v +' ' + m.children('#alertName').val());
}

function mysubmitfunc(v,m){
an = m.children('#alertName');
if(an.val() == ""){
an.css("border","solid #ff0000 1px");
return false;
}
return true;
}

jQuery.fn.extend({
myanimation: function(speed){
var t = $(this);
if(t.css("display") == "none")
t.show(speed,function(){ t.hide(speed,function(){ t.show(speed); }); });
else t.hide(speed,function(){ t.show(speed,function(){ t.hide(speed); }); });
}
});

var txt = 'Please enter your name:<br /><input type="text" id="alertName" name="myname" value="name here" />';
var txt2 = '<form action = "enter_distance.php" method = "post">Enter Your Distance:<br /><input type="text" id="alertName" name="distance" value=""/> <input name="ewr" type="submit" value="Submit" id="ewr" /></form>';

var brown_theme_text = '<h3>Example 13</h3><p>Save these settings?</p><img src="images/help.gif" alt="help" class="helpImg" />';


$(document).ready(function()
{
	$("#username").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax/user_availibility.php",{ user_name:$(this).val() } ,function(data)
        {
		  if(data=='spaces') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Username contains spaces').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  if(data=='short')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Username Isnt Long Enough').addClass('messageboxerror').fadeTo(900,1);	
			});
		  }
		  if(data=='no')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Username Is Unavailable').addClass('messageboxerror').fadeTo(900,1);	
			});
		  }
		  if(data=='yes')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Username Is Available').addClass('messageboxok').fadeTo(900,1);	
			});
		  }
				
        });
 
	});
});

$(document).ready(function()
{
	$("#email").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox2").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax/email_availibility.php",{ email_name:$(this).val() } ,function(data)
        {
		  if(data=='nono') //if username not avaiable
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Invalid Email').addClass('messageboxerror').fadeTo(900,1);
			});		
          }


		  if(data=='yesno') //if username not avaiable
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email Already In Use').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  
		  if(data=='noyes') //if username not avaiable
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Invalid Email').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  
		  if(data=='yesyes') //if username not avaiable
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email Ok').addClass('messageboxok').fadeTo(900,1);
			});		
          }
				
        });
 
	});
});

$(document).ready(function()
{
	$("#password").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox3").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax/check_password.php",{ password:$(this).val() } ,function(data)
        {
		  if(data==1) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Very Weak').addClass('messageboxerror').fadeTo(900,1);
			});		
          }


		  if(data==2) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Weak').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  
		  if(data==3) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Acceptable').addClass('messageboxok').fadeTo(900,1);
			});		
          }
		  
		  if(data==4) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Strong').addClass('messageboxok').fadeTo(900,1);
			});		
          }
				
        });
 
	});
});


$(document).ready(function()
{
	$("#group_password").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox3").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("../ajax/check_password.php",{ password:$(this).val() } ,function(data)
        {
		  if(data==1) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Very Weak').addClass('messageboxerror').fadeTo(900,1);
			});		
          }


		  if(data==2) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Weak').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  
		  if(data==3) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Acceptable').addClass('messageboxok').fadeTo(900,1);
			});		
          }
		  
		  if(data==4) //if username not avaiable
		  {
		  	$("#msgbox3").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Strong').addClass('messageboxok').fadeTo(900,1);
			});		
          }
				
        });
 
	});
});

/*Used for pop-up window*/
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=600,height=400,left=50,top=100,scrollbars=yes');
return false;
}


