/*-------------------------------------------------------------------------------------------
 2010-03-21 NEW 
 2010-10-10 Add contact us form
 2011-07-15 Div Hide toggle div
 2011-12-05 Countdown Days Timer for Home page
***-------------------------------------------------------------------------------------------*/

//	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
//	var filenm = location.href.substring(dir.length,location.href.length+1);
//	var thefile = filenm;

//******************************************************************************* 
//  Toggle show/hide div   http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/
//  toggle5('age30', 'imageDivLink30')
//******************************************************************************* 
function toggle5 (showHideDiv, switchImgTag) {
    var ele = document.getElementById(showHideDiv);
    var imageEle = document.getElementById(switchImgTag);
//	var sPlusIcon = '<img src="../images/icon-plus.gif">';
//	var sMinusIcon = '<img src="../images/icon-minus.gif">';
		var sPlusIcon = '<img src="/images/sitepicts/design2010/icon-plus.gif">';
		var sMinusIcon = '<img src="/images/sitepicts/design2010/icon-minus.gif">';		
		
		if(ele.style.display == "block") {
		    sDisplay = "none";
				sImage = sPlusIcon;
		}
		else {
				sDisplay = "block";
				sImage = sMinusIcon;
		}
 
	ele30 = document.getElementById('age30');
	imageEle30 = document.getElementById('imageDivLink30'); 				
	ele31 = document.getElementById('age31');
	imageEle31 = document.getElementById('imageDivLink31');
	ele32 = document.getElementById('age32');
	imageEle32 = document.getElementById('imageDivLink32'); 				
	ele33 = document.getElementById('age33');
	imageEle33 = document.getElementById('imageDivLink33');
	ele34 = document.getElementById('age34');
	imageEle34 = document.getElementById('imageDivLink34'); 	
	
	ele30.style.display = "none";
	imageEle30.innerHTML = sPlusIcon;	
	ele31.style.display = "none";
	imageEle31.innerHTML = sPlusIcon;
	ele32.style.display = "none";
	imageEle32.innerHTML = sPlusIcon;
	ele33.style.display = "none";
	imageEle33.innerHTML = sPlusIcon;
	ele34.style.display = "none";
	imageEle34.innerHTML = sPlusIcon;		

 	ele.style.display = sDisplay;	
 	imageEle.innerHTML = sImage;
     
}

//******************************************************************************* 
//  Toggle show/hide div   http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/
//******************************************************************************* 
function toggle5X (showHideDiv, switchImgTag) {
        var ele = document.getElementById(showHideDiv);
        var imageEle = document.getElementById(switchImgTag);
        if(ele.style.display == "block") {
                ele.style.display = "none";
		imageEle.innerHTML = '<img src="../images/icon-plus.gif">';
        }
        else {
                ele.style.display = "block";
                imageEle.innerHTML = '<img src="../images/icon-minus.gif">';
        }
}

function doContact ( form ) {	
//******************************************************************************* 
//  CONTACT US FORM
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "pc@twistedpixel.com";			// Default receipient 
 
 	if (spaceTrim(document.MailForm.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.MailForm.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
  	sEmail = spaceTrim(document.MailForm.Email.value);
		if (document.MailForm.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.MailForm.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Email address\n"} 
//	}
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.MailForm.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		
 	  	document.MailForm.mailto.value = sEmailto;
		
		if (testFlag == 1) {
			document.MailForm.mailto.value = "pc@twistedpixel.com";
			document.MailForm.Email.value 		= "pc@twistedpixel.com"; 
		}
 
 		document.MailForm.bcc.value = "pc@twistedpixel.com";			 	 	
 
	  sSubject = "CEDAR BRAE - CONTACT US";
 	  	
		document.MailForm.mailsubject.value = sSubject;
 
		document.MailForm.returnto.value =  "index.cfm?ID=512";
 		document.MailForm.action = "submaster.cfm?aPage=sendmailform.cfm";  	
 		
  	document.MailForm.method = "POST";
	  document.MailForm.submit()
 		return(0); 	
   }  
}

 
function setCookie(c_name,value,expiredays)
//*******************************************************************************
//	SET COOKIE  from http://www.w3schools.com/js/js_cookies.asp
//*******************************************************************************
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name) {

	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 
	    c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
	return ""
} 

function get_random(pcount) {
    var ranNum= Math.round(Math.random()* pcount);
    return ranNum;
}	

 function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1, 
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}

/*--------------------------------------------------------
Count down until any date script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
--------------------------------------------------------*/
//change the text below to reflect your own,
var before="Valentines day!"
var current=""
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
	var today=new Date()
	var todayy=today.getYear()
	if (todayy < 1000)
		todayy+=1900
	var todaym=today.getMonth()
	var todayd=today.getDate()
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy
	var futurestring=montharray[m-1]+" "+d+", "+yr
	var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
	if (difference <= 0)
	//	document.write(current)
		document.write(difference)
	else if (difference>0)
	//document.write("Only "+difference+" days until "+before)
		document.write(difference)
}
//enter the count down date using the format year/month/day
//countdown(2010,2,1)
