﻿var forms = {
	
	init : function()
	{
		/* Create Phone number listeners */
		var phone_fields = $$('.phone3');
		for (var i = 0; i < phone_fields.length; i++)
		{
			Event.observe(phone_fields[i], 'keyup', forms.checkPhoneLength.bindAsEventListener());
		}
	},
	checkPhoneLength : function(e)
	{
		var tag = Event.element(e);
		if (tag.value.length == 3)
		{
			var next_tag = tag.next();
			next_tag.focus();
		}
		
	}
	
}

/* Run these functions on page load */
Event.observe( window, 'load', function() { forms.init() } );




/* //////////// PHOTO UPOLOAD FUNCTIONS ///////////// */


	
	//xmlhttp.js
	
	//Function to create an XMLHttp Object.
	function getxmlhttp (){
		//Create a boolean variable to check for a valid microsoft active X instance.
		var xmlhttp = false;
		
		//Check if we are using internet explorer.
		try {
			//If the javascript version is greater than 5.
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//If not, then use the older active x object.
			try {
				//If we are using internet explorer.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				//Else we must be using a non-internet explorer browser.
				xmlhttp = false;
			}
		}
		
		//If we are using a non-internet explorer browser, create a javascript instance of the object.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	//Function to process an XMLHttpRequest.
	function processajax (obj, serverPage){
		//Get an XMLHttpRequest object for use.
		var theimg;
		xmlhttp = getxmlhttp ();
		xmlhttp.open("POST", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
				
			}
		}
		xmlhttp.send(null);
	}
	
	
function check_vars(){

//alert($('testing').value);
$('pic_ids').value = $('testing').value;

return true;
}	
	
	

////////////// HIDE FORM
function hide_form(content_div) {

document.getElementById(content_div).className = "noshow";
document.getElementById(content_div).innerHTML = "";

}




		//functions.js
	

	//Function to determine when the process_upload.php file has finished executing.
	function doneloading(theframe,model,model_id,url){

		var theloc = url+model+"/"+model_id;
		//alert(theloc);
	parent.document.getElementById('showimg_status').innerHTML='';
	parent.document.getElementById('showimg_status').className='noshow';

		theframe.processajax ("showimg",theloc);
		
	}
	

	//Function to determine when the process_upload.php file has finished executing.
	function doneloadingUpLevel(theframe,model,model_id){

		var theloc = "../../photo_uploads/display_pics/"+model+"/"+model_id;
		alert(theloc);
		parent.document.getElementById('showimg_status').innerHTML='';
	parent.document.getElementById('showimg_status').className='noshow';

		theframe.processajax ("showimg",theloc);
		
	}
	


	//Function to determine when the process_upload.php file has finished executing.
	function doneloadingAdmin(theframe,model,model_id){

		var theloc = "../../../../photo_uploads/display_pics/"+model+"/"+model_id;
		
		parent.document.getElementById('showimg_status').innerHTML='';
	parent.document.getElementById('showimg_status').className='noshow';

		theframe.processajax ("showimg",theloc);
		
	}
	





	function uploadimg (theform,url){
	//alert(url);
parent.document.getElementById('uploadframe').src = url;
		theform.submit();
	parent.document.getElementById('showimg_status').className='show';

		setStatus ("<span style=\"color: #808080;\">&nbsp;&nbsp;<b>Loading Image</b>...Please Wait</span><br><img src=\"../img/basic/upload-loader.gif\"  height=\"19\" width=\"220\" border=\"0\">","showimg_status");
	}



	function uploadimgUpLevel (theform,url){
parent.document.getElementById('uploadframe').src = url;
		theform.submit();
		//alert(url);
	parent.document.getElementById('showimg_status').className='show';
		setStatus ("<span style=\"color: #808080;\">&nbsp;&nbsp;<b>Loading Image</b>...Please Wait</span><br><img src=\"../../../img/basic/upload-loader.gif\"  height=\"19\" width=\"220\" border=\"0\">","showimg_status");
	}



	
	//Function to set a loading status.
	function setStatus (theStatus, theObj){
		var obj = document.getElementById(theObj);
		if (obj){
			obj.innerHTML = theStatus;
		}
	}
	
	function changesize (img, sml){
		//The display a loading message to the user.
		theobj = document.getElementById("showimg");
		if (theobj){
			setStatus ("<span style=\"color: #808080;\">&nbsp;&nbsp;<b>Loading Image</b>...Please Wait</span><br><img src=\"../img/basic/upload-loader.gif\"  height=\"19\" width=\"220\" border=\"0\">","showimg");
			var loc = "thumb.php?img=" + img + "&sml=" + sml;
			processajax ("showimg",loc);
		}
	}




function img_delete(model,model_id,img_id,img_name){

var photo_delete = confirm("Are you Sure You want to Delete this Photo?");
if(!photo_delete){return false;}

//var theloc = "../../photo_uploads/display_pics/"+model+"/"+model_id+"/"+img_id+"/"+img_name;
var theloc = "/photo_uploads/display_pics/"+model+"/"+model_id+"/"+img_id+"/"+img_name;
var params = '';
new Ajax.Updater('showimg', theloc, {asynchronous:true, parameters:params});

}
	
function fade_div(){
	var photo_edit = $('edit_img1');
	//alert(photo_edit);
	photo_edit.hide();
	if(photo_edit){
	new Effect.Appear('edit_img1', {duration: 1.0});
	}
}	


function img_edit(model,model_id,img_id){

var theloc = "../../photo_uploads/display_pics/"+model+"/"+model_id+"/"+img_id;
var params = 'edit=yes';

var stuff = new Ajax.Updater('showimg', theloc, {asynchronous:true, parameters:params});
//Effect.SlideDown('showimg', { duration: 1.0 });
}
	




function img_edit_save(model,model_id,img_id){
var description = $('description_edit').value;
var main_photo = $('PhotoUploadMainPhoto').value;
var photographer = $('photographer').value;

var theloc = "../../photo_uploads/display_pics/"+model+"/"+model_id+"/"+img_id;
var params = 'save=yes&description='+description+'&main_photo='+main_photo+'&photographer='+photographer;
//alert(params);
new Ajax.Updater('showimg', theloc, {asynchronous:true, parameters:params});

}
	


//// AUDIO UPLOAD FUNCTIONS ////////////////////////////////


function audio_edit(model,model_id,img_id){

var theloc = "../../audio_uploads/display_audio/"+model+"/"+model_id+"/"+img_id;
var params = 'edit_audio=yes';
new Ajax.Updater('showaudio', theloc, {asynchronous:true, parameters:params});

}
	

function audio_edit_save(model,model_id,img_id){
var description = $('description_audio').value;
var main_photo = $('AudioUploadMainAudio').value;
var photographer = $('author').value;

var theloc = "../../audio_uploads/display_audio/"+model+"/"+model_id+"/"+img_id;
var params = 'save_audio=yes&description='+description+'&main_photo='+main_photo+'&photographer='+photographer;
//alert(params);
new Ajax.Updater('showaudio', theloc, {asynchronous:true, parameters:params});

}
	

function audio_delete(model,model_id,img_id,img_name){

var audio_deleteC = confirm("Are you Sure You want to Delete this MP3?");
if(!audio_deleteC){return false;}

var theloc = "../../audio_uploads/display_audio/"+model+"/"+model_id+"/"+img_id+"/"+img_name;

var params = '';
new Ajax.Updater('showaudio', theloc, {asynchronous:true, parameters:params});

}
	

	function uploadaudio (theform,url){
parent.document.getElementById('uploadframeAudio').src = url;
		theform.submit();
	parent.document.getElementById('showaudio_status').className='show';
		setStatus ("<span style=\"color: #808080;\">&nbsp;&nbsp;<b>Loading Image</b>...Please Wait</span><br><img src=\"../img/basic/upload-loader.gif\"  height=\"19\" width=\"220\" border=\"0\">","showaudio_status");
	}



	//Function to determine when the process_upload.php file has finished executing.
	function doneloadingAudio(theframe,model,model_id,url){

		var theloc = url+model+"/"+model_id;

	parent.document.getElementById('showaudio_status').innerHTML='';
	parent.document.getElementById('showaudio_status').className='noshow';

		theframe.processajax ("showaudio",theloc);
		
	}
	



	function uploadaudioUpLevel (theform,url){
parent.document.getElementById('uploadframeAudio').src = url;
		theform.submit();
	parent.document.getElementById('showaudio_status').className='show';
		setStatus ("<span style=\"color: #808080;\">&nbsp;&nbsp;<b>Loading Audio</b>...Please Wait</span><br><img src=\"../../../img/basic/upload-loader.gif\"  height=\"19\" width=\"220\" border=\"0\">","showaudio_status");
	}




/* //////////// END OF  UPOLOAD FUNCTIONS ///////////// */

