function DHTMLSound() {
  document.getElementById("dummyspan").innerHTML=
    "<embed src='../DING.WAV' hidden=true autostart=true loop=false>";
}


function getfileextension(filename) 
	{  
	//var fileinput = document.getElementById("foo");  
	//if(!fileinput ) return "";  
	//var filename = fileinput.value;  

	//if( filename.length == 0 ) return "";  

	var dot = filename.lastIndexOf(".");  
	if( dot == -1 ) return "";  

	var extension = filename.substr(dot,filename.length).toUpperCase();  

	return extension; 
	} 
/*
function checkfileType(inputId,allowedExt) 
	{  
		var ext = getfileextension(inputId);  
		if( ext == allowedExt )   
		alert("Congrats");  
		else   alert("Sorry"); 
	} 

*/


//clear the form if the back button clicked
function clearForms()
{
//alert("company" + document.forms.candidateform.length);
clearcompany();
clearcv();
}

function clearcompany()
{
var i;
  for (i = 0; (i < document.forms.companyform.length); i++) {
    document.forms.companyform.reset();
  }
}
  
function clearcv()  
{
var i;
for (i = 0; (i < document.forms.candidateform.length); i++) 
	{
    document.forms.candidateform.reset();
  	}
}
/* ****************************************************** */
function checkfilename(cv)
{
 	var str = cv   
    var strlen = str.length
    var startindex = strlen - 3 
    var filetype = str.substring(startindex, strlen).toUpperCase()

    var a = str.split("\\");
    var b = a.reverse();
    var c = b.toString();
    var d = c.search(",");
	


if (d == -1)
    {
        d = c.length;
    }
else 
    {
        d = d;
    }
    
var e = c.substr(0,d);
if  (d > 35)
    {
    alert(e + "\n nom de fichier trop longtemps\n filename too long")
	return false;	
    }
}	
/*   *****************************************    */


function checkformcandidate()
{
//get cv file type

var str1 = document.candidateform.cv.value
var strlen = document.candidateform.cv.value.length
var startindex = strlen - 3 
//var cvfiletype = str1.substring(startindex, strlen).toUpperCase()


    if (checkfilename(document.candidateform.cv.value)== false)
    {
    document.candidateform.cv.className = "inputwrong";
	document.candidateform.cv.focus();
    return false;
    }

/*   ****************************************         */
if (document.candidateform.fname.value.length == 0) 
	{
	DHTMLSound();
	alert("Saisissez votre nom\n\nPlease enter first name");
	document.candidateform.fname.className = "inputwrong";
	document.candidateform.fname.focus();
	return false;
 	}
if (document.candidateform.lname.value.length == 0) 
	{
	DHTMLSound();
	alert("Saisissez votre prénom\n\nPlease enter last name");
	document.candidateform.lname.className = "inputwrong";
	document.candidateform.lname.focus();
	return false;	
 	} 	
if (document.candidateform.tel.value.length == 0) 
	{
	DHTMLSound();
	alert("Saisissez votre numéro de téléphone\n\nPlease enter telephone number");
	document.candidateform.tel.className = "inputwrong";
	document.candidateform.tel.focus();
	return false;	
 	}
if (document.candidateform.comments.value.length >1000) 
	{
	DHTMLSound();
	alert("Texte trop longtemps\nText too long");
	document.candidateform.comments.className = "inputwrong";
	document.candidateform.comments.focus();
	return false;	
 	}	
if (document.candidateform.cv.value.length == 0) 
	{
	DHTMLSound();	
	alert("Téléchargez votre CV \n\nPlease attache CV");
	document.candidateform.cv.className = "inputwrong";
	document.candidateform.cv.focus();
	return false;	
 	}
/*if (document.candidateform.cv.value.length > 55) 
	{
	alert("Téléchargez votre CV \n\nPlease attache CV");
	document.candidateform.cv.className = "inputwrong";
	document.candidateform.cv.focus();
	return false;	
 	}	
	*/
	
	
	
	var cvfiletype = getfileextension(document.candidateform.cv.value)
	
	
//alert ("File Ext " + cvfiletype)
	
	if ((cvfiletype == ".DOC") || (cvfiletype == ".DOCX")) 
	{
	}
	//do nothing
	else
	{
	DHTMLSound();
	alert(cvfiletype + " file! Please use a word document (.doc, .docx)");
	document.candidateform.cv.className = "inputwrong";
	document.candidateform.cv.focus();
	return false;	
 	}
	
	
	

	
	 if (checkfilename(document.candidateform.cv.value)== false)
    {
    document.candidateform.cv.className = "inputwrong";
	document.candidateform.cv.focus();
    return false;
    }

/*   ****************************************         */
 return true;
 
}





function checkformCompany()
{
//get cv file type
//var str = document.companyform.jobdesc.value
//var strlen = document.companyform.jobdesc.value.length
//var startindex = strlen - 3 
//var cvfiletype = str.substring(startindex, strlen).toUpperCase()

if (document.companyform.coname.value.length == 0) 
	{
	DHTMLSound();
	alert("Saisissez votre Raison sociale\n\nPlease enter company name");
	document.companyform.coname.className = "inputwrong";
	document.companyform.coname.focus();
	return false;
 	}
if (document.companyform.coregno.value.length == 0) 
	{
	DHTMLSound();
	alert("Saisissez votre N° Siret\n\nPlease enter last name");
	document.companyform.coregno.className = "inputwrong";
	document.companyform.coregno.focus();
	return false;	
 	} 	
if (document.companyform.tel.value.length == 0) 
	{
	DHTMLSound();
	alert("Saisissez votre numéro de téléphone\n\nPlease enter telephone number");
	document.companyform.tel.className = "inputwrong";
	document.companyform.tel.focus();
	return false;	
 	}
if (document.companyform.comments.value.length >1000) 
	{
	DHTMLSound();
	alert("Texte trop longtemps\nText too long");
	document.companyform.comments.className = "inputwrong";
	document.companyform.comments.focus();
	return false;	
 	}		
if (document.companyform.jobdesc.value.length == 0) 
	{
	DHTMLSound();
	alert("Téléchargez votre annonce\n\nPlease attache job specification");
	document.companyform.jobdesc.className = "inputwrong";
	document.companyform.jobdesc.focus();
	return false;	
 	}
	
	
	var cvfiletype = getfileextension(document.companyform.jobdesc.value);
		
	//alert ("File Ext " + cvfiletype);
	
	if ((cvfiletype == ".DOC") || (cvfiletype == ".DOCX")) 
	{
	//do nothing
	//alert ("File Ext " + cvfiletype);
	
	}
	
	else
	{
	DHTMLSound();
	alert(cvfiletype + " file! Please use a word document (.doc, .docx)");
	document.companyform.jobdesc.className = "inputwrong";
	document.companyform.jobdesc.focus();
	return false;	
 	}
	
	  if (checkfilename(document.companyform.jobdesc.value)== false)
    {
    document.companyform.jobdesc.className = "inputwrong";
	document.companyform.jobdesc.focus();
    return false;
    }
/*	
if (cvfiletype != "DOC") 
	{
	alert(cvfiletype + "  Please use a word document (.doc)");
	document.companyform.jobdesc.className = "inputwrong";
	document.companyform.jobdesc.focus();
	return false;	
 	}
*/	 	 	
 return true;     
 }                
              
