// Java Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
 }

function center_pos() {
//opera Netscape 6 Netscape 4x Mozilla
if (window.innerWidth || window.innerHeight){
docwidth = window.innerWidth;
docheight = window.innerHeight;
}
//IE Mozilla
if (document.body.clientWidth || document.body.clientHeight){
docwidth = document.body.clientWidth;
docheight = document.body.clientHeight;
}
w=document.getElementById("main_div")
w.style.left= docwidth/2 - 380 - 10
w.style.display = ''
document.getElementById("preload_content").style.display = 'none'
}

function ValidateForm(){



        if ((document.form1.FirstName.value == null) || document.form1.FirstName.value =="") {
                alert("Please, enter your first name")
                document.form1.FirstName.focus()
                return false
        }

        if ((document.form1.LastName.value == null) || document.form1.LastName.value =="") {
                alert("Please, enter your last name")
                document.form1.LastName.focus()
                return false
        }

        if ((document.form1.email.value == null) || document.form1.email.value =="") {
                alert("Please, enter your e-mail address")
                document.form1.email.focus()
                return false
        }

        if ((document.form1.email.value.search("@") == -1) || document.form1.email.value.search("[.*]") == -1) {
                alert("Please, enter correct e-mail address")
                document.form1.email.focus()
                return false
        }

        if ((document.form1.password.value == null) || document.form1.password.value =="") {
                alert("Please enter your password")
                document.form1.password.focus()
                return false
        }

        if (document.form1.password.value.length < 6) {
                alert("Please enter your password atleast 6 characters long")
                document.form1.password.focus()
                return false
        }

        if (document.form1.password.value != document.form1.password_v.value) {
                alert("Password doesn't match, please, re-enter your password")
                document.form1.password.focus()
                return false
        }
        return true
 }


function handleEnter (field, event) {
                var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
                if (keyCode == 13) {
/*                      var i;
                        for (i = 0; i < field.form.elements.length; i++)
                                if (field == field.form.elements[i])
                                        break;
                        i = (i + 1) % field.form.elements.length;
                        field.form.elements[i].focus();
*/
                        document.form1.Message.value = document.form1.Message.value + " ";
                        return false;
                }
                else
                return true;
        }



function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

function PercentFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.0; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	i = Math.round(i*10)/10
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.0'; }
	if(s.indexOf('.') == (s.length - 1)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function PercentFormatted()

function Calculate()
{
var A = parseFloat(document.Calculator.price.value);
var B = parseFloat(document.Calculator.stop1.value);
var C = parseFloat(document.Calculator.profit1.value);
var E4 = parseFloat(document.Calculator.e4.value);
var G4 = parseFloat(document.Calculator.g4.value);
var E6 = parseFloat(document.Calculator.e6.value);
var G6 = parseFloat(document.Calculator.g6.value);
var E8 = parseFloat(document.Calculator.e8.value);
var G8 = parseFloat(document.Calculator.g8.value);


document.Calculator.risk.value = PercentFormatted(((A - B) / A) * 100) + " %";
document.Calculator.securise.value = "$ " + CurrencyFormatted(A + (A - B));
document.Calculator.profit2.value = "$ " + CurrencyFormatted(A * (C/100) + A);
document.Calculator.e6.value = Math.round(E4 / A);
document.Calculator.e8.value = "$ " + CurrencyFormatted(E4 * (((A - B) / A)));
document.Calculator.g6.value = CurrencyFormatted(G4 * A);
document.Calculator.g8.value = "$ " + CurrencyFormatted((G4 * A) * (((A - B) / A)));


}

function ClearForm()
{
document.Calculator.price.value = "";
document.Calculator.risk.value = "";
document.Calculator.stop1.value = "";
document.Calculator.profit1.value = "";
document.Calculator.profit2.value = "";
document.Calculator.securise.value = "";
document.Calculator.e4.value = "";
document.Calculator.e6.value = "";
document.Calculator.e8.value = "";
document.Calculator.g4.value = "";
document.Calculator.g6.value = "";
document.Calculator.g8.value = "";
document.getElementById('link_yahoo_image').style.display = "none"; 
document.getElementById('link_lesaffaires_image').style.display = "none";
document.getElementById('produce_stock').value = "";
document.getElementById('produce_market').value = "";
}

function ValidateInput(x)
{
var anum=/(^\.\d+$)|(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert("Please input a valid number!")
testresult=false
}
return (testresult)
}

function ClearSuggestions()
{
document.suggest.stock.value = "";
document.suggest.market.value = "";
document.suggest.comments.value = "";
}

function poptastic(url)
{
	newwindow=window.open(url,'Calculator','height=248,width=562,left=100,top=100,resizable=no,scrollbars=no,toolbar=no,status=no');
	if (window.focus) {newwindow.focus()}
}

function mypopup(url, name, features)
 {
   mywindow = window.open (url, name, features);
   mywindow.moveTo(100,100);
 } 

function video_popup(vid)
{
	mypopup('viewvideo.php?vid=' + vid, 'Videos', 'location=0,toolbar=0,addressbar=0,resizable=1,width=860,height=740');
} 


function showDiv(pass, attrib) {

if (attrib =="u") {
document.getElementById('show_t_u').style.visibility = 'hidden';
document.getElementById('hide_t_u').style.visibility = 'visible';
}

if (attrib =="c") {
document.getElementById('show_t_c').style.visibility = 'hidden';
document.getElementById('hide_t_c').style.visibility = 'visible';
}



var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){

		if(divs[i].id.match(pass)){//if they are 'see' divs

			if(divs[i].style.visibility="hidden") {
				if (document.getElementById) // DOM3 = IE5, NS6
						divs[i].style.visibility="visible";// show/hide
					else
						if (document.layers) // Netscape 4
							document.layers[divs[i]].display = 'visible';
						else // IE 4
							document.all.divs[i].visibility = 'visible';
			} else {
				
								if (document.getElementById) // DOM3 = IE5, NS6
						divs[i].style.visibility="hidden";// show/hide
					else
						if (document.layers) // Netscape 4
							document.layers[divs[i]].display = 'hidden';
						else // IE 4
							document.all.divs[i].visibility = 'hidden';
			}
		} 
	}
}

function hideDiv(pass, attrib) {

if (attrib =="u") {
	document.getElementById('hide_t_u').style.visibility = 'hidden';
	document.getElementById('show_t_u').style.visibility = 'visible';
}

if (attrib =="c") {
	document.getElementById('hide_t_c').style.visibility = 'hidden';
	document.getElementById('show_t_c').style.visibility = 'visible';
}



var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){

		if(divs[i].id.match(pass)){//if they are 'see' divs

			if(divs[i].style.visibility="visible") {
				if (document.getElementById) // DOM3 = IE5, NS6
						divs[i].style.visibility="hidden";// show/hide
					else
						if (document.layers) // Netscape 4
							document.layers[divs[i]].display = 'hidden';
						else // IE 4
							document.all.divs[i].visibility = 'hidden';
			}
		} 
	}
}

function producelinks()
{
	var yahoo_suffixes = {'NASDAQ': '', 'NYSE' : '', 'TSE' : '.to', 'VSE' : '.v', 'OTCBB' : '.ob'};

	var stock  = document.getElementById('produce_stock').value;
	var market = document.getElementById('produce_market').value;
	var link_yahoo = document.getElementById('link_yahoo');
	var link_lf = document.getElementById('link_lesaffaires');

	if (stock && market) {
		link_yahoo.href = "http://finance.yahoo.com/q?s=" + stock + (yahoo_suffixes[market] || '');
		link_lf.href = "http://actions.lesaffaires.com/invest/investSQL/gx_f.symbol_rep?pi_symblist=" + stock;
	} else {
		link_yahoo.href = "http://finance.yahoo.com/";
		link_lf.href = "http://www.lesaffaires.com/";
	}
	document.getElementById('link_yahoo_image').style.display = ""; 
	document.getElementById('link_lesaffaires_image').style.display = ""; 
}

function showMomentums(table_id)
{
	if (tbl = document.getElementById(table_id)) {
		tbl.className = 'shown';
	}
}

function hideMomentums(table_id)
{
	if (tbl = document.getElementById(table_id)) {
		tbl.className = 'hidden';
	}	
}
