function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

    for (i=0; i<(args.length-2); i+=3)
    {
        test=args[i+2];

        if(test.indexOf('isCheck')!=-1)
        {
            val=args[i];
            if(!checkbox_checker(val))
            {
                errors += '- Region\n';
            }
        }
        else
        {
            val=MM_findObj(args[i]);
            if (val)
            {
                nm=val.name;
                if ((val=val.value)=="")
                {
                    if (test.charAt(0) == 'R')
                    {
                        if(args[i] == "Image")
                        {
                            if(!checkbox_checker("imageChosen"))
                            {
                                errors += '- '+nm+'\n';
                            }
                        }
                        else
                        {
                            errors += '- '+nm+'\n';
                        }
                    }
                    else
                    {
                        if (test.indexOf('NisEmail')!=-1)
                        {
                            p=val.indexOf('@');
                            if (p<1 || p==(val.length-1))
                                errors+='- '+nm+'\n';
                        }
                        else if (test!='R')
                        {
                            num = parseFloat(val);
                            if (isNaN(val))
                                errors+='- '+nm+' must contain a number.\n';
                            if (test.indexOf('inRange') != -1)
                            {
                                p=test.indexOf(':');
                                min=test.substring(8,p);
                                max=test.substring(p+1);
                                if (num<min || max<num)
                                    errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
                            }
                        }
                    }
                }
            }
        }
    }

    if (errors)
    {
        alert('The form is incomplete.\n Please fill in the following fields :\n\n'+errors);
    }

    document.MM_returnValue = (errors == '');
}
function checkbox_checker(nm)
{
    val=MM_findObj(nm);
    if (val)
    {
        if ((val=val.value)=="")
        {
            return (false);
        }
    }
    return (true);
}
function confirmSubmit()
{
    var agree=confirm("Do you really want to delete this item?");
    if (agree)
        return true ;
    else
        return false ;
}
function showLinks(val)
{
	var objOpt = val.options[val.selectedIndex];
    val=objOpt.value;
	var titleArray = new Array("consulting", "training", "speakers", "knowledge", "aboutUs");
	document.getElementById(val + "Links").style.display = 'block';
	for(i=0; i<titleArray.length; i++)
	{
		if(val != titleArray[i])
		{
			document.getElementById(titleArray[i] + "Links").style.display = 'none';
		}
	}
}
//show the proper input (text or file) for knowledge base - is it a website or a document?
function showTypeLinkInsert(val, num)
{
	var objOpt = val.options[val.selectedIndex];
    val=objOpt.value;
	document.getElementById(num + "_" + val).style.display = 'block';
	if(val == "web")
	{
		document.getElementById(num + "_download").style.display = 'none';
	}
	else
	{
		document.getElementById(num + "_web").style.display = 'none';
	}
}
//show the proper input (text or file) for knowledge base - is it a website or a document?
function showTotal(val, num, type)
{
	//course chosen
	if(type == 1)
	{
		if(val)
		{
			total += num;
		}
		else
		{
			total -= num;
		}
	}
	//discount chosen
	else
	{
		if(val)
		{
			discountNum++;
			discount = discount + num;
		}
		else
		{
			discountNum--;
			discount = discount - num;
		}
	}
	if(discountNum > 0)
	{
		temp = discount/discountNum;
		if(temp > 10)
		{
			discountVal = 15;
		}
		else
		{
			discountVal = 10;
		}
	}
	else
	{
		discountVal = 0;
	}
	cost = roundNumber((total*((100-discountVal)/100))*1.05, 2);
	cost += "";
	costDot = cost.indexOf('.');
	if(costDot == -1)
	{
		document.getElementById('totalText').innerHTML = "<strong>$ " + cost + ".00</strong>";
	}
	else if(costDot > cost.length-3)
	{
		document.getElementById('totalText').innerHTML = "<strong>$ " + cost + "0</strong>";
	}
	else
	{
		document.getElementById('totalText').innerHTML = "<strong>$ " + cost + "</strong>";
	}
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}