function create_object(){
	var request_type;
	
	try{
		// Opera 8.0+, Firefox, Safari
		request_type = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request_type = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request_type = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// other
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return request_type;
}

var http = create_object();
var nocache = 0;

//for sending request to jsession.php file that opens the user session on login
var http2 = create_object();

function login() {

var email = encodeURI(document.getElementById('user_email').value);
var pass = encodeURI(document.getElementById('user_password').value);

// Set random number to add to URL request (for IE)
nocache = Math.random();

http.open('get', 'login.php?email='+email+'&pass='+pass+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
}

function loginReply() {
if(http.readyState == 4){
var response = http.responseText;

if(response == 0){
	// if login fields not filled
	document.getElementById('login_result').innerHTML = '<span class="emsg">Login failed! Insert E-mail and password.</span>';
}else{

	if(response == 1){
		// if login fails
		document.getElementById('login_result').innerHTML = '<span class="emsg">Login failed! Verify E-mail and password.</span>';
	} else {

		//the respone contains now user name and email with ; between
		//separate them:
		var char_pos=response.indexOf(";");
		var response_email=response.substr(char_pos+1);
		response=response.substr(0,char_pos);


		document.getElementById('login_result_ok').innerHTML = '<span class="msg">Welcome '+response+'.</span>';
	
		//close the login popup after delay
		setTimeout('popup_close()',1000);

		//hide after correct login
		document.getElementById('login_form').style.visibility = 'hidden';
		document.getElementById('login_result').style.visibility = 'hidden';
		document.getElementById('not_member_yet').style.visibility = 'hidden';
		
		//show the logout_line module after login
		document.getElementById('logout_line').innerHTML = '<form name="logout_form" action="logout.php"><input value="Logout" type="submit"></form>';

		//hide the login_line
		//if this is the home page
		var i=document.getElementById('login_line_homepage');
		if (i){
		document.getElementById('login_line_homepage').style.visibility = 'hidden';
		}else{
		//this is not home page
		document.getElementById('login_line').style.visibility = 'hidden';
		}

		//send the user name and user email to the php file that open user session and insert session vars

		var nocache_login = 0;
		nocache_login = Math.random();

		http2.open('get', 'jsession.php?name='+response+'&email='+response_email+'&nocache='+nocache_login);
		http2.onreadystatechange = sessionReply;
		http2.send(null);

	}
}
}

}

function sessionReply() {

	if(http2.readyState == 4){
			location.reload();
	}
	
}


	//Ajax for password forgot


var http_pass_forgot = create_object();

//for sending request to pass_forgot.php file
var http_pass_forgot = create_object();

function pass_forgot() {

var email = encodeURI(document.getElementById('email_for_pass').value);

// Set random number to add to URL request (for IE)
nocache = Math.random();

http_pass_forgot.open('get', 'pass_forgot.php?email='+email+'&nocache = '+nocache);
http_pass_forgot.onreadystatechange = pass_forgotReply;
http_pass_forgot.send(null);
}


function pass_forgotReply() {
if(http_pass_forgot.readyState == 4){
var response = http_pass_forgot.responseText;

if(response == 0){
	document.getElementById('password_forgot_result').innerHTML = '<span class="emsg">You are not a member, the E-mail message could not be sent.</span>';
}else{
if (response == 1){
document.getElementById('password_forgot_result').innerHTML = '<span class="msg">An E-mail message has been sent to your E-mail address containing your member password.</span>';
//hide the body div of the popup
document.getElementById('password_form').style.visibility = 'hidden';
//close popup after 10 seconds
setTimeout('popup_close_password_forgot()',10000);
}else{
document.getElementById('password_forgot_result').innerHTML = '<span class="emsg">An error occurred during the process. Please try again.</span>';

}
}
}
}



	//Ajax for password change



function pass_change(){

document.getElementById('password_change_result').innerHTML ="";
var check=true;

//check for validation of input
if (document.getElementById('email_change_pass').value.length==0){
	document.getElementById('password_change_result').innerHTML = '<span class="emsg">Member E-mail field is required.</span>';
	check=false;
}

if (check){
	if (document.getElementById('cur_pass').value.length==0){
		document.getElementById('password_change_result').innerHTML = '<span class="emsg">Current password field is required.</span>';
		check=false;
	}
}

if (check){
	if (document.getElementById('new_pass').value.length==0){
		document.getElementById('password_change_result').innerHTML = '<span class="emsg">New password field is required.</span>';
		check=false;
	}
}

if (check){
	if (document.getElementById('con_new_pass').value.length==0){
		document.getElementById('password_change_result').innerHTML = '<span class="emsg">Confirm new password field is required.</span>';
		check=false;
	}
}

if (check){
password_change();
}


}




var http_pass_change = create_object();

//for sending request to pass_change.php file
var http_pass_change = create_object();

function password_change() {

var email = encodeURI(document.getElementById('email_change_pass').value);
var cur_pass = encodeURI(document.getElementById('cur_pass').value);
var new_pass = encodeURI(document.getElementById('new_pass').value);
var con_new_pass = encodeURI(document.getElementById('con_new_pass').value);

// Set random number to add to URL request (for IE)
nocache = Math.random();

http_pass_change.open('get', 'pass_change.php?email='+email+'&cur_pass='+cur_pass+'&new_pass='+new_pass+'&con_new_pass='+con_new_pass+'&nocache = '+nocache);
http_pass_change.onreadystatechange = pass_changeReply;
http_pass_change.send(null);
}


function pass_changeReply() {
if(http_pass_change.readyState == 4){
var response = http_pass_change.responseText;


if(response == 0){
document.getElementById('password_change_result').innerHTML = '<span class="emsg">New password field and Confirm new password field don\'t match. Please try again.</span>';
}

if (response==1){
document.getElementById('password_change_result').innerHTML = '<span class="emsg">New password must count at least 5 characters.</span>';
}

if (response==2){
document.getElementById('password_change_result').innerHTML = '<span class="emsg">Login failed! Verify E-mail and password.</span>';

}

if (response==3){
document.getElementById('password_change_result').innerHTML = '<span class="msg">Your password has been changed successfully.</span>';
document.getElementById('password_change_form').style.visibility = 'hidden';
//close popup after 10 seconds
setTimeout('popup_close_password_change()',10000);

}

if (response==4){
document.getElementById('password_change_result').innerHTML = '<span class="emsg">An error has occurred during the process. Please try again.</span>';
}


}
}



	//popup settings for login

//0 means disabled, 1 means enabled;  
var popupStatus = 0;

function popup_start(){
centerPopup();  
loadPopup(); 
}

//loading popup with jQuery  
function loadPopup(){  
//loads popup only if it is disabled  
if(popupStatus==0){  
$("#backgroundPopup").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup").fadeIn("fast");  
$("#popupContact").fadeIn("fast");  
popupStatus = 1;  

}  
}

//disabling popup with jQuery
function disablePopup(){  
//disables popup only if it is enabled  
if(popupStatus==1){  
$("#backgroundPopup").fadeOut("fast");  
$("#popupContact").fadeOut("fast");  
popupStatus = 0; 
}  
}

//centering popup  
function centerPopup(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact").height();  
var popupWidth = $("#popupContact").width();  
//centering  
$("#popupContact").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close(){
disablePopup();
window.location=window.location;
}





	//popup settings for Sign up

//0 means disabled, 1 means enabled;  
var popupStatus_signup = 0;

function popup_start_signup(){
centerPopup_signup();  
loadPopup_signup(); 
}

//loading popup with jQuery  
function loadPopup_signup(){  
//loads popup only if it is disabled  
if(popupStatus_signup==0){  
$("#backgroundPopup_signup").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup_signup").fadeIn("fast");  
$("#popupContact_signup").fadeIn("fast");  
popupStatus_signup = 1;  

}  
}

//disabling popup with jQuery
function disablePopup_signup(){  
//disables popup only if it is enabled  
if(popupStatus_signup==1){  
$("#backgroundPopup_signup").fadeOut("fast");  
$("#popupContact_signup").fadeOut("fast");  
popupStatus_signup = 0; 
}  
}

//centering popup  
function centerPopup_signup(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact_signup").height();  
var popupWidth = $("#popupContact_signup").width();  
//centering  
$("#popupContact_signup").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup_signup").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close_signup(){
disablePopup_signup();
//restore the form to it's regular by reloading the page
//window.location=window.location;
location.reload(); 

}




	//popup settings for password forgot

//0 means disabled, 1 means enabled;  
var popupStatus_password_forgot = 0;

function popup_start_password_forgot(){
centerPopup_password_forgot();  
loadPopup_password_forgot(); 
}

//loading popup with jQuery  
function loadPopup_password_forgot(){  
//loads popup only if it is disabled  
if(popupStatus_password_forgot==0){  
$("#backgroundPopup_password_forgot").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup_password_forgot").fadeIn("fast");  
$("#popupContact_password_forgot").fadeIn("fast");  
popupStatus_password_forgot = 1;  

}  
}

//disabling popup with jQuery
function disablePopup_password_forgot(){  
//disables popup only if it is enabled  
if(popupStatus_password_forgot==1){  
$("#backgroundPopup_password_forgot").fadeOut("fast");  
$("#popupContact_password_forgot").fadeOut("fast");  
popupStatus_password_forgot = 0; 
}  
}

//centering popup  
function centerPopup_password_forgot(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact_password_forgot").height();  
var popupWidth = $("#popupContact_password_forgot").width();  
//centering  
$("#popupContact_password_forgot").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup_password_forgot").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close_password_forgot(){
disablePopup_password_forgot();
//restore the form to it's regular by reloading the page
window.location=window.location;

}


	//popup settings for password change

//0 means disabled, 1 means enabled;  
var popupStatus_password_change = 0;

function popup_start_password_change(){
centerPopup_password_change();  
loadPopup_password_change(); 
}

//loading popup with jQuery  
function loadPopup_password_change(){  
//loads popup only if it is disabled  
if(popupStatus_password_change==0){  
$("#backgroundPopup_password_change").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup_password_change").fadeIn("fast");  
$("#popupContact_password_change").fadeIn("fast");  
popupStatus_password_change = 1;  

}  
}

//disabling popup with jQuery
function disablePopup_password_change(){  
//disables popup only if it is enabled  
if(popupStatus_password_change==1){  
$("#backgroundPopup_password_change").fadeOut("fast");  
$("#popupContact_password_change").fadeOut("fast");  
popupStatus_password_change = 0; 
}  
}

//centering popup  
function centerPopup_password_change(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact_password_change").height();  
var popupWidth = $("#popupContact_password_change").width();  
//centering  
$("#popupContact_password_change").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup_password_change").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close_password_change(){
disablePopup_password_change();
//restore the form to it's regular by reloading the page
window.location=window.location;

}



	//popup settings for show large image (process page)

//0 means disabled, 1 means enabled;  
var popupStatus_image = 0;

function popup_start_image(){
centerPopup_image();  
loadPopup_image(); 
}

//loading popup with jQuery  
function loadPopup_image(){  
//loads popup only if it is disabled  
if(popupStatus_image==0){  
$("#backgroundPopup_image").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup_image").fadeIn("fast");  
$("#popupContact_image").fadeIn("fast");  
popupStatus_image = 1;  

}  
}

//disabling popup with jQuery
function disablePopup_image(){  
//disables popup only if it is enabled  
if(popupStatus_image==1){  
$("#backgroundPopup_image").fadeOut("fast");  
$("#popupContact_image").fadeOut("fast");  
popupStatus_image = 0; 
}  
}

//centering popup  
function centerPopup_image(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact_image").height();  
var popupWidth = $("#popupContact_image").width();  
//centering  
$("#popupContact_image").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup_image").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close_image(){
disablePopup_image();
//restore the form to it's regular by reloading the page
//window.location=window.location;

}


function show_image(image){
var image_src=image.src;

//set the image to the popup body
document.getElementById("popup_body_image").innerHTML = '<table><tr><td><img src="'+image_src+'" alt="" /></td></tr></table>';

//set the h1 to the popup
var image_name=get_header(image_src);
document.getElementById('h1_container').innerHTML = '<h1>'+image_name+'</hi>';
popup_start_image();
}

function get_header(path){

//get the name of the file out of the path
var pos=path.lastIndexOf('/');
return path.substr(pos+1);
}


	//popup settings for video

//0 means disabled, 1 means enabled;  
var popupStatus_video = 0;

function popup_start_video(){
centerPopup_video();  
loadPopup_video(); 
}

//loading popup with jQuery  
function loadPopup_video(){  
//loads popup only if it is disabled  
if(popupStatus_video==0){  
$("#backgroundPopup_video").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup_video").fadeIn("fast");  
$("#popupContact_video").fadeIn("fast");  
popupStatus_video = 1;  

}  
}

//disabling popup with jQuery
function disablePopup_video(){  
//disables popup only if it is enabled  
if(popupStatus_video==1){  
$("#backgroundPopup_video").fadeOut("fast");  
$("#popupContact_video").fadeOut("fast");  
popupStatus_video = 0; 
}  
}

//centering popup  
function centerPopup_video(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact_video").height();  
var popupWidth = $("#popupContact_video").width();  
//centering  
$("#popupContact_video").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup_video").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close_video(){
disablePopup_video();
window.location=window.location;
}



	//popup settings for video IG (right side of IG homepage)

//0 means disabled, 1 means enabled;  
var popupStatus_video_IG = 0;

function popup_start_video_IG(){
centerPopup_video_IG();  
loadPopup_video_IG(); 
}

//loading popup with jQuery  
function loadPopup_video_IG(){  
//loads popup only if it is disabled  
if(popupStatus_video_IG==0){  
$("#backgroundPopup_video_IG").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup_video_IG").fadeIn("fast");  
$("#popupContact_video_IG").fadeIn("fast");  
popupStatus_video_IG = 1;  

}  
}

//disabling popup with jQuery
function disablePopup_video_IG(){  
//disables popup only if it is enabled  
if(popupStatus_video_IG==1){  
$("#backgroundPopup_video_IG").fadeOut("fast");  
$("#popupContact_video_IG").fadeOut("fast");  
popupStatus_video_IG = 0; 
}  
}

//centering popup  
function centerPopup_video_IG(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact_video_IG").height();  
var popupWidth = $("#popupContact_video_IG").width();  
//centering  
$("#popupContact_video_IG").css({  
"position": "fixed",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#backgroundPopup_video_IG").css({  
"height": windowHeight  
});  
  
} 

//call on click on X image
function popup_close_video_IG(){
disablePopup_video_IG();
window.location=window.location;
}




//switch popup functions - for the links inside the popups

function switchto_signup(){
disablePopup();
popup_start_signup();
}

function switchto_login(){
//close without reloading the sign up form
disablePopup_signup();
popup_start();
}

function switchto_password_forgot(){
disablePopup();
popup_start_password_forgot();
}

function switchto_password_change(){
disablePopup();
popup_start_password_change();
}




//download page - download request

/*
the download link need to be added in the article as follows:

for direct download:
<a href="#null" onclick="start_download('example.pdf')">

for sending link to download by e-mail to user:
<a href="#null" onclick="start_download('example.pdf','link')">

this calls the ajax function that show login popup for not logged users, and download file
for logged in users.
in order to log in the javascript redirect the page as follows:
window.location='download.php?download_file=example.pdf';
*/

var http3 = create_object();
var download_file;

//call this function to check if user logged in
function start_download(file_name,type){

//save download request in session - to continue after signup
//save_download_request(file_name,type);
//alert("saved");

    if (type=="link"){
          start_download_link(file_name);
	}else{

		download_file=file_name;
		var nocache = 0;
		// Set random number to add to URL request (for IE)
		nocache = Math.random();
		http3.open('get', 'download.php?download_file='+download_file+'&nocache = '+nocache);
		http3.onreadystatechange = start_download_loginReply;
		http3.send(null);
	}

}

function start_download_10x(file_name,type,ThankUPage,counter_file){

//save download request in session - to continue after signup
//save_download_request(file_name,type);
//alert("link="+link);

    if (type=="link"){
          start_download_link(file_name);
	}else{
        if(counter_file) hit_counter(counter_file);
//		send_verification(file_name);
  	    window.open(file_name,'download');
	    window.location=ThankUPage;
    }
//		var nocache = 0;
		// Set random number to add to URL request (for IE)
//		nocache = Math.random();
//		http3.open('get', 'download.php?download_file='+download_file+'&nocache = '+nocache);
//		http3.onreadystatechange = start_download_loginReply;
//		http3.send(null);
//	}
//	alert("thank you="+ThankUPage+"====");

}
function start_download_NOloginReply(){

  if(http3.readyState == 4){
    var response = http3.responseText;
    if(response != 0)
      window.location='download.php?download_file='+download_file;
  }
}


function start_download_loginReply(){

if(http3.readyState == 4){
var response = http3.responseText;
if(response == 0){
/*popup_start();*/
popup_start_signup();
}else{
//alert("ok");
window.location='download.php?download_file='+download_file;

}
}

}


var http_download_link = create_object();

function start_download_link(file_name){

var nocache = 0;
// Set random number to add to URL request (for IE)
nocache = Math.random();
http_download_link.open('get', 'download_link.php?download_file='+file_name+'&nocache = '+nocache, true);
http_download_link.onreadystatechange = start_download_link_loginReply;
http_download_link.send(null);

}


var chrome_check = true;
function start_download_link_loginReply(){


if(http_download_link.readyState == 4){
var response = http_download_link.responseText;

if(response == 0){
/*popup_start();*/
popup_start_signup();
}else{

if (chrome_check == true){
alert("An E-mail message containing direct download link to the requested file has been sent to your member E-mail address: "+response);
}
location.reload();
chrome_check = false;

//delete_download_req();
//window.location='download.php?download_file='+download_file;
}
}
}




/*--- functions for the comments in blog page ---*/

var http_comment = create_object();
var nocache_comment = 0;
var current_comment="";

//cheking if user is logged in
function comment_if_login(num){

//assign the recieved number of the article to the global var
current_comment=num;

// Set random number to add to URL request (for IE)
nocache_comment = Math.random();
http_comment.open('get', 'comments.php?nocache = '+nocache_comment);
http_comment.onreadystatechange = commentReply;
http_comment.send(null);

}


function commentReply(){

if(http_comment.readyState == 4){
var response = http_comment.responseText;
//show the add comment form

if(response == 0){
//user is not logged in
addComments(current_comment);
}else{
str=response;
//call function to fill form fields with the logged in user details
setTimeout('update_inputs()',100);
addComments(current_comment);

}
}

}

var str="";

function update_inputs(){

var num=current_comment;
if (document.getElementById("txtEmail"+num)){

//fill form with user data;
var pos=str.lastIndexOf(";");
document.getElementById("txtUser"+num).value=str.substr(0,pos);
document.getElementById("txtEmail"+num).value=str.substr(pos+1);

}else{
//call function again - since ajax response have not come yet
setTimeout('update_inputs()',200);
}

}




//onclick comment save link
function comment_on_save(num){

current_comment=num;
setTimeout("hide_comment_on_save()",1500);
saveComment(current_comment);

}

//if no error close the add comment form
function hide_comment_on_save(){
if (document.getElementById('zimbcommentError'+current_comment).innerHTML.length==0){
hideComments(current_comment);
window.location=window.location;
}else{
setTimeout("document.getElementById('zimbcommentError'+current_comment).innerHTML='';",1000);
}

}





//save download request in session - to continue after signup or login





var http_save_download_request = create_object();

function save_download_request(file_name,type){

var nocache = 0;

// Set random number to add to URL request (for IE)
nocache = Math.random();
http_save_download_request.open('get', 'jsession_download_req.php?download_req='+file_name+'&download_type=' + type + '&nocache = '+nocache);
http_save_download_request.onreadystatechange = save_download_requestReply;
http_save_download_request.send(null);

}


function save_download_requestReply(){
if(http_save_download_request.readyState == 4){
var response = http_save_download_request.responseText;

}
}





var http_delete_download_req = create_object();


function delete_download_req(){

var nocache = 0;
// Set random number to add to URL request (for IE)
nocache = Math.random();
http_delete_download_req.open('get', 'delete_download_req.php?nocache = '+nocache);
http_delete_download_req.onreadystatechange = delete_download_reqReply;
http_delete_download_req.send(null);

}


function delete_download_reqReply(){
if(http_delete_download_req.readyState == 4){
var response = http_delete_download_req.responseText;
//alert("session deleted");

}
}



function detect_IE(){

var browser=navigator.appVersion;
browser = browser.toLowerCase();
var pos=browser.indexOf("msie");
if (pos!=-1){
	return true;
}else{
	return false;
}

}
