// JavaScript Document

function viewJobSeekers()
{
	with (window.document.frmListProduct) {
		if (cboCategory.selectedIndex == 0) {
			window.location.href = 'index.php';
		} else {
			window.location.href = 'index.php?jcatId=' + cboCategory.options[cboCategory.selectedIndex].value;
		}
	}
}
function viewProduct()
{
	with (window.document.frmListProduct) {
		if (cboCategory.selectedIndex == 0) {
			window.location.href = 'index.php';
		} else {
			window.location.href = 'index.php?jcatId=' + cboCategory.options[cboCategory.selectedIndex].value;
		}
	}
}

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 check2()
{
    with (window.document.guestform) {
                gName=txtName;
                gSurname=txtSurname;
                gEmail=txtEmail;
               
		// if name is empty alert the visitor
                if(trim(gName.value) == '')
                {
                alert('Please enter your name');
                gName.focus();
                return false;
                }
                else if(trim(gSurname.value) == '')
                {
                alert('Please enter your last name');
                gSurname.focus();
                return false;
                }
                else if( !echeck(trim(gEmail.value)))
                {
                alert('Please enter a valid email address ');
                gEmail.focus();
                return false;
                }
                else
                {
      
                submit();
                }
	}
}









function checkAddProductForm()
{
	with (window.document.frmAddProduct) {
		if (cboCategory.selectedIndex == 0) {
			alert('Choose your job category');
			cboCategory.focus();
			return;
		} else if (isEmpty(txtPhone, 'Enter Your contact phone')) {
			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 (isEmpty(txtSkill, 'Enter Your skills')) {
			return;
                } else if (isEmpty(txtUname, 'Select a user name')) {
			return;
                } else if (isEmpty(txtPassword, 'Select a password')) {
			return;
		} else {
			submit();
		}
	}
}

function checkModifyProductForm()
{
	with (window.document.frmModifyProduct) {
		if (cboCategory.selectedIndex == 0) {
			alert('Choose your job category');
			cboCategory.focus();
			return;
                } else if (isEmpty(txtName, 'Enter Your Name')) {
			return;
                } else if (isEmpty(txtSurname, 'Enter Your Surame')) {
			return;
                } else if (isEmpty(txtEmail, 'Enter Your Email')) {
			return;
		} else if (isEmpty(txtPhone, 'Enter Your contact phone')) {
			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 (isEmpty(txtSkill, 'Enter Your skills')) {
			return;
                
		} else {
			submit();
		}
	}
}

function logincheck()
{
	with (window.document.loginform) {
		
	        if (isEmpty(txtUName, 'Enter Your username')) {
			return;
                } else if (isEmpty(txtPassword, 'Enter Your password')) {
			return;
                
		} else {
			submit();
		}
	}
}




function check3()

{
  
  with (window.document.frmRecPassword) {

              rEmail=txtEmail;
              if( !echeck(trim(rEmail.value)))
                                               {
                                                alert('Please enter a valid email address ');
                                                rEmail.focus();
                                                return false;
                                               }else{
                                                submit();
                                               }   
                                                
   }
}



function recPassword()
{
	window.location.href = 'index.php?view=recover';
}

function addProduct(jcatId)
{
	window.location.href = 'index.php?view=precheck&jcatId=' + jcatId;
}

function modifyProduct()
{
	window.location.href = 'index.php?view=check';
}
function checklisting(jcatId)
{
	window.location.href = 'index.php?view=check&jcatId=' + jcatId;
}
