function checkBoxCounterLoop(thisForm){

	//alert(thisForm);
	var countChk=0;
	   for(i=0; i<thisForm.elements.length; i++){
		  if(thisForm.elements[i].type == "checkbox"){
			if(thisForm.elements[i].checked == true) {
	          countChk=countChk+1;
	        }
	      }
	   }
	if(countChk == 0) {
		alert("No Funds Selected");
		return false;
	}
} 

function confirmDeleteAdminManagerClient(id) {
	if(confirm("Are you sure you wish to delete this client?")) {
		return true;
	}	
	return false;
}

function eaHandler(id,frmName,mode) {
	//alert(id+","+frmName+","+mode);
	document.getElementById(frmName).action="?pageId="+mode+"&id="+id;
	document.getElementById(frmName).submit();
}

function popFundsFormHandler(id,action) {
	//alert(id+","+action+",");
	document.getElementById(id).action=document.getElementById(id).action+action;
	//alert(document.getElementById(id).action);
	document.getElementById(id).submit();
}

function cvnumber(spage, sfeatures)
{								
	var c_win = window.open(spage,'CV2Number',sfeatures);
	c_win.focus();		
}

//blinker related
//var blink_onoff = true;
//var blinkspeed= 600;
//function blink()
//{
//	if( blink_onoff) {
//        doc('pleaseWait').style.color = '#FF0000';
//	    blink_onoff = false;
//	}
//	else {
//	    doc('pleaseWait').style.color = '#bbbbbb';
//	    blink_onoff = true;
//	}
//}

function blink() {
    doc('pleaseWait').style.display = "block";
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}


function doc(id)
{
	var ie	= (document.all);
	var ns4	= document.layers ? true : false;
	var dom	= document.getElementById && !document.all ? true : false;

	if (dom)
		return document.getElementById(id);
	else if (ie)
		return document.all[id];
	else if (ns4)
		return document.layers[id];
}


function FundSelection(id)
{
    var d = doc(id);
    var max = parseInt(doc("MaxFunds").value);
    var count = doc("SelectedFunds");
    var i = count.value;
    
    if (d.checked) {
        if (i<max) {
            d.checked = true;
            i++;
        }
        else {
            alert("You have already selected "+max+" funds.");
            d.checked = false;
        }
    }
    else {
        i--;
    }
    count.value = i;
}


function SubmitForm(invType)
{
    var SelectedFunds = parseInt(doc("SelectedFunds").value);
    var url = "fundbasket.aspx?FT="+invType+"&InitialInvestment=&addFund=";
    var funds = "";
    var selectedCount = 0;
    var form = doc("investForm");
    
    for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].checked == true) {
		    var mex = form.elements[i].value;
		    funds = funds += mex + ",";
		    selectedCount += 1
        }
    }
    
    funds = funds.slice(0,-1);
    
    if (selectedCount!=0) {
        url += funds;
        investForm.action = url;
        investForm.submit();
    }
    else {
        alert("Please select one or more funds to add to your basket");
    }
}


/*var menu = document.getElementById("nav-ul").getElementsByTagName("a");
//creates an array out of each "a" element
for(var i=0; i<menu.length; i++) {
    if(menu[i].href == "http://"+window.location.hostname+window.location.pathname) {
    // comparing each href vs this allows for query and hash variables
        menu[i].className="active";
   // add class of "active" if there is a match
    }
}*/

function emptyBasket() {
	if(!confirm("This will empty any current selections, proceed?")) {
		return false;
	}	
}



//---------------------------------------------------------------------------------------------------------------------------------------------
// INTERACTIVE QUESTIONNAIRE JS
//---------------------------------------------------------------------------------------------------------------------------------------------
function doc(id)
{
	var ie	= (document.all);
	var ns4	= document.layers ? true : false;
	var dom	= document.getElementById && !document.all ? true : false;

	if (dom)
		return document.getElementById(id);
	else if (ie)
		return document.all[id];
	else if(ns4)
		return document.layers[id];
}


function errorHandling(control, message)
{
    doc(control).innerHTML = message;
    doc(control).style.display = 'block';
}


function checkValues(thisForm)
{

	var count = 0;
    var errStr = 'Please make sure all fields have been completed.';
    var valid = false;
    
    // count the number of hidden form items have no value    
	for (var i=0; i<doc(thisForm).elements.length; i++) {
		if (doc(thisForm).elements[i].type == "hidden" && doc(thisForm).elements[i].value == '')
	        count++;
	}
    
    if (count>0)
        errorHandling('err_form',errStr);
    else
        valid = true;
     
    return valid;
}


function attitudeCalc(value, weight, position)
{
    // apply weighting
    var item = doc('h_' + position);
    item.value = weight;
    
    var c = doc('count_1'),
    t = doc('total_1');
    
    value = 0;
    for (var i=1; i<=parseInt(c.value); i++) {
        // if value is empty then display an asterisk
        if (doc('h_' + i).value == '' || doc('h_' + i).value == null)
            value += 0;
        else
            value += parseInt(doc('h_' + i).value);
    }
    
    t.value = value;
}