﻿function checkMatch(box1, box2, lbl, ignoreCase)
{
    /// <summary>Compares two textboxes and prints the result to errorLabel</summary>
    /// <param name="box1">string: ID of the first textbox</param>
    /// <param name="box2">string: ID of the second textbox</param>
    /// <param name="lbl">string: ID of the label to print the results to</param>
    /// <param name="ignoreCase" default="false">bool: Ignore the case of the textboxes</param>
    
	var b1 = document.getElementById(box1).value;
	var b2 = document.getElementById(box2).value;
	var info = document.getElementById(lbl);
	
	if( ignoreCase )
	{
		b1 = b1.toLowerCase();
		b2 = b2.toLowerCase();
	}
	
	if( b1 == "" && b2 == "" )
	{
		info.innerHTML = "";
		return;
	}
	
	if( b1 == b2 )
	{
		info.innerHTML = "&nbsp;<img src='/images/icons/accept.png' alt='' style='vertical-align:text-top;' /> <span class='small'>values match</span>";
	}
	else
	{
		info.innerHTML = "&nbsp;<img src='/images/icons/exclamation.png' alt='' style='vertical-align:text-top;' /> <span class='small'>values don't match</span>";
	}
}

function checkGamerTag(tag, lbl)
{
    /// <summary>Checks if the gamer tag is available through AJAX and prints the result to the given label.</summary>
    /// <param name="tag">string: Gamer tag to check</param>
    /// <param name="lbl">string: ID of the label to print the results</param>
    
	var info = document.getElementById(lbl);
	info.innerHTML = "";
	
	if( tag == "" )
	{
		return;	
	}
	
	var invalid = "`~!@#$%^&*+=\\?/<>\"'{}[]()|";
	for( var i = 0; i < tag.length; i++ )
	{
	    for( var j = 0; j < invalid.length; j++ )
	    {
	        if( tag.substring(i,i+1) == invalid.substring(j,j+1) )
	        {
	            info.innerHTML = "&nbsp;<img src='/images/icons/exclamation.png' alt='' style='vertical-align:text-top;' /> <span class='small'>invalid characters</span>";
	            return;
	        }
	    }
	}
	
	var temp = function(txt)
	{
		info.innerHTML = txt;
	}
	
	info.innerHTML = "&nbsp;<img src='/images/loader.gif' alt='' style='vertical-align:text-top;' /> <span class='small'>checking...</span>";
	AJAXCall("/ajax/wiiNumbers.aspx?action=4&tag=" + escape(tag),temp);
	info.innerHTML = "&nbsp;<img src='/images/loader.gif' alt='' style='vertical-align:text-top;' /> <span class='small'>checking...</span>";
}

function checkEmail(email)
{
    /// <summary>Checks if the email is available through AJAX and prints the result to the given label.</summary>
    /// <param name="tag">string: Email to check</param>
    /// <param name="lbl">string: ID of the label to print the results</param>
    
	var info = document.getElementById("lblEmailError");
	info.innerHTML = "";
	
	if( email == "" )
	{
		return;	
	}
	
	var temp = function(txt)
	{
		info.innerHTML = txt;
	}
	
	info.innerHTML = "&nbsp;<img src='/images/loader.gif' alt='' style='vertical-align:text-top;' /> <span class='small'>checking...</span>";
	AJAXCall("/ajax/wiiNumbers.aspx?action=5&email=" + escape(email),temp);
	info.innerHTML = "&nbsp;<img src='/images/loader.gif' alt='' style='vertical-align:text-top;' /> <span class='small'>checking...</span>";
}