// JavaScript Document



function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}


function checkFinMemForm()
{   
    with (window.document.frmFinMem) {
		if (isEmpty(txtName, 'Enter Your name'))  {
			return;
		} else if (isEmpty(txtFname, 'Enter Your contact family name')) {
			return;
                } else if (isEmpty(txtAddress, 'Enter Your address')) {
			return;
                } else if (isEmpty(txtSuburb, 'Enter Your suburb')) {
			return;
                } else if (isEmpty(txtPcode, 'Enter Your postcode')) {
			return;
                } else if (st_id.selectedIndex == 0) {
			alert('Choose your state');
			st_id.focus();
                        return;
                } else if (!document.frmFinMem.age.checked) {
			alert("Please check the box"); 
                        return false; 
                } else {
			submit();
                }
	}
      

}



function Hcheck()
{
    with (window.document.frmHome) {
                gPass2=txtPass;
                gEmail2=txtEmail;
               
		// if password box is empty alert the visitor
                if( !echeck(trim(gEmail2.value)))
                {
                alert('Please enter a valid email address ');
                gEmail2.focus();
                return false;
                }
                else if(trim(gPass2.value) == '')
                {
                alert('Please enter your password');
                gPass2.focus();
                return false;
                }
                else
                {
      
                submit();
                }
	}
}


function memcheck()
{
    with (window.document.frmLogMem) {
                gPass=txtPass;
                gEmail=txtEmail;
               
		// if password box is empty alert the visitor
                if( !echeck(trim(gEmail.value)))
                {
                alert('Please enter a valid email address ');
                gEmail.focus();
                return false;
                }
                else if(trim(gPass.value) == '')
                {
                alert('Please enter your password');
                gPass.focus();
                return false;
                }
                else
                {
      
                submit();
                }
	}
}


function joincheck()
{
    with (window.document.frmAddMem2) {
                gPass=txtPass;
                gEmail=txtEmail;
               
		// if password box is empty alert the visitor
                if( !echeck(trim(gEmail.value)))
                {
                alert('Please enter a valid email address ');
                gEmail.focus();
                return false;
                }
                else if(trim(gPass.value) == '')
                {
                alert('Please enter your password');
                gPass.focus();
                return false;
                }
                else
                {
      
                submit();
                }
	}
}
function check4()

{
  
  with (window.document.frmRecPass) {

              rEmail=txtEmail;
              if( !echeck(trim(rEmail.value)))
                                               {
                                                alert('Please enter a valid email address ');
                                                rEmail.focus();
                                                return false;
                                               }else{
                                                submit();
                                               }   
                                                
   }
}


function recPass()
{
	window.location.href = 'index.php?views=recover';
}

function addMem()
{
	window.location.href = 'index.php?views=add';
}


function loginMem()
{
	window.location.href = 'index.php?views=check';
}

function deleteImage(pdId,tnId)
{
	if (confirm('Delete this image')) {
		window.location.href = 'processPd.php?action=deleteImage&tnId=' + tnId + '&pdId=' + pdId;
	}
}