var IMG_ROOT= "/images/"

function popUp(URL, title) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=500,left = 162,top = 50');");
}

function imageOnOff(obj)
{	
	var resultSet = new Array();
	resultSet = getRenderedImgSrc(obj); //Gets the name of the ICON without the extention	

	// MOUSEOVER ACTION
	if((resultSet['imageState']) != ('on.'+resultSet['imageExtention'])) // Checks whether the button is on the ON state already
	{	
		obj.src=IMG_ROOT+resultSet['imageName']+"_on."+resultSet['imageExtention'];	 
		obj.onmouseout = backToOriginalState;			
	}
	
	function backToOriginalState()
	{
		obj.src=IMG_ROOT+resultSet['imageName']+"."+resultSet['imageExtention'];		
	}	
	
}

function getRenderedImgSrc(imgObj)
{
	imgsrc = imgObj.src;	
	img_root = imgsrc.split("/"); 
	img_name = img_root[img_root.length-1];	
	img_nameSpaces = img_name.split("_");

	img_state = img_nameSpaces[img_nameSpaces.length-1]; /* gets the word after last _ , looking for _on */	
	
	justImageName = img_name.split(".");
	
	var resultSet = new Array();
	resultSet['imageName'] = justImageName[0]; // send the image name only up until the extention 
	resultSet['imageExtention'] = justImageName[1]; // sends the image extention
	resultSet['imageState'] = img_state; //sends the state of an image like on.gif, on.jpg
	
	
	return resultSet; //Returns just the image name without the extention	
}


function addTableDiffTr(tableId,darkBg,lightBg)
{
	var tableObj = document.getElementById(tableId);
	var tBody = tableObj.getElementsByTagName('TBODY');
	if(tBody){
		var rows = tBody[0].getElementsByTagName('TR');
	}else{
		var rows = tableObj.getElementsByTagName('TR');
	}
	for(var no=0;no<rows.length;no++){
		if(no%2 == 0)
			rows[no].className=lightBg;
		else 
			rows[no].className=darkBg;
	}
	
}


function generateIndustrySelect()
{

	var s = '<select id="secondSelectTag" name="industry" onchange="secondSelectAction(this);"  class="styledSelect"><option value="">(All Industries)</option>';
	
	for(i=0; i< industries.length; i++)
	{
		s += '<option value="'+industries[i]+'">'+industries[i]+'</option>';
	}
	s += '</select>'
	
	return s;
}

function setFilterSelect(filterValue){
	document.getElementById('secondSelect').innerHTML = generateIndustrySelect();

	var s= document.getElementById('secondSelectTag');
	var a= industries;
	var targetIndex= null;
	

	for(var i= 0; i< a.length; i++){
		if(a[i]== filterValue){
			targetIndex= i;
			break;
		}
	}

	if(targetIndex){
		s.selectedIndex= targetIndex+1;
	}
}

function secondSelectAction(obj)
{
	if(obj.value!='')
	{
		window.location = "/company/clients.php?filter="+obj.value;		
	}
	else
	{
		window.location = "/company/clients.php";
	}
}

/* EMAIL ENCRYPTION */
var at = "@";
var dot = ".";
var atrep = "^";
var dotrep = "$";


function hg_em_encrypt(frm, text){

  var len = text.length;
  var tmp = "";

  for(var i=len-1; i>=0; i--){
    tmp +=text.charAt(i);
    var rand = Math.random();
    var j = Math.floor(rand*10);
    tmp += j;
  }
  while (tmp.indexOf(at)>-1) {
    var idx = tmp.indexOf(at);
    tmp = "" + (tmp.substring(0, idx) + atrep + tmp.substring((idx + at.length), tmp.length));
  }
  while (tmp.indexOf(dot)>-1) {
    var idx = tmp.indexOf(dot);
    tmp = "" + (tmp.substring(0, idx) + dotrep + tmp.substring((idx + dot.length), tmp.length));
  }

  //tmp = "<script>document.write('"+tmp+"');</script>";
  
  try{
    frm.emailstr.value = "";
    frm.genstr.value = tmp;
    frm.copystr.value = '<script>document.write(hg_em_decrypt2("'+tmp+'"));</script>';
  }catch(e){} 
    
  return tmp;
}


function hg_em_decrypt(frm, text){


  var len = text.length;
  var tmp = "";

  while (text.indexOf(atrep)>-1) {
    var idx = text.indexOf(atrep);
    text = "" + (text.substring(0, idx) + at + text.substring((idx + atrep.length), text.length));
  }

  while (text.indexOf(dotrep)>-1) {
    var idx = text.indexOf(dotrep);
    text = "" + (text.substring(0, idx) + dot + text.substring((idx + dotrep.length), text.length));
  }

  for(var i=len-1; i>=0; i--){
    if(i%2 == 0)
      tmp +=text.charAt(i);
  }

  try{
    frm.genstr.value = "";
    frm.copystr.value = "";
    frm.emailstr.value = tmp;
  }catch(e){}
  
  
  return tmp;
  
}


function hg_em_decrypt2(text){
  var len = text.length;
  var tmp = "";

  while (text.indexOf(atrep)>-1) {
    var idx = text.indexOf(atrep);
    text = "" + (text.substring(0, idx) + at + text.substring((idx + atrep.length), text.length));
  }

  while (text.indexOf(dotrep)>-1) {
    var idx = text.indexOf(dotrep);
    text = "" + (text.substring(0, idx) + dot + text.substring((idx + dotrep.length), text.length));
  }

  for(var i=len-1; i>=0; i--){
    if(i%2 == 0)
      tmp +=text.charAt(i);
  }
  tmp = '<a href="mailto:'+tmp+'">'+tmp+'</a>';

  return tmp;
  
}



function validateForm(){

	try{
	var frm = document.getElementById('userForm');
	
	if(frm.firstname.value==""){
		//alert("Please enter your name.");
		//frm.fullname.focus();
		return false;
	}
	if(frm.lastname.value==""){
		//alert("Please enter your name.");
		//frm.fullname.focus();
		return false;
	}

	if(frm.email.value==""){
		//alert("Please enter a valid email address.");
		//frm.email.focus();
		return false;
	}
	if(frm.phone.value==""){
		//alert("Please enter a valid phone number.");
		//frm.phone.focus();
		return false;
	}
	if(frm.company.value==""){
		//alert("Please enter your company name.");
		//frm.company.focus();
		return false;
	}
	if(frm.city.value=="" || frm.address1.value=="" || frm.postalCode.value==""){
		//alert("Please enter your company name.");
		//frm.company.focus();
		return false;
	}
	}catch(e){
		//alert(e.message);
	}
	replaceForm();
	return true;								
}

function replaceForm(){

	document.getElementById('formContainer').style.display = 'none';
	document.getElementById('submittedContainer').style.display= 'block';
	
}


Array.prototype.randomize= function () {
  var i = this.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = this[i];
     var tempj = this[j];
     this[i] = tempj;
     this[j] = tempi;
   }
}

//client logo images
 logoimages= [];
 logoimages[logoimages.length]= 'cna.gif'
 logoimages[logoimages.length]='mars.gif'
 logoimages[logoimages.length]='sikorsky.gif'
 logoimages[logoimages.length]='abb.gif'
 logoimages[logoimages.length]='constellation2.gif'
 logoimages[logoimages.length]='massalec.gif'
 logoimages[logoimages.length]='skanska.gif'
 logoimages[logoimages.length]='advertising.gif'
 logoimages[logoimages.length]='disney.gif'
 logoimages[logoimages.length]='merck.gif'
 logoimages[logoimages.length]='suntrust.gif'
 logoimages[logoimages.length]='aigcorp.gif'
 logoimages[logoimages.length]='doe.gif'
 logoimages[logoimages.length]='freescale.gif'
 logoimages[logoimages.length]='mellon.gif'
 logoimages[logoimages.length]='alion.gif'
 logoimages[logoimages.length]='dod.gif'
 logoimages[logoimages.length]='teradyne.gif'
 logoimages[logoimages.length]='aker.gif'
 logoimages[logoimages.length]='dpr.gif'
 logoimages[logoimages.length]='motorola.gif'
 logoimages[logoimages.length]='thales.gif'
 logoimages[logoimages.length]='amtrak.gif'
 logoimages[logoimages.length]='eds.gif'
 logoimages[logoimages.length]='nab.gif'
 logoimages[logoimages.length]='tiaacref.gif'
 logoimages[logoimages.length]='ap.gif'
 logoimages[logoimages.length]='ericsson.gif'
 logoimages[logoimages.length]='nasa.gif'
 logoimages[logoimages.length]='timewarner.gif'
 logoimages[logoimages.length]='apl.gif'
 logoimages[logoimages.length]='esi-intl.gif'
 logoimages[logoimages.length]='navsup.gif'
 logoimages[logoimages.length]='tishman.gif'
 logoimages[logoimages.length]='bae.gif'
 logoimages[logoimages.length]='faa.gif'
 logoimages[logoimages.length]='ng.gif'
 logoimages[logoimages.length]='usace.gif'
 logoimages[logoimages.length]='banknorth.gif'
 logoimages[logoimages.length]='federated.gif'
 logoimages[logoimages.length]='nu.gif'
 logoimages[logoimages.length]='usfreightways.gif'
 logoimages[logoimages.length]='bechtel.gif'
 logoimages[logoimages.length]='ge.gif'
 logoimages[logoimages.length]='nycsca.gif'
 logoimages[logoimages.length]='uu.gif'
 logoimages[logoimages.length]='bhpbilliton.gif'
 logoimages[logoimages.length]='givaudan.gif'
 logoimages[logoimages.length]='opm.gif'
 logoimages[logoimages.length]='va.gif'
 logoimages[logoimages.length]='bmg.gif'
 logoimages[logoimages.length]='gsa.gif'
 logoimages[logoimages.length]='pge.gif'
 logoimages[logoimages.length]='valero.gif'
 logoimages[logoimages.length]='bp.gif'
 logoimages[logoimages.length]='gsk.gif'
 logoimages[logoimages.length]='pmic.gif'
 logoimages[logoimages.length]='verizon.gif'
 logoimages[logoimages.length]='bunge.gif'
 logoimages[logoimages.length]='guardian.gif'
 logoimages[logoimages.length]='ppl2.gif'
 logoimages[logoimages.length]='verizon_wireless.gif'
 logoimages[logoimages.length]='capgemer.gif'
 logoimages[logoimages.length]='hovanian.gif'
 logoimages[logoimages.length]='carefirst.gif'
 logoimages[logoimages.length]='hp.gif'
 logoimages[logoimages.length]='raytheon.gif'
 logoimages[logoimages.length]='cisco.gif'
 logoimages[logoimages.length]='hsb.gif'
 logoimages[logoimages.length]='shell.gif'
 logoimages.randomize();
