/* Global Variables */
/* Absolute Reference for URL's and Images */
/* Needed so 3rd parties that host templated content can reference functionality on main server */
/* Without replicating files */
//var domain = "http://192.168.1.69/NuBsip/"
//var domain = "http://65.82.189.19/bsip/dev/"
var domain = "http://www.binarystar.com/"

 // Referenced by menu_data.js And flash.js

/* Global Utility functions */

// Open popup window
function OpenWindow(url,name,w,h,scroll,resize,status,title,tool,menu,location)
{
	var sFeatures;
	if (typeof(h) == "undefined") h = 300;
	if (typeof(w) == "undefined") w = 400;
	
	var screenW = screen.width;
	var screenH = screen.height;
	var posX = (screenW/2)-(w/2);
	var posY = (screenH/2)-(h/2);
	
	sFeatures = "top="+posY+",left="+posX+",height="+h+",width="+w;
	
	if (typeof(scroll) != "undefined"){ sFeatures += ",scrollbars=" + scroll; }
	if (typeof(resize) != "undefined"){ sFeatures += ",resizable=" + resize; }
	if (typeof(status) != "undefined"){ sFeatures += ",status=" + status; }
	if (typeof(title) != "undefined"){ sFeatures += ",titlebar=" + title; }
	if (typeof(tool) != "undefined"){ sFeatures += ",toolbar=" + tool; }
	if (typeof(menu) !="undefined"){ sFeatures += ",menubar=" + menu;}
	if (typeof(location) != "undefined"){ sFeatures += ",location=" + location;}
	
	var win = window.open(url,name,sFeatures);
	win.focus();
}

/* Legacy popup function from contact page */
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	name = "page" + id;
	
	OpenWindow(URL, name, 600, 450, 1, 0, 0, 1, 0, 0, 0)
}

// Simple Image Rollover

// Image Preloading
/* Absolute Reference for URL's and Images */
/* Needed so 3rd parties that host templated content can reference functionality on main server */
/* Without replicating files */
var iPath = "http://www.binarystar.com/images/"
var iExt = "jpg"
var suffix = new Array('on', 'off')
var loaded = false

function PreLoad()
{
  if(document.images)
  {
    var argLen = arguments.length;
    for(var i = 0; i < argLen; i++)
    {
      var arg = arguments[i];
      var sufLen = suffix.length;
      for(j = 0; j < sufLen; j++)
      {
        var suf = suffix[j]
        self[arg + '_' + suf] = new Image();
        self[arg + '_' + suf].src = iPath + arg + '_' + suf + '.' + iExt;
      }
    }   
    loaded = true;
  }
}

function RollOver(iName, iState)
{
  if(document.images && loaded)
  {
    document.images[iName].src = self[iName + '_' + iState].src;
  }
}

function OnLoad()
{
  PreLoad('nav_buy');
  PreLoad('nav_developernet');
  PreLoad('nav_corp_site');
  PreLoad('nav_register');
}

window.onload = OnLoad;

/*
    rollover example:
		<a href=domain + "about.html" 
		onMouseover="rollOver('about', 'on')" 
		onMouseout="rollOver('about', 'off')"><img 
		name="about" 
		src=domain + "images/about_off.gif" 
		height="25" 
		width="75" 
		border="0"
		alt="About"></a>
*/

/* Rendering Mode Check */
/* Checks to see if IE is running in Standards-compliant Mode or Not */
function fnCompatCheck()
{		
	var sAppend, sCompat = document.compatMode;
	if (sCompat == "CSS1Compat")
		{
			sAppend = "Standards-compliant mode is switched on.  \nThis document renders only standards-compliant standards rules.";
		}
	else if (sCompat == "BackCompat")
		{
			sAppend = "Standards-compliant mode is not switched on.  \nThis document renders non-standards-compliant style rules compatible with earlier versions of IE.";
		}
	else
		{
			 alert("Error.  Neither value was returned.");
			 return;
		}		
		
	alert("Value of compatMode property is " + 
	document.compatMode + ".\n" + sAppend);
}		

/**** Legacy Form Validation ****/
function isNum(passVal)  {
	for( i =0; i < passVal.length; i++ )  {
		if(passVal.charAt(i)  < "0" )  {
			return 1
		}   
		if(passVal.charAt(i)  >  "9" )  {
			return 1
		}   
	}
	return 0
}

function validForm(passForm)  {
	if(passForm.email.value == "" )  {
		alert("You must enter your email")
		passForm.email.focus()    
		return false
	}

	if(passForm.email.value.length < 6 )  {
	  alert("You have entered a invalid email address")
    passForm.email.focus()    
    return false
  }

	if(passForm.email.value.indexOf("@", 1)  == -1 ) {
	  alert("You have entered a invalid email address")
    passForm.email.focus()    
    return false
  }
	return true
}

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 changeCase(frmObj) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;

	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else {
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
		  	}
  		}
  	}
	}
	frmObj.value = tmpStr;
}

//always have a sequential number after the name of each checkbox
//ie: prod1, prod2, prod2, etc....
//adjust this number to the number of checkboxes that your form contains

var checkboxnum = 8;

//this is for the number of radio buttons
var radionum = 5;

// global variable to check for validity
var retcode;

//list of fields in the form
var fieldList = new Array();

function validate_form()
{
	retcode = true;
	for (var v_field in fieldList)
		if (retcode) 
		{
			if (v_field != "state") eval(fieldList[v_field]);
		}
	if (retcode) eval(fieldList['stateregion']); 
	return retcode;
}

function jsval_custom(fieldname, alertmsg )
{
	if (document.contact.state.selectedIndex == 0 && document.contact.region.value == "") 
	{
        	alert(alertmsg);
        	document.forms[1][fieldname].focus();
        	retcode = false;
    }
    return retcode;
}


function jsval_text( fieldname, alertmsg )
{
	if (document.forms[1][fieldname].value=='')
	{
        	alert(alertmsg);
        	document.forms[1][fieldname].focus();
        	retcode = false;
    }
    return retcode;
}

function jsval_checkbox(fieldname, alertmsg)
{
	var noneselected = true;
	for (i=1; i<=checkboxnum ;i++)
	{
		//alert(fieldname+i);
		if (document.forms[1][fieldname+i].checked == true)
		{
			noneselected = false;
			retcode = true;
			i = checkboxnum + 1;
		}
	}

	if (noneselected)
	{
		i = 1;
		alert(alertmsg);
		document.forms[1][fieldname+i].focus();
		retcode = false;
	}
	return retcode;
}

function jsval_radio(fieldname, alertmsg)
{
	var noneselected = true;
	for (i=0; i<radionum; i++)
	{
		if (document.forms[1][fieldname][i].checked == true)
		{
			noneselected = false;
			retcode = true;
			i = radionum + 1;
		}
	}

	if (noneselected)
	{
			i = 1;
			alert(alertmsg);
			document.forms[1][fieldname][i].focus();
			retcode = false;
	}
	return retcode;
}

function jsval_select(fieldname, alertmsg)
{
	if(document.forms[1][fieldname].selectedIndex == 0)
	{
			alert(alertmsg);
			document.forms[1][fieldname].focus();
			retcode = false;
	}
	return retcode;
}


function jsval_number(fieldname, alertmsg)
{
	var fnumvalue = "document.form." + fieldname + ".value";
	retcode  = true;
	if(fnumvalue.length==0) { return false; alert(alertmsg);}
	var RefString="1234567890";
	for (Count=0; Count < fnumvalue.length; Count++)
	{
		TempChar= fnumvalue.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)
		{
			alert(alertmsg)
			retcode = false
			return retcode;
		}
	}
	return retcode;
}

// Use jsval_text_email to "ensure correct format" of email. Use
// jsval_text to "require" email. Note, alertmsg is optional.

function jsval_text_email(fieldname, alertmsg) 
{
	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat = /^(.+)@(.+)$/;
	var specialChars= "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars  = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray = document.forms[1][fieldname].value.match(emailPat);

	if (matchArray == null) 
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */

		document.forms[1][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}
	
	var user = matchArray[1];
	var domain = matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			document.forms[1][fieldname].focus();
			alert(alertmsg);
			retcode = false;
			return retcode;
		}
	}

	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			document.forms[1][fieldname].focus();
			alert(alertmsg);
			retcode = false;
			return retcode;
		}

	}

	// See if "user" is valid 
	if (user.match(userPat) == null) 
	{
		// user is not valid
		document.forms[1][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray = domain.match(ipDomainPat);
	if (IPArray != null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				document.forms[1][fieldname].focus();
				alert(alertmsg);
				retcode = false;
				return retcode;
			}
		}
		retcode = true;
		return retcode
	}

	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			alert(alertmsg);
			retcode = false;
			return retcode;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		document.forms[1][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		document.forms[1][fieldname].focus();
		alert(alertmsg);
		retcode = false;
		return retcode;
	}

	// If we've gotten this far, everything's valid!
	retcode = true;
	return retcode;
}

//always use sequential numbering after the main name starting with "1"
// for checkboxes
fieldList['firstname'] = 'jsval_text("firstname", "Please enter your First Name.")';
fieldList['lastname'] = 'jsval_text("lastname", "Please enter your Last Name.")';
fieldList['title'] = 'jsval_text("title", "Please enter your Title.")';
fieldList['email'] = 'jsval_text_email("email", "Please enter a valid e-mail address.")';
fieldList['phone'] = 'jsval_text("phone", "Please enter your Phone Number.")';
fieldList['company'] = 'jsval_text("company", "Please enter Company name.")';
fieldList['address1'] = 'jsval_text("address1", "Please enter your Address.")';
fieldList['city'] = 'jsval_text("city", "Please enter your City.")';
fieldList['stateregion'] = 'jsval_custom("state", "Please select a State or enter Region.")';
fieldList['country'] = 'jsval_select("country", "Please enter the Country.")';
fieldList['zip'] = 'jsval_text("zip", "Please enter your Zip or Postal Code.")';
fieldList['function'] = 'jsval_select("function", "Please select your job function.")';
fieldList['industry'] = 'jsval_select("industry", "Please select your industry.")';
fieldList['integration'] = 'jsval_checkbox("integration", "Please select an area of integration.")';
fieldList['revenue'] = 'jsval_select("revenue", "Please select your organizations revenue.")';
fieldList['timeframe'] = 'jsval_select("timeframe", "Please select your projects timeframe.")';
fieldList['hearabout'] = 'jsval_select("hearabout", "Please select how you heard about Ascential.")';

// -->



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;

}

// popup windows

function windowfonts() { //v3.0
	window.open("mvlaser4.html",'Fonts','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=700,height=565')
}

function windowmvcomponents() { //v3.0
	window.open("mvlaser5.html",'Components','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=700,height=565')
}

function windowbinarystarsa() {
	window.open("press/pr_binarystar_sa.html",'Components','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=700,height=565')
}

function windowdmconsadded() {
	window.open("press/pr_dmcons_added.html",'Components','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=700,height=565')
}

function windowpresshist() { //v3.0
	window.open("press.html",'PressHistory','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=695,height=590,resizable=yes')
}

function windownuwikinews() { //v3.0
	window.open("NuWikiNews.html",'NuWikiNews','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=695,height=590,resizable=yes')
}
function windowpressrelease(myurl) { //v3.0
	window.open(myurl,'PressRelease','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=695,height=460,resizable=yes')
}

function windowpopup(myurl) { //v3.0
	window.open(myurl,'popup','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=685,height=570,resizable=yes')
}

function windowStarsite(myurl) { //v3.0
	window.open(myurl,'popup1','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=760,height=670,resizable=yes')
}

function windowStarsite2(myurl) { //v3.0
	window.open(myurl,'popup2','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=760,height=768,resizable=yes')
}
//French engineering
function windowfrenchengineering(myurl) { //v3.0
	window.open("press/pr_frenchengineeringworks.html",'popup2','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=760,height=670,resizable=yes')
}
//Nuwiki content management
function windownuwikicontentmanagement() { //v3.0
	window.open("pr_NuWikiNews_data.html",'popup2','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=760,height=670,resizable=yes')
}

//Ergos Software
function windowergosadded() { //v3.0
	window.open("press/pr_ergos_software_solutions.html",'popup2','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=760,height=670,resizable=yes')
}

//Terms of use
function termsofuse() { //v3.0
	window.open("legal.html",'popup2','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=760,height=670,resizable=yes')
}