// JavaScript Document

function doReadFoto(sID) {
	var width = 495;
	var height = 500;
	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);
	wRead =
		window.open('read_foto.php?id='+sID,
			'wread', 'scrollbars=1, toolbar=0, statusbar=1, width='+width+', height='+height+', left='+left+', top='+top);
	wRead.focus();
}

function doReadVideo(sID) {
	var width = 495;
	var height = 500;
	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);
	wRead =
		window.open('read_video.php?id='+sID,
			'wread', 'scrollbars=0, toolbar=0, statusbar=1, width='+width+', height='+height+', left='+left+', top='+top);
	wRead.focus();
}

function doComments(sID) {
	var width = 495;
	var height = 380;
	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);
	wComments =
		window.open('comments.php?id='+sID,
			'wcomments', 'scrollbars=1, toolbar=0, statusbar=1, width='+width+', height='+height+', left='+left+', top='+top);
	wComments.focus();
}

function doFoto(sContent, sID) {
	var width = 360;
	var height = 500;
	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);
	wComments =
		window.open('foto.php?content=person&id='+sID,
			'wcomments', 'scrollbars=1, toolbar=0, statusbar=1, width='+width+', height='+height+', left='+left+', top='+top);
	wComments.focus();
}

function doNewWindow(sURL, sX, sY) {
	var width = sX;
	var height = sY;
	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);
	wNewWindow =
		window.open(sURL,
			'newwindow', 'scrollbars=1, toolbar=0, statusbar=1, width='+width+', height='+height+', left='+left+', top='+top);
	wNewWindow.focus();
}

function doReadAudio(sID) {
	var width = 495;
	var height = 500;
	var left = (screen.availWidth/2) - (width/2);
	var top = (screen.availHeight/2) - (height/2);
	wRead =
		window.open('read_audio.php?id='+sID,
			'wread', 'scrollbars=1, toolbar=0, statusbar=1, width='+width+', height='+height+', left='+left+', top='+top);
	wRead.focus();
}

function checkNumber(text) {
	var checkOK = "0123456789-+ ";
	var checkStr = text;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j)) break;
		if (j == checkOK.length) {
			allValid = false;
			break;
		}
	}
	return allValid;
}

function checkEMail(text) {
	txt=text;
	if (txt == "") { return(false) }
	if (txt.indexOf(".") == -1) { return(false) }
	dog = txt.indexOf("@");
	if (dog == -1) { return(false) }
	if ((dog < 1) || (dog > txt.length - 5)) { return(false) }
	if ((txt.charAt(dog - 1) == '.') || (txt.charAt(dog + 1) == '.')) { return(false) }
	return(true);
}

// Cookie
function setCookie(name, value) {
        document.cookie = name + "=" + escape(value)+"; path=/; expires=Thursday, 31-Dec-2020 23:59:59 GMT;";
}

function setCookieNow(name, value) {
        document.cookie = name + "=" + escape(value)+"; path=/; expires=Thursday, 31-Dec-2020 23:59:59 GMT;";
}

function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return ''
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
// end Cookie
