isMac = (navigator.appVersion.indexOf("Mac") != -1);
isIE = (navigator.appName == "Microsoft Internet Explorer")
isNN = (navigator.appName == "Netscape")
isSafari = (navigator.userAgent.indexOf("Safari") != -1);
isWindows = (navigator.appVersion.indexOf("Windows") != -1);
isIE5 = (navigator.appVersion.indexOf("MSIE 5") != -1)

if (isIE) {
	document.write('<link rel="stylesheet" type="text/css" href="css/ie.css">');
}

function imageSwap(imgName,imgObj) { 
	if (document.images && preloaded) document.images[imgName].src = imgObj.src		
}

var aImages = new Array()

function preload(imgObj,imgSrc) {
	if (document.images) { 
		aImages[imgObj] = new Image()
		aImages[imgObj].src = imgSrc
	}
}

function msover(imgName) {
	imageSwap(imgName,aImages[imgName + '_over'])
}

function msout(imgName) { 
	imageSwap(imgName,aImages[imgName + ''])
}

var preloaded;
preloaded = false;

var gblEvoActive, gblIndActive;
gblEvoActive = true;
gblIndActive = false;

function preloadImages() {
        preload("roll_about_us_over","/images/mast/about_us_over.gif");
        preload("roll_about_us","/images/mast/about_us.gif");

        preload("roll_solar_solutions_over","/images/mast/solar_solutions_over.gif");
        preload("roll_solar_solutions","/images/mast/solar_solutions.gif");

        preload("roll_case_studies_over","/images/mast/case_studies_over.gif");
        preload("roll_case_studies","/images/mast/case_studies.gif");

        preload("roll_news_over","/images/mast/news_over.gif");
        preload("roll_news","/images/mast/news.gif");

        preload("roll_faq_over","/images/mast/faq_over.gif");
        preload("roll_faq","/images/mast/faq.gif");

        preload("roll_contact_us_over","/images/mast/contact_us_over.gif");
        preload("roll_contact_us","/images/mast/contact_us.gif");

        preload("roll_careers_over","/images/mast/careers_over.gif");
        preload("roll_careers","/images/mast/careers.gif");

        preload("roll_solar_over","/images/solar_over.gif");
        preload("roll_solar","/images/solar.gif");

        preload("roll_co2_over","/images/co2_over.gif");
        preload("roll_co2","/images/co2.gif");

        preload("homepage_col1_over","/images/boxes/homepage_col1_over.gif");
        preload("homepage_col2_over","/images/boxes/homepage_col2_over.gif");
        preload("homepage_col3_over","/images/boxes/homepage_col3_over.gif");
        preload("case_study_on","/images/caseStudyBgOn.jpg");
        
	try {
  		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}        
        
	preloaded = true;
}

function validateSolarEvaluation(f) {
	if (isBlank(f.name.value)) {
		alert("Please enter your name");
		f.name.focus();
		return false;
	}
	if (isBlank(f.phone.value)) {
		alert("Please enter your phone number");
		f.phone.focus();
		return false;
	}	
	if (isBlank(f.email.value)) {
		alert("Please enter your email address");
		f.email.focus();
		return false;
	}
	if (!isEmail(f.email.value)) {
		alert("Please enter a valid email address");
		f.email.focus();
		return false;
	}	
	return true;
}

function checkContactForm(f) {

    alert("iii");
    if (isBlank(f.ctl00_txtName.value)) {
		alert("You must enter your name");
		f.name.focus();
		return false;
	}
	if (isBlank(f.txtphone.value)) {
		alert("Please enter your phone number");
		f.phone.focus();
		return false;
	}		
	if (isBlank(f.txtemail.value)) {
		alert("You must enter your email address");
		f.email.focus();
		return false;
	}
	if (!isEmail(f.txtemail.value)) {
		alert("Please enter a valid email address");
		f.email.focus();
		return false;
	}	
	if (isBlank(f.txtmessage.value)) {
		alert("You must enter a message");
		f.message.focus();
		return false;
	}	
	return true;
}

function isBlank(v) {
	if ((v.length>0) && (v!=" ")) {
		return false;
	}
	else {
		return true;
	}
}

function isEmail(v) {
	at=v.indexOf('@');
	dot=v.lastIndexOf('.');
	end=v.length;
	subone=v.substring(at+1,dot);
	domainbeforedot=subone.length;
	subtwo=v.substring(dot+1,end);
	domainafterdot=subtwo.length;
   	if (v.indexOf ('@',0) == -1 || v.indexOf ('.',0) == -1  || domainbeforedot < 1 || domainafterdot < 2 ) {
      		return false;
	}
   	else { 
   		return true; 
   	}
}

function switchImage(name,action,id){ 
	if (name.replace("Image","") != id){
		var el 
		el= getElement(name)
		if (action=="on"){
			el.src='/images/navigation/' + name + '_over.gif';
		}
		else{
			el.src='/images/navigation/' + name + '.gif';
		}
	}
}



function showEvo() { 
	if (gblEvoActive)
	{
    		document.getElementById('evoNewsList').style.display = 'block';
    		document.getElementById('industryNewsList').style.display = 'none';
    		msout('rss_industry');
		gblEvoActive = false;
		gblIndActive = true;
   	}
   	return false;
}
function showInd() {
	if (gblIndActive)
	{
    		document.getElementById('evoNewsList').style.display = 'none';
    		document.getElementById('industryNewsList').style.display = 'block';
    		msout('rss_evo');
		gblEvoActive = true;
		gblIndActive = false;
   	}
	return false;   	
}

function getElement(id){
	if(document.all){
		el = document.all(id)
	} else if(document.getElementById){
		el = document.getElementById(id)
	} else {
		el = null
	}
	return el
}

function bookmark(title,url)
{
   if (window.sidebar) 
    { 
	window.sidebar.addPanel(title, url,""); 
    } 
   else if( document.all ) 
   {
 	window.external.AddFavorite( url, title);
   }
   else if( window.opera && window.print )
   {
	return true;
    }
}
