<!-- Initialize the XMLHttpRequest Object -->

	var xmlhttp=false;
	var http_nav=false;
	var http_login=false;

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	  http_nav = new XMLHttpRequest();
	  http_login = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      http_nav = new ActiveXObject("Microsoft.XMLHTTP");
      http_login = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
<!-- End XMLHttpRequest Initialization -->

function addLink(link_id) {
	//alert(link_id);
	link_url = "inc/addlink.php?link=" + link_id;
	//alert(link_url);
	http_nav.open("GET", link_url, true);
	http_nav.onreadystatechange = function addNav() {

		if(http_nav.readyState == 4) {
			//alert(http_nav.responseText);
			//document.getElementById("nav").innerHTML = http_nav.responseText;
			//document.getElementById("main_table").innerHTML = http_nav.responseText;
		}
	}
	http_nav.send(null);
}


function author_movies(id) {
	
	ajaxURL	= 'main.php?do=home&action=author_movies&id=' + id;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {

			ajaxResponse = xmlhttp.responseText;
			document.getElementById("home").innerHTML = ajaxResponse;
			//addLink('update('+obj+')');
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}


function save_movies() {

	var doc = document.movies;
	title = doc.title.value;
	keywords= doc.keywords.value;
	uploadmovies= doc.uploadmovies.value;
	uploadimages = doc.uploadimages.value;
	Publishingdate = doc.Publishingdate.value;
	
	if (title == ""){
		alert("Enter title name.");
		doc.title.focus();
		return false;
	}	
	
	if (keywords == ""){
		alert("Enter keywords");
		doc.keywords.focus();
		return false;
	}	
	
	if (uploadmovies == ""){
		alert("Upload movie here");
		doc.uploadmovies.focus();
		return false;
	}
	if (uploadimages == ""){
		alert("Upload images here.");
		doc.uploadimages.focus();
		return false;
	}	
	if (Publishingdate == ""){
		alert("Enter publishing date.");
		doc.Publishingdate.focus();
		return false;
	}
	if (!document.getElementById("IframeId"))
	{
		createFrame();
	}
	doc.target = "IframeId";
	doc.submit();
	home();

}

function createFrame(secureUri){

	// IE does not allow the setting of id and name attributes as object
	// properties via createElement().  A different iframe creation
	// pattern is required for IE.
	var frameId = 'IframeId';
	if(window.ActiveXObject){
		var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');

		// IE will throw a security exception in an SSL environment if the
		// iframe source is undefined.
		if(typeof secureUri == 'boolean'){
			io.src = 'javascript:false';
		}
		else if(typeof secureURI == 'string'){
			// Deprecated
			io.src = secureUri;
		}
	}
	else{
		var io = document.createElement('iframe');
		io.id = frameId;
		io.name = frameId;
	}

	/* io.style.position = 'absolute';
	io.style.top	= '500px';
	io.style.left	= '200px';
	io.style.width	= '200px';
	io.style.height	= '200px';
	io.style.border	= '0px';*/
	
	io.style.position = 'absolute';
	io.style.top	= '-1000px';
	io.style.left	= '-1000px';
	io.style.width	= '0px';
	io.style.height	= '0px';
	io.style.border	= '0px';

	document.body.appendChild(io);
}

function subject_movies(id) {
	
	ajaxURL	= 'main.php?do=home&action=subject_movies&id=' + id;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {

			ajaxResponse = xmlhttp.responseText;
			document.getElementById("home").innerHTML = ajaxResponse;
			//addLink('update('+obj+')');
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}

function category_movies(id) {
	
	ajaxURL	= 'main.php?do=home&action=category_movies&id=' + id;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {

			ajaxResponse = xmlhttp.responseText;
			document.getElementById("home").innerHTML = ajaxResponse;
			//addLink('update('+obj+')');
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}


function search2(string2besearched){
	//modifyby JMA
	loadingsearch = 'Y';
	var doc = document.search_form;
	//alert(document.getElementById("search_keyword"));
	keyword_obj = string2besearched;
	//alert("Keyword:"+string2besearched);
	
	
	ajaxURL	= 'main.php?do=home&action=search_movies&keyword=' + keyword_obj;
//	alert(ajaxURL);
	show_loading();
	http_nav.open("GET", ajaxURL, true);
	http_nav.onreadystatechange = function() {
		if (http_nav.readyState==1 && loadingsearch)
		{
			document.getElementById("searchLoading").style.display = "block";
		}
		if (http_nav.readyState==4) {
			ajaxResponse = http_nav.responseText;
			
			if (ajaxResponse.indexOf("no records") != -1 || ajaxResponse.indexOf("nichts gefunden") != -1  )
			{
				document.getElementById("searchMsg").innerHTML = '<FONT COLOR="red">'+ajaxResponse+'</FONT>';
				document.getElementById("search_keyword").value = "";
			}else{
			
	
				document.getElementById("dinamicDiv").innerHTML = ajaxResponse;
				openPage('dinamic');
			}
			//addLink('update('+obj+')');
			document.getElementById("searchLoading").style.display = "none";
		   hide_loading()
		}
	}
	http_nav.send(null);
}



function register(){
	//modifyby JMA
	loadingregister = 'Y';
	if(document.getElementsByName("email_name")[0].value.length=="")
	{
		alert("Bitte geben Sie eine Email-Adresse an!");
		document.getElementById("email_name").focus();
		return false;
	}

	if(document.getElementsByName("email_name")[0].value !="" && document.getElementsByName("email_name")[0].value.indexOf('@')==-1 || document.getElementsByName("email_name")[0].value.indexOf('.')==-1 ){
		alert("Bitte geben Sie eine gültige Email-Adresse an!");
		document.getElementsByName("email_name")[0].value="";
		document.getElementsByName("email_name")[0].focus();
		return false;
	}

	
	email_obj = document.getElementsByName("email_name")[0].value;
	//alert(email_obj);
	
	ajaxURL	= 'main.php?do=home&action=register_email&email=' + email_obj;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==1 && loadingregister)
		{
			document.getElementById("newsletterLoading").style.display = "block";
		}
		if (xmlhttp.readyState==4) {

			ajaxResponse = xmlhttp.responseText;
		  
      
			if (document.getElementById("email").value == ''){
      document.getElementsByName("newsletterMessage_name")[0].innerHTML = ajaxResponse;
      }
      else
      {
      document.getElementById("newsletterMessage").innerHTML = ajaxResponse;
      }

      
      
			document.getElementsByName("email_name")[0].value = '';
			//addLink('update('+obj+')');
			document.getElementById("newsletterLoading").style.display = "none";
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}

function show_loading(){
	//var div_obj = document.getElementById('div_loading');
	//div_obj.style.display = 'block';
}

function hide_loading(){
	if (document.getElementById("searchLoading"))
	{
		document.getElementById("searchLoading").style.display = "none";
	}
	
	//var div_obj = document.getElementById('div_loading');
	//div_obj.style.display = 'none'; 
}

function login_new(){
	var doc = document.loginform;
	user = doc.uname.value;
	password= doc.pwd.value;
	
	if (user == ""){
		alert("Enter user name.");
		doc.uname.focus();
		return false;
	}
	if (password == ""){
		alert("Enter password.");
		doc.pwd.focus();
		return false;
	}
	ajaxURL	= 'main.php?do=home&action=summary&uname='+user+'&pwd=' + password;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {
			ajaxResponse = xmlhttp.responseText;
			if (ajaxResponse.indexOf("Invalid") == -1)
			{
				document.getElementById("loginBar").innerHTML = '<A HREF="javascript:logout();" class="white"><IMG SRC="images/logout.gif" WIDTH="47" HEIGHT="18" BORDER="0"></A>&nbsp;&nbsp;<A HREF="javascript:movies();" class="white"><IMG SRC="images/movies.gif" WIDTH="47" HEIGHT="18" BORDER="0"></A>&nbsp;&nbsp;';
				home();
			}else{
				document.getElementById("loginMsg").innerHTML = ajaxResponse;
			}
			//document.getElementById("home").innerHTML = ajaxResponse;
			//addLink('update('+obj+')');
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}


function check_availability(){	
	
	var doc = document.form;
	email_value = doc.email.value;
	

	ajaxURL	= 'main.php?do=home&action=save&email=' + email_value;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {
			ajaxResponse = xmlhttp.responseText;
			
			if (ajaxResponse.indexOf("exists") != -1)
			{
				document.getElementById("emailBar").innerHTML = ajaxResponse;			
				
			}else{
				document.getElementById("emailBar").innerHTML = '';
			}			
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}




function logout(){
	

	ajaxURL	= 'main.php?do=home&action=logout';
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {
			ajaxResponse = xmlhttp.responseText;
			if (ajaxResponse.indexOf("You are successfully logout") == -1)
			{
				document.getElementById("loginBar").innerHTML = '<A HREF="javascript:login();" class="white"><IMG SRC="images/login.gif" WIDTH="38" HEIGHT="18" BORDER="0" id="login_img"></A>&nbsp;&nbsp;<A HREF="javascript:signup();" class="white"><IMG SRC="images/signup.gif" WIDTH="53" HEIGHT="18" BORDER="0" id="signup_img"></A>';
				home();
			}else{
				document.getElementById("logoutMsg").innerHTML = ajaxResponse;
			}			
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}


function chk(){
	
	var doc = document.form;
	id = doc.id.value;
	fname = doc.fname.value;
	lname = doc.lname.value;
	address = doc.address.value;
	city = doc.city.value;
	state = doc.state.value;
	country = doc.country.value;
	phone = doc.phone.value;
	mobile = doc.mobile.value;
	fax = doc.fax.value;
	user = doc.uname.value;
	password= doc.pwd.value;
	cpassword= doc.cpwd.value;	
	email = doc.email.value;
	
	if (fname == ""){
		alert("Enter first name.");
		doc.fname.focus();
		return false;
	}	
		
	if (email == ""){
		alert("Enter Email Address.");
		doc.email.focus();
		return false;
		}
		
	if(doc.email.value !="" && doc.email.value.indexOf('@')==-1 || doc.email.value.indexOf('.')==-1 ){
		alert("Please Enter Correct Email Address");
		doc.email.value="";
		doc.email.focus();
		return false;
	}
		
		if (user == ""){
			alert("Enter user name.");
			doc.uname.focus();
			return false;
		}
		if (password == ""){
			alert("Enter password.");
			doc.pwd.focus();
			return false;
		}	
		if (cpassword == ""){
			alert("Enter Confirm password.");
			doc.cpwd.focus();
			return false;
		}
		
		if (doc.pwd.value != doc.cpwd.value){
			alert("Confirm password should be same as confirm password.");
			doc.cpwd.value = "";
			doc.cpwd.focus();
			return false;
		}


	ajaxURL	= 'main.php?do=home&action=save&id='+id+'&fname='+fname+'&lname=' +lname+'&address='+address+'&city='+city+'&state='+state+'&country='+country+'&email='+email+'&phone='+phone+'&mobile='+mobile+'&fax='+fax+'&uname='+user+'&pwd='+password;
	//alert(ajaxURL);
	show_loading();
	xmlhttp.open("GET", ajaxURL, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {

			ajaxResponse = xmlhttp.responseText;
			if (ajaxResponse.indexOf("Your") == -1)
			{
				document.getElementById("loginBar").innerHTML = '<A HREF="javascript:logout();" class="white"><IMG SRC="images/logout.gif" WIDTH="47" HEIGHT="18" BORDER="0"></A>&nbsp;&nbsp;<A HREF="javascript:movies();" class="white"><IMG SRC="images/movies.gif" WIDTH="47" HEIGHT="18" BORDER="0"></A>&nbsp;&nbsp;';
				home();
			}else{
				document.getElementById("signupMsg").innerHTML = ajaxResponse;
			}
		   hide_loading()
		}
	}
	xmlhttp.send(null);
}
