
function CheckPasswordFormat(source, arguments){
	
   var password = document.all.PinTextBox.value;
   var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var validNumbers = "0123456789";
   var validAll = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
   var isValid = false;
   var hasChars = false;
   var hasNumbers = false;
   var hasAllValid = false;
   var char;

   for (i = 0; i < password.length; i++){ 
      
      char = password.charAt(i); 
      if (validChars.indexOf(char) != -1) 
      {
				hasChars = true;
      }
    }

   for (i = 0; i < password.length; i++){ 
      
      char = password.charAt(i); 
      if (validNumbers.indexOf(char) != -1) 
      {
				hasNumbers = true;
      }
    }
    
    for (i = 0; i < password.length; i++){ 
      
      char = password.charAt(i); 
      if (validAll.indexOf(char) != -1) 
      {
				hasAllValid = true;
      }
      else
      {
				hasAllValid = false;
      }
    }

   if (hasChars && hasNumbers && hasAllValid && password.length >= 8 && password.length <= 12)
   {
		isValid = true;
   }
    arguments.IsValid = isValid;

}

function showHideDIV(divName)
{
	el = document.getElementById(divName);
	if (el.style.display == 'none')
	{
		document.getElementById(divName).style.display = 'block';
	}
	else {
		document.getElementById(divName).style.display = 'none';
	}
}

/// <summary>
/// Opens the reports in a new window
/// Valentin Gosetto
/// </summary>
function OpenWindonReport(page){
	window.open(page, 'window', 'width=850, height=650, menubar=no, resizable=no, scrollbars=yes');
}


/// <summary>
/// Sends to the printer the page
/// Valentin Gosetto
/// </summary>
function PrintWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

/// <summary>
/// Used in all pages
/// Disables the Enter key.
/// Valentin Gosetto - 23.Jan.2006
/// </summary>
function CheckKey()
{
	var pagePath = window.location.pathname;
	var pageName = pagePath.substring(pagePath.lastIndexOf('/') + 1);
	if (pageName != 'Login.aspx')
	{
		if (window.event.keyCode == 13)
			window.event.keyCode = null;
	}
}

function showDetails(action)
{
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "link";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}
		
	linkText = document.getElementById(action);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
	////
	link = action + "lineup";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}
		
	linkText = document.getElementById(link);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
	////
	link = action + "linedown";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}
		
	linkText = document.getElementById(link);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
}

function showSubDetails(action)
{
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "sublink";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}

	linkText = document.getElementById(action);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
	///
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "linedown";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}

	linkText = document.getElementById(link);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
	
	///
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "lineup";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}

	linkText = document.getElementById(link);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
}

function showDetailsLeftMenu(action)
{
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = "DistributorInfoBar1_" + action + "linkLeft";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	linkText = document.getElementById("DistributorInfoBar1_" + action);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}

}

/// <summary>
/// Used in Contact.aspx
/// If Yes, the field Distributor can not be empty
/// Valentin Gosetto - 27.Jan.2006
/// </summary>
function CheckMember(source, arguments)
{
	if (document.all.MemberYesRadioButton.checked==true){
		if (document.all.DistributorTextBox.value == ''){
			arguments.IsValid = false;
			return;
		}
	}
	arguments.IsValid = true;
	return;
}


/// <summary>
/// Used in Contact.aspx
/// Valentin Gosetto - 27.Jan.2006
/// </summary>
function AcceptTerms(source, arguments)
{
	if (document.all.AcceptCheckBox.checked==false){
		arguments.IsValid = false;
		return;
	}
	arguments.IsValid = true;
	return;
}


/// <summary>
/// Used in BasicEnrollment.ascx
/// Mask for phone numbers, it adds a "-" between the numbers
/// Diana Marín - 09.Feb.2006
/// </summary>
function mask(str,textbox,loc,delim){
var locs = loc.split(',');

for (var i = 0; i <= locs.length; i++){
	for (var k = 0; k <= str.length; k++){
	 if (k == locs[i]){
	  if (str.substring(k, k+1) != delim){
	   if (event.keyCode != 8){ //backspace
	    str = str.substring(0,k) + delim + str.substring(k,str.length);
       }
	  }
	 }
	}
 }
textbox.value = str
}

/// <summary>
/// Used in BasicEnrollment.ascx and UpgradeCOE
/// Hide all the controls of Social Security Number when the country is Canada
/// Diana Marín - 01.Aug.2006
/// </summary>
function hideCanadaSSN( canadaSSNLabel, tableSocialSN) { 
	if( canadaSSNLabel == null ) 
	return; 

	tableSocialSN.style.display = "none";
}


function setLength(id, length){
   window.document.getElementById(id).setAttribute('maxlength', length);
}



function setFocus(control)
{
document.getElementById(control).focus()
}

function SimpleShowDetails(action)
{
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "link";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}
		
	linkText = document.getElementById(action);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
}
function showSubDetails(action)
{
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "sublink";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}

	linkText = document.getElementById(action);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
	///
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "linedown";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}

	linkText = document.getElementById(link);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
	
	///
	var action;
	IE4 = (document.all && !document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE5 = (document.all && document.getElementById) ? true : false;
	NS6 = (!document.all && document.getElementById) ? true : false;
		
	var link;
	link = action + "lineup";
	linkText = document.getElementById(link);
	linkText.firstChild.nodeValue;

	if (linkText.firstChild.nodeValue == "+")
	{
		linkText.firstChild.nodeValue = "- ";
	}
	else if (linkText.firstChild.nodeValue == "- ")
	{
		linkText.firstChild.nodeValue = "+";
	}

	linkText = document.getElementById(link);
	if (IE4) { prefix = document.all(arguments[0]).style; }
	if (NS6 || IE5) { prefix = linkText.style }
	if (NS4){ prefix = document.layers(arguments[0]); }

	if (prefix.display == "block")
	{
		prefix.display = "none";
	}
	else
	{
		prefix.display = "block";
	}
	
}

	function EmptyLabel(labelID)
	{
		document.getElementById(labelID).innerText= '';
	
	}

		function printReport(){
		
			var reportsUrl = document.getElementById("TextBoxReportServerPath").value;
			var reportPath = document.getElementById("TextBoxReportPath").value;
			var reportParameters = document.getElementById("TextBoxReportParameters").value;
			/*RSClientPrint.MarginLeft = 15;
			RSClientPrint.MarginTop = 12.7;
			RSClientPrint.MarginRight = 0;
			RSClientPrint.MarginBottom = 40;*/
			var tempStr = reportParameters;
			reportParameters = tempStr.substr(0, tempStr.indexOf("&rc:zoom=Page Width")) + tempStr.substr(tempStr.indexOf("&rc:zoom=Page Width")+19);
			RSClientPrint.Culture = 1040;
			RSClientPrint.UICulture = 1042;
			RSClientPrint.Print(reportsUrl, reportPath+"_print"+reportParameters, document.title);
		}

	function disableButton(item, message)
	{
		if (message == null){
		message = 'Processing, please wait';
		}
		//parentElement = item.parentNode;
		var messageDiv = document.createElement('div');
		messageDiv.setAttribute('align', 'center');
		messageDiv.setAttribute('innerHTML', message);
		messageDiv.className = "FormTextError";
		item.parentNode.appendChild(messageDiv);
		
		item.disabled = 'DISABLED';
		
	}
	function showLoadingImage(divId){
		document.getElementById(divId).innerHTML ="<IMG src=../images/preLoader.gif>";		
	}
	
	
	
//mask for  phone number

var patron = new Array(3,3,4);
var patronZipUSA = new Array(4);
var patronZipCanada = new Array(3,3);

function mascara(d,sep,pat,nums){
if(d.valant != d.value){
	val = d.value;
	largo = val.length;
	val = val.split(sep);
	val2 = '';
	for(r=0;r<val.length;r++){
		val2 += val[r];	
	}
	if(nums){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g");
				val2 = val2.replace(letra,"");
			}
		}
	}
	val = '';
	val3 = new Array();
	for(s=0; s<pat.length; s++){
		val3[s] = val2.substring(0,pat[s])
		val2 = val2.substr(pat[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q];
		}
		else{
			if(val3[q] != ""){
				val += sep + val3[q];
				}
		}
	}
	d.value = val;
	d.valant = val;
	}
}


function MixMatchValidator(divMixItems,divMixFreeItems,mult,msg) {

var dMixItems = document.getElementById(divMixItems);
var dMixFreeItems = document.getElementById(divMixFreeItems);
var message = document.getElementById(msg);

var sum;
var multiles; 

multiles  = mult;
sum = 0;


var elms = dMixItems.getElementsByTagName("input");

for(var i = 0, maxI = elms.length; i < maxI; ++i) {

var elm = elms[i];
if (elm.type == "text")
{
	if(elm.value != ''){
	sum = sum + parseInt(elm.value);}
}
}
	if( (sum % mult)== 0 )
	{
		var itemfree = sum / mult
		MixMatchDisableFreeitems(divMixFreeItems,false);
		message.innerHTML = "(Choose "+itemfree.toString()+" item(s) Free)";
	}
	else
	{
		MixMatchDisableFreeitems(divMixFreeItems,true);
		message.innerHTML = "(You have to choose a quantity in multiples of "+ mult.toString()+" )"; 
	}
}


function MixMatchDisableFreeitems(divMixFreeItems,bool) 
{

var div =  document.getElementById(divMixFreeItems);

div.enabled = bool;

var elms = div.getElementsByTagName("*");

   for(var i = 0, maxI = elms.length; i < maxI; ++i) 
  {

	var elm = elms[i];
	elm.disabled = bool;
   }
}


/* Created by Abel Martin. It's used to align columns and add zebra style to downline report table*/
function InitializeReport(reportTableID)
{
	AlignData(reportTableID);
	AddCounterAndZebra(reportTableID);
}

function AddCounterAndZebra(tableID)
{
	try{
	var counterTitle = "#";
	var counterIndex = 0;
	var table = document.getElementById(tableID);
    if (table != null)
    {
		
		var trs = table.getElementsByTagName("tr");
		var ths = trs[0].getElementsByTagName("th");
		
		for (i = 0; i < ths.length; i++)
		{
			if (ths[i].innerHTML == counterTitle)
			{
				counterIndex = i;
				break;
			}
		}
		var lastTR = "";
		var temp;
		for (i = 1; i < trs.length; i++)
		{
			var tds = trs[i].getElementsByTagName("td");
			
			if (tds.length >= counterIndex)
			{
				tds[counterIndex].innerHTML = i;
			}
			
			if (trs[i].className != "") //if it's the last recently-opened distributor
			{
				lastTR = trs[i];
			}
			
			HighLightClickedDistributor(trs[i]);
			if (i%2 == 0)
			{
				AddZebraToTr(trs[i]);
			}
		}
		if (lastTR != "")
		{
			
			lastTR.focus();
		}
		div = document.getElementById("waitingDiv");
		div.style.display = "none";
		table.style.display = "";
    }
    }catch(err){alert(err);}
}

var zebraCounter = 0;
function HighLightClickedDistributor(tr)
{
		if ((zebraCounter == 0) && (tr.className != ""))
		{
			tr.previousSibling.className = "lastOpened lastClicked";
			tds2 = tr.previousSibling.getElementsByTagName("td");
			var link = document.createElement("a");
			link.setAttribute("name", "goToLastClicked");
			tds2[0].appendChild(link);
			location.href='#goToLastClicked';
			zebraCounter++;

		}
}
function AddZebraToTr(tr)
{
	if (tr.className == "")
	{
		tr.className = "zebra2";
		return 0;
	}
	else
	{
		tr.className = "zebra2LastOpened";
		return tr.getElementsByTagName("td")[0];		
	}

}    

function AlignData(tableID)
{
	var center = "LV,#,MI,Type,Title,C,Calc Rank,Pd Gen";
	var centerTitles = center.split(",");
	var right = "PQV,PCV,PCV+<br>PrCstV,PCV+<br/>PrCstV,PQV+<br>PrCstV,PQV+<br/>PrCstV,PGQV,PGCV,Rolled UP<br>Group QV,Rolled UP<br/>Group QV,Org QV,Pd Gen,Last<br>Month<br>PGQV,Last<br/>Month<br/>PGQV,Dist ID#";
	var right = "PQV,PCV,PCV,PrCstV,PGQV,PGCV,Rolled UP,Org QV,Pd Gen,Last,Dist ID#";
	var rightTitles = right.split(",");
	
	var rightPositions = new Array();
	var centerPositions = new Array();
	
	var table = document.getElementById(tableID);
    if (table != null)
    {
		var trs = table.getElementsByTagName("tr");
		var ths = trs[0].getElementsByTagName("th");//header (all ths)
		
		for (i = 0; i < ths.length; i++)
		{
			for (j = 0; j < rightTitles.length; j++)
			{
				
				if (ths[i].innerHTML.indexOf(rightTitles[j]) == 0)
				{
					rightPositions.push(i);
				}
				else if (ths[i].innerHTML.indexOf(centerTitles[j]) == 0)
				{
					centerPositions.push(i);
				}
				/*if (ths[i].innerHTML == rightTitles[j])
				{
					rightPositions.push(i);
				}
				else if (ths[i].innerHTML == centerTitles[j])
				{
					centerPositions.push(i);
				}*/

			}
		}
		
		for (i = 0; i < trs.length; i++)
		{
			var tds = trs[i].getElementsByTagName("td");
			
			trs[i].onclick = highLightRow;
			if (tds.length > 0)
			{
				for (j = 0; j < rightPositions.length; j++)
				{
					tds[rightPositions[j]].setAttribute("class", "r");
					tds[rightPositions[j]].setAttribute("className", "r");
				}
				for (j = 0; j < centerPositions.length; j++)
				{
					tds[centerPositions[j]].setAttribute("class", "c");
					tds[centerPositions[j]].setAttribute("className", "c");
				}

			}
		}
    }
}

var table;
var tableOriginal;
function HidePC()
{
try{
	table = document.getElementById("reportTable");
	tableOriginal = table;
	var typeColumnOrder = -1;
	var typeColumnHeader = "Type";
	
	var trs = table.getElementsByTagName("tr");
	var ths = trs[0].getElementsByTagName("th");//header (all ths)
	for (i = 0; i < ths.length; i++)
	{
		if (ths[i].innerHTML == typeColumnHeader)
		{
			typeColumnOrder = i;
			break;
		}
	}
	if (typeColumnOrder == -1)
	{
		alert("Cannot hide PCs from report. Column 'Type' has not been found");
	}
	else
	{
		for (i = trs.length-1; i > 0; i--)
		{	
			var tds = trs[i].getElementsByTagName("td");
			trs[i].removeAttribute("class");
			trs[i].removeAttribute("className");			
			if (tds[typeColumnOrder].innerHTML == "PC")
			{
				table.deleteRow(i);
			}
		}
	}
	InitializeReport("reportTable");
}
catch(err)
{
alert("error: " + err);
}		
	
}

var stylesBuffer = new Array();
function highLightRow()
{
	tr = this;
	if (stylesBuffer[tr.rowIndex] == undefined)
	{
		stylesBuffer[tr.rowIndex] = tr.className;
		tr.className += " selectedReportRow";
	}
	else
	{
		tr.className = stylesBuffer[tr.rowIndex];
		stylesBuffer[tr.rowIndex] = undefined;
	}
}
