// JavaScript Document
$(document).ready(function() {
	var screenH = screen.height;
	var screenW = screen.width;

	if(document.all) {
		availW = document.body.clientWidth;
		availH = document.body.clientHeight;
	}
	else {
		availW = innerWidth;
		availH = innerHeight;
	}
	var footer_min_h=40;
	var content_h=$('#principal').height() + $('#breadcrumbs').height() + $('#menu-h').height() + $('#header').height() + footer_min_h/2 + 2;
	var gap_h=(availH - content_h);
	var h=gap_h > footer_min_h ? gap_h : footer_min_h;
	$('#footer').css('height',h+'px');
	
	// PDF icon
	$('a img[src*="pdf"]').not('.as-is').each(function() {
		$(this).hide().parent('a').append('<span class="link-pdf">&nbsp;</span>').addClass('relative-block');
	});
	// PDF icon />
	// fancybox
	$('a[rel^="fancybox"]').click(function() {
		var aVars0 = $(this).attr('rel').split(';');
		var aVars1 = {};
		var aTmp = Array();
		for(p in aVars0) {
			aTmp = aVars0[p].split(':');
			aVars1[aTmp[0]] = aTmp[1];
		}
		$.fancybox({
			'titleShow'     : true,
			'type'			: aVars1['type'] ? aVars1['type'] : 'iframe',
			'width'			: aVars1['width'] ? parseInt(aVars1['width']) : 680,
			'height'		: aVars1['height'] ? parseInt(aVars1['height']) : 440,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack'
		});
		$(this).blur();
		return false;
	});
	// fancybox />
});
function switchImage(id, source) {
	var img=document.getElementById(id);
	img.src="/images/"+source;
}
function verify(lang) {
	al=0;
	i=document.forms[0].elements.length;
	if(lang=="f")
		sRet="Veuillez completer les champs suivants:\n\n";
	else
		sRet="Please complete these required fields:\n\n";
	for(j=0;j<i;j++) {
		el=eval(document.forms[0].elements[j]);
		if(el.value=="" && el.id!="") {
			sRet+="\n"+el.id;
			if(al!=1) {
				if(el.type!="hidden") el.focus();
			}
			al=1;
			switchClass(el,1);
		}
		else {
			if(el.id.indexOf("email")!=-1 || el.id.indexOf("Email")!=-1 || el.id.indexOf("ourriel")!=-1) {
				if (echeck(el.value)==false) {
					if(lang=="f")
						sRet+="\n"+el.id+" n'est pas valide";
					else
						sRet+="\n"+el.id+" is not valid";
					al=1;
					switchClass(el,1);
				}
				else {
					switchClass(el,0);
				}
			}
			else {
				switchClass(el,0);
			}
		}
	}
	if(al==1) {
		alert(sRet);
		return false;
	}
	else {
		//document.getElementByName("submit").disabled=true;
		return true;
	}
}
function switchClass(el,c) {
	var cl;
	if(c==1) {
		if(el.tagName.toLowerCase()=="select") cl="selErr"; else cl="err";
		//alert(t);
	}
	else {
		cl="norm";
	}
	el.className=cl;
	//var t;
	//t=toString(el.id+'-txt');
	//eltxt=document.getElementById(t)
	//if(eltxt) 
	//alert(eltxt.className);//="errtxt";
}
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){
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
		   return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false;
		}
		if (str.indexOf(dot,(lat+2))==-1){
		   return false;
		}		
		if (str.indexOf(" ")!=-1){
		   return false;
		}
 		return true;
}
function confLink(lang,url) {
	switch(lang) {
		case 'f':
			if(window.confirm('Vous allez quitter le site XMedius Downloads pour vous diriger vers faxserver.com.\n\n Continuer?')) document.location.href=url;
		break;
		case 'e':
			if(window.confirm('You are about to leave XMedius Downloads site to go to faxserver.com.\n\n Continue?')) document.location.href=url;
		break;
	}
}
