function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}

		// Test for cookie capability; send to uh-oh page if not
		// ********************************************************
		if (!navigator.cookieEnabled)
		{
			if (!document.cookie || document.cookie == null || document.cookie == "")
			{
								document.location.href="/index_main.php?page=no_unique_id";
			}
		}

		// Set exit variable based on page type
		// ********************************************************
		var exit = true;

		// Set onLoad Pop
		// ********************************************************
		function pop_onLoad()
		{
					}

		// Set onUnload popup
		// ********************************************************
		function pop_onUnload()
		{
			if (exit)
			{
								window.focus();
			}
			return true;
		}

		// Set Pop Title
		// ********************************************************
		function set_title (ref, title)
		{
			ref.document.title = title;
		}

		// ********************************************************
		function pop_bookmark(page_req, bookmark)
		{
			page_url = "/index_main.php"+page_req+"#"+bookmark;
			win = window.open(page_url,"popwin","width=490,height=420,resizable=no,scrollbars=yes,toolbar=no,menubar=no");
		}

		// Spawn local pops from drop-down menus
		// ********************************************************
		function pop_dropdown(dropdown_obj)

		{
			page_req = dropdown_obj.options[dropdown_obj.selectedIndex].value;
			switch (page_req)
			{
				// these do nothing:
				case "":
				case "Quick Navigation":
					break;
				//these change location:
				case "?page=home":
				case "?page=cs_login":
					document.location.href = "/index_main.php"+page_req+"";
					break;
				// this spawns the popup:
				case "?page=cs_removeme":
				default:
					page_url = "/index_main.php"+page_req+"";
					window.open(page_url,"popwin","width=490,height=420,resizable=no,scrollbars=yes,toolbar=no,menubar=no");
					break;
			}
		}

		// Spawn external sites in standard sized pop (800x600)
		// ********************************************************
		function pop_newsite(page_url, bookmark)
		{
			if (bookmark)
			{
				page_url = page_url+"#"+bookmark;
			}
			window.open(page_url,"tss_win","width=800,height=600,resizable=yes,scrollbars=yes,location=yes,toolbar=yes,menubar=yes");
		}

		// Spawn local pops from menus
		// ********************************************************
		function pop_menu(page_req)
		{
			switch (page_req)
			{
				// these change location:
				case "":
				case "?page=prequal":
					//document.location.href = "index_main.php"+page_req;
					document.location.href = "/index_main.php?unique_id=3f5aed33fb8570e2437385ddca2092f5";
					break;
				// this spawns the popup:
				default:
					page_url = page_req+"";
					window.open("/index_main.php" + page_url,"popwin","width=490,height=420,resizable=no,scrollbars=yes,toolbar=no,menubar=no");
					break;
			}
		}

		// Redirect links INSIDE of a popup back to parent window
		// ********************************************************
		function back2opener(loc_str)
		{
			opener.location.href = loc_str;
		}



		function _check_state(val)
		{
			hide_div("ca_form");
			switch(val)
			{
				case "CA":
					show_div("ca_form");
					break;
			}
		}
function _how_often(val)
{

	hide_div("paydate_monthly");
	hide_div("paydate_weekly");
	hide_div("paydate_biweekly");
	hide_div("paydate_twicemonthly");

	switch(val)
	{
	case "WEEKLY":
		show_div("paydate_weekly");
		break;
	case "BI_WEEKLY":
		show_div("paydate_biweekly");
		break;
	case "TWICE_MONTHLY":
		show_div("paydate_twicemonthly");
		break;
	case "MONTHLY":
		show_div("paydate_monthly");
		break;
	}
}

function _biweekly_day(val)
{
	hide_div("paydate_biweekly_MON");
	hide_div("paydate_biweekly_TUE");
	hide_div("paydate_biweekly_WED");
	hide_div("paydate_biweekly_THU");
	hide_div("paydate_biweekly_FRI");
	show_div("paydate_biweekly_" + val);
}


function show_div(id)
{
	div = document.getElementById(id);
	div.style.display = "block";
}

function hide_div(id)
{
	div = document.getElementById(id);
	if (!div.style)
		alert(id + " is not a div!");
	div.style.display = "none";
}

function twicemonthly_date_show()
{

	hide_div("twicemonthly_day");
	show_div("twicemonthly_date");
}

function twicemonthly_day_show()
{
	show_div("twicemonthly_day");
	hide_div("twicemonthly_date");
}

function monthly_date_show()
{
	show_div("monthly_date");
	hide_div("monthly_day");
	hide_div("monthly_after");
}

function monthly_day_show()
{
	hide_div("monthly_date");
	show_div("monthly_day");
	hide_div("monthly_after");
}

function monthly_after_show()
{
	hide_div("monthly_date");
	hide_div("monthly_day");
	show_div("monthly_after");
}
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(ele){
	var Phone=document.getElementById(ele);
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number");
		Phone.value="";
		Phone.focus();
		return false;
	}
	return true;
 }


function checkPhone(eleName,specific_msg,Dtype){
	var obj = document.getElementById(eleName);
	if(Dtype==1){
		var dec = 10;
	}else{
		var dec = 5;
	}
	if((obj.value == '') && (obj.value.length!=dec)){
		alert('Please Enter Proper ' + specific_msg + ' Phone Number');
		return false;
	}else
	{
		if(Dtype==1){
			var pattern3 = /\d{10}/;
		}else{
			var pattern3 = /\d{5}/;
		}
		if(pattern3.test(obj.value))
			return true;
		else
		{
			if(!pattern3.test(obj.value))
			{
				if(Dtype==1){
					alert('Invalid ' + specific_msg + ' Phone Number! Must be in form 1234567890. Please re-enter.');
				}else{
					alert('Invalid Zipcode! Must be in form 55555. Please re-enter.');
				}
				obj.focus();
				return false;
			}
		}
	}
}

