var charexp=/./
var letterexp=/[a-z]/i
var phoneexp=/^\d{10}$/i
var zipexp=/^\d{5}$|^\d{5}[\-\s]?\d{4}$/
var emailexp=/^[a-z][\-\]*[a-z_0-9\.]+@[a-z_0-9\.][\-\]*[a-z_0-9\*]+\.[a-z]{3}$/i
var priceexp=/^\d*$|^\d*\.\d{2}$|^\d*\.\d{1}$/
var dateexp=/^\d{1,2}[\-\s\/]?\d{1,2}[\-\s\/]?\d{2}$|^\d{1,2}[\-\s\/]?\d{1,2}[\-\s\/]?\d{4}$/
var colorexp=/^[a-z_0-9]{6}$/i
var numexp=/^[0-9]$/

function isColor(str){
	return colorexp.test(str);
}

function stripSpace(str){
	return str.replace(/\s/g, '');
}

function stripChars(pattern, str){
	return str.replace(pattern,'');	
}

function stripNonDigits(str) {
	return str.replace(/[^0-9]/g,'');
}

function isNumber(str){
	return numexp.test(str);
}	
 
function notEmpty(str){
	return charexp.test(str);
}

function hasLetter(str){
	return letterexp.test(str);
}
function isNotEmpty(String) {
   // Return false if "string" is empty or all blank
  if (String.length == 0) {return (false);}
  for (var i=0; i < String.length; i++) {
    if (String.substring(i) != " ") {return (true);}
  }
  return (false);
}

var whitespace = " \t\n\r";

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isEmail(s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isEmail_back(str){
	return emailexp.test(stripSpace(str));
}

function isZip(str){
	return zipexp.test(str);
}

function isPrice(str){
	var amount='';
	amount=stripChars(/\$/,str);
	if (amount=='')
		return false;
	else
		return priceexp.test(amount);
}

function isDate(str){
	return dateexp.test(str);
}

function isPhone(str){
	return phoneexp.test(stripNonDigits(stripSpace(str)));
}

function isValid(pattern,str){
	return pattern.test(str);
}
function ReCenterMap(f) {
	f.coordx.value=this.event.offsetX;
	f.coordy.value=this.event.offsetY;
	f.submit();		
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//used on order page to reload for Echeck (1.16.03 BB)
function redirectForm(formname,destination){
	var objForm = eval("document."+formname);
	var status = false;
	objForm.action = destination;
	status = true;
	//return status;
	if (status){
		objForm.submit();
	}
}


function ActionDeterminator(loanType)
{
if(loanType == 1) {
   document.myform.action = 'https://secure.lendingtree.com/mortgage/ctl_Borrower.asp?page=loan_selection&verb=continue&O_loan_type=LOAN_TYPE_MORTGAGE&bp=consumerinfo&source=25329&alliance=true&SITEID=&InitData=&esourceid=25329&init=1&author=&VERSION=&intro=0';
   document.myform.submit();
   }
if(loanType == 2) {
   document.myform.action = 'https://secure.lendingtree.com/mortgage/ctl_Borrower.asp?page=loan_selection&verb=continue&O_loan_type=LOAN_TYPE_REFINANCE&bp=consumerinfo&source=25329&alliance=true&SITEID=&InitData=&esourceid=25329&init=1&author=&VERSION=&intro=0';
   document.myform.submit();
   }
if(loanType == 3) {
   document.myform.action = 'https://secure.lendingtree.com/home_equity/ctl_Borrower.asp?page=loan_selection&verb=continue&O_loan_type=LOAN_TYPE_HOME_EQUITY&bp=consumerinfo&source=25329&alliance=true&SITEID=&InitData=&esourceid=25329&init=1&author=&VERSION=&intro=0';
   document.myform.submit();
   }
if(loanType == 4) {
   document.myform.action = 'http://www.lendingtree.com/common/bp/consumerinfo/reintro.asp?source=25329&esourceid=25329&intro=0';
   document.myform.submit();
   }
}
function ActionDeterminator2()
{
if(document.myform.loanType[0].checked == true) {
   document.myform.action = 'https://secure.lendingtree.com/mortgage/ctl_Borrower.asp?page=loan_selection&verb=continue&O_loan_type=LOAN_TYPE_MORTGAGE&bp=consumerinfo&source=25329&alliance=true&SITEID=&InitData=&esourceid=25329&init=1&author=&VERSION=&intro=0';
   }
if(document.myform.loanType[1].checked == true) {
   document.myform.action = 'https://secure.lendingtree.com/mortgage/ctl_Borrower.asp?page=loan_selection&verb=continue&O_loan_type=LOAN_TYPE_REFINANCE&bp=consumerinfo&source=25329&alliance=true&SITEID=&InitData=&esourceid=25329&init=1&author=&VERSION=&intro=0';
   }
if(document.myform.loanType[2].checked == true) {
   document.myform.action = 'http://www.lendingtree.com/common/bp/consumerinfo/reintro.asp?source=25329&esourceid=25329&intro=0';
   }
if(document.myform.loanType[3].checked == true) {
   document.myform.action = 'https://secure.lendingtree.com/home_equity/ctl_Borrower.asp?page=loan_selection&verb=continue&O_loan_type=LOAN_TYPE_HOME_EQUITY&bp=consumerinfo&source=25329&alliance=true&SITEID=&InitData=&esourceid=25329&init=1&author=&VERSION=&intro=0';
   }
return true;
}

//Following function added by Ali Sefati for Quick Apply Cobrand Top Banner Pop Up
function opentopguide(){
var winl = (screen.width-300)/2;
var wint = (screen.height-250)/2;
window.open('http://www.quickapply.com/pop_how60000.htm','topguide','scrollbars=no,menubar=no,height=250,width=300,resizable=yes,toolbar=no,location=no,status=no,top='+ wint +',left='+ winl); 
return;
}


/* Functions for writing Flash Obj */

function writeFlashTag(file, width, height, id, align, params)
{
	var strTag					= '';		

	strTag	+= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '" align="' + align + '">';
	strTag	+= '<param name="allowScriptAccess" value="sameDomain" />';
	strTag	+= '<param name="movie" value="' + file + '" />';
	strTag	+= '<param name="quality" value="high" />';
	strTag	+= getArgs(params, 'object');
	strTag	+= '<embed src="' + file + '" quality="high" width="' + width + '" height="' + height + '" name="' + id + '" align="' + align + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ' + getArgs(params, 'embed') + ' />';
	strTag	+= '</object>';
		
	document.write(strTag);
}

function getArgs(params, tag)
{
	var args			= new Object();
	var pairs			= params.split(",");
	var returnObj		= '';
	var returnEmbed		= '';

	for (var i=0; i<pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = trim(pairs[i].substring(0,pos));
		var value = trim(pairs[i].substring(pos+1));
		args[argname] = unescape(value);

		returnObj		+= '<param name="' + argname + '" value="' + value + '" />';
		returnEmbed		+= argname + '="' + value + '" ';
	}

	if (tag == 'object')
	{
		return returnObj;
	}
	else
	{
		return returnEmbed;
	}
}

function trim(s)
{
	while (s.substring(0,1) == ' ')
	{
		s = s.substring(1,s.length);
	}

	while (s.substring(s.length-1,s.length) == ' ')
	{
		s = s.substring(0,s.length-1);
	}

	return s;
}
