function getPage(page) {
	document.getElementById('rcontent').innerHTML='<img src="images/loader.gif">';
	var xmlHttp = createAjax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('rcontent').innerHTML = xmlHttp.responseText;
			tb_init('a.thickbox, area.thickbox, input.thickbox');
			imgLoader = new Image();
			imgLoader.src = tb_pathToImage;
		}
	}
	getAjax(xmlHttp,page);
}

function createAjax() {
	var xmlHttp;
	try {
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

function postAjax(xmlHttp,url,parameters) {
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function getAjax(xmlHttp,url) {
    xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function createQuery(formname) {
	var elements;
	if ( formname == 'movetrack' ) {
		elements = document.movetrack.elements;
	}
	else {
		elements = document.myForm.elements;
	}
    var pairs = new Array();
    for (var i = 0; i < elements.length; i++) {
		if ( elements[i].type == 'checkbox' ) {
			if ( elements[i].checked ==  true ) {
	        	if ((name = elements[i].name) && (value = elements[i].value)) {
	    	        pairs.push(name + "=" + encodeURIComponent(value));
				}
			}
		}
		else {
			if ( elements[i].type == 'radio' ) {
				if ( elements[i].checked ==  true ) {
					if ((name = elements[i].name) && (value = elements[i].value)) {
						pairs.push(name + "=" + encodeURIComponent(value));
					}
				}
			}
        	else {
				if ((name = elements[i].name) && (value = elements[i].value)) {
					if ( elements[i].type == 'hidden' ) {
						//alert(name + "=" + encodeURIComponent(value));
					}
					pairs.push(name + "=" + encodeURIComponent(value));
				}
			}
		}
    }
    return pairs.join(";");
}

var pic = null
var popImg = null  // use this when referring to pop-up image
var picTitle = null
var imgCount = 0
var imgWinName = "popImg"

function openPopImg(picName, windowTitle, windowWidth, windowHeight){
  closePopImg()
  picTitle = windowTitle
  imgWinName = "popImg" + imgCount++ //unique name for each pop-up window
  popImg = window.open(picName, imgWinName,
   "toolbar=no,scrollbars=no,resizable=no,width="
   + (parseInt(windowWidth)+20)  + ",height="
   + (parseInt(windowHeight)+15))
}

function closePopImg(){    // close pop-up window if it is open
  if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popImg != null) if(!popImg.closed) popImg.close()
}

function setStatus(msg){
	status = msg
	return true
}

var priorPic = new Array()
var noPic = 0
var foundit = false

function openPopImg( picName,  windowTitle, windowWidth, windowHeight ) {
	var i = 0
	if ( pic == picName && winOpen() ) {
	popImg.focus()
	}
	else{
		foundit = false
		for(i=0; i<=noPic; i++){
			if (priorPic[i] == picName)
				foundit = true
		}
		pic = picName
		closePopImg()
		picTitle = windowTitle
		imgWinName = "popImg" + imgCount++ //unique name for each pop-up window
		if(!foundit){
			priorPic[noPic++] = pic
		}
		popImg = openPopImgWin(imgWinName, windowWidth, windowHeight)
	}
}

function openPopImgWin(imgWinName, windowWidth, windowHeight){
	var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight
	return window.open("pimg.htm", imgWinName, winFeatures)
}

function winOpen() {
	if(popImg != null){
		if(popImg.closed != true) return true; else return false
    }
	else
		return false
}

function openPopImgWin(imgWinName, windowWidth, windowHeight){
	var leftX = 20  // distance of window's left side from left of screen
	var topY = 20   // distance of window's top side from top of screen
	var winFeatures = "toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight
	if (leftX>0){
		winFeatures += ",screenX=" + leftX + ",left=" + leftX + ",screenY=" + topY + ",top=" + topY
    }
	return window.open("pimg.htm", imgWinName, winFeatures)
}

function addToFavorites(id,login,not) {
	if ( !not ) {
		not = '0';
	}
	if ( login ) {
		var xmlHttp = createAjax();
		xmlHttp.onreadystatechange = function() {
			if ( xmlHttp.readyState == 4 ) {
				alert(xmlHttp.responseText);
				window.location.reload( true );
			}
		}
		getAjax(xmlHttp,'addtofavorites.asp?id='+id+';not='+not);
	}
	else {
		alert('Δεν είστε εγγεγραμένος στο site, γίνετε μέλος τώρα');
		document.location = 'exclusive_card.asp';
	}
}

function submitLoginForm() {
	var parameters = 'login=1&username=' + escape(document.LoginForm.username.value) + '&password=' + escape(document.LoginForm.password.value);
	var xmlHttp = createAjax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			if ( xmlHttp.responseText == 1 ) {
				document.getElementById('membersarea').innerHTML='';
				window.location.reload( true );
			}
			else {
				alert('Λάθος Username ή Password!');
			}
		}
	}
	postAjax(xmlHttp,'membersarea.asp',parameters);
}

function checkDates(myForm) {
	var dayfield = myForm.date;
	var monthfield = myForm.month;
	var yearfield = myForm.year;

	var mydate = dayfield.options[dayfield.selectedIndex].value + monthfield.options[monthfield.selectedIndex].value + yearfield.options[yearfield.selectedIndex].value;
	if ( check_date(mydate) ) {
		return true;
	}
	else {
		return false;
	}
}

function check_date(field){
	var checkstr = "0123456789";
	var DateValue = field;
	var DateTemp = "";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	for (i = 0; i < DateValue.length; i++) {
	  	if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + DateValue.substr(i,1);
	  	}
	}
	DateValue = DateTemp;
	if (DateValue.length == 6) {
	  	DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
	if (DateValue.length != 8) {
	  	err = 19;
	}
	year = DateValue.substr(4,4);
	if (year == 0) {
	  	err = 20;
	}
	month = DateValue.substr(2,2);
	if ((month < 1) || (month > 12)) {
	  	err = 21;
	}
	day = DateValue.substr(0,2);
	if (day < 1) {
	 	err = 22;
	}
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
	  	leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)) {
	  	err = 23;
	}
	if ((month == 2) && (leap != 1) && (day > 28)) {
	  	err = 24;
	}
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
	  	err = 25;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
	  	err = 26;
	}

	if (err == 0) {
		return 1;
	}
	else {
		return 0;
	}
}

