// JavaScript Document
more = "data-driven-marketing.asp";
answer = "0";

function ValidateContact(theform) {
	answer = '';

    for (var i = 1; i<theform.elements.length; i++) {
        if ((theform.elements[i].type=='text' || theform.elements[i].type=='textarea') && theform.elements[i].value=='' && theform.elements[i].name!='Notes' && theform.elements[i].name!='Link' && theform.elements[i].name!='Other_notified_SMEs' && theform.elements[i].name!='URL_Link') {
            thestring = theform.elements[i].name
			thestring = thestring.replace(/_/,' ');
			answer += thestring + '\n';
			
        }
    }
	if (answer!='') {
		answer = answer.replace(/_/g,' ');
		alert('The following fields are incomplete\n\n'+answer);
		return false;
	}
	return true;
}
	

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    //set the current image as background
    
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    
    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src = imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
}


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_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];}
}
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 changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}
function showanswer(id) {
	if(document.getElementById) {
		var thelink = document.getElementById('l'+id);
	} else if (document.all){
		var thelink = document.all['l'+id];
	}
	if (answer==id) {
		changeClass ('a'+id,"hidden");
		MM_swapImage('q'+id,'','im/plus.gif',1);
		thelink.blur();
		answer = "0";
	} else {
		changeClass ('a'+id,"shown");
		MM_swapImage('q'+id,'','im/minus.gif',1);
		thelink.blur();
		answer = id;
	}
}

function homeswap(img) {
//	if(slideshowt) clearTimeout(slideshowt);
	
	MM_swapImgRestore();
	MM_swapImage('more','','im/button_more_'+img+'.gif',1);
	MM_swapImage('connect','','im/but_connect.jpg',1);
	MM_swapImage('how','','im/but_how.jpg',1);
	MM_swapImage('know','','im/but_know.jpg',1);
	MM_swapImage(img,'','im/but_'+img+'_f2.jpg',1);
	
//	if (img=="connect") { blendimage('blenddiv','blendimage', 'im/home_banner_f2.jpg',200); }
//	if (img=="know") { blendimage('blenddiv','blendimage', 'im/home_banner_f3.jpg',200); }
//	if (img=="how") { blendimage('blenddiv','blendimage', 'im/home_banner_f4.jpg',200); }
	
	changeClass('navcontainer', img);
	more = img+".asp";
}
function homeswapback() {
	//MM_swapImgRestore();
//	blendimage('blenddiv','blendimage', 'im/home_banner.jpg',200);
	changeClass('navcontainer', 'home');
	
}
function getmore() {
	window.location = more;
}

var menucount = -38;

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
//	currentpr=1;
	
	showRight();
	showMenu();
}

function showRight(){
	var obj = document.getElementById("subscribewrapper");
	if(obj) obj.style.display = 'block';

}

function showMenu(){
	var obj = document.getElementById("homebuttons");
	if(obj && menucount < 0) {
		menucount += 1;	
		obj.style.top = menucount;
		setTimeout("showMenu()",20);
	}
}

//var prImg = new Array();

//var xx = 0;
//prImg[0] = 'im/quote_sun.gif';
//prImg[1] = 'im/netstore.gif';

function changepr(){

	var obj = MM_findObj("divquotesscroll");
	var obj2 = MM_findObj("casedivtext");
	
	if(obj && prImg && xx && obj2 && prTxt) { 
		blendimage('casediv','casestudies',prImg[xx],400);
		obj2.innerHTML = prTxt[xx];
		xx++;
		if(xx >= prImg.length) xx = 1;
		setTimeout("changepr()", 10*1000);
		
	}

}

function ajaxRead(file){
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
  xmlObj.open ('GET', file, false);
  xmlObj.send ('');
  return xmlObj.responseText;
 }
 
function pageLoad(p){

   var d = new Date();
 	var page = ajaxRead(p + "?" + d);
	document.write(page);
	//setTimeout("changemenu()", 1*1000);
	
 
 }

 
 function menuLoad(){

   var d = new Date();
 	var menu = ajaxRead("/mk/get/CRMMENU?" + d);
	document.write(menu);
	//setTimeout("changemenu()", 1*1000);
	
 
 }
 
 function loginLoad(){
 var d = new Date();

 	var login = ajaxRead("/mk/get/CRMLOGIN?" + d);
	document.write(login);
	//setTimeout("changemenu()", 1*1000);
	
 
 }

 
 function changemenu(){

var d = new Date();
	var menu = ajaxRead("/mk/get/CRMMENU?" + d);
	var obj = MM_findObj("menu");
	if(obj) obj.innerHTML = menu;
 }



// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 7000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

var Pic = new Array() 

Pic[0] = 'im/home_banner.jpg'
Pic[1] = 'im/home_banner_f2.jpg'
Pic[3] = 'im/home_banner_f3.jpg'
Pic[2] = 'im/home_banner_f4.jpg'

var Btn = new Array();

Btn[0] = 'im/button_bkg_blue.jpg'
Btn[1] = 'im/but_connect.jpg';
Btn[2] = 'im/but_know.jpg';
Btn[3] = 'im/but_how.jpg';

var Img = new Array();

Img[0];
Img[1] = 'connect';
Img[2] = 'know';
Img[3] = 'how';


var slideshowt;
var j = 0
var p = Pic.length
var done = 0;

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
   var c = getCookie("__donecrm");
   if(c=="1") { showRight()}
	
   if (document.all){
      document.images.mainim.style.filter="blendTrans(duration=2)"
      document.images.mainim.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.mainim.filters.blendTrans.Apply()      
	  document.images.mainim.src = preLoad[j].src
	
	  //if(Img[j]) blendimage('homebuttons',Img[j],Btn[j],400);

      document.images.mainim.filters.blendTrans.Play()

   }
   else {
	   blendimage('blenddiv','blendimage', preLoad[j].src ,200);
   }
   j = j + 1
   if (j > (p-1)) {j=0;done=1}
   if(j==1 && done==1) { document.cookie="__donecrm=1;";return};
   slideshowt = setTimeout('runSlideShow()', slideShowSpeed)
}




function subscribesubmit(){
	if(document.subscribe.PRIMARY_EMAIL_ADDR.value=='' || document.subscribe.PRIMARY_EMAIL_ADDR.value=='Email Address') {
		alert('Please Enter your Emaill Address');
		document.subscribe.PRIMARY_EMAIL_ADDR.focus();
		return false; 
	}
	return true;
}

function getCookie(name) { // use: getCookie("name");
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
}


function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE

if (window.ActiveXObject)
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation 
&& document.implementation.createDocument)
  {
  xmlDoc=document.implementation.createDocument("","",null);
  }
else
  {
  alert('Your browser cannot handle this script');
  }
xmlDoc.async=false;
xmlDoc.load(fname);

return(xmlDoc);
}

function displayXSL(element,xmldoc,xsldoc)
{
xml=loadXMLDoc(xmldoc);
xsl=loadXMLDoc(xsldoc);
// code for IE

if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  
  document.getElementById(element).innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation 
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  
  document.getElementById(element).appendChild(resultDocument);
  }
}




function displayResult(element)
{
xml=loadXMLDoc("/TheLead/SyndicationService.asmx/GetRss");
xsl=loadXMLDoc("/TheLead.xsl");
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  
  document.getElementById(element).innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation 
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  
  document.getElementById(element).appendChild(resultDocument);
  }
}
