function showPreview(script_path, type, target) {
	if (typeof(target) != 'undefined' && target != '') {
		document.forms["data"].target = target;
	}
	document.forms["data"].elements["type"].value = type;
	document.forms["data"].action = script_path;
	document.forms["data"].submit();
}

// Edit Data
function editData(script_path, nid, target) {

	if (typeof(target) != 'undefined' && target != '') {
		document.forms["data"].target = target;
	}
	document.forms["data"].elements["nid"].value = nid;
	document.forms["data"].action = script_path;
	document.forms["data"].submit();
	
}

// Delete Data
function deleteData(script_path, nid, target) {

	if (typeof(target) != 'undefined' && target != '') {
		document.forms["data"].target = target;
	}
	if (confirm("削除します。よろしいですか？")) {
		document.forms["data"].elements["nid"].value = nid;
		document.forms["data"].action = script_path;
		document.forms["data"].submit();
	}
	
}

// Delete Data(With Message)
function deleteDataWithMessage(script_path, nid, message, target) {

	if (typeof(target) != 'undefined' && target != '') {
		document.forms["data"].target = target;
	}

	if (confirm(message)) {
		document.forms["data"].elements["nid"].value = nid;
		document.forms["data"].action = script_path;
		document.forms["data"].submit();
	}
	
}


// submit
function doSubmit(formname, action, target) {

	if (typeof(target) != 'undefined' && target != '') {
		document.forms[formname].target = target;
	}
	if (typeof(action) != 'undefined' && action != '') {
		document.forms[formname].action = action;
	}
	
	document.forms[formname].submit();
}

// confirm and Submit
function doConfirmAndSubmit(formname, action, message, target) {

	if (confirm(message)) {
	
		if (typeof(target) != 'undefined' && target != '') {
			document.forms[formname].target = target;
		}
		if (typeof(action) != 'undefined' && action != '') {
			document.forms[formname].action = action;
		}
		
		document.forms[formname].submit();
		
	}
}


// checkbox select all
function selectAll(formname, targetitem, flg) {

	//var flg = document.forms[formname].elements[keyitem].checked;

	if (document.forms[formname].elements[targetitem].length) {
		for (var i = 0; i < document.forms[formname].elements[targetitem].length; i++) {
			document.forms[formname].elements[targetitem][i].checked = flg;
		}
	} else {
		document.forms[formname].elements[targetitem].checked = flg;
	}

}

// zoom image
function imageOpen(url, x, y){
	iX = eval(x) + 20;
	iY = eval(y) + 20;

	window.open(url,"_blank","width=" + iX+ ",height=" + iY + ",resizable=yes,toolbar=no,menubar=no,location=no,status=no,scrollbars=no");
}

// clear cookie
function clearCookie(cookieName) {

	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	this.setCookie(cookieName, 'cookieValue', yesterday);
	this.setCookie(cookieName, 'cookieValue', yesterday);

}
// set cookie
function setCookie(cookieName, cookieValue, expires, path, domain, secure) {

	document.cookie =

		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');

}

// get cookie
function getCookie(cookieName) {

	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');

	if (posName != -1) {

		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);

		if (endPos != -1) {
			cookieValue = unescape(document.cookie.substring(posValue, endPos));
		} else {
			cookieValue = unescape(document.cookie.substring(posValue));
		}

	}

	return (cookieValue);

}

/***************************************************************************************
Common Code for Ajax
***************************************************************************************/
var httpObj;
var httpTgID;
var httpCnt;
var httpCntID;

function ajaxGetUrl(url, params) {

	try {
		// IEはキャッシュが残るのでタイムスタンプで対策
		var d = new Date();
		var ts = d.getTime();
		
		return url + "?" + params + "&ts=" + ts;
	} catch (e) {
	
	}
	
}

function ajaxCreateHttpObject(url, params, mode) {

	try {
	    if (window.XMLHttpRequest) {             // Mozilla, Firefox, Safari, IE7
	        httpObj = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {       // IE5, IE6
	        try {
	            httpObj = new ActiveXObject("Msxml2.XMLHTTP");    // MSXML3
	        } catch(e) {
	            httpObj = new ActiveXObject("Microsoft.XMLHTTP"); // MSXML2まで
	        }
	    } else {
	        httpObj = false;
	    }
	    
		if (httpObj) {
		
			// IEはキャッシュが残るのでタイムスタンプで対策
			var d = new Date();
			var ts = d.getTime();
			
			if (mode == "POST") {
				httpObj.open("POST", url, true);
				httpObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8');
				httpObj.send(params);
			} else {
				httpObj.open("GET", url + "?" + params + "&ts=" + ts, true);
				httpObj.send("");
			}
				
			
			httpObj.onreadystatechange = function() {
				
				if (httpObj.readyState == 4) {
					
					clearInterval(httpCntID);
					
					if (httpObj.status == 200) {
						ajaxExecAction(httpObj.responseText);
					} else {
						//alert("サーバとの通信エラーが発生いたしました。再度お試しください。");
					}
					
				}
			}
			
			httpCnt = 5;
			httpCntID = setInterval("ajaxTimeOut()", 1000);
			
		} else {
		
			
		}
	} catch(e) {
	
	}

}



function ajaxTimeOut() {

	try {
		httpCnt--;
		if (httpCnt < 1) {
		
			clearInterval(httpCntID);
			httpObj.abort();
			//alert("サーバとの通信エラーが発生いたしました。再度お試しください。");
	
		}
	} catch(e) {
	
	}
}

