﻿function GetDiv(divname){
	return document.all?document.all[divname]:document.getElementById?document.getElementById(divname) : "";
}
function FormatInt(i){
	if (i<10) i='0'+i;
	return i;
}
function ShowHour(){
	var now=new Date(); GetDiv("ShowHour").innerHTML = now.getHours()+':'+FormatInt(now.getMinutes())+':'+FormatInt(now.	getSeconds())+' ';
	setTimeout(ShowHour,1000);
}
function smile(code){
	document.getElementById("textarea").value=document.getElementById("textarea").value + code;
	document.getElementById("textarea").focus();
}
function checkct(){
	if(GetDiv("username").value==""){ alert("Please enter your name"); return false;}
	else if(GetDiv("email").value==""){ alert("Please enter your email"); return false;}
	else if(!CheckEmailAddress(GetDiv("email").value)) { alert("Please enter the correct email format"); return false;}
	else if(GetDiv("title").value==""){ alert("Please enter Subject"); return false;}
	else if(GetDiv("content").value==""){ alert("Please enter content"); return false;}
	else if(GetDiv("code").value==""){ alert("Please enter word verification"); return false;}
	else return true;
}
function Trim(iStr)
{
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr=iStr.substr(1);
	}

	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr=iStr.substr(0, iStr.length - 1);
	}

	return iStr;
}
function CheckEmailAddress(Email)
{
	Email = Trim(Email);
	while (Email != '')
	{
		c = Email.charAt(0);	
		if (c==' ' || c=='<' || c==39 || c==':' || c=='.')
		{
			Email = Email.substr(1);
		}
		else
		{
			break;
		}
	}

	i = Email.indexOf('>');
	if (i==-1)
	{
		while (Email != '')
		{
			c = Email.charAt(Email.length - 1);
			if (c==' ' || c==39 || c=='.')
			{
				Email = Email.substr(0, Email.length - 1);
			}
			else
			{
				break;
			}
		}
	}
	else
	{
		Email = Email.substr(0, i);
	}

	if (Email.length > 96)
		return '';

	i = Email.lastIndexOf('@');
	j = Email.lastIndexOf('.');
	if (i < j)
		i = j;

	switch (Email.length - i - 1)
	{
	case 2:
		break;
	case 3:
		switch (Email.substr(i))
		{
		case '.com':
		case '.net':
		case '.org':
		case '.edu':
		case '.mil':
		case '.gov':
		case '.biz':
		case '.pro':
		case '.int':
			break;
		default:
			return '';
		}
		break;
	default:
		switch (Email.substr(i))
		{
		case '.name':
		case '.info':
			break;
		default:
			return '';
		}
		break;
	}

	Email = Email.toLowerCase();

	if (Email == '')
		return '';

	if (Email.indexOf(' ') != -1)
		return '';

	if (Email.indexOf('..') != -1)
		return '';

	if (Email.indexOf('.@') != -1)
		return '';

	if (Email.indexOf('@.') != -1)
		return '';

	if (Email.indexOf(':') != -1)
		return '';

	for (i=0; i < Email.length; i++)
	{
		c = Email.charAt(i);

		if (c >= '0' && c <= '9')
			continue;
		
		if (c >= 'a' && c <= 'z')
			continue;
		
		if ('`~!#$%^&*-_+=?/\\|@.'.indexOf(c) != -1)
			continue;

		return '';
	}

	if ((i=Email.indexOf('@'))==-1)
		return '';

	if (Email.substr(i + 1).indexOf('@')!=-1)
		return '';

	if (Email.charAt(0)=='.' || Email.charAt(Email.length - 1)=='.')
		return '';

	return Email;
}
