
// This is the flash Embed Script
function ziplineFlash(id,file,width,height){
    var flashinstalled = 0;
    var windows = ControlVersion();
    var flash = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=" + width + " height=" + height + "><param name='wmode' value='transparent' /><param name='movie' value=" + file + " /><param name='quality' value='high' /><embed src=" + file + " quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent' width=" + width + " height=" + height + "></embed></object>";
    
    if(navigator.plugins && navigator.plugins.length){
        x = navigator.plugins['Shockwave Flash'];
        if(x){
            flashinstalled = 2;
        }else{
            flashinstalled = 1;
            if(navigator.plugins['Shockwave Flash 2.0']){
                flashinstalled = 2;
            }
        }
    }else if(navigator.mimeTypes && navigator.mimeTypes.length){
        x = navigator.mimeTypes['application/x-shockwave-flash'];
        if(x && x.enabledPlugin){
            flashinstalled = 2;
        }else{
            flashinstalled = 1;
        }
    } else {
        if(windows != '-1') {
            flashinstalled = 2;    
        } else {
            flashinstalled = 1;
        }
    }

    if(flashinstalled == 2){
        document.getElementById(id).innerHTML = flash;
    }
}

// This function find the broswer/flash type for IE.
function ControlVersion(){
    var version;
    var axo;
    var e;
    try {
        axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
        version = axo.GetVariable('$version');
    } catch (e) {
    }

    if (!version){
        try {

            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
            version = 'WIN 6,0,21,0';    
            axo.AllowScriptAccess = 'always';
            version = axo.GetVariable('$version');

        } catch (e) {
        }
    }
    if (!version){
        try {
            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.3');
            version = axo.GetVariable('$version');
        } catch (e) {
        }
    }

    if (!version) {
        try {
            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.3');
            version = 'WIN 3,0,18,0';
        } catch (e) {
        }
    }
    if (!version) {
        try {
            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
            version = 'WIN 2,0,0,11';
        } catch (e) {
            version = -1;
        }
    }
    return version;
}

function lastUpdate()
{
	var updateDate = "Last Updated: "+document.lastModified;
	return updateDate.substr(0,24);
}

function validEmail(email)
{
	invalidChars = " /:,;"
	
	if (email == "")		// cannot be empty
	{			
		return false
	}
	for (i=0; i<invalidChars.length; i++)   // does it contain any invalid characters?
	{	                                   
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1)
		{
			return false
		}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1)
	{
		return false
	}
	if (email.indexOf("@",atPos+1) != -1)   // and only one "@" symbol
	{	
		return false
	}
	periodPos = email.indexOf(".",atPos)    // and at least one "." after the "@"
	if (periodPos == -1)
	{		                    
		return false
	}
	if (periodPos+3 > email.length)		    // must be at least 2 characters after the "."
	{		                        
		return false
	}
	return true
}

function isNum(passedVal)		// Is this a number?
{					
	if (passedVal == "")
	{
		return false
	}
	for (i=0; i<passedVal.length; i++)
	{
		if (passedVal.charAt(i) < "0")
		{
			return false
		}
		if (passedVal.charAt(i) > "9")
		{
			return false
		}
	}
	
	return true
}

// validate all entries in estimate form
function validateEstimateForm(estimateForm)	
{
	// make sure they enter a Company Name
	if (estimateForm.compName.value == "")
	{
		alert("You must enter a Company Name.");
		estimateForm.compName.focus();
		estimateForm.compName.select();
		return false;
	}	
	
	// make sure they enter a Service address
	if (estimateForm.servAddress.value == "")
	{
		alert("You must enter a Service Address.");
		estimateForm.servAddress.focus();
		estimateForm.servAddress.select();
		return false;
	}
			
	// make sure they enter a City
	if (estimateForm.city.value == "")
	{
		alert("You must enter a City.");
		estimateForm.city.focus();
		estimateForm.city.select();
		return false;
	}
	
	// make sure they enter a Contact name
	if (estimateForm.contactName.value == "")
	{
		alert("You must enter a Contact name.");
		estimateForm.contactName.focus();
		estimateForm.contactName.select();
		return false;
	}
	
	// make sure they enter a Contact phone
	if (estimateForm.contactPhone.value == "")
	{
		alert("You must enter a Contact phone.");
		estimateForm.contactPhone.focus();
		estimateForm.contactPhone.select();
		return false;
	}
	
	// check to see if the contact email is valid
	if (!validEmail(estimateForm.contactEmail.value))
	{
		alert("Invalid Contact E-Mail address.")
		estimateForm.contactEmail.focus()
		estimateForm.contactEmail.select()
		return false
	}
	
	// make sure they enter the Total square feet
	if (estimateForm.sqFeet.value == "")
	{
		alert("You must enter the Total square feet.");
		estimateForm.sqFeet.focus();
		estimateForm.sqFeet.select();
		return false;
	}
	
	// make sure they enter Days per week
	if (estimateForm.daysPerWeek.value == "")
	{
		alert("You must enter Days per week.")
		estimateForm.daysPerWeek.focus();
		estimateForm.daysPerWeek.select();
		return false;
	}

	// If we made it to here, everything's valid, so submit employment form
	estimateForm.submit();
}

// validate all entries in employment form	
function submitIt(employmentForm)	
{
	// make sure they enter a first name
	if (employmentForm.firstName.value == "")
	{
		alert("You must enter a First Name.")
		employmentForm.firstName.focus()
		employmentForm.firstName.select()
		return false
	}	
	
	// make sure they enter a last name
	if (employmentForm.lastName.value == "")
	{
		alert("You must enter a Last Name.")
		employmentForm.lastName.focus()
		employmentForm.lastName.select()
		return false
	}
	
	// make sure they enter a current address
	if (employmentForm.currentAddress.value == "")
	{
		alert("You must enter a Current Address.")
		employmentForm.currentAddress.focus()
		employmentForm.currentAddress.select()
		return false
	}
	
	// make sure they enter a City, State, Zip
	if (employmentForm.cityStateZip.value == "")
	{
		alert("You must enter a City, State, Zip.")
		employmentForm.cityStateZip.focus()
		employmentForm.cityStateZip.select()
		return false
	}
			
	// make sure they enter a homePhone
	if (employmentForm.phoneNumber.value == "")
	{
		alert("You must enter a Phone Numer.")
		employmentForm.phoneNumber.focus()
		employmentForm.phoneNumber.select()
		return false
	}
	
	// check to see if the email is valid
	if (!validEmail(employmentForm.emailAddy.value))
	{
		alert("Invalid E-Mail address.")
		employmentForm.emailAddy.focus()
		employmentForm.emailAddy.select()
		return false
	}

	// If we made it to here, everything's valid, so submit employment form
	employmentForm.submit();
}

// validate all entries in contact form	
function validateContactForm(contactForm)	
{
	// make sure they enter a first name
	if (contactForm.name.value == "")
	{
		alert("You must enter a Name.");
		contactForm.name.focus();
		contactForm.name.select();
		return false;
	}	
	
	// check to see if the email is valid (now using laples)
	//var em = contactForm.mail.value;
	//var temp = new Array();
	//temp = em.split(':');
	//temp[0] = 'E-mail:';
	//temp[1] = 'whatever enetered';

	if (!validEmail(contactForm.Cmail.value))
	{
		alert("Invalid E-Mail address.");
		contactForm.Cmail.focus();
		contactForm.Cmail.select();
		return false;
	}
	
	// make sure they enter a last name
	if (contactForm.msg.value == "")
	{
		alert("You must enter a Message.");
		contactForm.msg.focus();
		contactForm.msg.select();
		return false;
	}	

	// If we made it to here, everything's valid, so submit employment form
	contactForm.submit();
}

// function for scrolling status bar
function scrollit(seed)
{
	var timerTwo;   
	var m1  = "Welcome to Capital Janitorial Services.com.   ";			
	var m2  = "Cleaning the Triangle since 1994.   ";					
	var m3  = "Please fill out a FREE ESTIMATE form.   ";
	var m4  = "Feel free to contact us @ 919-844-7484. ";
	
	var msg=m1+m2+m3+m4;
	var out = " ";
	var c   = 1;

	if (seed > 200)
	{
			seed--;  
			var cmd="scrollit(" + seed + ")";
			timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 200 && seed > 0)
	{
		for (c=0 ; c < seed ; c++)
		{
				out+=" ";
		}
		out+=msg;
		seed--;
		var cmd="scrollit(" + seed + ")";
			window.status=out;
		timerTwo=window.setTimeout(cmd,200);
	}
	else if (seed <= 0)
	{
		if (-seed < msg.length)
		{
				out+=msg.substring(-seed,msg.length);
				seed--;
				var cmd="scrollit(" + seed + ")";
				window.status=out;
				timerTwo=window.setTimeout(cmd,200);
		}
		else
		{
				window.status=" ";
				timerTwo=window.setTimeout("scrollit(200)",75);
		}
	}
}

function getExpiryDate(nodays)
{
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getCookie(cookiename)
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

// set a cookie that has 3 parameters
function setCookie(name,value,duration)
{
	cookiestring=name+"="+escape(value)+";EXPIRES="+getExpiryDate(duration);
 	document.cookie=cookiestring;
 	if(!getCookie(name))
  	{
  		return false;
 	}
 	else
  	{
   		return true;
  	}
}

// set a cookie that has 2 parameters, 3rd is left out so it will be for this session only
function setSessionCookie(name,value)
{
	cookiestring=name+"="+escape(value);
 	document.cookie=cookiestring;
 	if(!getCookie(name))
  	{
  		return false;
 	}
 	else
  	{
   		return true;
  	}
}
	
function counterCookieCheck()				    // see if user has been here before via 'counter' cookie
{
    count = getCookie("counter"); 			    // get the value for the cookie named counter

	if(isNaN(count))     				        // if no cookie is set... 
	{
   		y=setCookie('counter',0,3650);		    // ...set one that expires in 10yrs.
   		count=0;
	}

	count++;
	y=setCookie('counter',count,1);			    // rewrite cookie to reflect # of visits
								
	//document.write("You have visited "+count+" times<br>");    ***test code***	
}

function sessionCookieCheck()                 //see if user has been here during this session
{
    isOnSite = getCookie("session");		    // get the value for the cookie named session

	if(isNaN(isOnSite))     				    // if no cookie is set... 
	{ 
   		y=setSessionCookie('session',1);		// ...set one, here 1 is an arbitrary default value
	}
	if(isOnSite == "" )     				    // if no cookie is set... 
	{  
   		y=setSessionCookie('session',1);		// ...set one, here 1 is an arbitrary default value
	}	
}

function onInit()
{
	preloadImages();                                   <!-- Load all slices -->
	<!-- commented out b/c no major browsers support writing to the status bar by default anymore -->
	//timerONE=window.setTimeout('scrollit(100)',500);   <!-- Start scrolling status bar -->
	counterCookieCheck();					           <!-- Check for counter cookie   --> 
	sessionCookieCheck();					           <!-- Check for session cookie   --> 
	//alert('loaded');  **test code**
}

