function show_subs(which)
{
	divs = document.getElementsByTagName("div");
	for (var x in divs) {
		if (divs[x].className && divs[x].className.search(/^sub_/) != -1) {
			results = divs[x].className.match(/^sub_(.*)$/);
			divs[x].style.display = (results[1] == which) ? "" : "none";
		}
	}
}

//Functions for mouseover to show captions
function showLayer(layerName)
{
    if (document.getElementById) // Netscape 6 and IE 5+
    {
        var targetElement = document.getElementById(layerName);
		targetElement.style.visibility = 'visible';
    }
}


function hideLayer(layerName)
{
	if (document.getElementById)
	{
		var targetElement = document.getElementById(layerName);
		targetElement.style.visibility = 'hidden';
	}
}
function jumpTo()
{
    var f = document.forms['frmRegions'];
    window.location.href = f.regions.options[f.regions.selectedIndex].value;
}
function jumpLocation(href)
{
    if(href)
    {
        window.location.href = href;
    }
}
/**
*	delete customer file
*/
function deleteFile(msg, oid)
{
	var frm = document.frmFile;
	if(window.confirm(msg))
	{

		frm.oid.value= oid;
		frm.submit();
	}
	return false;

}

function emailAccessDetails(oid, emailTo)
{
	$('#oid').val(oid);
	$('#email_to').val(emailTo);
	$('#emailDetailsWindow').jqmShow();
	return false;
}

function doEmailAccessDetails()
{
	var options =
	{
		dataType:'json',
		beforeSubmit:function()
		{
			ajaxStart('#emailDetailsWindow');
		},
		error:function(xml,msg, e)
		{
			alert(msg);
		},
		complete:function()
		{
			ajaxStop('#emailDetailsWindow img.ajaxLoadingImg');
			$('#emailDetailsWindow').jqmHide();
		},
		success:function(json)
		{
			if(typeof(json.error) == 'undefined')
			{
				alert('Unexpected Results');
			}else if(json.error != '')
			{
				alert(json.error);
			}else
			{//succeed
				alert('Email has been sent out successfully.');

			}
		}
	};

	$('#frmEmailAccessDetails').ajaxSubmit(options);

};

function notifyNewFiles(numNewFiles)
{
	if(numNewFiles > 0)
	{
		$('#newFileWindow').jqmShow();
	}else
	{
		alert('There are no new files added');
	}


	return false;
}

function doNotifyNewFiles()
{
	var options =
	{
		dataType:'json',
		beforeSubmit:function()
		{
			ajaxStart('#newFileWindow');
		},
		error:function(xml,msg, e)
		{
			alert(msg);
		},
		complete:function()
		{
			ajaxStop('#newFileWindow img.ajaxLoadingImg');
			$('#newFileWindow').jqmHide();
		},
		success:function(json)
		{
			if(typeof(json.error) == 'undefined')
			{
				alert('Unexpected Results');
			}else if(json.error != '')
			{
				alert(json.error);
			}else
			{//succeed
				alert('Notification letter has been sent out successfully.');

			}
		}
	};

	$('#frmNewFileWindow').ajaxSubmit(options);
}


function notifyNewPhotos(numNewFiles)
{
	if(numNewFiles > 0)
	{
		$('#newPhotoWindow').jqmShow();
	}else
	{
		alert('There are no new photos added');
	}


	return false;
}

function doNotifyNewPhotos()
{
	var options =
	{
		dataType:'json',
		beforeSubmit:function()
		{
			ajaxStart('#newPhotoWindow');
		},
		error:function(xml,msg, e)
		{
			alert(msg);
		},
		complete:function()
		{
			ajaxStop('#newPhotoWindow img.ajaxLoadingImg');
			$('#newPhotoWindow').jqmHide();
		},
		success:function(json)
		{
			if(typeof(json.error) == 'undefined')
			{
				alert('Unexpected Results');
			}else if(json.error != '')
			{
				alert(json.error);
			}else
			{//succeed
				alert('Notification letter has been sent out successfully.');

			}
		}
	};

	$('#frmNewPhotoWindow').ajaxSubmit(options);
}
/**
* @param mixed destinationSelector where the animation image will be append to
*	@param mixed selectorOfAnimation the jquery selector of the animation
*/
function ajaxStart(destinationSelector, selectorOfAnimation)
{
	if(typeof(selectorOfAnimation) == 'undefined')
	{//set defaullt animation
		selectorOfAnimation = '#ajaxLoading img.ajaxLoadingImg';
	}
	$(selectorOfAnimation).clone().appendTo(destinationSelector);

};
/**
* remove the ajax animation
*	@param mixed selectorOfAnimation the jquery selector of the animation
*/
function ajaxStop(selectorOfAnimation)
{
	$(selectorOfAnimation).remove();
};
/**
*	generate hidden iframe to download specific file
*/
function generateDownloadIframe(url)
{
	var frameId = 'ajaxDownloadIframe';
	$('#' + frameId).remove();
	if(window.ActiveXObject) {
			var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');


	}
	else {
			var io = document.createElement('iframe');
			io.id = frameId;
			io.name = frameId;
	}
	io.style.position = 'absolute';
	io.style.top = '-1000px';
	io.style.left = '-1000px';
	io.src = url;
	document.body.appendChild(io);
	return false;
};

function sendCustomerPhotos(customerOid)
{
	var numSelected = 0;
	var options = {};
	var body = $('#photoListingBody');

	$(body).empty();
	$('#selected_photos').removeOption(/./);

	$('input[@name=photos]').each(
		function()
		{
			if(this.checked)
			{
				options[this.value] = this.value;
/*				'<tr id="photo' + this.value + '">'
				+ '<td><a href="' + urls.current_page + photos[this.value].oid + '/" target="_blank"><img src="' +  urls.photo + photos[this.value].thumbnail_name + '" class="borderedThumbImage"></a></td>' +
				'<td><dl><dt>'+ photos[this.value].title + '</dt><dd><b>Date Taken:</b> ' + photos[this.value].tdate + '</dd><dd><b>Date Added:</b> ' + photos[this.value].cdatetime + '</dd></dl></td>' +
				'<td><a href="#" onclick="return removeSendPhoto(\'' + this.value + '\');">Don\'t Email This Photo</a></td>'
				+ '</tr>'*/
				var html = '<tr id="photo' + this.value + '">'
				+ '<td><a href="' + urls.current_page + photos[this.value].oid + '/" target="_blank"><img src="' +  urls.photo + photos[this.value].thumbnail_name + '" class="borderedThumbImage"></a></td>' +
				'<td class="left"><p>'+ photos[this.value].title + '<br><b>Date Taken:</b> ' + photos[this.value].tdate + '<br><b>Date Added:</b> ' + photos[this.value].cdatetime + '</p></td>' +
				'<td><a href="#" onclick="return removeSendPhoto(\'' + this.value + '\');">Don\'t Email This Photo</a></td>'
				+ '</tr>';
				//alert(photos[this.value].title);


				$(body).append(html);




				numSelected++;
			}
		}

	);
	if(numSelected > 0)
	{
		$('#selected_photos').addOption(options, true);
		//populate the photo listing

		$('#sendPhotosWindow').jqmShow();
	}else
	{
		alert('No photos has been selected.');
	}


	return false;
}


function removeSendPhoto(photoId)
{

	$('#photo' + photoId).remove();
	$('#selected_photos').removeOption(photoId);
	return false;
}
function doSendCustomerPhotos()
{
	var options =
	{
		dataType:'json',
		beforeSubmit:function()
		{
			ajaxStart('#sendPhotosWindow');
		},
		error:function(xml,msg, e)
		{
			alert(msg);
		},
		complete:function()
		{
			ajaxStop('#sendPhotosWindow img.ajaxLoadingImg');
			$('#sendPhotoWindow').jqmHide();
		},
		success:function(json)
		{
			if(typeof(json.error) == 'undefined')
			{
				alert('Unexpected Results');
			}else if(json.error != '')
			{
				alert(json.error);
			}else
			{//succeed
				alert('Email has been sent successfully.');

			}
		}
	};

	$('#frmSendPhotosWindow').ajaxSubmit(options);
	return false;
}


function sendCustomerPhoto()
{

	$('#sendPhotoWindow').jqmShow();
	return false;
}

function doSendCustomerPhoto()
{
	var options =
	{
		dataType:'json',
		beforeSubmit:function()
		{
			ajaxStart('#sendPhotoWindow');
		},
		error:function(xml,msg, e)
		{
			alert(msg);
		},
		complete:function()
		{
			ajaxStop('#sendPhotoWindow img.ajaxLoadingImg');
			$('#sendPhotoWindow').jqmHide();
		},
		success:function(json)
		{
			if(typeof(json.error) == 'undefined')
			{
				alert('Unexpected Results');
			}else if(json.error != '')
			{
				alert(json.error);
			}else
			{//succeed
				alert('Email has been sent successfully.');

			}
		}
	};

	$('#frmSendPhotoWindow').ajaxSubmit(options);
	return false;
};

function closeWin(winId)
{
	$('#' + winId + ' img.ajaxLoadingImg').remove();
	$('#' + winId).jqmHide();
	return false;
};
/**
*	delete the specified customer
*/
function deleteCustomer(customerOid, msg)
{
	if(window.confirm(msg))
	{
		$('#hidden_oid').val(customerOid);
		document.getElementById('frmCustomerDeletion').submit();
	}
	return false;
}

function toggleAllPhotos(elem)
{
	$('input[@name=photos]').each(function ()
	{
		this.checked = elem.checked;
	}
	);
}