function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function check_email(address) {
	//var emailPat = /^((\w|\.|\_)+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	var emailPat = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	var matchArray = address.match(emailPat);
	if (matchArray == null)
		return false;
	else
		return true;
}

function isDigit() {
	if ((event.keyCode < 48)||(event.keyCode > 57 )) {
	  if (event.keyCode != 46)
		{event.returnValue=false;}
	}
}

function trim(inputString)
{
	var retValue = inputString;
	var ch = retValue.substring(0, 1);

	while (ch == " ")
	{ // Check for space at the start of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}

	ch = retValue.substring(retValue.length-1, retValue.length);

	while (ch == " ")
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	return retValue;
}

function login()
{
	if (document.f.tEmail.value == ""){
		alert("Please input your email");
		document.f.tEmail.focus();
		return;
	}
	if(trim(document.f.tPassword.value) == "")
	{
		alert("Please input your password");
		document.f.tPassword.focus();
		return;
	}
	
	document.f.submit();
}

function CountLeft(field, count, max) {
	// if the length of the string in the input field is greater than the max value, trim it
	if (field.value.length > max)
	field.value = field.value.substring(0, max);
	else
	// calculate the remaining characters
	count.value = max - field.value.length;
}

function tell_friend()
{
	//check if the friend email is the same with the sender email
	if(trim(document.fSendTo.tYName.value) == "")
	{		
		alert("Please input your name");
		document.fSendTo.tYName.focus();
		return;
	}
	if(trim(document.fSendTo.tYEmail.value) == "" || !check_email(document.fSendTo.tYEmail.value))
	{		
		alert("Please input your email correctly");
		document.fSendTo.tYEmail.focus();
		return;
	}
	
	if(trim(document.fSendTo.elements['tFEmail[]'][0].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][1].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][2].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][3].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][4].value) == ""){
		alert("Please input one your friend data");
		document.fSendTo.elements['tFName[]'][0].focus();
		return;
	}
	
	//check tell a friend section
	if (!(trim(document.fSendTo.elements['tFName[]'][0].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][0].value) == "") ){
		if(trim(document.fSendTo.elements['tFName[]'][0].value) == "")
		{		
			alert("Please input your friend name");
			document.fSendTo.elements['tFName[]'][0].focus();
			return;
		}
		if(trim(document.fSendTo.elements['tFEmail[]'][0].value) == "" || !check_email(document.fSendTo.elements['tFEmail[]'][0].value))
		{		
			alert("Please input your friend email correctly");
			document.fSendTo.elements['tFEmail[]'][0].focus();
			return;
		}
	}
	
	if (!(trim(document.fSendTo.elements['tFName[]'][1].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][1].value) == "") ){
		if(trim(document.fSendTo.elements['tFName[]'][1].value) == "")
		{		
			alert("Please input your friend name");
			document.fSendTo.elements['tFName[]'][1].focus();
			return;
		}
		if(trim(document.fSendTo.elements['tFEmail[]'][1].value) == "" || !check_email(document.fSendTo.elements['tFEmail[]'][1].value))
		{		
			alert("Please input your friend email correctly");
			document.fSendTo.elements['tFEmail[]'][1].focus();
			return;
		}
	}
	
	if (!(trim(document.fSendTo.elements['tFName[]'][2].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][2].value) == "") ){
		if(trim(document.fSendTo.elements['tFName[]'][2].value) == "")
		{		
			alert("Please input your friend name");
			document.fSendTo.elements['tFName[]'][2].focus();
			return;
		}
		if(trim(document.fSendTo.elements['tFEmail[]'][2].value) == "" || !check_email(document.fSendTo.elements['tFEmail[]'][2].value))
		{		
			alert("Please input your friend email correctly");
			document.fSendTo.elements['tFEmail[]'][2].focus();
			return;
		}
	}
	
	if (!(trim(document.fSendTo.elements['tFName[]'][3].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][3].value) == "") ){
		if(trim(document.fSendTo.elements['tFName[]'][3].value) == "")
		{		
			alert("Please input your friend name");
			document.fSendTo.elements['tFName[]'][3].focus();
			return;
		}
		if(trim(document.fSendTo.elements['tFEmail[]'][3].value) == "" || !check_email(document.fSendTo.elements['tFEmail[]'][3].value))
		{		
			alert("Please input your friend email correctly");
			document.fSendTo.elements['tFEmail[]'][3].focus();
			return;
		}
	}
	
	if (!(trim(document.fSendTo.elements['tFName[]'][4].value) == "" && trim(document.fSendTo.elements['tFEmail[]'][4].value) == "") ){
		if(trim(document.fSendTo.elements['tFName[]'][4].value) == "")
		{		
			alert("Please input your friend name");
			document.fSendTo.elements['tFName[]'][4].focus();
			return;
		}
		if(trim(document.fSendTo.elements['tFEmail[]'][4].value) == "" || !check_email(document.fSendTo.elements['tFEmail[]'][4].value))
		{		
			alert("Please input your friend email correctly");
			document.fSendTo.elements['tFEmail[]'][4].focus();
			return;
		}
	}
	
	if(trim(document.fSendTo.tVerCode.value) == ""){
		alert("Please input verification code");
		document.fSendTo.tVerCode.focus();
		return;
	}
	
	document.fSendTo.submit();
}

function ldDropDown(obj,url,params)
{
	$.ajax({		
	   type: "POST",		   
	   url: url,
	   data: params,
	   success: function(msg){	
	   	alert(msg);
		//$(obj).html(msg);
	   }
	 });
}