/*
Ansbacher.com 
Javascript Functions
*/

//Swap classnames
function swapclass(loc,cls) {
   		if(loc.className)
      	loc.className=cls;
}
		

function displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.returnValue = true;
}

// show hide layers browser safe
// show hide divs by id 
function hideLayer(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) {
			document.id.display = 'none';
		}
		else {
			document.all.id.style.display = 'none';
		}
	}
}

function showLayer(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) {
			document.id.display = 'block';
		}
		else {
			document.all.id.style.display = 'block';
		}
	}
}
	
function titleOtherChange(action) {
	if (action == "Other")
		{
			showLayer("otherInput");
			document.InfoRequest.Title_Other.focus();
		}
	else
		{
			hideLayer("otherInput");
			document.InfoRequest.Title_Other.value="";
		}
}
	
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 MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

var privacyWindow=null;

function openPrivacyPolicy() {
	privacyWindow=window.open("ansbacher-privacy-statement.html","PrivacyPolicy","location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=630,height=580");
	privacyWindow.focus()
}

var noticeWindow=null;

function openImportantNotices() {
	noticeWindow=window.open("important-notices.html","ImportantNotices","location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=630,height=580");
	noticeWindow.focus()
}

function openFraudWarning() {
	fraudWindow=window.open("ansbacher-fraudwarning.html","FraudWarning","location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=630,height=580");
	fraudWindow.focus()
}

var patriotWindow=null;

function openPatriotAct(jurisdiction) {
	PatriotWindow=window.open("pdf/patriot-act-" + jurisdiction + ".pdf","PatriotAct" + jurisdiction,"location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=630,height=580");
	PatriotWindow.focus()
}

var prntLctn;

function openDisclaimer()
{
	window.location.href = "disclaimer.html";
}

// confirm that you read the disclaimer and agreed it	
function do_confirm() {
	setCookie("ansDisclaim", "ansbacher_confirm=yes");
	window.location.href = getCookie("ansbacherurlname");
}

function go_to(lcn) {
//	alert("=" + lcn +"=");
	location.href=lcn;
}

function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
      document.cookie = escape(cookieName) + '=' + escape(cookieValue)
         + (expires ? '; EXPIRES=' + expires.toGMTString() : '')
         + (path ? '; PATH=' + path : '')
         + (domain ? '; DOMAIN=' + domain : '')
         + (secure ? '; SECURE' : '');
}
   
// A complementary function to unwrap a cookie.
function getCookie(cookieName) {
   var cookieValue = null;
   var posName = document.cookie.indexOf(escape(cookieName) + '=');
	
   if (posName != -1)
   {
      var posValue = posName + (escape(cookieName) + '=').length;
      var endPos = document.cookie.indexOf(';', posValue);
      if (endPos != -1)
      {
           cookieValue = unescape(document.cookie.substring(posValue, endPos));
      }
      else
      {
           cookieValue = unescape(document.cookie.substring(posValue));
      }
   }
	return cookieValue;
}
   
   // Browser and Platform Detection
var agt=navigator.userAgent.toLowerCase(); 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion);

var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
                && (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2)); 
var is_nav3 = (is_nav && (is_major == 3)); 
var is_nav4 = (is_nav && (is_major == 4)); 
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav45up = (is_nav && (is_minor >= 4.5));
var is_nav6up = (is_nav && (is_minor >= 5));
var is_nav5down = (is_nav && (is_minor < 5));

var is_ie = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4)); 
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) ); 
var is_ie4up = (is_ie  && (is_major >= 4)); 
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) ); 
var is_ie5up = (is_ie  && !is_ie3 && !is_ie4); 

var is_webtv = (agt.indexOf('webtv')!=-1);
var is_opera = (agt.indexOf('opera')!=-1);
var is_mac = (agt.indexOf("mac") != -1);
var is_win   = ((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1));	


// RealPlayer detection
var RealMode=0;
var RealPlayer5=0;
var RealPlayer4=0;
var RealPlayerG2=0;


if (is_nav || (is_ie5up && is_mac)) {
	numPlugins = navigator.plugins.length;
	for (i = 0; i < numPlugins; i++) {
		plugin = navigator.plugins[i];
		if (plugin.name.substring(0,10)=="RealPlayer") {
			RealMode=1;
		}
	}
}
else if (is_ie && !is_mac) {
	document.write('<SCR' + 'IPT LANGUAGE="VBScript"\> \n');
	document.write('on error resume next \n');
	document.write('RealPlayerG2 = (NOT IsNull(CreateObject("rmocx.RealPlayer G2 Control")))\n'); 
	// Uncomment the following lines to detect RP 5 and 4 on IE for windows
	//document.write('RealPlayer5 = (NOT IsNull(CreateObject("RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)")))\n');
	//document.write('RealPlayer4 = (NOT IsNull(CreateObject("RealVideo.RealVideo(tm) ActiveX Control (32-bit)")))\n');
	document.write('</SCR' + 'IPT\> \n');
}
if (RealMode || RealPlayerG2 || RealPlayer5 || RealPlayer4) {
	RealMode=1; 
}

layerRef = ""
styleRef = ""

if (is_ie)
{
layerRef = ".all"
styleRef = ".style"
statusMsg = "IE";
}
else if (is_nav6up)
//(navigator.appName == "Netscape")
{
layerRef = "getElementById"
styleRef = ".style"
statusMsg = "6up";
}
else
{
layerRef = ".layers"
styleRef = ""
statusMsg = "4.5down";
}

function validateBrowser() {
	if (is_webtv)
	{
	location.href="unsupported-browser.html";
	}
	else
	{
		if (is_ie4up)
		{
		return true;
		}
		else
		{
			if (is_nav4up)
			{
			return true;
			}
			else
			{
			location.href="unsupported-browser.html";
			}
		}
	}
}


function emailcheck(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }

		 return true;	
}

function ValidateForm() {
	var emailID=document.InfoRequest.Email;
	var firstnameID=document.InfoRequest.First_Name;
	var lastnameID=document.InfoRequest.Last_Name;
	
	if((firstnameID.value==null)||(firstnameID.value=="")){
	alert("First name is a mandatory field.");
	firstnameID.focus();
	return false;
	}
	else
	{
	
	if((lastnameID.value==null)||(lastnameID.value=="")){
	alert("Last name is a mandatory field.");
	lastnameID.focus();
	return false;
		}
		else
			{
			
			if ((emailID.value==null)||(emailID.value=="")){
				alert("A valid E-mail Address format should be\nexample@yourdomain.com");
				emailID.focus();
				return false;
			}
				if (emailcheck(emailID.value)==false){
					emailID.value="";
					emailID.focus();
					return false;
				}
		}
	}
	return true;
 }