//Genuine code by Corneliu Lucian 'Kor' RUSU corneliulucian[at]gmail[dot]com

//Applied upon the textboxes and textarea in the box "Contactez nous"
AttachEvent(window,'load',attachValidate,false);

AttachEvent(window,'unload',clearSp,false);

function clearSp(){
var txt=document.getElementsByName('questionaire')[0];
txt.value='';
}

function attachValidate(){
var allInp=document.getElementsByTagName('input'), inp, i=0;
while(inp=allInp[i++]){
	if(inp.form.id.match(/form_/)){
		if(inp.className.match(/bgreq/)){
		inp.onfocus=function(){this.blur()};
		}
		
		continue
		}
	else if(inp.className.match(/quinp_tx|qu_tarif|qu_nr/)){continue}
	else if(inp.type=='text'){inp.onfocus=focusOn;inp.onblur=blurOn}
}


}

// reset the Default value

function focusOn(){
this.value==this.defaultValue?this.value='':null;
}
function blurOn(){
this.value==''?this.value=this.defaultValue:null;
}

//Contactez validation

function valid(f){
var elem=f.elements, e, i;
var vname={
'nom':'last name',
'prenom':'first name',
'societe':'company',
'tel':'tel',
'email':'e-mail'
}; // fields to be validate
var message="Please, fill all the required fields!";
	for(name in vname){
		if(f[name].value.length<1||f[name].value==vname[name]){
		alert(message);
		f[name].focus();
		return false;
		}
	}

//removes the defaultValues
var defname={'nom':'last name','prenom':'first name','societe':'company','adr1':'address','adr2':'complete address','adr3':'complete address','codepost':'postcode','boitepost':'B.P.','ville':'city','pays':'country','tel':'tel','email':'e-mail'};

return true
}
//
function validInteger(obj){
obj.value=obj.value.replace(/[^\d]/g,'');
}

function isSkypeInstalled() {
    try {
        /*@cc_on
        //The Microsoft way, thanks to the conditional comments only run in IE
        if (new ActiveXObject("Skype.Detection")) return true;
        @*/

        //Tested for firefox on win
        if (navigator.mimeTypes["application/x-skype"]) return true;
    }
    catch(e){}
    return false;
}
// try for Skype
function trySkype(obj){
var sky=skypeCheck();
if(sky){
setTimeout(function () {changeSkyClass(obj)}, 2);	
}
return sky;

}

function changeSkyClass(obj){
obj.parentNode.onmouseover=function(){null};
obj.parentNode.onmouseout=function(){null};
obj.parentNode.className='con_skype_on';
document.getElementById('con_jos').innerHTML='<span style="font-size:18px;color:#fbda70">Appel activé</span>';
setTimeout(function(){redoContactez(obj)},30000)
}
function redoContactez(obj){
obj.parentNode.className='con_skype left';

document.getElementById('con_jos').innerHTML='<span style="font-size:14px;color:#fff">Contact immédiat <br>via Skype</span>';
attachContactez();
}

function validSpeed(f){
var vname={
'nom':'name',
'prenom':'first name',
'societe':'company',
'tel':'tel',
'email':'e-mail'
}; // fields to be validate

var ele=f.elements, i=0, e;
while(e=ele[i++]){
if(e.nodeName=='TEXTAREA'){
	if(e.value.length<1){
	alert('Please, fill all the required fields!');
	e.focus();
	return false
	}
}
else if(e.nodeName=='INPUT'){
	if(e.type=='text'){
		if(e.value.length<1||(e.value==vname[e.name])){
			
			alert('Please, fill all the required fields!');
			e.focus();
			return false
		}
	}
}
}
return true
}