var version = navigator.appVersion.charAt(0);

if (navigator.appName.indexOf('Microsoft') != -1)
{
	var isIE = true;
	var isNS = false;
	var isMoz = false;
	var layerRef = 'document.all["';
	var styleSwitch = '"].style';	
} 
else if ((navigator.appName.indexOf('Netscape') != -1) && (version == 4))
{
		var isNS = true;
		var isIE = false;
		var isMoz = false;
		var layerRef = 'document.layers["';
		var styleSwitch = '"]';		
} 
else if ((navigator.appName.indexOf('Netscape') != -1) && (version == 5))
{
		var isNS = false;
		var isIE = false;
		var isMoz = true;
		var layerRef = 'document.getElementById("';
		var styleSwitch = '").style';		
}

var isWin = navigator.userAgent.indexOf("Win") != -1;
var isMac = navigator.userAgent.indexOf("Mac") != -1;
var isUnix = navigator.userAgent.indexOf("X11") != -1;

var iBPmix = 0
if (isWin)
{
	if (isIE)
	{
		iBPmix = 1;
	}
	if (isNS)
	{
		iBPmix = 2;
	}
}
if (isMac)
{
	if (isIE)
	{
		iBPmix = 3;
	}
	if (isNS)
	{
		iBPmix = 4;
	}
}
function showBig(picname)
{
	var winID = window.open('/tempInc/showpic.asp?pic=' + picname, 'bigpic', 'width=100,height=100,scrollbars=no,resizable=yes');
}
function popEmail(articleID, channelID)
{
	var emailID = window.open('email.asp?chid=' + channelID + '&id=' + articleID, 'emailer', 'width=400,height=230,scrollbars=no');
}
function popRate(channelID, articleID)
{
	var rateID = window.open('rate.asp?chid=' + channelID + '&id=' + articleID, 'ratings', 'width=400,height=500,scrollbars=no');
}
function rollOver(imageName)
{
	eval('document.images["' + imageName + '"].src = \'/images/' + imageName + '_f2.gif\'');
}
function rollOut(imageName)
{
	eval('document.images["' + imageName + '"].src = \'/images/' + imageName + '.gif\'');
}	
// Set navigation bar
function setNavigation(setEntry)
{
	window.parent.nav.location = 'nav.asp?sec=' + setEntry;
}

// Set breadcrumb trail
function setTrail(entryList)
{
	window.parent.trail.location = 'trail.asp?tr=' + entryList
}

// Netscape resizing bug fix
function WM_netscapeCssFix() {
  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape
  // fires a resize event when the scrollbars pop up. This
  // checks to make sure that the window's available size
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth ||
document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape
  // in use contains the bug; if so, it records the window's
  // width and height and sets all resize events to be handled
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn()

// End NS resizing bug fix

function checkrequired( formname) {

	var pass=0, box=0, theForm;
	theForm = document.forms[formname];

	if (document.images) {
		for (i=0; i < theForm.length; i++) {
			var tempobj=theForm.elements[i];
			if (tempobj.name.substring(0,1) == "*") {
						
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					pass=1;
					break;
	      }
	    } 
		}
		
		if (pass==1) {		
			shortFieldName=tempobj.name.substring(1,30).toUpperCase();
			alert("Veuillez renseigner le champ "+shortFieldName);
		} else {
			theForm.submit();
		}
	}			
}

function emailCheck(thisControl)
{

	var emailStr = thisControl.value
	//alert(thisControl);
	
	if (emailStr != "") {
		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)
		{
			alert(" L'adresse email entrée n'est pas valide (vérifiez les @ et apostrophes)")
			thisControl.select()
	  	thisControl.focus()
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]
	
		if (user.match(userPat)==null)
		{
			alert("Le login entré est incorrect")
			thisControl.select()
	  	thisControl.focus()
			return false
		}
	
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null)
		{
			for (var i=1;i<=4;i++)
			{
				if (IPArray[i]>255)
				{
					alert("L'adresse IP de destination est incorrecte")
					thisControl.select()
		 	 		thisControl.focus()
					return false				
				}
			}
			return true
		}
	
		var domainArray=domain.match(domainPat)
		if (domainArray==null)
		{
			alert("Le nom de domaine semble incorrect")
			thisControl.select()
	  	thisControl.focus()
			return false		
		}
	
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
		{
			alert("L'adresse doit finir par un domaine de trois lettres, ou par un pays de deux lettres")
			thisControl.select()
	  	thisControl.focus()
			return false
		}
	
		if (len<2)
		{
			var errStr="Veuillez ajouter un nom d'hébergeur a cette adresse"
			alert(errStr)
			thisControl.select()
	  	thisControl.focus()
			return false
		}
		return true;
	} else {
		return false;
	}
}
