<!--

function capitalizeMe(obj) {
        val = obj.value;
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length);
        }
        obj.value = newVal;
}
//
function validateit(ourform){
		
	var good=true;
	
	//fix phone
	phone=ourform.custom_phone.value;
	//alert(phone);
	//remove non numbers
	phone=NumOnly(phone);
	//check that 10 or 11 numbers left
	if (phone.length>11 || phone.length<10 ){
		//kill
		good=false;
		msg='Please enter a valid phone number.';
		formpart='custom_phone1';
	}
	//get rid of 1 
	if (phone.length==11){
	if (Left(phone,1)==1){
		phone=Right(phone,10);
	}else{
	//not a 1	
		good=false;
		msg='Please enter a valid phone number.';
		formpart='custom_phone1';
		}
	}
	
	ourform.custom_phone.value=phone;
	
	//check name
	thename=ourform.category2.value;
	if(thename==''){
	msg = "You didn't enter your name.\n";
   good=false;
   formpart='category2';
}
	//check email
	theemail=ourform.category3.value;
	if (theemail == "") {
   msg = "You didn't enter an email address.\n";
   good=false;
   formpart='category3';
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(theemail))) { 
       msg = "Please enter a valid email address.\n";
	   good=false;
   formpart='category3';
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (theemail.match(illegalChars)) {
          msg = "The email address contains illegal characters.\n";
		   good=false;
   			formpart='category3';
       }
    }

	if(good){
		SaveCookies(phone,theemail,thename);
		ourform.confirmation.value='http://www.freecellphonelookups.com/processing.php?p=' + phone
		ourform.submit();
		//alert('good');
	}else{
	
	alert(msg);
	ourform[formpart].focus()
	}
	
	
}
//------------
function validateit2(ourform){
		
	var good=true;
	
	//fix phone
	phone=ourform.custom_phone2.value;
	//alert(phone);
	//remove non numbers
	phone=NumOnly(phone);
	//check that 10 or 11 numbers left
	if (phone.length>11 || phone.length<10 ){
		//kill
		good=false;
		msg='Please enter a valid phone number.';
		formpart='custom_phone2';
	}
	//get rid of 1 
	if (phone.length==11){
	if (Left(phone,1)==1){
		phone=Right(phone,10);
	}else{
	//not a 1	
		good=false;
		msg='Please enter a valid phone number.';
		formpart='custom_phone2';
		}
	}
	
	ourform.custom_phone2.value=phone;
	
	if(good){
		ourform.submit();
		//alert('good');
	}else{
	
	alert(msg);
	ourform[formpart].focus()
	}
	
	
}

//----------------
function NumOnly(item){
	temp1=item.length;
	temp2='';
		for(x=0;x<temp1;x++){
		//remove non numbers
		tempitem=item.substr(x,1);
		//alert(tempitem + " " + ascii_value(tempitem) );
				if (ascii_value(tempitem)>47 && ascii_value(tempitem)<58){
					temp2=temp2+item.substr(x,1);
				}
		}
	return temp2;
}
function ascii_value (c)
{
	// restrict input to a single character
	c = c . charAt (0);

	// loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++ i)
	{
		// convert i into a 2-digit hex string
		var h = i . toString (16);
		if (h . length == 1)
			h = "0" + h;

		// insert a % character into the string
		h = "%" + h;

		// determine the character represented by the escape code
		h = unescape (h);

		// if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	return i;
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function SaveCookies(cphone,cemail,cname){
//
//parse phone first

setCookie('custom_phone', SplitPhone(cphone), 1);
setCookie('category2', cname, 1);
setCookie('category3', cemail, 1);
}

function SplitPhone(spphone){
var a=Left(spphone,3);
var b=spphone.substr(3,3);
var c=Right(spphone,4);	
return a + '-' + b + '-' + c;
}

function setCookie(NameOfCookie, value, expiredays)
{

// Three variables are used to set the new cookie.
// The name of the cookie, the value to be stored,
// and finally the number of days until the cookie expires.
// The first lines in the function convert
// the number of days to a valid date.

var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

// The next line stores the cookie, simply by assigning
// the values to the "document.cookie" object.
// Note the date is converted to Greenwich Mean time using
// the "toGMTstring()" function.

document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
