/*****************************************************
 * Common Javascript functions
 *****************************************************/

function doProcess() {
 return void(0)
}

/***********************************************
* Dynamic Countdown script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function cdtime(container, targetdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date()
this.targetdate=new Date(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 60000) //update time every 60 seconds
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this
var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

function formatresults(){
if (this.timesup==false){//if target date/time not yet met
var displaystring="<span class='orange10'>Countdown to <b>Election Day</b><br>"+arguments[0]+" days, "+arguments[1]+" hours, "+arguments[2]+" minutes</span>"
}
else{ //else if target date/time met
var displaystring="Today is Election day!"
}
return displaystring
}

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var rootdomain="http://"+window.location.hostname

function fetchPage(url, containerid) {
 var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
 var loadedobjects=""
 var rootdomain="http://"+window.location.hostname
 var bustcacheparameter=""
 var page_request = false

if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid) {
 if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
 document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs() {
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
// End Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)

function goToCenter(wchCenter) {
	if (wchCenter != 'Click for other Centers') {
		 window.location.href = 'center.' + wchCenter + '.asp';
	}
}

function getItemDetails(itemDetails) {
 itemDetails = itemDetails.split("|")
 document.productDetail.itemId.value = itemDetails[0]
 document.productDetail.itemName.value = itemDetails[1]
 document.productDetail.itemPrice.value = itemDetails[2]
}

function openCart() {
 if (document.getElementById("cartButton").src==rootdomain + '/grfx/cart.open.gradientBg.gif') {
  document.getElementById("cartDetail").style.display='';
  document.getElementById("cartButton").src='/grfx/cart.close.gradientBg.gif';
 } else {
  document.getElementById("cartDetail").style.display='none';
  document.getElementById("cartButton").src='/grfx/cart.open.gradientBg.gif';
 }
}

function submitCart() {
 document.formCart.submit();
}

function showClock() {
 var dte = new Date();
 var hrs = dte.getHours();
 var min = dte.getMinutes();
 var day = dte.getDate();
 var month = dte.getMonth();
 var year = dte.getFullYear();
 var apm;
 var monthname=new Array("Jan","Feb","Mar","April","May","June","July","Aug","Sep","Oct","Nov","Dec");
 if (12 < hrs) {
  apm = "pm";
  hrs -= 12;
 } else {
  apm = "am";
 }
 if (hrs == 0) hrs = 12;
 if (min<=9) min = "0" + min;
 clock = document.getElementById("clockHeader");
 clock.innerHTML = monthname[month] + " " + day + ", " + year + " " + hrs + ":" + min + " " + apm;
}

function openWin(x,width,height) {
 window.open(x,null,"width="+width+",height="+height+",menubar=0,toolbar=0,resizable=0,scrollbars=1");
}

function redirectUrlHelp(url) {
 if (url != 'Select') {
  window.location.href = url;
 }
}

function redirectUrlFooter(url) {
 if (url != '') {
  siteUrl = 'http://' + url 
  //window.location.href = siteUrl;
  window.open(siteUrl);
 }
}

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_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_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 MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


//--------------------------------------------------------------------------------------------------------------------------------------------------------

//													Antonella  Page Java Script

//-------------------------------------------------------------------------------------------------------------------------------------------------------


function mytrim(val)
{
		val1 = "";
		val2="";
		ctrr = 0;
		lngth = val.length;
		for (i=0; i<lngth; i++)
		{
		if (val.charCodeAt(i) != 32)
		{
		for(j=i;j<lngth;j++)
		{
		if (val.charCodeAt(j) != 13 && val.charCodeAt(j) != 10 )
			{
			val1 += val.charAt(j);
			}
		}
		break;
		}
		}
		if (val1 != "")
		{
		lngth = val1.length
		ctrr=lngth;
		for (k=0; k<lngth; k++)
		{
		ctrr=ctrr-1;
		if (val1.charCodeAt(ctrr) != 32)
		{
		for(l=0;l<lngth-k;l++)
		{
		val2 += val1.charAt(l);
		}
		val1=val2;
		break;
		}
		}
		}
		return val1;
}
function IsNumeric(sText)
 {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

 }
function isValidPhoneNumber(numval,message) {
 var valid = "0123456789-";
 var hyphencount = 0;
 var ret_val=true; 
 if (numval.length!=12)
 {
  ret_val =  false;
 }
 if (ret_val)
 {
 for (i=0;i<numval.length;i++)
 {
  if(valid.indexOf(numval.charAt(i))==-1)
   ret_val=false;
  else if ( (i != 3 && i != 7) && !(parseInt(numval.charAt(i)) >= 0 && parseInt(numval.charAt(i)) <=9) )
	ret_val=false;
  }
 if (ret_val && (numval.charAt(3) != "-" || numval.charAt(7) != "-" ))
 {
 ret_val=false;
 }
 }
 if (!ret_val)
 {
 alert(message+"\n The format is 999-999-9999");
 }
 return ret_val;
}

function emptyvalue(x)
{
	if(x.value=="First Name" || x.value=="Last Name" || x.value=="Email ID")
	{
		x.value="";
	}
	
}
function fillValue()
{
	
	if(mytrim(document.contactform.firstname.value)=="")
	{
		  document.contactform.firstname.value="First Name";		
	}
	if(mytrim(document.contactform.lastname.value)=="")
	{
		  document.contactform.lastname.value="Last Name";
	}
	if(mytrim(document.contactform.email.value)=="")
	{
		  document.contactform.email.value="Email ID";
	}
}
function ValidateContact()
{
		if(mytrim(document.contactform.firstname.value)=="" || mytrim(document.contactform.firstname.value)=="First Name")
		{
					  alert("Please enter First Name");
					  document.contactform.firstname.focus();
					  return false;
		}
		if(mytrim(document.contactform.lastname.value)=="" || mytrim(document.contactform.lastname.value)=="Last Name")
		{
					  alert("Please enter Last Name");
					  document.contactform.lastname.focus();
					  return false;
		}
				  
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.contactform.email.value))) {
			  alert("Please enter a valid email address");
			  document.contactform.email.focus();
			  return false;
		}
		if (mytrim(document.contactform.comment.value)=="")
		{
			alert("Please enter Comment");
			document.contactform.comment.focus();
			return false;
		}
		if (mytrim(document.contactform.comment.value).length>5000)
		{
			alert("Please enter Comment below 5000 worlds.");
			document.contactform.comment.focus();
			return false;
		}
		
}

function ValidateSendEmail()
{
		if(mytrim(document.sendemailform.firstname.value)=="")
		{
					  alert("Please enter First Name");
					  document.sendemailform.firstname.focus();
					  return false;
		}
		if(mytrim(document.sendemailform.lastname.value)=="")
		{
					  alert("Please enter Last Name");
					  document.sendemailform.lastname.focus();
					  return false;
		}
				  
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.sendemailform.email.value))) {
			  alert("Please enter a valid email address");
			  document.sendemailform.email.focus();
			  return false;
		}
				
}


function ValidateGetStart()
{
		if(mytrim(document.frmgetstart.firstname.value)=="")
		{
					  alert("Please enter first name");
					  document.frmgetstart.firstname.focus();
					  return false;
		}
		if(mytrim(document.frmgetstart.lastname.value)=="")
		{
					  alert("Please enter last name");
					  document.frmgetstart.lastname.focus();
					  return false;
		}
				  
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.frmgetstart.email.value))) {
			  alert("Please enter a valid email address");
			  document.frmgetstart.email.focus();
			  return false;
		}
		if(mytrim(document.frmgetstart.phone.value)=="")
		{
					  alert("Please enter phone number");
					  document.frmgetstart.phone.focus();
					  return false;
		}
		if(!IsNumeric(document.frmgetstart.phone.value))
		{
					 alert("Please enter valid phone number.");
					  document.frmgetstart.phone.focus();
					  return false;
		}	
				
			
}


function ValidateDataForm()
{
	var checkedCount=0;
	LenOfCheckBox= document.senddata.whatproducts.length;
	if(mytrim(document.senddata.firstname.value)=="")
	{
		  alert("Please enter First Name");
		  document.senddata.firstname.focus();
		  return false;
	}
	if(mytrim(document.senddata.lastname.value)=="")
	{
		  alert("Please enter Last Name");
		  document.senddata.lastname.focus();
		  return false;
	}
	if (document.senddata.state.selectedIndex ==0)
	{
		alert("Please select State")
		document.senddata.state.focus();
		return false;
	}
	if(mytrim(document.senddata.phonenumber.value)=="")
	{
		  alert("Please enter Phone Number");
		  document.senddata.phonenumber.focus();
		  return false;
	}
	if (!isValidPhoneNumber(document.senddata.phonenumber.value,"Please enter valid Phone Number"))
	{
		document.senddata.phonenumber.focus();
		return false;
	}
	var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
	if (!(chkFilter.test(document.senddata.email.value))) {
		  alert("Please enter a valid email address");
		  document.senddata.email.focus();
		  return false;
	}
	
	for (var i=0; i<LenOfCheckBox; i++)
	 {
		var curBox=document.senddata.whatproducts[i];
		checkedCount += (curBox.checked)?1:0;
	 }
	 if (checkedCount == 0)
	 {
		alert("You have to select at least one Product");
 		return false;
	 }
	
	if (document.senddata.numberofitems.selectedIndex ==0)
	{
		alert("Please select Number of Items")
		document.senddata.numberofitems.focus();
		return false;
	}
	if(!mytrim(document.senddata.comments.value)=="")
	{
		  if(document.senddata.comments.value.length>5000)
		  {
			  alert("Please enter comments less than 5000 words");
			  document.senddata.comments.focus();
			  return false;
		  }
	}
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+"="+escape(value)+((expiredays == null) ? "" : ";expires="+exdate.toGMTString());
}

function countdown() {
 var todayVal, displayVal;
 displayVal = document.getElementById("displayVal").value;
 todayVal = parseFloat(displayVal) + 0.012;
 todayVal = todayVal.toFixed(3);
 document.getElementById("displayVal").value = todayVal;
 document.getElementById("countdownRaise").innerHTML = "<b>$" + todayVal + "</b>";
 document.getElementById("countdownRaise").innerHTML = "As of Today <b>$" + todayVal + "</b> is being raised online. What are you waiting for?"
}

function splitwithc(x) {
 var res;
 res=""
 var st=x.split("");
 var le=x.length;
 var count=0
 for (i=le-1;i>=0 ;i-- ) {
  if (count != 3) {
   res= st[i] + res;
   count=count + 1
  } else {
   res= st[i] + "," + res;
   count=1
  }
 }
 return res;
}

