// JavaScript Document


/** Main Function : Navigator bar drawing
 *  Parameters    :		index : Number	: selected menu index
 *  Return Value  :		none
 */
function draw_navigator(index) {
	var sOutStream = "";
	
	sOutStream += "<table width='194px' height='122px' border='0' cellpadding='0' cellspacing='0' style='margin:8px 0 16px 30px;'>";
	sOutStream += "    <tr>";
	sOutStream += "        <td colspan='2' class='menu'>";
	sOutStream += "            <b>How to...</b>";
	sOutStream += "        </td>";
	sOutStream += "    </tr>";
	sOutStream += "    <tr>";
	sOutStream += "        <td class='padding-blank'></td>";
	if (index == 1) {
		sOutStream += "        <td class='menu-sel'>";
		sOutStream += "            Change your search defaults";
	} else {
		sOutStream += "        <td class='menu2'>";
		sOutStream += "            <a href='_GTAG_URL=http://www.msn.co.uk/clickscount/searchdefaults/&&HL=SEARCH%20DEFAULTS&CE=l01_/GTAG_'>Change your search defaults</a>";
	}
	sOutStream += "        </td>";
	sOutStream += "    </tr>";
	sOutStream += "    <tr>";
	sOutStream += "        <td class='padding-blank'></td>";
	if (index == 2) {
		sOutStream += "        <td class='menu-sel'>";
		sOutStream += "            Add to your favourites";
	} else {
		sOutStream += "        <td class='menu2'>";
		sOutStream += "            <a href='_GTAG_URL=http://www.msn.co.uk/clickscount/favourites/&&HL=SEARCH%20DEFAULTS&CE=l02_/GTAG_'>Add to your favourites</a>";
	}
	sOutStream += "        </td>";
	sOutStream += "    </tr>";
	sOutStream += "    <tr>";
	sOutStream += "        <td class='padding-blank'></td>";
	if (index == 3) {
		sOutStream += "        <td class='menu-sel'>";
		sOutStream += "            Make clickscount.co.uk your default homepage";
	} else {
		sOutStream += "        <td class='menu2'>";
		sOutStream += "            <a href='_GTAG_URL=http://www.msn.co.uk/clickscount/sethomepage/&&HL=SEARCH%20DEFAULTS&CE=l03_/GTAG_'>Make clickscount.co.uk your default homepage</a>";
	}
	sOutStream += "        </td>"; 
	sOutStream += "    </tr>";
	sOutStream += "    <tr>";
	sOutStream += "        <td class='padding-blank'></td>";
	if (index == 4) {
		sOutStream += "        <td class='menu-sel'>";
		sOutStream += "            Add an email signature";
	} else {
		sOutStream += "        <td class='menu2'>";
		sOutStream += "            <a href='_GTAG_URL=http://www.msn.co.uk/clickscount/emailsig/&&HL=SEARCH%20DEFAULTS&CE=l04_/GTAG_'>Add an email signature</a>";
	}
	sOutStream += "        </td>";
	sOutStream += "    </tr>";
	sOutStream += "    <tr>";
	sOutStream += "        <td class='padding-blank'></td>";
	if (index == 5) {
		sOutStream += "        <td class='menu-sel'>";
		sOutStream += "            Email a friend";
	} else {
		sOutStream += "        <td class='menu2'>";
		sOutStream += "            <a href='_GTAG_URL=http://www.msn.co.uk/clickscount/emailafriend/&&HL=SEARCH%20DEFAULTS&CE=l05_/GTAG_'>Email a friend</a>";
	}
	sOutStream += "        </td>";
	sOutStream += "    </tr>";
	sOutStream += "</table>";
	
	document.write(sOutStream);	
}

String.prototype.trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

function validation() {
	
	var name1 = "";
	var emailaddr1 = "";
	var name2 = "";
	var emailaddr2 = "";
	
    //var re = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
	var re = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	var rtn = false;

	name1 = emailform.friend_name.value.trim();
	emailaddr1 = emailform.friend_email.value.trim();
	name2 = emailform.your_name.value.trim();
	emailaddr2 = emailform.your_email.value.trim();
	
	
	try {
		if (name1 == "") {
			alert("Please type your friend's name!");
			emailform.friend_name.select();
		} else if (emailaddr1 == "") {
			//alert("Please type your friend's complete e-mail address!");
			alert("Please enter a valid email address!");
			emailform.friend_email.select();
		} else if (!re.test(emailaddr1)) {
			//alert("\"" + emailform.friend_email.value + "\"" + " is not a valid e-mail address!");
			alert("Please enter a valid email address!");
			emailform.friend_email.select();
		} else if (name2 == "") {
			alert("Please type your name!");
			emailform.your_name.select();
		} else if (emailaddr2.trim() == "") {
			//alert("Please type your complete e-mail address!");
			alert("Please enter a valid email address!");
			emailform.your_email.select();
		} else if (!re.test(emailaddr2)) {
			//alert("\"" + emailform.friend_emai2.value + "\"" + " is not a valid e-mail address!");
			alert("Please enter a valid email address!");
			emailform.your_email.select();
		} else {
			rtn = true;
		}
	} catch(e) {}

    return rtn;
}

// validates if the email address is in the correct format
// input: string
// output: boolean
function validateEmailAddress( emailAddress )
{
	var isValid = false;

	var atLocation = emailAddress.indexOf( "@" )
	var dotLocation = emailAddress.indexOf( "." )
	
	// check the length
	if( emailAddress.length < 5 )
		isValid = false
	// check @ and .
	else if( atLocation == -1  || dotLocation == -1 || atLocation > dotLocation )
	    isValid = false
	// is there at least one character before @
	else if( atLocation == 0 )
	    isValid = false
    else if( dotLocation - atLocation <= 1 )
        isValid = false
	// is there at least one character after .
	else if( emailAddress.length - dotLocation <= 1 )
	    isValid = false
	else
	    isValid = true

	return isValid;
}