//admin js
function toggleSlide(objname, num){
	//alert(document.getElementById(objname).style.display);
 if(document.getElementById(objname).style.display == "none"){
       document.getElementById(objname).style.display = "block";
  }else{
    // div is not hidden, so slide up
    document.getElementById(objname).style.display = "none";
  }

  for(i=0; i<num; i++){
  	divname = "sub"+i;
  	if(divname != objname){
  		if(document.getElementById(divname).style.display == "block"){
       		document.getElementById(divname).style.display = "none";
  		}
  	}
  }
  
}

function editSlide(divId){
	divname = new Array('thumb', 'editThumb');
 	for(i=0; i<2; i++){
  		if(document.getElementById(divname[i]+divId).style.display == "none"){
       		document.getElementById(divname[i]+divId).style.display = "block";
  		}
  		
  		else{
  			document.getElementById(divname[i]+divId).style.display = "none";
  		}
  	}


}


function editName(divId){
	divname = new Array('nameLink', 'nameEdit', 'editName', 'deleteName');
 	for(i=0; i<4; i++){
  		if(document.getElementById(divname[i]+divId).style.display == "none"){
       		document.getElementById(divname[i]+divId).style.display = "block";
  		}
  		
  		else{
  			document.getElementById(divname[i]+divId).style.display = "none";
  		}
  	}


}




function showResponse(req){
	alert(req.responseText);
}


function updateOrder(list, table){
	var options = {
	method : 'post',
	parameters : 'table='+table+'&list='+list+'&'+Sortable.serialize(list),
	//onComplete: showResponse 
};
	new Ajax.Request('reorder.php', options);
}



//change the label of the quick contact button on open or close of the div
var quickOpenClose = function() { 
	qcBnt = document.getElementById('quickContactButton');
	txt = qcBnt.innerHTML;
	
	if(txt == "Close"){
		qcBnt.innerHTML = "Quick Contact";
	}
	
	else{
		qcBnt.innerHTML = "Close";
	}
	
}; 

 function submitForm(id){
 
 	  
      e = document.getElementById(id);
      e.submit();
  }
  
  
 function verifyForm(){
 	//required = new Array("First Name", "Last Name", "Email", "Street Address", "City", "State", "Zip", "Country", "What architectural style is your home", "What colors are you most comfortable living with", "What is the total estimated budget for this project", "Is your estimated budget amount flexible" );
 	
 	required = new Array("First Name", "Last Name", "Email");
 	problem = new Array();
 	
 	// find out what is up
 	for(i=0; i<required.length; i++){
 		var check = document.getElementById("r"+i).value;
 		if(check == ""){
 			problem[i] = "1";
 		}
 		else{ 
 			problem[i] = "0";
 		}
 	}
 	
 	//look for problems
 	var sendForm = 0;
 	for(i=0; i<required.length; i++){
 		sendForm += problem[i];
 	}
 	
 	//send the form or give a warning
 	if(sendForm > 0){
 	// create warning messaage
 	
 	var warning = "<strong>Please fill out the following fields:</strong> <br/>";
 	for(i=0; i<required.length; i++){
 		if(problem[i]){
 			warning += required[i] +"<br/>"
 		}
 	
 	}
 	
 		
 		document.getElementById("warning").style.display = "block";
 		document.getElementById("warningMessage").innerHTML = warning;
 		//alert(warning);
 	}
 	
 	else{
 		//send the form
 		submitForm('the_form');
 	}
 	
 	
 	
  
  }
  
  
  
  
  function LoadPage(page,usediv) {
         // Set up request varible
         try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
         //Show page is loading
         document.getElementById(usediv).innerHTML = '<img src="../_images/ajax-loader.gif" /> Loading Page...';
         //scroll to top
         scroll(0,0);
         //send data
         xmlhttp.onreadystatechange = function(){
                 //Check page is completed and there were no problems.
                 if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
                        //Write data returned to page
                        document.getElementById(usediv).innerHTML = xmlhttp.responseText;
                 }
         }
         xmlhttp.open("GET", page);
         xmlhttp.send(null);
         //Stop any link loading normaly
         return;
}


function submitQC(){
	name = escape(document.getElementById('qcName').value);
	email = escape(document.getElementById('qcEmail').value);
	phone = escape(document.getElementById('qcPhone').value);
	reason = escape(document.getElementById('qcReason').value);
	comments = escape(document.getElementById('qcComments').value);
	
	string = "?name="+name+"&email="+email+"&phone="+phone+"&reason="+reason+"&comments="+comments;
	
	if(string == "?name=&email=&phone=&reason=&comments="){
		alert("Please fill out the fields.");
	}
	
	else{
		LoadPage('/quick-contact-send.php'+string, 'qcForm');
	}
}


function toggleSlide(objname){
	//alert(document.getElementById(objname).style.display);
 if(document.getElementById(objname).style.display == "none"){
       document.getElementById(objname).style.display = "block";
  }else{
    // div is not hidden, so slide up
    document.getElementById(objname).style.display = "none";
  }

    
}


 function swapImg(id, image){
  	img = document.getElementById(id);
  	img.src = image;
  
  }
  
  
  function baImg(img, caption){
  	
  	//swap img
  	swapImg('imgDetail', img);
  	
  	// swap caption
  	capId = document.getElementById('imgCaption');
  	capId.innerHTML = caption;	
  
  }


