function ValidEmail(emailStr)
{
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null)
	{
		alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null)
	{
		alert("The domain name doesn't seem to be valid.");
		return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)
	{
		alert("The address must end in a three-letter domain, or two letter country.");
		return false;
	}
	if (len<2)
	{
		var errStr="This address is missing a hostname!";
		alert(errStr);
		return false;
	}
	return true;
}

function Trim( rsString )
{
	var nIndex = 0;
	var lcReturnString = "";
	if (rsString.length <=0)
	{
		llValid="F";
	}
	while (nIndex < rsString.length)
	{ 
		if(rsString.charAt( nIndex )!= " ")
		{
			lcReturnString = lcReturnString + rsString.charAt( nIndex );
		}
		nIndex++;
	}
	return (lcReturnString);
}

function checksize (pstring)
{
	var size=0;
	return (pstring.length);
}

function validator(){ /*to be used for login page only*/
	if((Trim(document.signup.username.value)=="") || (Trim(document.signup.pasword.value)=="")){
		if (Trim(document.signup.username.value)==""){
			alert("Please fill the username!");
			document.signup.username.value="";
			document.signup.username.focus();	
			return false;
		}else{	
			alert("Please fill the password!");
			document.signup.pasword.value="";
			document.signup.pasword.focus();						
			return false;
		}
	}else{
		document.signup.submit_login_bool=true;
		document.signup.submit();
	}
}

function __initTxtBox(selector) {
	
	var __obj = $(selector);
		
	if ( ! __obj.val()) __obj.val(__obj.attr('title'));	
	if (__obj.val() == __obj.attr('title'))	__obj.css('color', '#999');
	
	__obj.focus(function() {
		if (( ! this.value) || (this.value == this.title)) {
			$(this).css('color', '');
			$(this).val('');
		}		
	});
	__obj.blur(function() {
		if (( ! this.value) || (this.value == this.title)) {
			$(this).css('color', '#999');
			$(this).val($(this).attr('title'));
		}
	});
}

function __hideFloatingMsgBox()
{
	$('#floating_msg_box').hide();
	$.cookie("STARTING_MSG_BOX_OFF", "off", { expires: 365 });
}
$(document).ready(function() {
	$('#floating_msg_box').fadeIn(1500);
});

function __showModalWindow(elem, _title, onProcessMsg, ajaxURL, ajaxData) {		
	
	//Get the A tag
	var self = elem;
	var title = _title;
	
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set height and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});				
	
	//transition effect		
	$('#mask').fadeIn(500);	
	$('#mask').fadeTo(500,0.8);

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
	
	// Show Ajax loader
	$('#dialog .window_title').html('');
	$('.window_content', self).html($('#ajaxLoaderTemplate').html());
	if (onProcessMsg) { 
		$('.window_content .ajaxLoaderTemplate_msg', self).html(onProcessMsg); 
	}
	$('.window_content', self).css({height: 'auto', width: 'auto'});
	
	//Set the popup window to center
	$(self).css('top',  winH/2-$(self).height()/2);
	$(self).css('left', winW/2-$(self).width()/2);
	$(self).fadeIn(500);
	
	// Get ajax
	if (ajaxURL) {
		__GBL_xhr = $.ajax({
			url: ajaxURL, 
			type: 'post',
			data: ajaxData,
			success: function(data) {
				// Hide for the meantime...
				$(self).css('top', -9000);
				$(self).css('left', -9000);
				
				// Prepare Content
				$('.window_content', self).html(data);
				$('.window_title', self).html(title);
				
				// Prepare to show
				$(self).hide();
				var t = winH/2-$(self).height()/2; if (t < 0) t = 0;
				var l = winW/2-$(self).width()/2; if (l < 0) l = 0;
				$(self).css('top',  t);
				$(self).css('left', l);					
				$(self).fadeIn(500); // Fade in to show
			}
		});
	} else {			
		$('#dialog .window_title').html(title);			
		$(self).fadeIn(500); // Fade in to show
	}
}

$(document).ready(function() {
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
		__GBL_xhr.abort();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		//$(this).hide();
		//$('.window').hide(); __GBL_xhr.abort();
	});
});
