/*
$(document).ready(function() {


})
*/

function idGet(item) {
  return document.getElementById(item); 
}

function showList( passId ) {
  if( idGet(passId).className != 'on' ) {
    idGet(passId).className = 'on';
  }
  else {
    idGet(passId).className = 'off';
  }
}

function exchange(li) {
  li.parentNode.parentNode.firstChild.nodeValue = li.firstChild.nodeValue;
  var end = li.firstChild.nodeValue.length - 2;
  idGet('distance').value = li.firstChild.nodeValue.substring(0,end);
}



// some AJAX that might need to be re-done

var ajaxRequest;

function makeRequest() { 
  try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
}

function executeRequest() {
  ajaxRequest.onreadystatechange = function(){
   	if(ajaxRequest.readyState == 0){ //uninitialized
     }
   	
     else if(ajaxRequest.readyState == 1){ //loading 
       idGet('search-box').innerHTML = '<h1 style="text-align:center;">Loading...</h1>';
     }
     
     else if(ajaxRequest.readyState == 2){ } //loaded
     
     else if(ajaxRequest.readyState == 3){ } //interactive
   
     else if(ajaxRequest.readyState == 4){ //complete
   	  idGet('search-box').innerHTML = ajaxRequest.responseText;
 	    writeMap("float-holder");
     }
   }  
}

function searchBox( imageId ) {
  addBox();
  
  if ( idGet('flash-holder') ) {
    writeBlank(); 
  }
	makeRequest();  
	executeRequest();
	
  ajaxRequest.open('GET', '/php/search.php', true);
  ajaxRequest.send(null); 
}

var shadeCount = 0;
var shadeIntvl;

function addBox( topMargin ) {
  var wrap = idGet('shell');
  var shade = document.createElement('div');
  shade.id = 'shader';
  shade.style.opacity = '.00';
  shade.style.filter = 'alpha(opacity=00)';
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
    shade.style.background = "#a6f8ff";
  }
  shade.style.height = document.body.offsetHeight + 'px';
  shade.style.width = document.body.offsetWidth + 'px';
    
  
  var box = document.createElement('div');
  box.id = 'search-box';
  if ( topMargin != null && topMargin != 0 ) {
    box.style.marginTop = topMargin + 'px'; 
  }
  
  wrap.appendChild(box);  
  wrap.appendChild(shade);
  
  
  shadeCount = 0;
  shadeIntvl = setInterval( 'shadeIn()' , 10);
  scrollPage('search-box');
}

function shadeIn() {
  shadeCount += 15;
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
    if ( shadeCount >= 85 ) {
      idGet('shader').style.filter = 'alpha(opacity=85)'; 
      clearInterval(shadeIntvl);
      //scrollPage('search-box');
    }
    idGet('shader').style.filter = 'alpha(opacity=' + shadeCount + ')';
  }
  else {
    if ( shadeCount >= 100 ) {
      idGet('shader').style.opacity = '1'; 
      clearInterval(shadeIntvl);
      //scrollPage('search-box');
    }
    else if ( shadeCount >= 10 ) {
      idGet('shader').style.opacity = '.' + shadeCount;
    }
    else {
      idGet('shader').style.opacity = '.0' + shadeCount;  
    }
//    idGet('shader').style.opacity = '.' + shadeCount;
  }
}

function writeMap(place) {
  if ( idGet(place) ) {
    var so = new SWFObject("../flash/map.swf", "map", "630", "430", "8", "#ffffff");
    if ( place == "flash-holder") {
      so.addParam("wmode", "transparent");
    }
    else {
      so.addParam("wmode", "opaque"); 
    }
    so.write(place); 
  }
}

function writeBlank() {
  var flash = idGet('flash-holder');
  flash.innerHTML = '';
}

function closeMap() {
  var shade = idGet('shader');
  var box = idGet('search-box');
  var wrap = idGet('shell');
  
  wrap.removeChild(shade);
  wrap.removeChild(box);

  if ( idGet('flash-holder') ) {
    writeMap('flash-holder');
  } 
}

function showDescription() {
  var desc = idGet('class-description');
  var h2 = idGet('class');
    
  desc.className = 'on';
  desc.style.width = h2.offsetWidth + 'px';
  desc.style.left = (h2.offsetLeft + 15 ) + 'px';
  desc.style.top = (h2.offsetTop + 35 ) + 'px';
}

function noDescription() {
  var desc = idGet('class-description');
    
  desc.className = '';
  desc.style.width = '0px';
  desc.style.left = '-9999px';
}

function showSubStars($number) {
  var stars = idGet('sub-stars-' + $number);
  var liveStars = idGet('live-stars-' + $number);
    
  stars.className = 'sub-stars on';
  //stars.style.width = liveStars.offsetWidth + 'px';
  stars.style.width = '530px';
  stars.style.left = (liveStars.offsetLeft - 535 ) + 'px';
  stars.style.top = (liveStars.offsetTop - 60 ) + 'px';
}

function noSubStars($number) {
  var stars = idGet('sub-stars-' + $number);
    
  stars.className = 'sub-stars';
  stars.style.width = '0px';
  stars.style.left = '-9999px';
}

function brandsBox( storeId ) {
  addBox();

	makeRequest(); 
	executeRequest(); 

  ajaxRequest.open('GET', '/php/brands.php?id=' + storeId, true);
  ajaxRequest.send(null); 
}

function descriptionBox( box ) {
  addBox();

	switch(box) {
		case 'certification':
			idGet('search-box').innerHTML = '<div class="pop-top"><a href="javascript:closeMap();" class="closer hidden">close</a></div><div class="box-inside"><h4 class="top-adjust">Certification Process</h4><p>For a store to be listed as a Certified Store on BabyProductExperts.com, the store was mystery shopped and evaluated by an independent Retail Evaluation Service familiar with the juvenile industry.  Only stores with a passing score have the opportunity to be listed on our site.</p><p>Each store was graded on the following categories: Telephone Etiquette, Store Appearance, Associate Greeting, Product Knowledge and Customer Service. The evaluations are used not only to certify a store but also to improve the stores future performance.</p> <p>We hope that you will use the information on our site and visit your local juvenile specialty stores very soon.  In fact, we hope that you come back to our site and provide any feedback after your store visit.  Thanks for visiting BabyProductExperts.com.</p><a class="find-store hidden" href="javascript:closeMap();searchBox();">Find a Store</a></div><div class="pop-bot"></div>';
		break;
		case 'detailed':
			idGet('search-box').innerHTML = '<div class="pop-top"><a href="javascript:closeMap();" class="closer hidden">close</a></div><div class="box-inside"><h4 class="top-adjust">Detailed Store Information</h4><p>Each store listed on our site will also provide detail store information regarding its showroom size, major brands carried, and the various services offered.  This information is very useful and will allow a customer to learn more about a store before leaving home.</p><a class="find-store hidden" href="javascript:closeMap();searchBox();">Find a Store</a></div><div class="pop-bot"></div>';		
		break;
		case 'reviews':
			idGet('search-box').innerHTML = '<div class="pop-top"><a href="javascript:closeMap();" class="closer hidden">close</a></div><div class="box-inside"><h4 class="top-adjust">Consumer Reviews</h4><p>We encourage consumers to review our stores after their store visit to provide constructive feedback to our stores so that we continually try to improve our customer service and performance.</p><a class="find-review hidden" href="javascript:closeMap();searchBox();">Find a Store to Review</a></div><div class="pop-bot"></div>';				
		break;
		
	
	}
	
}

function registerBox( email ) {
  addBox(175);

	makeRequest(); 
	executeRequest(); 

  ajaxRequest.open('GET', '/php/register.php?email=' + email, true);
  ajaxRequest.send(null); 
}

var lastcount = 0;

function kidCount( kids ) {
  var kidsCount = parseInt(kids);
  run = true;
  
  
  if ( kidsCount == 0 ) {
  	kidsCount = 0;
  	run = false;
  	lastcount = kidsCount;
  	var kidHole = idGet('kid-hole');
  	kidHole.innerHTML = '';
  }
  else if ( kidsCount < 1 ) {
    kidsCount = 1;
    idGet('number').value = kidsCount;
  }
  else if ( kidsCount > 6 ) {
    kidsCount = 6; 
    idGet('number').value = kidsCount;
  }
  else if ( kidsCount != 1 && kidsCount != 2 && kidsCount != 3 && kidsCount != 4 && kidsCount != 5 && kidsCount != 6 ) {
    run = false;
  }
  
  if ( run ) {
    var i = lastcount;
    var kidHole = idGet('kid-hole');
    
    if ( i > kidsCount ) {
      while ( i > kidsCount ) {
        kidHole.removeChild(idGet('child_' + (i-1)));
        i--;
      }    
    } 
    
    else if ( kidsCount > i ) {
      while ( i < kidsCount ) {
        var tempDiv = document.createElement('div');
        tempDiv.id = 'child_' + i;
        tempDiv.className = 'child-box';
//        tempDiv.innerHTML += 'Date of Birth<input type="text" class="text zip" id="date_of_birth_' + i + '" name="date_of_birth_' + i + '" /> Gender: <input type="radio" class="radio" id="gender_' + i + '" name="gender_' + i + '" value="male" />Male <input type="radio" class="radio" name="gender_' + i + '" id="gender_' + i + '" value="female" />Female';
        tempDiv.innerHTML += '<div class="block" style="width:200px;">Date of Birth<br /><select id="date_of_birth_month_' + i + '" name="date_of_birth_month_' + i + '">' +
        											'<option value="01">01</option>' +
        											'<option value="02">02</option>' +
        											'<option value="03">03</option>' +
        											'<option value="04">04</option>' +
        											'<option value="05">05</option>' +
        											'<option value="06">06</option>' +
        											'<option value="07">07</option>' +
        											'<option value="08">08</option>' +
        											'<option value="09">09</option>' +
        											'<option value="10">10</option>' +
        											'<option value="11">11</option>' +
        											'<option value="12">12</option>' +
        										 '</select>' +
        										 
        										 '<select id="date_of_birth_day_' + i + '" name="date_of_birth_day_' + i + '">' +
        											'<option value="01">01</option>' +
        											'<option value="02">02</option>' +
        											'<option value="03">03</option>' +
        											'<option value="04">04</option>' +
        											'<option value="05">05</option>' +
        											'<option value="06">06</option>' +
        											'<option value="07">07</option>' +
        											'<option value="08">08</option>' +
        											'<option value="09">09</option>' +
        											'<option value="10">10</option>' +
        											'<option value="11">11</option>' +
        											'<option value="12">12</option>' +
        											'<option value="13">13</option>' +
        											'<option value="14">14</option>' +
        											'<option value="15">15</option>' +
        											'<option value="16">16</option>' +
        											'<option value="17">17</option>' +
        											'<option value="18">18</option>' +
        											'<option value="19">19</option>' +
        											'<option value="20">20</option>' +
        											'<option value="21">21</option>' +
        											'<option value="22">22</option>' +
        											'<option value="23">23</option>' +
        											'<option value="24">24</option>' +
        											'<option value="25">25</option>' +
        											'<option value="26">26</option>' +
        											'<option value="27">27</option>' +
        											'<option value="28">28</option>' +
        											'<option value="29">29</option>' +
        											'<option value="30">30</option>' +
        											'<option value="31">31</option>' +
        										 '</select>' +
        										 
        										 '<select id="date_of_birth_year_' + i + '" name="date_of_birth_year_' + i + '">' +
        											'<option value="2009">2009</option>' +
        											'<option value="2008">2008</option>' +
        											'<option value="2007">2007</option>' +
        											'<option value="2006">2006</option>' +
        											'<option value="2005">2005</option>' +
        											'<option value="2004">2004</option>' +
        											'<option value="2003">2003</option>' +
        											'<option value="2002">2002</option>' +
        											'<option value="2001">2001</option>' +
        											'<option value="2000">2000</option>' +
        											
        											'<option value="1999">1999</option>' +
        											'<option value="1998">1998</option>' +
        											'<option value="1997">1997</option>' +
        											'<option value="1996">1996</option>' +
        											'<option value="1995">1995</option>' +
        											'<option value="1994">1994</option>' +
        											'<option value="1993">1993</option>' +
        											'<option value="1992">1992</option>' +
        											'<option value="1991">1991</option>' +
        											'<option value="1990">1990</option>' +
        											
        											'<option value="1989">1989</option>' +
        											'<option value="1988">1988</option>' +
        											'<option value="1987">1987</option>' +
        											'<option value="1986">1986</option>' +
        											'<option value="1985">1985</option>' +
        											'<option value="1984">1984</option>' +
        											'<option value="1983">1983</option>' +
        											'<option value="1982">1982</option>' +
        											'<option value="1981">1981</option>' +
        											'<option value="1980">1980</option>' +
        											
        											'<option value="1979">1979</option>' +
        											'<option value="1978">1978</option>' +
        											'<option value="1977">1977</option>' +
        											'<option value="1976">1976</option>' +
        											'<option value="1975">1975</option>' +
        											'<option value="1974">1974</option>' +
        											'<option value="1973">1973</option>' +
        											'<option value="1972">1972</option>' +
        											'<option value="1971">1971</option>' +
        											'<option value="1970">1970</option>' +

        										 
        										 '</select></div><div class="block">Gender<br /><input type="radio" class="radio" id="gender_' + i + '" name="gender_' + i + '" value="male" />Male ' + 
        										 '<input type="radio" class="radio" name="gender_' + i + '" id="gender_' + i + '" value="female" />Female</div><div class="destroyer"></div>';
        kidHole.appendChild(tempDiv);
        i++;
      }
    } 
    lastcount = kidsCount;
  }
}

function registerInline( ourForm ) {
  idGet(ourForm).innerHTML = '<h2 style="text-align:center;">Thank you for registering with us.</h2>';
}

function showReview() {
  var space = idGet('review');
  var btn = idGet('add-button');
  
  btn.style.display = "none";
  space.style.height = "auto";
}

function videoBox(videoURL, videoName, stillName) {
  addBox(200);
	
	idGet('search-box').innerHTML = '<div class="pop-top"><a href="javascript:closeMap();" class="closer hidden">close</a></div><div class="box-inside" style="text-align:center;"><h4 class="top-adjust">'+ videoName + '</h4><div id="video-holder"></div></div><div class="pop-bot"></div>';
	
	writeMovie(videoURL, stillName);
	
}

function youtubeBox(videoCode, videoName, stillName) {
  addBox(200);
  
  var newCode = videoCode.replace("\'", "'");
	
	idGet('search-box').innerHTML = '<div class="pop-top"><a href="javascript:closeMap();" class="closer hidden">close</a></div><div class="box-inside" style="text-align:center;"><h4 class="top-adjust">'+ videoName + '</h4><div id="video-holder" class="youtube">' + newCode + '</div></div><div class="pop-bot"></div>';
	
	//writeMovie(videoURL, stillName);
	
}

function writeMovie(videoURL, stillName) {
  var so = new SWFObject( "bpe_store/videos/store_video.swf", "video", "480", "310", "8", "#ffffff");
  so.addVariable("still_url","../images/screenshot_"+ stillName +".jpg");
  so.addVariable("movie_url", videoURL );
  so.addParam("wmode", "transparent");
  so.useExpressInstall("expressinstall.swf");
  so.write("video-holder");  
}

function photoBox( imageArray, total ) {
  addBox();
  
  var currImage = 0;
  total--;
  
  //imageURL += 'full_';
  
  var output =  '<div class="pop-top">' +
                ' <a href="javascript:closeMap();" class="closer hidden">close</a>' +
                '</div>' +
                '<div id="photobox" class="box-inside registerme" style="text-align:center;" >' +
                ' <img id="photo-0" src="' +imageArray[0]  + '" class="on" />';
                
  for ( var i = 1; i<imageArray.length; i++ ) {
    output += ' <img id="photo-' + i + '" src="' + imageArray[i]  + '" class="off" />';
  }
              
  if ( total > 0 ) {
    output += '<div id="navi"><a class="photo-block right" href="javascript:nextPhoto( ' + currImage + ', ' + total +  ');">Next</a></div>';
  }
                
                //' <div id="photobox" class="box-inside registerme" style="text-align:center;">';
                
                
                
  /*                
                
  output += '<img src="' + imageArray[currImage] + '" /><br />' + imageArray[currImage];
  
  if ( total > 1 ) {
    output += '<script type="text/javascript">' +
              ' var imageArrayTemp = new Array();';
    
    for ( var i = 0; i<imageArray.length; i++ ) {
      output += '   imageArrayTemp[' + i + '] = "' + imageArray[i] + '";';
    }
    
    output += '</script>' +
              '<a class="photo-block right" href="javascript:nextPhoto( imageArrayTemp, ' + currImage + ', ' + total +  ');">Next</a>';
  }
           */
  output += '<div class="destroyer"></div>' +
            '</div>' +
            '<div class="pop-bot"></div>';
   
  
  idGet('search-box').innerHTML = output;
  
}

function nextPhoto( currImage, total ) {
  currImage++;
  
  //var output = '<img src="' + imageArray[currImage] + '.jpg" /><br />' + imageArray[currImage];
  
  idGet('photo-' + ( currImage - 1 )).className="off";  
  idGet('photo-' + currImage).className="on";
  
  var output ='';  
  if ( currImage > 0 ) {
    output += '<a class="photo-block" href="javascript:lastPhoto(' + currImage + ', ' + total +  ');">Previous</a>';
  }   
  if ( currImage < total ) {
    output += '<a class="photo-block right" href="javascript:nextPhoto(' + currImage + ', ' + total +  ');">Next</a>';
  }

  output += '<div class="destroyer"></div>';

  idGet('navi').innerHTML = output;
}

function lastPhoto( currImage, total ) {
  currImage--;
  
  //var output = '<img src="' + imageArray[currImage] + '.jpg" /><br />' + imageArray[currImage];
  
  idGet('photo-' + ( currImage + 1 )).className="off";  
  idGet('photo-' + currImage).className="on";  
  
  var output = '';
  if ( currImage > 0 ) {
    output += '<a class="photo-block" href="javascript:lastPhoto(' + currImage + ', ' + total +  ');">Previous</a>';
  }  
  if ( currImage < total ) {
    output += '<a class="photo-block right" href="javascript:nextPhoto(' + currImage + ', ' + total +  ');">Next</a>';
  }
  
  output += '<div class="destroyer"></div>';
  
  idGet('navi').innerHTML = output;  
}

var windowScroll;
var windowPos;
var windowStop;

function scrollPage( id ) {
	clearScroll();
		
	windowPos = window.pageYOffset;
	//windowPos = document.documentElement.scrollTop;
	//windowPos = document.body.scrollTop;
	
	windowStop = idGet(id).offsetTop;
  //alert(idGet(id).offsetTop);
	
	windowScroll = setInterval( 'scrollin()' , 10);
}

function scrollin() {
	if ( windowPos < ( windowStop - 9 ) ) {
		windowPos += 10;
		scroll(0, windowPos);
	}
	else if ( windowPos > ( windowStop + 9 ) ) {
		windowPos -= 10;
		scroll(0, windowPos);
	}
	else {
		scroll(0, windowStop);
		clearScroll();
	}
}
function clearScroll() {
	clearInterval(windowScroll);
}

function viewBPERating(storeID, starCount) {
  addBox();

	makeRequest(); 
	executeRequest(); 

  ajaxRequest.open('GET', '/php/bpe_score.php?store_id=' + storeID + '&starcount=' + starCount, true);
  ajaxRequest.send(null);  
}

function editOwner(id) {
  addBox();
	makeRequest(); 
	executeRequest(); 
	url = '/php/edit_owner.php';
	if ( id != 0 ) {
		url += '?owner=' + id;
	}
  ajaxRequest.open('GET', url, true);
  ajaxRequest.send(null);  
}

function checkRegistration() {
  if ( idGet('password') ) {
    if ( idGet("password").value != idGet("confirm-password").value ) {
      idGet("confirm-password").value = null;
      idGet("error_confirm-password").innerHTML = "Passwords must match";
    }
  }

  validateForm("owner-register");
}

function saveEdit() {
  var spans = idGet('owner-register').getElementsByTagName('span');
  var i = 0;
  var saveEdits = true;
  
  for ( i = 0; i < spans.length; i++ ) {
    if ( spans[i].style.display ==  'block' && spans[i].id != 'error_save' ) {
      saveEdits = false;
    }
  }
  
  if ( saveEdits ) {
    var owner = new Array();
    var address = new Array();
    
    owner["email"] = idGet("email").value;	
    owner["first_name"] = idGet("first_name").value;
    owner["last_name"] = idGet("last_name").value;
    owner["title"] = idGet("title").value;
    owner["phone_number"] = idGet("phone_number").value;
    
    address["address_id"] = idGet("address_id").value;
    address["address1"] = idGet("address1").value;
    address["address2"] = idGet("address2").value;
    address["city"] = idGet("city").value;
    address["state"] = idGet("state").value;
    address["zip_code"] = idGet("zip_code").value;	
	  address["phone_number"] = idGet("phone_number").value;  
    
  	makeRequest();
  	
    ajaxRequest.onreadystatechange = function(){
     	if(ajaxRequest.readyState == 0){ //uninitialized
       }
     	
       else if(ajaxRequest.readyState == 1){ //loading 
         idGet('box-inside').innerHTML = '<h1 style="text-align:center;">Saving...</h1>';
       }
       
       else if(ajaxRequest.readyState == 2){ } //loaded
       
       else if(ajaxRequest.readyState == 3){ } //interactive
     
       else if(ajaxRequest.readyState == 4){ //complete
     	  idGet('box-inside').innerHTML = ajaxRequest.responseText;
       }
     }  
 
    var query = '/php/save_owner.php?email=' + owner["email"] + '&first_name=' + owner["first_name"] + '&last_name=' + owner["last_name"] + '&title=' + owner["title"] + '&phone_number=' + owner["phone_number"];
    query+= '&address1=' + address["address1"] + '&address2=' + address["address2"] + '&city=' + address["city"] + '&state=' + address["state"] + '&zip_code=' + address["zip_code"] + '&address_id=' + address["address_id"];
    
    ajaxRequest.open('GET', query, true);
    ajaxRequest.send(null);   
  }
}

function storeHours(id) {
  addBox(175);

	makeRequest(); 
	executeRequest(); 

  ajaxRequest.open('GET', '/php/hours.php?id=' + id, true);
  ajaxRequest.send(null); 
}

function checkZip(zipField, zipFormName){
  var zipInput = idGet(zipField);
  var zipForm = idGet(zipFormName);
  
  if ( zipInput.value != '' && zipInput.value != 'ZIP' ) {
    zipForm.submit();
  }
}

function checkCountry(countryForm){
  countryForm.submit();
}

function zipFade( zipField, zipButton ) {
  var zipInput = idGet(zipField);
  var zipButton = idGet(zipButton);
  
  if ( zipInput.value != '' && zipInput.value != 'ZIP' ) {
    zipButton.className = 'home-go';
  }
  else {
    zipButton.className = 'home-go fade';
  }
}

function checkName(nameField, nameFormName){
  var nameInput = idGet(nameField);
  var nameForm = idGet(nameFormName);
    
  if ( nameInput.value != '' && nameInput.value != 'Enter Store Name' ) {
    nameForm.submit(); 
  }
}

function nameFade( nameField, nameButton){
  var nameInput = idGet(nameField);
  var nameButton = idGet(nameButton);
  
  if ( nameInput.value != '' && nameInput.value != 'Enter Store Name' ) {
    nameButton.className = 'home-go'; 
  }
  else {
    nameButton.className = 'home-go fade';
  }
}

var oldId = 'furniture';

function showCategory( divId ) {
   if ( idGet(oldId) ) {
    idGet(oldId).className = 'hide-brand';
   }

   oldId = divId;   
   idGet(divId).className = 'hide-brand on';
}

function initOwnerStore() {
  $('#logo-link').click( function(event) { 
    event.preventDefault();
    addBox(175);
  } );
}


var DAY;
var SUPERSTATE;
var TEXTDAY;

function timePicker( dayId, state, textDay ) {
  DAY = dayId;
  SUPERSTATE = state;
  TEXTDAY = textDay;
  idGet('time-box').style.top = idGet('hours-box').offsetTop + 'px';
  idGet('time-box').style.left = (idGet(textDay + '-' + state).offsetLeft + 100) + 'px';
  idGet(textDay + '-' + state).className = 'static-time on';
  //idGet('time-box').style.left = '50%';
  //alert(idGet('hours-box').offsetTop + 'px');
  
}

function timePicked( time, properTime, timePM ) {
  idGet('time-box').style.left = '-9999px';
  
  if ( idGet('am').checked ) {
    idGet(TEXTDAY + '-' + SUPERSTATE).innerHTML = properTime + ' AM';
    idGet( SUPERSTATE + '-' + DAY ).value = time;
  }
  else {
    idGet(TEXTDAY + '-' + SUPERSTATE).innerHTML = properTime + ' PM';     
    idGet( SUPERSTATE + '-' + DAY ).value = timePM;    
  }
  
  idGet(TEXTDAY + '-' + SUPERSTATE).className = 'static-time';
  if ( idGet(TEXTDAY + '-closed').checked ) {
    closeCheck( DAY, TEXTDAY );
  }
}

function closeTime() {
  idGet('time-box').style.left = '-9999px';  
  idGet(TEXTDAY + '-' + SUPERSTATE).className = 'static-time';  
}

function closeCheck( numDay, textDay ) {
  var isChecked = idGet(numDay + '-closed').checked;
  var openTime = idGet('open-' + numDay);
  var closeTime = idGet('close-' + numDay);  
  
  if ( isChecked ) {
    openTime.disabled = true;
    closeTime.disabled = true;    
  }
  else {
    openTime.disabled = false;
    closeTime.disabled = false;    
  }
  /*
  if ( isChecked ) {
    idGet('open-' + numDay).value = '00:00:00';
    idGet('close-' + numDay).value = '00:00:00';
    idGet(textDay + '-open').innerHTML = 'Closed';
    idGet(textDay + '-close').innerHTML = 'Closed';
  }
  else {
    idGet('open-' + numDay).value = '09:00:00';
    idGet('close-' + numDay).value = '18:00:00';
    idGet(textDay + '-open').innerHTML = '9:00 AM';
    idGet(textDay + '-close').innerHTML = '5:00 PM';    
  }
  */
}

function killImage(store_id, image_id, owner_id) {
	addBox();

	makeRequest(); 
	executeRequest(); 
	url = '/php/delete_image.php?store_id=' + store_id + '&image_id=' + image_id;
	
	if ( owner_id != 0 ) {
		url += '&owner=' + owner_id;
	}
	
	ajaxRequest.open('GET', url, true);
	ajaxRequest.send(null); 
}




