var id_rec;

function validate_input() {
	var email1 = document.getElementById('email1').value;
	var email2 = document.getElementById('email2').value;
	var email3 = document.getElementById('email3').value;
	var email4 = document.getElementById('email4').value;
	
	if(email1 == '' && email2 == '' && email3 == '' && email4 == '') {
		alert("Please Give atleast one email address!");
		return false;
	}
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	
	if( !emailpat.test( email1 ) && email1 != '' ) {
		alert('Email address written in first row is Invalid!');
		return false;
	}
	
	if( !emailpat.test( email2 ) && email2 != '' ) {
		alert('Email address written in second row is Invalid!');
		return false;
	}
	
	if( !emailpat.test( email3 ) && email3 != '' ) {
		alert('Email address written in third row is Invalid!');
		return false;
	}
	if( !emailpat.test( email4 ) && email4 != '' ) {
		alert('Email address written in fourth row is Invalid!');
		return false;
	}
	
	document.form1.submit();
}

function ValidateInputs() 
{
	var email = document.getElementById('user').value;
	if(email == ''){
		document.getElementById('error').innerHTML = "Email address can not left empty! ";
		return false;
	}
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	if( !emailpat.test( email ) ) {
 		document.getElementById('error').innerHTML = "Please! Eneter Valid Email Address! ";
 		return false;
	}
	http_request = get_xhttp_object();
	var url = '/cgi-bin/b2c-v3/fn_login.cgi?action=ec&user='+ email;
	http_request.open('GET',url,false);
    http_request.send(null);
	if ( http_request.status == 200 ) {
		var response = http_request.responseText;
		if(response == 'NOK') {
			document.getElementById('error').innerHTML = "Email Address is already Registered! ";
 			return false;
		}
	}else{
		alert("can not check availability");
		return false;
	}
	var pass  = document.getElementById('pass').value;
	var rpass = document.getElementById('repass').value;
	if(pass != rpass){
		document.getElementById('error').innerHTML = "Password is not matching! ";
		return false;
	}
	if(pass.length < 5){
		document.getElementById('error').innerHTML = "Password is too short! Minimum 5 character long ";
		return false;
	}
	document.contact.submit();
}
function do_track_login(){
	var username = document.getElementById("mail_add").value;
	var passwd   = document.getElementById("passwd").value;

	http_request = get_xhttp_object();
	var url = '/cgi-bin/b2c-v3/fn_login.cgi?action=login&user='+ username+'&passwd='+passwd;
	http_request.open('GET',url,false);
    http_request.send(null);
	if ( http_request.status == 200 ) {
		var response = http_request.responseText;
		if(response == "OK"){
			window.location.href='/cgi-bin/b2c-v3/Track_account.cgi'; 

		}else{
			document.getElementById("login_err_disp").innerHTML = "<td class='fdetailtitle_n1 'style='color:#ff2345;'>The username or password you entered is incorrect.</td>";			
		}
	}else {
       alert( 'Sorry, An error occurred. Please try again later.' );
   	   return false;
   	}
}

function rename_alert(id) {
	document.getElementById('wrapper_bg').style.display = 'block';
	document.getElementById('wrapper_rename').style.display = 'block';
	
	var topp = scrollwindow();
	var wd     = screen.width;
    var hg     = screen.height; 
    document.getElementById('wrapper_bg').style.width  = wd + 'px';
    document.getElementById('wrapper_bg').style.height = hg + 'px';
    document.getElementById('wrapper_bg').style.top    = topp + 'px';
    document.getElementById('wrapper_rename').style.left  = ((wd-575) / 2) + 'px';
    document.getElementById('wrapper_rename').style.top   = (topp+100) + 'px';
	id_rec = id;
}
function change_name() {
	var alert_name = document.getElementById("alert_name").value;
	
	http_request = get_xhttp_object();
	var url = '/cgi-bin/b2c-v3/Track_account.cgi?action=chname&name='+ alert_name + '&id=' + id_rec;
	
	http_request.open('GET',url,false);
    http_request.send(null);
	if ( http_request.status == 200 ) {
		window.location.href = '/cgi-bin/b2c-v3/Track_account.cgi';
	}else {
       alert( 'Sorry, An error occurred. Please try again later.' );
   	   return false;
   	}
}

function del_alert() {
	
	http_request = get_xhttp_object();
	var url = '/cgi-bin/b2c-v3/Track_account.cgi?action=delflight&id=' + id_rec;
	
	http_request.open('GET',url,false);
    http_request.send(null);
	if ( http_request.status == 200 ) {
		window.location.href = '/cgi-bin/b2c-v3/Track_account.cgi';
	}else {
       alert( 'Sorry, An error occurred. Please try again later.' );
   	   return false;
   	}
}

function delete_alert(id) {
	document.getElementById('wrapper_bg').style.display = 'block';
	document.getElementById('wrapper_del').style.display = 'block';
	var topp = scrollwindow();
	var wd     = screen.width;
    var hg     = screen.height; 
    document.getElementById('wrapper_bg').style.width  = wd + 'px';
    document.getElementById('wrapper_bg').style.height = hg + 'px';
    document.getElementById('wrapper_bg').style.top    = topp + 'px';
    document.getElementById('wrapper_del').style.left  = ((wd-575) / 2) + 'px';
    document.getElementById('wrapper_del').style.top   = (topp+ 100) + 'px';
	id_rec = id;
}

function close_frame(id) {
	document.getElementById("wrapper_bg").style.display="none";
	document.getElementById(id).style.display="none";
}

function similar_alert(id) {
	http_request = get_xhttp_object();
	var url = '/cgi-bin/b2c-v3/Track_account.cgi?action=similar&id=' + id;
	
	http_request.open('GET',url,false);
    http_request.send(null);
	if ( http_request.status == 200 ) {
		var response = http_request.responseText;
		window.location.href = response;
	}else {
       alert( 'Sorry, An error occurred. Please try again later.' );
   	   return false;
   	}
}
function scrollwindow(){
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfY;
}
function get_xhttp_object(){
	var http_request = false;
    if (window.XMLHttpRequest)
	{ //all but IE
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
		{
            http_request.overrideMimeType('text/xml');
        }
    }
	else if (window.ActiveXObject)
	{ //IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
	if (!http_request)
	{
        alert("http_request could not be established.");
        return false;
    }
	return http_request;
}
