// JavaScript Document

var ajax;
var currSection = "";
var currId = "";
var currField = "";

// Trap right clicks...
/*
function onmousedown(e) {
	if (e != null) {
		var clickType = e.which;
		if (clickType!=1) {
			var div = document.getElementById("divOneClick_AddDel_Window");
			if (div != null) {
				div.style.visibility = "visible";
			}
			//alert("Right click!!");
		}
	}
}
document.addEventListener("mouseclick", onmousedown, false);
*/

function Image_Popup(url) {
	window.open (url, "_blank", "width=720, height=520, status=no, location=no, scrolling=yes");	
}


function OneClick_OnMouseDown(SectionName, tID, Field) {
	//alert ("Entering; e = " + e);
	//if (e != null) {
		//var clickType = e.which;
		//if (clickType!=1) {
		
		currSection = SectionName;
		currId = tID;
		currField = Field;
		//alert ("currSection = '" + currSection + "'");
			
			var div = document.getElementById("divOneClick_AddDel_Window");
			//++div.style.zIndex = 70;
			if (div != null) {
				div.style.visibility = "visible";
			}
			//alert("Right click!!");
		//}
	//}
}

function OneClick_EditRecord() {  
	//alert ("The ID = " + currId) ;
	OneClick_Edit_Row(currSection, currId, currField);
}

function OneClick_AddRecord(SectionName) {
	//alert ("Adding record... " + SectionName);	
	
	var div = document.getElementById("divOneClick_AddRecord");
	var iframe = document.getElementById("iframeOneClick_AddRecord");
	
	div.style.visibility = "visible";
	iframe.src = "OneClick/OneClick_HTML_AddRecord.aspx?SectionName=" + SectionName;
	
}

function OneClick_DelRecord(SectionName, tID) {
	//alert ("Deleting record... " + tID);

	var div = document.getElementById("divOneClick_ConfirmDelete");
	var iframe = document.getElementById("iframeOneClick_ConfirmDelete");
	
	div.style.visibility = "visible";
	iframe.src = "OneClick/OneClick_HTML_ConfirmDelete.aspx?SectionName=" + SectionName + "&Id=" + tID + "&r=" + Math.random();	
}

function OneClick_EditFlash(Section) {
	
	var div = document.getElementById("divOneClick_AddRecord");
	var iframe = document.getElementById("iframeOneClick_AddRecord");
	
	div.style.visibility = "visible";
	iframe.src = "OneClick/OneClick_HTML_Edit_Flash.aspx?SectionName=" + Section;
	
	//alert ("Flash is calling EditFlash('" + Section + "') !");	
}


function OneClick_Edit_Row(SectionName, Id, Field) {
	Create_AjaxObject();		
	
	var div = document.getElementById("divOneClick_EditWindow");
	var iframe = document.getElementById("iframeOneClick_EditField");
	iframe.src = "OneClick/OneClick_HTML_Edit_RowField.aspx?Id=" + Id + "&SectionName=" + SectionName + "&Field=" + Field + "&mode=edit" ;
	div.style.visibility = "visible";
	
	//alert ("Id = " + Id + ", Field = " + Field);
}

function Create_AjaxObject() {
	if (ajax == null) {
		if (window.XMLHttpRequest) {	
			// Mozilla, Safari, etc
	        ajax = new XMLHttpRequest();
		} else {
			// Internet Explorer
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					// Ajax OK response.
					alert ("Ajax 200 OK!");
				}
			}
		}		
		//
	}
}


function OneClick_Refresh() {
	
	var url = unescape(window.location.pathname);
	
	var newURL = url;
	if (newURL.indexOf('?') < 0) {
		window.location.href = url + "?r="+ Math.random();
	} else {
		window.location.href = url + "&r="+ Math.random();
	}		
	
	//document.write ('<meta http-equiv="refresh" content="3">');
}



//////////////   NEW :: 2011 Oneclick. Flash calls.
function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

function Create_Image_Field(imgFile) {
	// Calls Flash, notifies User selected a new file..
	//alert ("Create_Image_Field() called..");
	
	//var flashObj = document.getElementById('objFlash1');
	getFlashMovie("objFlash1").CreateImageField(imgFile);  // <--- Calls Flash AS3 function directly!!!  :^)
	
	//alert ("flashObj = " + flashObj);	
	//alert ("Execed!");
}

function Show_Image_Manager() {
	var div = document.getElementById('OneClick_ImageManager');
	div.style.visibility = "visible";
}

function Hide_Image_Manager() {
	var div = document.getElementById('OneClick_ImageManager');
	div.style.visibility = "hidden";
}

function Finish_Editing() {
	// "Finish" button on OneClick Flash interface.
	window.location = "logout.aspx";
}


