//Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'

function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

//ACCESSIBLE VARIABLES (for use within your callback functions):
//1) ajaxpack.ajaxobj //points to the current ajax object
//2) ajaxpack.filetype //The expected file type of the external file ("txt" or "xml")
//3) ajaxpack.basedomain //The root domain executing this ajax script, taking into account the possible "www" prefix.
//4) ajaxpack.addrandomnumber //Set to 0 or 1. When set to 1, a random number will be added to the end of the query string of GET requests to bust file caching of the external file in IE. See docs for more info.

//ACCESSIBLE FUNCTIONS:
//1) ajaxpack.getAjaxRequest(url, parameters, callbackfunc, filetype)
//2) ajaxpack.postAjaxRequest(url, parameters, callbackfunc, filetype)

///////////END OF ROUTINE HERE////////////////////////


//////EXAMPLE USAGE ////////////////////////////////////////////
/* Comment begins here

//Define call back function to process returned data
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}

/////1) GET Example- alert contents of any file (regular text or xml file):

ajaxpack.getAjaxRequest("example.php", "", processGetPost, "txt")
ajaxpack.getAjaxRequest("example.php", "name=George&age=27", processGetPost, "txt")
ajaxpack.getAjaxRequest("examplexml.php", "name=George&age=27", processGetPost, "xml")
ajaxpack.getAjaxRequest(ajaxpack.basedomain+"/mydir/mylist.txt", "", processGetPost, "txt")

/////2) Post Example- Post some data to a PHP script for processing, then alert posted data:

//Define function to construct the desired parameters and their values to post via Ajax
function getPostParameters(){
var namevalue=document.getElementById("namediv").innerHTML //get name value from a DIV
var agevalue=document.getElementById("myform").agefield.value //get age value from a form field
var poststr = "name=" + encodeURI(namevalue) + "&age=" + encodeURI(agevalue)
return poststr
}

var poststr=getPostParameters()

ajaxpack.postAjaxRequest("example.php", poststr, processGetPost, "txt")
ajaxpack.postAjaxRequest("examplexml.php", poststr, processGetPost, "xml")

Comment Ends here */	







var catering = '';
	var filterparam ='';
	var	order_by = '';
	var	asc_by = '';
	var	key;
	var	tot_ph = 0;
	var	temp = 0;
	
	

	function disableEnterKey(e)
	{
			 var key;      
			 if(window.event){  
			 key = window.event.keyCode; //IE
			 }
			 else { 
			 key = e.which; //firefox 
			 }     
		
			 return (key != 13);
	}
		
		
		function capWords(fo,p) {
		
			 
		var f 	= document.getElementById(fo);

		var p = f[p]; // The input text field
		var inputString = p; // The input text field
		

		var tmpStr, tmpChar, preString, postString, strlen;
		tmpStr = inputString.value.toLowerCase();
		stringLen = tmpStr.length;
		if (stringLen > 0)
		{
		  for (i = 0; i < stringLen; i++)
		  {
			if (i == 0)
			{
			  tmpChar = tmpStr.substring(0,1).toUpperCase();
			  postString = tmpStr.substring(1,stringLen);
			  tmpStr = tmpChar + postString;
			}
			else
			{
			  tmpChar = tmpStr.substring(i,i+1);
			  if (tmpChar == " " && i < (stringLen-1))
			  {
			  tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
			  preString = tmpStr.substring(0,i+1);
			  postString = tmpStr.substring(i+2,stringLen);
			  tmpStr = preString + tmpChar + postString;
			  }
			}
		  }
		}
		inputString.value = tmpStr;
		
 		}
		


	function EditPost(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
				
 				 
				 if (myajax.responseText !== 0){
 					 
					 $(".msg_saved").animate({opacity: 1.0}, 400);
					 $(".msg_saved").fadeIn("fast");
					 $(".msg_saved").animate({opacity: 1.0}, 800);
					 $(".msg_saved").fadeOut("fast");
					 
					 $("#btn_save").fadeOut("fast");					
					 $("#btn_save").animate({opacity: 1.0}, 1600);
					 $("#btn_save").fadeIn("fast");					
					 
				} 
			}
		}
	}
	
	 
 

	function processSend(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){  
				var valo = Number(myajax.responseText);
 				if (valo == 0){  

					} else{ 
					
						$("#theform").fadeOut("fast");
						$("#thefeedback").animate({opacity: 1.0}, 1300);
						$("#thefeedback").fadeIn("fast");

					}
			}
		}
	}
	 


	function updatePost(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
		//alert(myajax.responseText);
 		    refreshit();
			}
		}
	}




	function processGetPost(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){  
		//alert("c");
		
				var valo = Number(myajax.responseText);
 				if (valo == 0){  
					 document.getElementById("container_temp").innerHTML = "No results."; 
					 document.getElementById("container").innerHTML = "";
					 
					} else{ 
					 document.getElementById("container").innerHTML = myajax.responseText;
					 document.getElementById("container_temp").innerHTML = ""; 
				}

			}
		}
	}
	 

 
	function processAddPost(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
			// alert(myajax.responseText);			
							eval("window.location='"+paramAddPost2+".php?"+paramAddPost3+"="+ paramAddPost1 +"&"+paramAddPost4+"="+paramAddPost5+"'");
		
			}
		}
	}
	
	
	function changePress(p){
		
		document.getElementById("p"+1).className = "btn_press";
		document.getElementById("p"+2).className = "btn_press";
		document.getElementById("p"+3).className = "btn_press";
		
		document.getElementById("p"+p).className = "btn_press_select";
		ajaxpack.postAjaxRequest("process_press.php", "press_category="+p, processPress, "txt");
	}
	
	function processPress(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){  
		
				var valo = Number(myajax.responseText);
 				if (valo == 0){  
					 document.getElementById("press_cont").innerHTML = "";
					 
					} else{ 
					 document.getElementById("press_cont").innerHTML = myajax.responseText;
				}

			}
		}
	}
	 


	function refreshit(){
		ajaxpack.postAjaxRequest(proccessurl, key+"", processGetPost, "txt");
	}
	
	function change_input_stye(param,hasFocus){
			document.getElementById(param).style.border='1px solid #666666';
			document.getElementById(param).style.backgroundColor='#f6f6f6';
	}
	
		
	function empty_Search(){
			document.getElementById('search_Box').value = '';
	}
	
		
	function change_hover_style(param){
			document.getElementById(param).style.backgroundColor='#F6F6F6';
			document.getElementById(param).style.border='1px solid #aaaaaa';
	}
	
	
	function change_input_rtn(param,hasFocus){
			document.getElementById(param).style.backgroundColor='#F6F6F6';
 			document.getElementById(param).style.borderBottom='1px solid #D1D1D1';
			document.getElementById(param).style.borderTop='1px solid #F6F6F6';
			document.getElementById(param).style.borderLeft='1px solid #F6F6F6';
			document.getElementById(param).style.borderRight='1px solid #F6F6F6';
			//alert(document.getElementById(param).value);
			
			if(document.getElementById(param).value == "" || document.getElementById(param).value == "Search"){
				document.getElementById(param).value = "Search";
			}
			
	}
	
	
	function change_out_style(param){
			document.getElementById(param).style.backgroundColor='#F6F6F6';
 			document.getElementById(param).style.borderBottom='1px solid #D1D1D1';
			document.getElementById(param).style.borderTop='1px solid #F6F6F6';
			document.getElementById(param).style.borderLeft='1px solid #F6F6F6';
			document.getElementById(param).style.borderRight='1px solid #F6F6F6';
	}
	

	function change_input_back(param){
			document.getElementById(param).style.backgroundColor='#F6F6F6';
 			document.getElementById(param).style.borderBottom='1px solid #D1D1D1';
			document.getElementById(param).style.borderTop='1px solid #F6F6F6';
			document.getElementById(param).style.borderLeft='1px solid #F6F6F6';
			document.getElementById(param).style.borderRight='1px solid #F6F6F6';
			
		 
	}
	
	function refreshordit(order_by,asc_by){ 
  		ajaxpack.postAjaxRequest(proccessurl, key+"&order_by="+order_by+"&asc_by="+asc_by+"&filterTxt="+filterparam, processGetPost, "txt");
	}
	
 	function filterCancel(){
		
			//alert(proccessurl);

		filterparam = '';
		document.getElementById("filtercancel").style.display = "none";
		document.getElementById("filterbox").value="Type here";
		ajaxpack.postAjaxRequest(proccessurl, key+"&order_by="+order_by+"&asc_by="+asc_by+"&filterTxt=&", processGetPost, "txt");
	}
	
	
	
	function filterList(param, id){
		document.getElementById("filtercancel").style.display="block";
		filterparam = param;
		ajaxpack.postAjaxRequest(proccessurl, key+"&order_by="+order_by+"&asc_by="+asc_by+"&filterTxt="+filterparam+"&catering="+catering+"&thisid="+id, processGetPost, "txt");
		
	}

	function selectag(param){
		$(".tags").removeClass('selectag');
		$("#"+param).addClass('selectag');
	}

	
	 
	
	
	
	
	
	function processWeds(wedcont){
		 
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){  
				
				
				var valo = Number(myajax.responseText);
 				if (valo == 0){  
					 document.getElementById("container"+wedcont).innerHTML = "No results.";
					} else{ 
					 document.getElementById("container"+wedcont).innerHTML = myajax.responseText;
				}

			}
		}
	}
	 
	function filterThis(p){
		
		var m = document.getElementById("wed_frm"+p);
		var p1 = m.filterEvent.value;
		var n  = m.filterState;
		var p2 = n.options[n.selectedIndex].value;
		filterWedddings(p1, p2, p);
	
	}
	
	
	function filterWedddings(param,param2,wedcont){
		ajaxpack.postAjaxRequest(proccessurl, key+"&order_by="+order_by+"&asc_by="+asc_by+"&filterTxt="+param+"&filterState="+param2, processWeds, "txt", wedcont);
	}
	


	
	
	
	
	function processCats(wedcont){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
		//alert(myajax.responseText);
				var valo = (myajax.responseText);
 				if (valo == 0){  
					 document.getElementById("container"+wedcont).innerHTML = "No results.";
					} else{ 
					 document.getElementById("container"+wedcont).innerHTML = myajax.responseText;
				}

			}
		}
	}
	 
	function filterThisCatering(cont){
		
		var m = document.getElementById("catr_frm"+cont);
		var n  = m.filterState;
		var state = n.options[n.selectedIndex].value;
		filterCatering(state, cont);
	
	}
	
	
	
	





	
	 function gallery_movenext() { //alert(tot_ph);
			 
		 if(temp < tot_ph-1){
	   		 temp = temp + 1; 
			 gallery_move_reset();			 
	   		 var _ml = document.getElementById("wg_box").style.marginLeft; 
			 var _ml = Number(_ml.replace("px","")); 
	   		 var _xx = _ml - 680; 
			 $("#wg_box").animate({marginLeft: _xx+"px"}, 1000, "swing", function(){ gallery_moveprev_reset(); gallery_movenext_reset(); } );
		}
			 
	 }; 
	 
	 
	 function  gallery_moveprev() { 
	 	  
		 if(temp > 0){
			 
			 gallery_move_reset();	
			 temp = temp - 1; 
	   		 var _ml = document.getElementById("wg_box").style.marginLeft; 
			 var _ml = Number(_ml.replace("px","")); 
	   		 var _xx = _ml + 680; 
			 $("#wg_box").animate({marginLeft:  _xx+"px"}, 1000, "swing", function(){ gallery_moveprev_reset(); gallery_movenext_reset(); } );
		 
		 }
	 
	 }; 
	 
	 
	 
	 function  gallery_move_reset() { 
			 document.getElementById("btn_prev").style.display = "none";
			 document.getElementById("btn_next").style.display = "none";
			 document.getElementById("btn_prev_temp").style.display = "block";
			 document.getElementById("btn_next_temp").style.display = "block";
	 };
	 
	 function  gallery_movenext_reset() { 
			 	document.getElementById("btn_next").style.display = "block";
			 	document.getElementById("btn_next_temp").style.display = "none";
	 };
	 
	 function  gallery_moveprev_reset() { 
	 		 	document.getElementById("btn_prev").style.display = "block";
	 		 	document.getElementById("btn_prev_temp").style.display = "none";
	 };
	 
	 
	 
	 
	 
	
	function showWg(weddings_id, wg_title, tot){
			 temp = 0;
			 tot_ph = tot;
			 document.getElementById("wg_title").innerHTML = wg_title;
			 $("#wg_container").slideDown("slow");
			 $("#wg_navbar").slideDown("slow");
			 ajaxpack.postAjaxRequest("process_wedgallery.php", "weddings_id="+weddings_id, processWedGallery, "txt");
	}
	
	
	
	function processWedGallery(){
		
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){  
				
					 document.getElementById("wg_container").style.display = 'block';
					 document.getElementById("wg_container").innerHTML = myajax.responseText;
			 
			}
		}
	}
	 
	function processGallery(){
		
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){  
				
					 document.getElementById("wg_container").style.display = 'block';
					 document.getElementById("wg_container").innerHTML = myajax.responseText;
			 
			}
		}
	}
	 

	
	

	function searchBox_clear(){
		
		var ss = document.getElementById('search_Box');
		
		if(ss.value=="Search"){
			
			ss.value="";
			
		}
	}
	
	
	
	function changeMyValue(par){
			if(document.getElementById(par).checked){
				document.getElementById(par).value = "1";
			}else{
				document.getElementById(par).value = "0";
			}
	}
	
	
	
	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_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 publishit(param1, param2, param3){ 
		ajaxpack.postAjaxRequest("process_submitit.php", "order_by="+order_by+"&asc_by="+asc_by+"&pre_table="+param1+"&id="+param2+"&filterTxt="+filterparam+"&catering="+catering+"&val="+param3, processpublishit, "txt");
	}
	
	
	
	function checked_it(param1, param2, param3, param4){ 
	//alert(param1 +" "+ param2 +" "+ param3+" "+ param4);
		ajaxpack.postAjaxRequest("process_submititslide.php", "order_by="+order_by+"&asc_by="+asc_by+"&pre_table="+param1+"&pre_row="+param2+"&id="+param3+"&val="+param4, processpublishit, "txt");
	}
	
	 



 	function processpublishit(){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ 
		
				ajaxpack.postAjaxRequest(proccessurl, "order_by="+order_by+"&asc_by="+asc_by+"&filterTxt="+filterparam+"&catering="+catering+"&"+key, processGetPost, "txt");
			
			}
		}
	}

	 


	
	function deleteit(param){
		if(param!=false){
		ajaxpack.postAjaxRequest(proccessurl, key+"action=delete&id="+param, processGetPost, "txt");
		}
	}
	
	function movedw(param){
		ajaxpack.postAjaxRequest(proccessurl, key+"action=movedw&id="+param, processGetPost, "txt");
	}
	
	
	function moveup(param){
		ajaxpack.postAjaxRequest(proccessurl, key+"action=moveup&id="+param, processGetPost, "txt");
	}




////



function formReset(p)
{
	document.getElementById(p).reset();
}




function startUpload(param){
	
      document.getElementById('upload_loader').style.visibility = 'visible';
      document.getElementById('upload_msg').innerHTML = '';
      document.getElementById('upload_msg').style.visibility = 'hidden';      
	
	
   var theForm =  document.getElementById(param);
  var request = {};
  var fileName = '';
  
  for (var i=0; i < theForm.elements.length; i++) { 
    ele = theForm.elements[i];
    if (ele.type == 'file') {
      var fileName = ele.value;
    	if (fileName.indexOf('/') > -1) { 
    	  fileName = fileName.substring(fileName.lastIndexOf('/')+1, fileName.length);
      }	else {
    	  fileName = fileName.substring(fileName.lastIndexOf('\\')+1, fileName.length);
      }
      break;
    }
  }
  if (fileName.replace('/\s/', '').toString() === '') {return;}
  theForm.submit();
  return true;
}



function stopUpload(success){
      var result = '';

	  if (success == "1"){
         result = '<div class="msg">File Uploaded!</div><br />';
      } else if (success == "2"){
		  
         result = '<div class="emsg">Error. <br/>Filename contains invalid characters (ex. %$^&*#@).  <br/>Retry by renaming your file.</div><br />';
	  
	  } else {
		  
         result = '<div class="emsg">Error. File not uploaded. Retry.</div><br />';
      }
       
      document.getElementById('upload_loader').style.visibility = 'hidden';
      document.getElementById('upload_msg').innerHTML = result;
      document.getElementById('upload_msg').style.visibility = 'visible';      
      return true;   
}




function  changeTitle(p,c) {
		 
	  for(i=0;i < c; i++) {
		  
		 	document.getElementById('title'+i).style.marginLeft = '-3600px';
	  }
	
	  document.getElementById('title'+p).style.marginLeft = '0px';
	 
 }
	 
 function  openFlash() { $("#flash_slideshow").animate({height: "280px" }, 1000 );	}; 
 function  closeFlash(){ $("#flash_slideshow").animate({height: "0px" }, 1000 );	}; 






