function isValidMail(val)
{
  var wildchar="~!#$%^&*()+=|\\/?<>;:'\"\¥\£`{}[] "
  var m1;
  var m2;
  var i=0;
  var count=0;
  m1 = val
  for (i=0;i<wildchar.length;i++)
  {
    if(m1.indexOf(wildchar.charAt(i)) != -1)
    {
      if (wildchar.charAt(i)==" ")
      {
        alert("Email ID Shouldn't Contain Spaces");
        return false;
      }
      else
      {
        alert("Email ID Shouldn't Contain \" " + wildchar.charAt(i) + " \" Character");
        return false;
      }
    }
  }

  if(m1.charAt(0)=="" || m1.charAt(0)=="@" || m1.charAt(0)==".")
  {
    alert("Please Enter A Valid Email ID")
    return false;
  }
  else if(m1.charAt(m1.length)=="." || m1.charAt(m1.length)=="@" || m1.charAt(m1.length)==" " || m1.indexOf(" ")!="-1")
  {
    alert("Please Enter A Valid Email ID")
    return false;
  }
  else
  {
    if(m1.indexOf("@")==-1)
    {
      alert("Please Enter A Valid Email ID");
      return false;
    }
    else
    {
      for(i=0; i<m1.length; i++)
      {
        if(m1.charAt(i)=="@")
          count++;
      }
      if(count>1)
      {
        alert ("Please Enter A Valid Email ID");
        return false;
      }
      else
      {
        if(count==1)
        {
          m2 = m1.substring(m1.indexOf("@")+1, m1.length)
          if(m2.indexOf(".")==-1)
          {
            alert ("Please Enter A Valid Email ID");
            return false;
          }
          else
          {
            for(i=0; i<1; i++)
            {
              if(m2.charAt(i)==".")
              {
                alert ("Please Enter A Valid Email ID");
                return false;
              }
            }
            return true;
          }
        }
      }
    }
  }
}
	


function isMMDDDate(val)
	{

	var dt, mon, yr, dt1, maxday,strDate1,strDate2
		dt1 = val
	
		//find the first slash position
		slashIndex=dt1.indexOf('/');
		if (slashIndex=="-1")
		{
			alert('Please select Valid Date');
			return false;
		}
		//find the second slash position		
		slashIndex1=dt1.lastIndexOf("/");
		if (slashIndex1==slashIndex)
		{
			alert('Please select Valid Date');
			return false;
		}

		mon  = parseInt(dt1.substring(0,slashIndex), 10)
		if (isNaN(mon))
			{
			   alert('Please select Valid Date');
			return false;					
			}
		dt = parseInt(dt1.substring(slashIndex+1,slashIndex1), 10)
		if (isNaN(dt))
			{
			   alert('Please select Valid Date');
			return false;					
			}
		yr  = parseInt(dt1.substring(slashIndex1+1,10), 10)

		if (isNaN(yr))
			{
			   alert('Please select Valid Date');
			return false;					
			}

		if (checkDate(mon,dt,yr))
			return true;
		else
		{
			alert('Please select Valid Date');
			return false;
		}
		
	}



function checkDate(mon,dt,yr)
{
	var MinMilli = 1000 * 60
  	var HrMilli = MinMilli * 60
  	var DyMilli = HrMilli * 24

	mon1=parseInt(mon)+1
	
	if(mon < 1 || mon > 12)
	{
		return false
	}				
	if(yr < 1 || yr > 9999)
	{
		return false
	}		
	strDate1 = new Date(yr,mon-1,'1');
	strDate2 = new Date(yr,mon1-1,'1')
	//Find the number of days for a given month
	maxday=(Math.round((strDate2-strDate1)/DyMilli))

	if (parseInt(dt,10)>parseInt(maxday,10))
		return false;
	else
	return true;
}


// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1998;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ForgotPassword()
{
 var t,l
   l=(screen.width-420)/2
   t=(screen.height-180)/3

	window.open("temp/forgotpassword.asp","_blank","width=390,height=200,top="+t+",left="+l);
}
function ForgotCitizensName()
{
 var t,l
   l=(screen.width-420)/2
   t=(screen.height-180)/3

	window.open("forgotcitizenname.asp","_blank","width=390,height=225,top="+t+",left="+l);
}
function UserName()
{
 var t,l
   l=(screen.width-420)/2
   t=(screen.height-180)/3

	window.open("temp/userName.asp","_blank","width=390,height=200,top="+t+",left="+l);
}
function CCVCode()
{
 var t,l
   l=(screen.width-420)/2
   t=(screen.height-180)/3

	window.open("CCVCode.asp","_blank","width=390,height=200,top="+t+",left="+l);
}
function ValidateLogin()
{
 if(document.frmlogin.txtusername.value == "")
 {
  alert("Please Enter Your UserName");
  document.frmlogin.txtusername.focus();
  return false;   
 }
 else if(document.frmlogin.txtpassword.value == "")
 {
  alert("Please Enter Your Password");
  document.frmlogin.txtpassword.focus();
  return false;   
 }     
 else
  return true;
}

var message="Sorry, you don't have permission to right click."; // Message for the alert box
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

function sendimtofriend(x)
{

 var t,l
 l=(screen.width-420)/4
 t=(screen.height-180)/12
 
window.open("im/send_message.asp?id="+x,"_blank","scrollbars=yes,height=300,width=350,top="+t+",left="+l);
 	
}

function friendslist(friendid)
{
	
  if(confirm("Are you sure you want to Add? ")) 
  {
   	location.href="Couple_profile.asp?friendid="+friendid+"&memberid="+friendid   	
  }
	
}
function blockmem(blockid)
{

  if(confirm("Are you sure you want to Block this member from contacting you? ")) 
  {
   	location.href="Couple_profile.asp?blockid="+blockid+"&memberid="+blockid   	
  }

}
function validate()
{
 if(document.frmstep2.txtemailid.value=="")
  { 
   alert("Please Enter Your Email Address!")
   document.frmstep2.txtemailid.focus();
   return false;    
  }   
 else if(!isValidMail(document.frmstep2.txtemailid.value))
 {
  document.frmstep2.txtemailid.focus();
  document.frmstep2.txtemailid.select();     
  return false;
 }    
else
  return true; 
}

