function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function formValidation()
{if(document.getElementById('author').value=='')
{alert("You must add your name or alias in the \"name\" field to submit your comment!");document.getElementById('author').style.borderColor='#FF0000';document.getElementById('author').focus();return false;}
if(document.getElementById('callerType').selectedIndex==0)
{alert("A \"Caller Type\" must be Identified!\n\nPlease choose from the dropdown menu!");document.getElementById('callerType').style.borderColor='#FF0000';document.getElementById('author').style.borderColor='#26508C';return false;}
if(document.getElementById('comment').value=='')
{alert("The \"Call Comment\" field must be filled in!\n\nPlease include all your comments!");document.getElementById('comment').style.borderColor='#FF0000';document.getElementById('comment').focus();document.getElementById('callerType').style.borderColor='#26508C';document.getElementById('author').style.borderColor='#26508C';return false;}
if(document.getElementById('captcha_code').value=='')
{alert("The \"Validation Code\" field must be filled in!\n\nMust use all CAPITAL letters!");document.getElementById('captcha_code').style.borderColor='#FF0000';document.getElementById('captcha_code').focus();document.getElementById('callerType').style.borderColor='#26508C';document.getElementById('author').style.borderColor='#26508C';document.getElementById('captcha_code').style.borderColor='#26508C';return false;}
return true;}

function myTempOne()
{
	document.commentform.refresh.value = rand ( 1000 );
	return true;
}

function myTempTwo()
{
	if(document.getElementById('captcha_code').value=='' || document.getElementById('captcha_code').value.length<6 || document.getElementById('captcha_code').value.length>6)
	{alert("The \"Validation Code\" field must be filled in to submit your comment!");document.getElementById('captcha_code').style.borderColor='#FF0000';document.getElementById('captcha_code').focus();document.getElementById('captcha_code').select();document.getElementById('callerType').style.borderColor='#26508C';document.getElementById('author').style.borderColor='#26508C';return false;}
	
	document.commentform.refresh.value = rand ( 1000 );
	return true;
}

function newCommentFormValidationOne()
{if(document.getElementById('author').value=='')
{alert("You must add your name or alias in the \"name\" field to submit your comment!");document.getElementById('author').style.borderColor='#FF0000';document.getElementById('author').focus();return false;}
else{
	var count=0;
	var ref=" 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var result=1;
	var chr="";
	var offset=0;
		
	for(count=0;count<document.getElementById('author').value.length;count++)
	{
		chr=document.getElementById('author').value.substring(count,count+1);
			
		if(ref.indexOf(chr)<0)
		{
			result=0;
			offset=count+1;
			count=document.getElementById('author').value.length;
		}
	}
	if(result==0)
	{
		var errorMsg="\"Name\" field contains an invalid charactor '"+chr+"' at offset "+offset+"!\n\nOnly alphanumerical charactors are allowed (letters a-z and number 0-9)!";
		alert(errorMsg);
		document.getElementById('author').style.borderColor='#FF0000';
		document.getElementById('author').focus();
		document.getElementById('author').select();
		return false;
	}
	else
	{
		document.getElementById('author').style.borderColor='#26508C';
	}
}
if(document.getElementById('callerType').selectedIndex==0)
{alert("A \"Caller Type\" must be Identified!\n\nPlease choose from the dropdown menu!");document.getElementById('callerType').style.borderColor='#FF0000';document.getElementById('author').style.borderColor='#26508C';return false;}
if(document.getElementById('comment').value=='')
{alert("The \"Call Comment\" field must be filled in!\n\nPlease include all your comments!");document.getElementById('comment').style.borderColor='#FF0000';document.getElementById('comment').focus();document.getElementById('callerType').style.borderColor='#26508C';document.getElementById('author').style.borderColor='#26508C';return false;}
else{
	var count=0;
	var ref=" .,!?0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var result=1;
	var chr="";
	var offset=0;
		
	for(count=0;count<document.getElementById('comment').value.length;count++)
	{
		chr=document.getElementById('comment').value.substring(count,count+1);
			
		if(ref.indexOf(chr)<0)
		{
			result=0;
			offset=count+1;
			count=document.getElementById('comment').value.length;
		}
	}
	if(result==0)
	{
		var errorMsg="\"Comment\" field contains an invalid charactor '"+chr+"' at offset "+offset+"!\n\nOnly alphanumerical charactors (letters a-z and number 0-9) and punctuation charactors (. , ! ?) are allowed!";
		alert(errorMsg);
		document.getElementById('comment').style.borderColor='#FF0000';
		document.getElementById('comment').focus();
		document.getElementById('comment').select();
		return false;
	}
	else
	{
		document.getElementById('comment').style.borderColor='#26508C';
	}
}
if(document.getElementById('captcha_code').value=='' || document.getElementById('captcha_code').value.length<6 || document.getElementById('captcha_code').value.length>6)
{alert("The \"Validation Code\" field must be filled in to submit your comment!");document.getElementById('captcha_code').style.borderColor='#FF0000';document.getElementById('captcha_code').focus();document.getElementById('captcha_code').select();document.getElementById('callerType').style.borderColor='#26508C';document.getElementById('author').style.borderColor='#26508C';return false;}
document.commentform.refresh.value = rand ( 1000 );
return true;}

function newCommentFormValidationTwo()
{if(document.getElementById('author').value=='')
{alert("You must add your name or alias in the \"name\" field to submit your comment!");document.getElementById('author').style.borderColor='#FF0000';document.getElementById('author').focus();return false;}
else{
	var count=0;
	var ref=" 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var result=1;
	var chr="";
	var offset=0;
		
	for(count=0;count<document.getElementById('author').value.length;count++)
	{
		chr=document.getElementById('author').value.substring(count,count+1);
			
		if(ref.indexOf(chr)<0)
		{
			result=0;
			offset=count+1;
			count=document.getElementById('author').value.length;
		}
	}
	if(result==0)
	{
		var errorMsg="\"Name\" field contains an invalid charactor '"+chr+"' at offset "+offset+"!\n\nOnly alphanumerical charactors are allowed (letters a-z and number 0-9)!";
		alert(errorMsg);
		document.getElementById('author').style.borderColor='#FF0000';
		document.getElementById('author').focus();
		document.getElementById('author').select();
		return false;
	}
	else
	{
		document.getElementById('author').style.borderColor='#26508C';
	}
}
if(document.getElementById('callerType').selectedIndex==0)
{alert("A \"Caller Type\" must be Identified!\n\nPlease choose from the dropdown menu!");document.getElementById('callerType').style.borderColor='#FF0000';document.getElementById('author').style.borderColor='#26508C';return false;}
if(document.getElementById('comment').value=='')
{alert("The \"Call Comment\" field must be filled in!\n\nPlease include all your comments!");document.getElementById('comment').style.borderColor='#FF0000';document.getElementById('comment').focus();document.getElementById('callerType').style.borderColor='#26508C';document.getElementById('author').style.borderColor='#26508C';return false;}
else{
	var count=0;
	var ref=" .,!?0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var result=1;
	var chr="";
	var offset=0;
		
	for(count=0;count<document.getElementById('comment').value.length;count++)
	{
		chr=document.getElementById('comment').value.substring(count,count+1);
			
		if(ref.indexOf(chr)<0)
		{
			result=0;
			offset=count+1;
			count=document.getElementById('comment').value.length;
		}
	}
	if(result==0)
	{
		var errorMsg="\"Comment\" field contains an invalid charactor '"+chr+"' at offset "+offset+"!\n\nOnly alphanumerical charactors (letters a-z and number 0-9) and punctuation charactors (. , ! ?) are allowed!";
		alert(errorMsg);
		document.getElementById('comment').style.borderColor='#FF0000';
		document.getElementById('comment').focus();
		document.getElementById('comment').select();
		return false;
	}
	else
	{
		document.getElementById('comment').style.borderColor='#26508C';
	}
}
document.commentform.refresh.value = rand ( 1000 );
return true;}

function searchTop(number)
{	
	if(number.length==0)
	{
		alert("Type in a phone number and press enter!");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else if(number.length<13)
	{
		alert("A Valid US Phone Number must contain 10 digits!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else if(number.length>13)
	{
		alert("A Valid US Phone Number CANNOT exceed 10 digits in Length!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else
	{
		ref="()-0123456789";
		result=1;
		
		for(count=0;count < number.length; count++)
		{
			chr=number.substring(count,count+1);
			
			if(ref.indexOf(chr)<0)
			{
				result=0;
				offset=count+1;
				count=number.length;
			}
		}
		if(result==0)
		{
			var errorMsg="Search Field contains an invalid charactor at offset "+offset+"!\n\nOnly NUMERICAL CHARACTORS 0 - 9 are allowed!";
			alert(errorMsg);
			document.searchformtop.s.style.borderColor='#FF0000';
			document.searchformtop.s.style.border.width='15';
			document.searchformtop.s.value='';
			document.searchformtop.s.focus();
			return false;
		}
		else
		{
			document.searchformtop.s.style.borderColor='#000000';
			document.searchformtop.s.style.border.width='0';
		}
	}
	return true;
}

function findPhoneVerify(number)
{	
	if(number.length==0)
	{
		alert("Type in a phone number and press enter!");
		document.searchfindphone.findphone.style.borderColor='#FF0000';
		document.searchfindphone.findphone.style.border.width='15';
		document.searchfindphone.findphone.value="";
		document.searchfindphone.findphone.focus();
		return false;
	}
	else if(number.length<13)
	{
		alert("A Valid US Phone Number must contain 10 digits!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchfindphone.findphone.style.borderColor='#FF0000';
		document.searchfindphone.findphone.style.border.width='15';
		document.searchfindphone.findphone.value="";
		document.searchfindphone.findphone.focus();
		return false;
	}
	else if(number.length>13)
	{
		alert("A Valid US Phone Number CANNOT exceed 10 digits in Length!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchfindphone.findphone.style.borderColor='#FF0000';
		document.searchfindphone.findphone.style.border.width='15';
		document.searchfindphone.findphone.value="";
		document.searchfindphone.findphone.focus();
		return false;
	}
	else
	{
		ref="()-0123456789";
		result=1;
		
		for(count=0;count < number.length; count++)
		{
			chr=number.substring(count,count+1);
			
			if(ref.indexOf(chr)<0)
			{
				result=0;
				offset=count+1;
				count=number.length;
			}
		}
		if(result==0)
		{
			var errorMsg="Search Field contains an invalid charactor at offset "+offset+"!\n\nOnly NUMERICAL CHARACTORS 0 - 9 are allowed!";
			alert(errorMsg);
			document.searchfindphone.findphone.style.borderColor='#FF0000';
			document.searchfindphone.findphone.style.border.width='15';
			document.searchfindphone.findphone.value='';
			document.searchfindphone.findphone.focus();
			return false;
		}
		else
		{
			document.searchfindphone.findphone.style.borderColor='#000000';
			document.searchfindphone.findphone.style.border.width='0';
		}
	}
	//document.searchformtop.refresh.value = "send";
	document.searchfindphone.refresh.value = rand ( 1000 );
	return true;
}

function searchBottom(number)
{	
	var returnValue = true;
	
	if( number.length == 0 )
	{
		alert("Type in a phone number and press enter!");
		document.searchformbottom.s.style.borderColor='#FF0000';
		document.searchformbottom.s.style.border.width='15';
		document.searchformbottom.s.value="";
		document.searchformbottom.s.focus();
		returnValue = false;
	}
	else if( number.length < 13 )
	{
		alert("A Valid US Phone Number must contain 10 digits!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchformbottom.s.style.borderColor='#FF0000';
		document.searchformbottom.s.style.border.width='15';
		document.searchformbottom.s.value="";
		document.searchformbottom.s.focus();
		returnValue = false;
	}
	else if( number.length > 13 )
	{
		alert("A Valid US Phone Number CANNOT exceed 10 digits in Length!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchformbottom.s.style.borderColor='#FF0000';
		document.searchformbottom.s.style.border.width='15';
		document.searchformbottom.s.value="";
		document.searchformbottom.s.focus();
		returnValue = false;
	}
	return returnValue;
}

function searchareacodeBottom(number)
{	
	var returnValue = true;
	
	if( number.length == 0 )
	{
		alert("Type in a phone number and press enter!");
		document.searchformbottom.z.style.borderColor='#FF0000';
		document.searchformbottom.z.style.border.width='15';
		document.searchformbottom.z.value="";
		document.searchformbottom.z.focus();
		returnValue = false;
	}
	else if( number.length < 13 )
	{
		alert("A Valid US Phone Number must contain 10 digits!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchformbottom.z.style.borderColor='#FF0000';
		document.searchformbottom.z.style.border.width='15';
		document.searchformbottom.z.value="";
		document.searchformbottom.z.focus();
		returnValue = false;
	}
	else if( number.length > 13 )
	{
		alert("A Valid US Phone Number CANNOT exceed 10 digits in Length!\n\nPlease Enter a 10 digit Valid Phone Number!\n\nInternational Number Formats Coming soon to Called.com");
		document.searchformbottom.z.style.borderColor='#FF0000';
		document.searchformbottom.z.style.border.width='15';
		document.searchformbottom.z.value="";
		document.searchformbottom.z.focus();
		returnValue = false;
	}
	return returnValue;
}

function validate()
{var errorMsg="";if((document.mailform.fromemail.value==null)||(document.mailform.fromemail.value==""))
{errorMsg="Email Address Field Must be Filled In!\n\n";document.mailform.fromemail.focus();}
else if(echeck(document.mailform.fromemail.value)==false)
{document.mailform.fromemail.value=""
document.mailform.fromemail.focus();errorMsg+="INVALID Email address FORMAT!\n\n";}
if(document.mailform.firstname.value=="")
{errorMsg+="First Name Field Must be Filled In!\n\n";}
if(document.mailform.message.value=="")
{errorMsg+="You Must Enter Information Into the Body of the Email!\n\n";}
if(errorMsg!="")
{alert(errorMsg);return false;}}
function echeck(str)
{var at="@";var dot=".";var lat=str.indexOf(at);var lstr=str.length-1;var ldot=str.indexOf(dot);if(str.indexOf(at)==-1)
{return false;}
if(str.indexOf(at)==-1||str.indexOf(at)==0||str.indexOf(at)==lstr)
{return false;}
if(str.indexOf(dot)==-1||str.indexOf(dot)==0||str.indexOf(dot)==lstr)
{return false;}
if(str.indexOf(at,(lat+1))!=-1){return false;}
if(str.substring(lat-1,lat)==dot||str.substring(lat+1,lat+2)==dot)
{return false;}
if(str.indexOf(dot,(lat+2))==-1)
{return false;}
if(str.indexOf(" ")!=-1)
{return false;}
return true;}

function validateSMS()
{
	var errorMsg="";

	if((document.mailform.fromemail.value==null)||(document.mailform.fromemail.value==""))
	{
		errorMsg="Email Address Field Must be Filled In!\n\n";
		document.mailform.fromemail.focus();
	}
	else if(echeck(document.mailform.fromemail.value)==false)
	{
		document.mailform.fromemail.value=""
		document.mailform.fromemail.focus();
		errorMsg+="INVALID Email address FORMAT!\n\n";
	}

	if(document.mailform.toEmail.value=="")
	{
		errorMsg+="SMS Email Address Field Must be Filled In!\n\n";
	}

	if(document.mailform.subject.value=="")
	{
		if ( errorMsg == "" )
		{
			document.mailform.subject.focus();	
		}

		errorMsg+="Subject Field Must be Filled In!\n\n";
	}

	if(document.mailform.firstname.value=="")
	{
		if ( errorMsg == "" )
		{
			document.mailform.firstname.focus();	
		}
		errorMsg+="First Name Field Must be Filled In!\n\n";
	}

	if(document.mailform.lastname.value=="")
	{
		if ( errorMsg == "" )
		{
			document.mailform.lastname.focus();	
		}

		errorMsg+="Last Name Field Must be Filled In!\n\n";
	}

	if(document.mailform.areacode.value=="")
	{
		errorMsg+="Area Code Field Must be Filled In!\n\n";
	}

	if(document.mailform.exchange.value=="")
	{
		errorMsg+="Exchange Field Must be Filled In!\n\n";
	}

	if(document.mailform.lastfour.value=="")
	{
		errorMsg+="Last Four Field Must be Filled In!\n\n";
	}

	if(document.mailform.message.value=="")
	{
		if ( errorMsg == "" )
		{
			document.mailform.message.focus();	
		}

		errorMsg+="Cannot send an empty/blank SMS text message! Enter SMS text message to send\n\n";
	}
	
	if(errorMsg!="")
	{
		alert(errorMsg);
		return false;
	}	
}

function getScreenWidth() {
	var result = 2000;

	if (window.innerWidth) {
		// all except Explorer
		result = parseInt(window.innerWidth);
	} else if (document.documentElement && document.documentElement.clientWidth) {
		// Explorer 6 Strict Mode
		result = parseInt(document.documentElement.clientWidth);
	} else if (document.body) {
		// other Explorers
		result = parseInt(document.body.clientWidth);
	}
	if (isNaN(result)) {
		result = 2000;
	}
	return result;
}

function getScreenHeight() {
	var result = 2000;

	if (window.innerHeight) {
		// all except Explorer
		result = parseInt(window.innerHeight);
	} else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
		result = parseInt(document.documentElement.clientHeight);
	} else if (document.body) {
		// other Explorers
		result = parseInt(document.body.clientHeight);
	}
	if (isNaN(result)) {
		result = 2000;
	}
	return result;
}

function getScreenOffsetX() {
	var result = 2000;

	if (window.pageXOffset) {
		// all except Explorer
		result = parseInt(window.pageXOffset);
	} else if (document.documentElement && document.documentElement.scrollLeft) {
		// Explorer 6 Strict Mode
		result = parseInt(document.documentElement.scrollLeft);
	} else if (document.body) {
		// other Explorers
		result = parseInt(document.body.scrollLeft);
	}
	if (isNaN(result)) {
		result = 2000;
	}
	return result;
}

function getScreenOffsetY() {
	var result = 2000;

	if (window.innerHeight) {
		// all except Explorer
		result = parseInt(window.pageYOffset);
	} else if (document.documentElement && document.documentElement.scrollTop) {
		// Explorer 6 Strict Mode
		result = parseInt(document.documentElement.scrollTop);
	} else if (document.body) {
		// other Explorers
		result = parseInt(document.body.scrollTop);
	}
	if (isNaN(result)) {
		result = 2000;
	}
	return result;
}

function TogglePreloader(fl) {	
	var x,y;
	x = getScreenWidth();
	y = getScreenHeight();
	var table=document.getElementById('preloader_table');
	var td=document.getElementById('preloader_td');
	var el=document.getElementById('div_desktop');
	
	if(null!=el) {
		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.width = x + "px";
		el.style.height = y + "px";
		el.style.zIndex = 1;
	}

	var el=document.getElementById('loader');
	if(null!=el) 
	{
		var top = (y/2) - 50;
		var left = (x/2) - 200;
		if( left<=0 ) left = 10;
		td.style.width = (getScreenWidth() + getScreenOffsetX()) + "px";
		td.style.height = (getScreenHeight() + getScreenOffsetY()) + "px";
		top += getScreenOffsetY();
		left += getScreenOffsetX(); 
		table.style.display=(fl==1)?'block':'none';
		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.left = left + "px"
		el.style.top = top + "px";
	}
}

function ShowTogglePreloaderDelayed(delay) {
	setTimeout("TogglePreloader(1)", delay);
}

function HideTogglePreloaderDelayed(delay) {
	setTimeout("TogglePreloader(0)", delay);
}


<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object)
{
	phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object)
{
	phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) 
{
	var keycode;

	if(e)
	{
		e = e
	} 
	else
	{
		e = window.event
	}
	if(e.which)
	{
		keycode = e.which
	} 
	else
	{
		keycode = e.keyCode
	}

	ParseForNumber1(object)

	if(keycode >= 48)
	{
		ValidatePhone(object)
	}
}

function backspacerDOWN(object,e) {
if(e){
e = e
} else {
e = window.event
}
if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}
ParseForNumber2(object)
}

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i < t1.length; i++)
{
if (t1.substring(i,1) != t2.substring(i,1)) {
if(!bool) {
cursorposition=i
bool=true
}
}
}
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
object.value=p
} else if(p.length==3){
pp=p;
d4=p.indexOf('(')
d5=p.indexOf(')')
if(d4==-1){
pp="("+pp;
}
if(d5==-1){
pp=pp+")";
}
object.value = pp;
} else if(p.length>3 && p.length < 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

object.value = pp;

} else if(p.length >= 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

l40 = pp.length;
p40 = pp.substring(0,8);
p40 = p40 + "-"

p41 = pp.substring(8,l40);
ppp = p40 + p41;

object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
	if (sChar.length == null)
	{
		zChar = new Array(sChar);
	}
	else 
	{
		zChar = sChar;
	}

	for (i=0; i<zChar.length; i++)
	{
		sNewStr = "";

		var iStart = 0;
		var iEnd = sStr.indexOf(sChar[i]);

		while (iEnd != -1)
		{
			sNewStr += sStr.substring(iStart, iEnd);
			iStart = iEnd + 1;
			iEnd = sStr.indexOf(sChar[i], iStart);
		}
		sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

		sStr = sNewStr;
	}
	return sNewStr;
}

function moveOnMax(field,nextFieldID)
{
  if(field.value.length >= field.maxLength)
  {
    document.getElementById(nextFieldID).focus();
  }
}

function initialize( lat_switch, long_switch, lat_city, long_city, city, state, company, fullnumber, formatNumber, isUsersLocation ) 
{	  
	//alert(fullnumber);
	
	if ( fullnumber == '(602)405-9540' )
	{
		alert( "Got Here!" );
	}
	
	if ( company == '' )
	{
	   company = 'Unknown';
  	}

	var geocoder;
	var mainLatLong;

  	if ( lat_switch != 0 && long_switch != 0 )
	{
		mainLatLong = new google.maps.LatLng(lat_switch, long_switch);
	}
	else if ( lat_city != 0 && long_city != 0 )
	{
		mainLatLong = new google.maps.LatLng(lat_city, long_city);	
	}

	var myOptions = { zoom: 12,center: mainLatLong,mapTypeId: google.maps.MapTypeId.ROADMAP };
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var tempSwitch = '';
	var switchContentString = '';

	if ( isUsersLocation )
	{
		switchContentString = tempSwitch.concat('<div id="gmap_tag_switch"><b>-- Your Approximate Loaction is -- </b><br /><b>Latitude: </b>',lat_switch,', <b>Longitude: </b>',long_switch,'<br /><b>Your Name & Address: </b>Coming Soon to <a href="http://www.called.com">Called.com</a><br /><b>Address: </b>place.address</div>');	
	}
	else
	{
		if ( city == '' && state == '' )
		{
  			//switchContentString = tempSwitch.concat('<div id="gmap_tag_switch"><b>Location of switch for: </b>',formatNumber,'<br /><b>Latitude: </b>',lat_switch,', <b>Longitude: </b>',long_switch,'<br /><b>Phone Company: </b>',company,'<br /><b>Owner Information: </b>Coming Soon to <a href="http://www.called.com">Called.com</a><br /></div>');
  			switchContentString = tempSwitch.concat('<div id="gmap_tag_switch"><b>Location of switch for: </b>',formatNumber,'<br /><b>Latitude: </b>',lat_switch,', <b>Longitude: </b>',long_switch,'<br /><b>Owner Information: </b><a href="http://www.intelius.com/redir.php?refer=5038&adword=reverse+phone&qp=[',fullnumber,']" title="Get Detailed Phone Number Info" target="blank" rel="nofollow">On File - Click Here</a><br /></div>');
		}
		else
		{
			//switchContentString = tempSwitch.concat('<div id="gmap_tag_switch"><b>Location of switch for: </b>',formatNumber,'<br /><b>City &amp; State: </b>',city,', ',state,'<br /><b>Latitude: </b>',lat_city,', <b>Longitude: </b>',long_city,'<br /><b>Phone Company: </b>',company,'<br /><b>	Owner Information: </b>Coming Soon to <a href="http://www.called.com">Called.com</a><br /></div>');
			switchContentString = tempSwitch.concat('<div id="gmap_tag_switch"><b>Location of switch for: </b>',formatNumber,'<br /><b>City &amp; State: </b>',city,', ',state,'<br /><b>Latitude: </b>',lat_city,', <b>Longitude: </b>',long_city,'<br /><b>	Owner Information: </b><a href="http://www.intelius.com/redir.php?refer=5038&adword=reverse+phone&qp=[',fullnumber,']" title="Get Detailed Phone Number Info" target="blank" rel="nofollow">On File - Click Here</a><br /></div>');	
		}
	}

	var switchInfowindow = new google.maps.InfoWindow({content: switchContentString});
	var marker_switch = new google.maps.Marker({position: mainLatLong,map: map,title:"Switch Location", icon: "http://www.called.com/images/green-marker-icon.png"});
	switchInfowindow.open(map,marker_switch);
	google.maps.event.addListener(marker_switch, 'click', function() {switchInfowindow.open(map,marker_switch);});
  
  	if ( lat_city != 0 || long_city != 0 )
	{	
		tempCity = '';
		var cityContentString = tempCity.concat('<div id="gmap_tag_city"><b>Location of nearest city for: </b>',fullnumber,'<br /><b>City &amp; State: </b>',city,', ',state,'<br /><b>Latitude: </b>',lat_city,', <b>Longitude: </b>',long_city,'<br /><b>Phone Company: </b>',company,'<br /><b>Owner Information: </b>Coming Soon to <a href="http://www.called.com">Called.com</a><br /></div>');
	
		var cityLatLong = new google.maps.LatLng(lat_city, long_city);
		var cityInfowindow = new google.maps.InfoWindow({content: cityContentString});
		var marker_city = new google.maps.Marker({position: cityLatLong,map: map,title:"City Location", icon: "http://www.called.com/images/blue-marker-icon.png"});
		google.maps.event.addListener(marker_city, 'click', function() {cityInfowindow.open(map,marker_city);});
	}
}

function setLastCommentDateTime(theDate, theTime)
{
	document.getElementById('myDate').innerHTML = theDate;
	document.getElementById('myTime').innerHTML = theTime;
}

function show_help(show_id) 
{
	document.getElementById('why_file_complaint_help').style.display='none';
	document.getElementById('name_nickname_help').style.display='none';
	document.getElementById('caller_type_help').style.display='none';
	document.getElementById('comments_complaint_help').style.display='none';
	document.getElementById('captcha_help').style.display='none';
	document.getElementById(show_id).style.display='block';
}

function searchIP( reference, myevent )
{
	var returnValue = '';
	var number = reference.value;

	if ( myevent != '' && myevent.keyCode == 8 )
	{
		return true;
	}

	if( number.split("..").length > 1 )
	{
		var newNum = number.substr( 0, ( number.length - 1 ) );
		reference.value = newNum;	
		return false;
	}

	var ip_array=number.split(".");
	
	if ( ip_array[0] <= 0 )
	{
		reference.value = '';
		return false;
	}

	if ( number.split(".").length === 4 )
	{	
		var octetFourCount = number.length - number.lastIndexOf( "." ) - 1;

		if ( octetFourCount > 3 )
		{
			var newNum = number.substr( 0, ( number.length - 1 ) );
			reference.value = newNum;
			return false;
		}
	}
 
	for( count = 0; count < ip_array.length; count++ )
	{
		ip_array[count] = parseFloat( ip_array[count] );
 
	  	if ( ip_array[count] == 0 )
	  	{
	  		ip_array[count] = 0;
	  	}
	  	else if ( isNaN( ip_array[count] ) || ip_array[count] == '' )
		{
			ip_array[count] = '';
		}
	  	else if ( ip_array[count] > 255 )
		{
	   		ip_array[count] = 255;
		}
	  	else if ( ip_array[count] <= 0 )
		{
	    		ip_array[count] = 0;
		}
		
	 	returnValue = '' + returnValue + ip_array[count];
 
	  	if ( ( ( count == ( ip_array.length - 1 ) ) && ( ip_array[count] > 99 ) ) || ( count < ip_array.length - 1 ) )
	  	{		
	  		if ( count < 3) 
			{
				returnValue = '' + returnValue + ".";
	      	}
	  	}
	}
	reference.value = returnValue;
}

function searchSubmit( reference, myevent )
{	
	var returnValue = false;
	var myDataArray = reference.value.split(".");
	
	if ( myDataArray.length === 4 )
	{
		var lastOctet = reference.value.substr( ( reference.value.lastIndexOf( "." ) ) );
		
		if ( lastOctet.length > 1 )
		{
			//alert( "IP Address: " + reference.value );
			returnValue = searchIP( reference, myevent );
			if ( returnValue )
			{
				returnValue = submitIPAddress( reference.value );	
			}
		}	
	}
	else if ( ( reference.value.indexOf( "(" ) !== -1 ) && ( reference.value.indexOf( ")" ) !== -1 ) && ( reference.value.indexOf( "-" ) !== -1 ) )
	{
		//alert( "Phone Number: " + reference.value );
		returnValue = searchTop( reference.value );
	}

	if ( returnValue == false )
	{
		alert("A Valid IP Address must be in the format: (www.xxx.yyy.zzz)!\n\nPlease Enter a Valid IP Address!");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();	
	}
	return returnValue;
}

function submitIPAddress( ip )
{	
	if ( ip.split(".").length !== 4 )
	{
		alert("A Valid IP Address must contain at least 7 digits in the format: (X.X.X.X)!\n\nPlease Enter a Valid IP Address!");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else if( ip.length == 0 )
	{
		alert("Type in a IP Address and press enter!");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else if( ip.length < 8 )
	{
		alert("A Valid IP Address must contain at least 7 digits in the format: (X.X.X.X)!\n\nPlease Enter a Valid IP Address!");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else if( ip.length > 16 )
	{
		alert("A Valid IP Address CANNOT exceed 15 digits in Length and must be in the format:(XXX.XXX.XXX.XXX)!\n\nPlease Enter a valid IP Address!");
		document.searchformtop.s.style.borderColor='#FF0000';
		document.searchformtop.s.style.border.width='15';
		document.searchformtop.s.value="";
		document.searchformtop.s.focus();
		return false;
	}
	else
	{
		ref=".0123456789";
		result=1;
		
		for(count=0;count < ip.length;count++)
		{
			chr=ip.substring(count,count+1);
			
			if(ref.indexOf(chr)<0)
			{
				result=0;
				offset=count+1;
				count=ip.length;
			}
		}
		if(result==0)
		{
			var errorMsg="Search Field contains an invalid charactor at offset "+offset+"!\n\nOnly NUMERICAL CHARACTORS \"0 - 9\" and \".\" are allowed!";
			alert(errorMsg);
			document.searchformtop.s.style.borderColor='#FF0000';
			document.searchformtop.s.style.border.width='15';
			document.searchformtop.s.value='';
			document.searchformtop.s.focus();
			return false;
		}
		else
		{
			document.searchformtop.s.style.borderColor='#000000';
			document.searchformtop.s.style.border.width='0';
		}
	}
	return true;
}

function IsNumeric( sText )
{
   	var ValidChars = "0123456789";
   	var IsNumber=true;
   	var Char;

   	for (i = 0; i < sText.length && IsNumber == true; i++) 
   	{ 
      	Char = sText.charAt( i ); 
      	if (ValidChars.indexOf( Char ) == -1) 
      	{
         		IsNumber = false;
      	}
   	}
	return IsNumber;
}

function searchBarProcessing( reference, event )
{
	var number = reference.value;

	if ( number.length > 15 )
	{
		var newNum = number.substr( 0, 15 );
		reference.value = newNum;
		return false;	
	}

	switch( number.length )
	{
		case 1:
  			if ( IsNumeric( number[0] ) == false )
			{
				reference.value = '';
				return false;		
			}
  			break;
		case 2:
			if ( number.indexOf( "." ) != -1 )
			{
				searchIP( reference, event );
			}
			else if ( IsNumeric( number[1] ) == false )
			{
				reference.value = number[0];
				return false;		
			}
			break;
		case 3:
  			if ( number.indexOf( "." ) != -1 )
			{
				searchIP( reference, event );
			}
			else if ( IsNumeric( number[2] ) == false )
			{
				reference.value = number[0] + number[1];
				return false;		
			}
  			break;
		case 4:
			if ( number.indexOf( "." ) != -1 )
			{
				searchIP( reference, event );
			}
			else
			{
				backspacerUP( reference, event );	
			}
  			break;
		default:
			if ( number.indexOf( "(" ) != -1 && number.indexOf( ")" ) != -1 )
			{	
				backspacerUP( reference, event );
			}
			else
			{
				searchIP( reference, event );		
			}
			break;
	}
}

function enforcechar(what,limit)
{
	if ( event.keyCode == 8 )
	{
		if ( what.value.length == 0 )
		{
			document.getElementById('max_chars').style.backgroundColor= '#FFFFFF';
			document.getElementById('max_chars').value = limit;
			return false;
		}
		else
		{
			document.getElementById('max_chars').style.backgroundColor= '#FFFFFF';
			document.getElementById('max_chars').value = ( limit - ( what.value.length - 1 ) );	
			return true;
		}
	}
	else
	{
		if ( what.value.length >= limit )
		{
			document.getElementById('max_chars').value = 0;
			document.getElementById('max_chars').style.backgroundColor= '#FF0000';
			what.value = what.value.substring(0, (limit-1));
			return false;
		}
		else
		{
			document.getElementById('max_chars').style.backgroundColor= '#FFFFFF';
			document.getElementById('max_chars').value = limit - ( what.value.length + 1 );
			return true;
		}
	}
}

function enforcecharKeyup(what,limit)
{
	if ( what.value.length >= limit )
	{
		document.getElementById('max_chars').value = 0;
		document.getElementById('max_chars').style.backgroundColor= '#FF0000';
		what.value = what.value.substring(0, (limit-1));
		return false;
	}
}

function reportSpam( id ) 
{
	document.getElementById('spam_'+id).style.display = 'none';
	document.getElementById('reported_'+id).innerHTML = 'Thank you. We will look into this.';
}
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupCommentStatus = 0;
var popupCommentResultStatus = 0;

//loading popup with jQuery magic!
function loadCommentPopup(){
	//loads popup only if it is disabled
	if(popupCommentStatus==0){
		//centering with css
		centerCommentPopup();
	
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupCommentStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disableCommentPopup(){
	//disables popup only if it is enabled
	if(popupCommentStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupCommentStatus = 0;
	}
}
//centering popup
function centerCommentPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2)+scrOfY,
		"left": (windowWidth/2-popupWidth/2)+scrOfX
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
//loading popup with jQuery magic!
function loadCommentResultPopup(){
	//loads popup only if it is disabled
	if(popupCommentResultStatus==0){
		//alert("Got Here!");
		centerCommentResultPopup();
		$("#commentResultBackgroundPopup").css({
			"opacity": "0.7"
		});
		$("#commentResultBackgroundPopup").fadeIn("slow");
		$("#popupCommentResult").fadeIn("slow");
		popupCommentResultStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disableCommentResultPopup(){
	//disables popup only if it is enabled
	if(popupCommentResultStatus==1){
		$("#commentResultBackgroundPopup").fadeOut("slow");
		$("#popupCommentResult").fadeOut("slow");
		popupCommentResultStatus = 0;
	}
}
//centering popup
function centerCommentResultPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupCommentResult").height();
	var popupWidth = $("#popupCommentResult").width();
	
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	
	//centering
	$("#popupCommentResult").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2)+scrOfY,
		"left": (windowWidth/2-popupWidth/2)+scrOfX
	});
	//only need force for IE6
	
	$("#commentResultBackgroundPopup").css({
		"height": windowHeight
	});
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#showPopup").click(function(){
		//load popup
		loadCommentPopup();
		document.getElementById('author').focus();
	});
	$("#showPopup2").click(function(){
		//load popup
		loadCommentPopup();
		document.getElementById('author').focus();
	});
					
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disableCommentPopup();
	});
	//Click the from cancel button!
	$("#popupContactCancel").click(function(){
		disableCommentPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupCommentStatus==1){
			disableCommentPopup();
		}
	});
	//LOADING POPUP
	//Click the button event!
	$("#showCommentResult").click(function(){
		//load popup
		loadCommentResultPopup();
	});
	//CLOSING POPUP
	//Click the x event!
	$("#commentResultPopupClose").click(function(){
		disableCommentResultPopup();
	});
	$("#commentResultViewAll").click(function(){
		disableCommentResultPopup();
	});
	$("#commentResultPopupHelp").click(function(){
		disableCommentResultPopup();
	});
	//Click out event!
	$("#commentResultBackgroundPopup").click(function(){
		disableCommentResultPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupCommentResultStatus==1){
			disableCommentResultPopup();
		}
	});
});

