﻿function textCounter(txtField, lblField, MaxAllowedCharacters) 
{
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb. of characters.
*/ 
if (document.getElementById(txtField).value.length > MaxAllowedCharacters) // if the current length is more than allowed
{
        document.getElementById(txtField).value =document.getElementById(txtField).value.substring(0, MaxAllowedCharacters); // don't allow further input
        document.getElementById(lblField).innerHTML=   
                    '0 allowed characters';    
}
else
{
document.getElementById(lblField).innerHTML=   
            (MaxAllowedCharacters - document.getElementById(txtField).value.length) + ' allowed characters'; 
} // set the display field to remaining number

}  

/* Report a scam form rptscam.aspx */
	function aboutThem(){
		var doc = window.open(null, null,"width=640,height=160,resizable=yes,top=200,left=200").document;
		doc.write('<html><head>');
		doc.write('<title>What do you know about them?</title>');
		doc.write('<link rel="stylesheet" href="/style/structure.css" type="text/css" media="screen">');
		doc.write('<link rel="stylesheet" href="/style/style.css" type="text/css" media="screen">');
		doc.write('</head>');
		doc.write('<body><div id="main">');
		doc.write('For example:');
		doc.write('<div style="width:100%;"');
		doc.write('<ul><li>Where do they work?</li>');
		doc.write('<li>Are the affiliated with a group?</li>');
		doc.write('<li>What is their age, phone number, address, or spouse\'s name?</li>');
		doc.write('</ul></div></div></body></html>');
	}
	
	function addMoreThem(){	// id=btnAdd1
		var allWhos = document.getElementsByName('txtWho');
		var rowCount = document.getElementById('txtRowCount');
		var counter;
		var strInnerHtml = ''
		counter = parseInt(rowCount.value);
		// check if all name fields contain some text
		for (var i=0; i<counter; i++){
			if (isEmpty(allWhos[i].value)){
				alert('Please enter Name or Group in row ' + (i+1) + '.');
				allWhos[i].focus();
				return;
			}
		}
		// increase counter to add new row
		counter += 1;	
		// create new row, add cells and content
		var Table = document.getElementById('tbMain');
		var oTR = document.createElement('TR');
		var oTD1 = document.createElement('TD');

        strInnerHtml += '<table width="100%" border="0" cellpadding="0" cellspacing="2">';
        strInnerHtml += '<tr><td valign="top" width="30%">Name/Group</td><td valign="top"><input id="txtWho' + counter + '" name="txtWho" type="text" class="form-text text-full-width" onkeydown="textCounter(\'txtWho'+ counter +'\', \'lblWho'+ counter +'\', 200); " onkeyup="textCounter(\'txtWho'+ counter +'\', \'lblWho'+ counter +'\', 200); " /><br /><div id="lblWho'+ counter +'">200 characters still available.</div><br /></td></tr>';
       strInnerHtml += '<tr> <td valign="top" width="30%">What do you know about them?</td><td valign="top"><textarea class="form-textarea text-full-width" id="txtExpandedWhat' + counter + '" name="txtExpandedWhat" rows="5" cols="50" onkeydown="textCounter(\'txtExpandedWhat' + counter +'\', \'lblWhat'+ counter +'\', 2000); " onkeyup="textCounter(\'txtExpandedWhat'+ counter +'\', \'lblWhat'+ counter +'\', 2000); "></textarea><br /><div id="lblWhat'+ counter +'">2000 characters still available.</div><br /></td></tr>';
        
        strInnerHtml += '</table>';
        
        oTD1.innerHTML = strInnerHtml;

		
		oTR.appendChild(oTD1);
		Table.appendChild(oTR);
		// store the number of rows displayed
		rowCount.value = counter;
	}
	
	function expandTheWhat(Row){
		var TheWhat = document.getElementById('txtWhat'+Row);
		var TheExpandedWhat = document.getElementById('txtExpandedWhat'+Row);
		var ExpandButton = document.getElementById('btnExpand'+Row);
		var State = (TheWhat.style.display == 'none' ? 0 : 1);
		// if textarea is hidden display it and hide textbox
		if (State == 1) {
			TheWhat.style.display = 'none';			
			TheExpandedWhat.style.display = '';
			TheExpandedWhat.value = TheWhat.value;
			ExpandButton.innerHTML = '-';
		}
		else{
			TheWhat.style.display = '';			
			TheExpandedWhat.style.display = 'none';	
			TheWhat.value = TheExpandedWhat.value.replace(/\n/g, ' ');
			ExpandButton.innerHTML = '+';
		}
	}

	function syncWhat(TextBox, Row){
		var TheWhat = document.getElementById('txtWhat'+Row);
		var TheExpandedWhat = document.getElementById('txtExpandedWhat'+Row);
		
		if (TextBox == TheWhat) {
			TheExpandedWhat.value = TextBox.value;
		}
		else {
			TheWhat.value = TextBox.value;
		}
	}
	

	
	function openLegalPage(){
		window.open('content.aspx?id=116', null,"width=750,height=600,resizable=no,top=100,left=20,scrollbars=yes")
	}
	
/* end of Report a scam form rptscam.aspx */

// all pages

//===================JavaScript function=====================================================		
function isEmpty(strInput)
{
    if (strInput == null || strInput == "") {
        return true;
    }
    return false;
}
//===================JavaScript function=====================================================		
function isInteger(strInput)
{
    var i;
    var OneChar;
    
    for (i = 0; i < strInput.length; i++) {
        OneChar = strInput.charAt(i)
        if (OneChar < "0" || OneChar > "9") {
            return false;
        }
    }
    return true;
}
//===================JavaScript function=====================================================		
function isNumber(strInput)
{
    var i;
    var OneChar;
    var CharsAllowed = "0123456789.,"
    var NumDecimal;
    NumDecimal = 0;
    for (i = 0; i < strInput.length; i++) {
        OneChar = strInput.charAt(i)
        if (OneChar == "."){
			NumDecimal = NumDecimal + 1
        }
        if (inString(CharsAllowed,OneChar) == false) {
            return false;
        }
    }
    if (NumDecimal > 1){
		return false;
		}
    return true;
}
//===================JavaScript function=====================================================		
function checkPhone(strInput){
    var i;
    var OneChar;
    var CharsAllowed = "0123456789-()"
    for (i = 0; i < strInput.length; i++) {
        OneChar = strInput.charAt(i)
        if (inString(CharsAllowed,OneChar) == false) {
            return false;
        }
    }
    return true;
}
//===================JavaScript function=====================================================		
function checkPhoneFreeText(strInput){
    var i;
    var OneChar;
    var CharsAllowed = "0123456789-() "
    for (i = 0; i < strInput.length; i++) {
        OneChar = strInput.charAt(i)
        if (inString(CharsAllowed,OneChar) == false) {
            return false;
        }
    }
    return true;
}
//===================JavaScript function=====================================================		
function checkEmail(m){
    var Email;
    
    Email=m.value;

    if (Email.indexOf('@')==-1)
    {
        alert ("Please enter your e-mail address!");
        return false;
    }    

    if (Email.indexOf('.')==-1)
    {
        alert ("Please enter your e-mail address!");
        return false;
    }    

    return true;
}

//===================JavaScript function=====================================================		
function Trim(orgString){
    return LTrim(RTrim(orgString))
}

//===================JavaScript function=====================================================		
function LTrim(orgString){
    return orgString.replace(/^\s+/,'')
}


//===================JavaScript function=====================================================		
function RTrim(orgString){
    return orgString.replace(/\s+$/,'')
}


//===================JavaScript function=====================================================		
function inString(String1, String2){
//returns true if String2 is found in String1
    var myString=new String(String1);
    if (myString.indexOf(String2)!=-1)
        return true;
    return false;
}

//===================JavaScript function=====================================================		
function inStrCount(str1, str2){
//returns number of occurrences of str2 in str1
	var Count = 0;
	var Posit = 0;

	while (Posit != -1){
		Posit = str1.indexOf(str2, Posit);
		if (Posit == -1) break;
		Count += 1;
		Posit += str2.length;
	}
	return Count;
}
//===================JavaScript function=====================================================		
function formatPhoneNumber(PhoneBox){
// phone box is an HTML (text box) that holds phone number
	var PhoneNo = PhoneBox.value;
	var PhoneLen = PhoneNo.length;
	var AreaCode;
	var Phone1, Phone2;
			
	PhoneNo = PhoneNo.replace('(', '');
	PhoneNo = PhoneNo.replace(')', '');
	PhoneNo = PhoneNo.replace('-', '');
	PhoneNo = correctPhoneNumber(PhoneNo);
	AreaCode = PhoneNo.substr(0, 3);

	if(AreaCode.length == 3){
		AreaCode = '(' + AreaCode + ')';
	}
	
	Phone1 = PhoneNo.substr(3, 3);
	
	if (Phone1.length == 3){
		Phone1 += '-';
	}
	
	Phone2 = PhoneNo.substr(6, 4);
	PhoneNo = AreaCode + Phone1 + Phone2;

	PhoneBox.value = PhoneNo;
}
//===================JavaScript function=====================================================		
function correctPhoneNumber(PhoneNumber){
	var Allowed = '0123456789';
	var CorrectNo;

	for(var i = 0; i < PhoneNumber.length; i++){
		if(Allowed.indexOf(PhoneNumber.substr(i, 1)) == -1){
			CorrectNo = PhoneNumber.substr(0, i);
			
			if (CorrectNo.length == 0){
				CorrectNo = '';
			}
			
			return CorrectNo;
		}
	}
			
	return PhoneNumber;
}			
//===================JavaScript function=====================================================		
function checkSpecChr(InputString)
{
	var Result = true;
	var NotAllowed = '<>';
	
	for (var i=0; i<InputString.length; i++)
	{
		if (NotAllowed.indexOf(InputString.charAt(i)) != -1)
		{
			Result = false;
			break;
		}
	}
	// if Result is true, no special characters found			
	return Result;
}

//===================JavaScript function=====================================================		
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum){
		limitField.value = limitField.value.substring(0, limitNum);
	}
}
//===================JavaScript function=====================================================		


