// JavaScript Document


function displayBloc(idBloc){
	jQuery('#'+idBloc)
	.toggle();
}


function zipzouProducts(idArticle){
	jQuery('#blocProduct_'+idArticle)
	.toggle();
}

function showProductArticle(idArticle){
	$('#productArticleContent').load('spip.php?page=article_Product_Content&id_article='+idArticle);	
}

function showTCArticle(idArticle){
	$('#TCArticleContent').load('spip.php?page=article_Technical_Corner_Content&id_article='+idArticle);	
}

function showProductRubrique(idRubrique){
	$('#productArticleContent').load('spip.php?page=rubrique_Product_Content&id_rubrique='+idRubrique);	
}

function showTCRubrique(idRubrique){
	$('#TCArticleContent').load('spip.php?page=rubrique_Technical_Corner_Content&id_rubrique='+idRubrique);	
}

function showHighlightArticle(idArticle){
	$('#HighlightsContentsZone').load('spip.php?page=article_Highlights_Content&id_article='+idArticle);	
}

$(function() {
  $("#mainProducts img").hover(function() {
    $(this).attr("src", $(this).attr("src").split(".").join("-hover."));
  }, function() {
    $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
  });
});

$(function() {
  $("#selLangue").change(function() {
	switch(this.value){
		case 'en':
			document.location.href='/?lang=en';
			break;
		case 'fr':
			document.location.href='/?lang=fr';
			break;
		case 'de':
			document.location.href='http://www.genosphere-biotech.com/de/';
			break;
		case 'es':
			document.location.href='/?lang=es';
			break;
	}
  });
});


function addMessage(inMsg, inStr){
	if (inMsg) 
		inMsg += '<br/>';
	inMsg += inStr;	
	return(inMsg);
}

function validateEmail(emailStr){
	if (emailStr.length == 0) {
		return true;
	}
	// TLD checking turned off by default
	var checkTLD=0;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	if (user.match(userPat)==null) {
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 &&
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	if (len<2) {
		return false;
	}
	return true;
} 



function populateAntibodiesMain(inForm){
	var str = '';
	switch(inForm){
		case "APA":
			$('#formNumber').val('APA');
			
			str = $('#FComments1').val(); 
			$('#formComments').val(str);
			
			str = $('#FSequences').val(); 
			$('#APA_ProjectDescription').val(str);

			str = $('input[@name=Carrier]').fieldValue();
			$('#APA_CarrierConjugate').val(str);

			str = $('#fCarrierText').val();
			$('#APA_CarrierConjugateOther').val(str);
			
			str = $('input[@name=Protocol]').fieldValue();
			$('#APA_Protocol').val(str);
				
			str = $('#fNbPeptidesPerProject').val();
			$('#APA_ProtocolNbPeptidePerProject').val(str);
				
			str = $('#fProtocolText').val();
			$('#APA_ProtocolOther').val(str);
				
			str = $('#fPeptideSpecials1').attr('checked');
			if(str)
				str = $('#fPeptideSpecials1').val();
			else
				str = '';
			$('#APA_PeptideSpecials').val(str);
				

			str = $('#fPeptideSpecials2').attr('checked');
			if(str)
				str = $('#fPeptideSpecials2').val();
			else
				str = '';
			$('#APA_PeptideSpecialsPurityLevelRequired').val(str);

			str = $('#fPurityRequired').val();
			$('#APA_PeptideSpecialsPurityValueRequired').val(str);
				
			str = $('#fPeptideSpecials3').attr('checked');
			if(str)
				str = $('#fPeptideSpecials3').val();
			else
				str = '';
			$('#APA_PeptideSpecialsQuantityRequired').val(str);
				
			str = $('#fQuantityRequired').val();
			$('#APA_PeptideSpecialsQuantityValueRequired').val(str);
				
			str = $('input[@name=HostChoice]').fieldValue();
			$('#APA_Host').val(str);
				
			str = $('#fSelectedHost1').val();
			$('#APA_HostSelectedHost').val(str);
				
			str = $('#fnbHost').val();
			$('#APA_HostNbHostPerProject').val(str);
				
			str = $('#fHost2Text').val();
			$('#APA_HostCombination').val(str);
				
			str = $('input[@name=Purification]').fieldValue();
			$('#APA_Purification').val(str);

			str = '';
			$('#AAP_ProjectDescription').val(str);
			$('#AAP_Host').val(str);
			$('#AAP_HostSelectedHost').val(str);
			$('#AAP_HostNbHostPerProject').val(str);
			$('#AAP_HostCombination').val(str);
			$('#AAP_Purification').val(str);

			break;
		case "AAP":
			$('#formNumber').val('AAP');
			str = $('#FProjectDescription2').val(); 
			$('#AAP_ProjectDescription').val(str);

			str = $('#FComments2').val(); 
			$('#formComments').val(str);

			str = $('input[@name=HostChoice2]').fieldValue();
			$('#AAP_Host').val(str);
				
			str = $('#fSelectedHost2').val();
			$('#AAP_HostSelectedHost').val(str);
				
			str = $('#fnbHost2').val();
			$('#AAP_HostNbHostPerProject').val(str);
				
			str = $('#fHost2Text2').val();
			$('#AAP_HostCombination').val(str);
				
			str = $('input[@name=Purification2]').fieldValue();
			$('#AAP_Purification').val(str);

			str = '';
			$('#APA_ProjectDescription').val(str);
			$('#APA_CarrierConjugate').val(str);
			$('#APA_CarrierConjugateOther').val(str);
			$('#APA_Protocol').val(str);
			$('#APA_ProtocolNbPeptidePerProject').val(str);
			$('#APA_ProtocolOther').val(str);
			$('#APA_PeptideSpecials').val(str);
			$('#APA_PeptideSpecialsPurityLevelRequired').val(str);
			$('#APA_PeptideSpecialsPurityValueRequired').val(str);
			$('#APA_PeptideSpecialsQuantityRequired').val(str);
			$('#APA_PeptideSpecialsQuantityValueRequired').val(str);
			$('#APA_Host').val(str);
			$('#APA_HostSelectedHost').val(str);
			$('#APA_HostNbHostPerProject').val(str);
			$('#APA_HostCombination').val(str);
			$('#APA_Purification').val(str);

			break;
	}
}


