var loadedyes=0;
var menuwidth=898;
//configure menu height (in px):
var menuheight=25;
//Specify scroll buttons directions ("normal" or "reverse"):
var scrolldir="normal";
//configure scroll speed (1-10), where larger is faster
var scrollspeed=7;
//specify menu content
var loadedyes=0;
var error_border = '1px solid rgb(220, 3, 3)';
var fix_border = '1px solid #1a84bb';
var error_border_color = 'rgb(220,3,3)';
function findPosX(obj)
{
  var curleft = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}

function moveleft(){
  if (loadedyes){
  if (parseInt(cross_scroll.style.left)>(menuwidth-actualwidth)){
  cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px"
  }
  else if (document.layers&&ns_scroll.left>(menuwidth-actualwidth))
  ns_scroll.left-=scrollspeed
  }
  lefttime=setTimeout("moveleft()",50)
}

function moveright(){
  if (loadedyes){
  if (parseInt(cross_scroll.style.left)<0)
  cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px"
  else if (document.layers&&ns_scroll.left<0)
  ns_scroll.left+=scrollspeed
  }
  righttime=setTimeout("moveright()",50)
}

function fillup(line){
  menucontents = line;
  cross_scroll = document.getElementById('scroll_div');
  cross_scroll.innerHTML=menucontents;
  //actualwidth=document.getElementById("temp").offsetWidth;
  actualwidth=1125;

  loadedyes=1;
}

function setActionPath(base_url)
{
  if ( document.login_form.login.value == '' || document.login_form.login.value == null ) {
      document.getElementById('error_message').style.display = 'block';
      document.getElementById('error_message').innerHTML="Please Enter Username."
      return false;
  }
  else if ( document.login_form.passwd.value == '' || document.login_form.passwd.value == null ) {
      document.getElementById('error_message').style.display = 'block';
      document.getElementById('error_message').innerHTML="Please Enter Password."
      return false;
  }
  var url = base_url;
        url = "http://login.itimes.com/Logonnew.aspx?ru="+url+"&IS=6fff66bc-e4bf-4e62-9cf1-8a05cfcbdd75&NS=Times&HS=pvkx41mrq4pnJy55YKDoHQfjvrQ=";
	document.login_form.action=url;
	document.login_form.submit();
}

/*function OnClickSignup() {
  document.getElementById('register_form_block').style.display='block';
  document.getElementById('register_confirm_block').style.display='none';
  document.getElementById('full_name').focus();
}*/

var clear_bubble_hide;
var clear_green_bubble_hide;
function show_green_bubble_tip(field_id, text, a, b) {
  document.getElementById('bubble_body').style.display='none';
  document.getElementById('bubble_body_green').style.display='block';
  showToolTipGreen_from(field_id, text, a, b);
}

function CheckUsernameAvailability(event_name) {
  var user_name =trim(document.getElementById('user_name').value);
  if (!user_name) {
    show_bubble_tip('user_name', 'Username cannot be left blank.',195, 6);
    $('#user_name').css('border', error_border);
    return true;
  } else if (!CheckUserName()) {
    var check_url = base_url + "/ajax/check_username_availability.php?name="+user_name;
    $.get(
       check_url,
       {
       },
       function(response) {
          if(response == 0) {
            show_bubble_tip('user_name', 'Username not available.',195, 6);
            $('#user_name').css('border', error_border);
            return true;
          } else {
            if(event_name == 'onclick') {
              show_green_bubble_tip('user_name', 'Username available.',195, 6);
            } else if(event_name == 'onblur') {
              // Doing nothing ... but can be used later if required
            }
          }
       }
     );
   }
  $('#user_name').css('border', fix_border);
  return false;
}

function CheckFullName() {
  var full_name =trim(document.getElementById('full_name').value);
  var fullnameRegEx = /^[a-zA-Z\s]+$/;
  if(!trim(full_name)) {
    $('#full_name').css('border', error_border);
    show_bubble_tip('full_name', 'Full name is mandatory. Please enter your First and Last name with a space between the two. Eg: Angelina Sharma. No special characters are allowed.', 195, 6);
    return true;
  } else if(full_name.length>50 || full_name.length<3) {
    show_bubble_tip('full_name', 'Full name should be 2-50 characters long.',195, 6);
    $('#full_name').css('border', error_border);
    return true;
  } else if (full_name.split(' ').length < 2) {
    show_bubble_tip('full_name', 'Invalid full name. Please enter your First and Last name with a space between the two. Eg: Angelina Sharma. No special characters are allowed.',195, 6);
    $('#full_name').css('border', error_border);
    return true;
  } else if(full_name.search(fullnameRegEx) == -1) {
    show_bubble_tip('full_name', 'Invalid full name. Please enter your First and Last name with a space between the two. Eg: Angelina Sharma. No special characters are allowed.',195, 6);
    $('#full_name').css('border', error_border);
    return true;
  }
  $('#full_name').css('border', fix_border);
  return false;
}

function CheckUserName() {
  var user_name =trim(document.getElementById('user_name').value);
  var usernameRegEx = /^[a-zA-Z0-9.]+$/;
  //var usernameRegEx = /^[a-zA-Z_0-9.]+$/;
  if(!trim(user_name)) {
    show_bubble_tip('user_name', 'Username is mandatory. It can be alphanumeric ranging from 3-50 characters', 195, 6);
    $('#user_name').css('border', error_border);
    return true;
  } else if(user_name.length>50 || user_name.length<3) {
    show_bubble_tip('user_name', 'Invalid username. It can be alphanumeric ranging from 3-50 characters', 195, 6);
    $('#user_name').css('border', error_border);
    return true;
  } else if ( !isNaN(user_name) ) {
    show_bubble_tip('user_name', 'Invalid username. It can be alphanumeric ranging from 3-50 characters', 195, 6);
    $('#user_name').css('border', error_border);
    return true;
  }else if(user_name.search(usernameRegEx) == -1) {
    show_bubble_tip('user_name', 'Invalid username. It can be alphanumeric ranging from 3-50 characters', 195, 6);
    $('#user_name').css('border', error_border);
    return true;
  }
  $('#user_name').css('border', fix_border);
  return false;
}

function CheckEmail() {
  var email =document.getElementById('email').value;
  var emailRegEx = /^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,}$/i;
  if(!trim(email)) {
    show_bubble_tip('email', 'Please enter a valid email id. It will be used to activate your account.', 195, 6);
    $('#email').css('border', error_border);
    return true;
  } else if (email.search(emailRegEx) == -1) {
    show_bubble_tip('email', 'Invalid email address.', 195, 6);
    $('#email').css('border', error_border);
    return true;
  } else if (email.toLowerCase().indexOf('@indiatimes.com') != -1) {
    //show_bubble_tip('email', 'If you are an existing indiatimes email user, please use your email id and password to login to itimes.', 205, 6);
    alert('If you are an existing indiatimes email user, please use your email id and password to login to itimes.')
    document.getElementById('username').focus();
    $('#email').css('border', error_border);
    return true;
  } else if (email.toLowerCase().indexOf('@itimes.com') != -1) {
    show_bubble_tip('email', 'If you are an existing itimes user, please use your itimes id and password to login to LeadIndia.', 205, 6);
    $('#email').css('border', error_border);
    return true;
  } else {
    $.get(
     base_url + "/ajax/check_registration_fields.php?field_name=alternate_email&field_value="+email,
     {
     },
     function(response) {
      if ( response == 1 ) {
        show_bubble_tip('email', 'Email id already exists.', 195, 6);
        $('#email').css('border', error_border);
        return true;
      }
     }
    );
  }
  $('#email').css('border', fix_border);
  return false;
}

function CheckPassword() {
  var pass_word =trim(document.getElementById('pass_word').value);
  var confirm_pass_word =trim(document.getElementById('confirm_pass_word').value);
  var pass_wordRegEx = /^[a-zA-Z0-9.~@#\$]+$/;
  if(!trim(pass_word)) {
    show_bubble_tip('pass_word', 'Please enter password. It must be between 6-14 characters and may contain a combination of alphabets, numbers and symbols.', 195, 6);
    $('#pass_word').css('border', error_border);
    return true;
  } else if(pass_word.length>14 || pass_word.length<6) {
    show_bubble_tip('pass_word', 'Invalid password. Password must be between 6-14 characters and may contain a combination of alphabets, numbers and symbols.', 195, 6);
    $('#pass_word').css('border', error_border);
    return true;
  } else if(pass_word.search(pass_wordRegEx) == -1) {
    show_bubble_tip('pass_word', 'Invalid password. Password must be between 6-14 characters and may contain a combination of alphabets, numbers and symbols.', 195, 6);
    $('#pass_word').css('border', error_border);
    return true;
  }
  $('#pass_word').css('border', fix_border);
  return false;
}
function CheckCNFPassword() {
  var pass_word =trim(document.getElementById('pass_word').value);
  var confirm_pass_word =trim(document.getElementById('confirm_pass_word').value);
  if(!trim(confirm_pass_word)) {
    show_bubble_tip('confirm_pass_word', 'Please re-type your password', 195, 6);
    $('#confirm_pass_word').css('border', error_border);
    return true;
  } else if(pass_word!=confirm_pass_word) {
    show_bubble_tip('confirm_pass_word', 'Passwords do not match.', 195, 6);
    $('#confirm_pass_word').css('border', error_border);
    return true;
  }
  $('#confirm_pass_word').css('border', fix_border);
  return false;
}

function CheckRegisterSubmit() {
  var is_error = false;
  var passcode_block =document.getElementById('passcode_block');
  var chkbox_agree =document.getElementById('chkbox_agree').checked;
  if(CheckFullName() && (is_error != true)) {
    $('#full_name').css('border', error_border);
    is_error = true;
  } /*else if(CheckUserName() && (is_error != true)) { //commented due to Open Id
    $('#user_name').css('border', error_border);
    is_error = true;
  }*/ 
  else if(CheckEmail() && (is_error != true)) {
    $('#email').css('border', error_border);
    is_error = true;
  } else if(CheckPassword() && (is_error != true)) {
    is_error = true;
  } else if (CheckCNFPassword() && (is_error != true)) {
    is_error = true;
  } else if(CheckDate() && (is_error != true)) {
    is_error = true;
  } else if(CheckGender() && (is_error != true)) {
    is_error = true;
  } /*else if(passcode_block.style.display=='block') {
    var passcode =document.getElementById('passcode').value;
    if(!trim(passcode) && (is_error != true)) {
      show_bubble_tip('passcode', 'Passcode cannot be left blank.',195, 6);
      document.getElementById('passcode').focus();
      $('#passcode').css('border', error_border);
      is_error = true;
    }
  }*/ else if(wordVerify() && (is_error != true)) {
    is_error = true;
  } else if(validate_terms() && (is_error != true)) {
    is_error = true;
  }
  $('#gender').css('border', fix_border);
  $('#txtNumber').css('border', fix_border);
  $('#chkbox_agree').css('border', fix_border);
  return !is_error;
}

function validate_terms() {
  var chkbox_agree =document.getElementById('chkbox_agree').checked;
  if ( chkbox_agree == false ) {
    show_bubble_tip('chkbox_agree', 'Please click on the check box to agree to Terms of Use of itimes.', 15, 6);
    $('#chkbox_agree').css('border', error_border);
    return true;
  }
  return false;
}

function CheckGender() {
  var gender =document.getElementById('gender').value;
  if ( gender == 0 ) {
    show_bubble_tip('gender', 'Please specify gender', 65, 6);
    $('#gender').css('border', error_border);
    return true;
  }
  $('#gender').css('border', fix_border);
  return false;
}

function wordVerify() {
  var word_verify = document.getElementById('txtNumber').value;
  var captha_string = document.getElementById('captha_string').value
  if(!trim(word_verify)) {
    show_bubble_tip('txtNumber', 'Verfication word cannot be left blank', 195, 6);
    $('#txtNumber').css('border', error_border);
    return true;
  } else if ( word_verify != captha_string ) {
    show_bubble_tip('txtNumber', 'The verification code did not match', 195, 6);
    $('#txtNumber').css('border', error_border);
    return true;
    /*$.get(
     base_url + "/ajax/check_registration_fields.php?field_name=txtNumber&field_value="+word_verify,
     {
     },
     function(response) {
      if ( response == 0 ) {
        show_bubble_tip('txtNumber', 'The verification code did not match', 195, 6);
        $('#txtNumber').css('border', error_border);
        return true;
      }

     }
    );*/
  }
  $('#txtNumber').css('border', fix_border);
  return false;
}

/*function URLEncode(url) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = url;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}*/

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



function setHomepage(what, url) {
  if (navigator.appName == 'Microsoft Internet Explorer' && document.getElementById)
  setHomepageExplorer(what, url);
  else if (document.layers || document.getElementById) setHomepageNetscape(what, url);
  return false;
}

function setHomepageNetscape(what, url) {
  var warn = 'Due to Netscapes security handling, this page will show you a dialog with a warning.' + 'If you do not wish to grant this site the access to ' + 'your browser settings, you can manually copy ' + 'http://itimes.com and paste it in the location field in ' + 'Edit|Preferences|Navigator.';
  if (confirm(warn))
  {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
  navigator.preference('browser.startup.homepage', url);netscape.security.PrivilegeManager.disablePrivilege("UniversalPreferencesWrite");
  }
}

function setHomepageExplorer(what, url) {
  what.style.behavior = 'url(#default#homepage)';
  what.setHomePage(url);
}

function save_registration_info(obj) { 
  if ( CheckRegisterSubmit() ) {
    $('#bubble_body_green').css('display', 'none');
    $('#bubble_body').css('display', 'none');
    $('#bubble_iframe').css('display', 'none');
    var len = obj.elements.length;
    var params = {};
    for ( i=0; i < len; i++ ) {
      params[ obj.elements[i].name ] = obj.elements[i].value;
    }
    $.post(
      base_url + "/ajax/save_registration_info.php",
      params,
      function(htmlData) {
        var data = htmlData.split('##$$%%@@##');
        $('#registration_form_inner').html(data[0]);
        if ( data[1] ) {
          if ( data[1] == 15026 ) {
            show_bubble_tip('passcode', 'Invalid passcode', 195, 6);
            $('#passcode').css('border', error_border);
          } else if ( data[1] == 'Please enter correct verification number' ) {
            show_bubble_tip('txtNumber', data[1], 195, 6);
            $('#txtNumber').css('border', error_border);
          } else if ( data[1] == 15024 ) {
            show_bubble_tip('dob_year', 'Invalid date of birth.', 55, 6);
            $('#dob_month').css('border', error_border);
            $('#dob_day').css('border', error_border);
            $('#dob_year').css('border', error_border);
          } else if ( data[1] == 15027 ) {
            show_bubble_tip('email', 'Email id already exists.', 195, 6);
            $('#email').css('border', error_border);
          }  else if ( data[1] == 15038 ) {
           // show_bubble_tip('email', 'If you are an existing indiatimes email user, please use your email id and password to login to itimes.', 205, 6);
            alert('If you are an existing indiatimes email user, please use your email id and password to login to itimes.')
            document.getElementById('username').focus();
            $('#email').css('border', error_border);
          } else if ( data[1] == 15025 ) {
            show_bubble_tip('txtNumber', 'The verification code did not match', 195, 6);
            $('#txtNumber').css('border', error_border);
          } else if ( data[1] == 15017 ) {
            show_bubble_tip('user_name', 'Login name is already taken', 195, 6);
            $('#user_name').css('border', error_border);
          } else {
            $('#message').css('display', 'block');
            var msg = '<span > <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr><td><img src="'+base_url+'/images/left-b-img.gif" width="5" height="24" alt="" /> </td> <td height="24" style="background:url('+base_url+'/images/repeater-b-img.gif) repeat-x;"><div style="margin:0;padding:0;height:19px;"> <span style="padding:0 4px 0 0;color:#fff;font-weight:bold;">'+data[1]+'</span><span><img src="'+base_url+'/images/cross-img-new.gif" alt="" onclick = "hide_div();" /></span></div></td><td><img src="'+base_url+'/images/right-b-img.gif" width="5" height="24" alt="" /></td></tr></table></span>';
            $('#message').html(msg);
          }
        }
      }
    );
  }
  return false;
}

function show_help_text_registration_old(type) {
  var all_types = new Array('full_name', 'user_name', 'pass_word', 'confirm_pass_word', 'email', 'txtNumber', 'passcode');
  var len = all_types.length;
  for ( var i = 0; i < len; i++ ) {
    if ( all_types[i] == type ) {
      var txt_index = i;
      break;
    }
  }
  var msg_of_types = new Array(
    'Enter your First and Last name with a space between the two. Eg: Angelina Sharma. No special characters are allowed',
    'Choose a username for logging in. Username is not case sensitive and can be alphanumeric ranging from 3-50 characters',
    'Password is case sensitive and must range from 6-14 characters. Passwords may contain a combination of alphabets, numbers and symbols',
    'Please re-type your password',
    'Please enter a valid email id. It will be used to activate your account',
    'Please enter the text fom the image provided. The text is not case sensitive. Please do not enter space in between any of the characters',
    'Passcode is your access key to itimes. Entering a passcode is not mandatory'
  );
  if ( txt_index == 1 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckFullName() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color)  ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 195, 6);
      }
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 195, 6);
      }
      return;
    }
  } else if ( txt_index == 2 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckUserName() || CheckUsernameAvailability() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 195, 6);
      }
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 195, 6);
      }
      return;
    }
  } else if ( txt_index == 3 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckPassword() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 195, 6);
      }
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 195, 6);
      }
      return;
    }
  } else if ( txt_index == 4 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckCNFPassword() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 195, 6);
      }
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 195, 6);
      }
      return;
    }
  } else if ( txt_index == 5 ) {
    txt_index_final = txt_index - 1;
    if ( CheckGender() ) {
      return;
    } else if ( CheckDate() ) {
      return;
    } else if  ( CheckEmail() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 195, 6);
      }
      return;
    } else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 195, 6);
      }
      return;
    }
  } else if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
    show_help_tip(type, msg_of_types[i], 195, 6);
  }
}

function show_help_text_registration(type) {   
  var all_types = new Array('full_name', 'email', 'pass_word', 'confirm_pass_word', 'txtNumber', 'passcode');
  var len = all_types.length;
  for ( var i = 0; i < len; i++ ) {
    if ( all_types[i] == type ) {
      var txt_index = i;
      break;
    }
  }
   
 var msg_of_types = new Array(
    'Enter your First and Last name with a space between the two. Eg: Angelina Sharma. No special characters are allowed', 
    'Please enter a valid email id. It will be used to activate your account',
    'Password is case sensitive and must range from 6-14 characters. Passwords may contain a combination of alphabets, numbers and symbols',
    'Please re-type your password',
    'Please enter the text fom the image provided. The text is not case sensitive. Please do not enter space in between any of the characters',
    'Passcode is your access key to itimes. Entering a passcode is not mandatory'
  );
  if ( txt_index == 1 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckFullName() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color)  ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 205, 6);
      }
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 205, 6);
      }
      return;
    }
  } else if ( txt_index == 2 ) {//commented due to Open Id
       txt_index_final = txt_index - 1;
     if  ( CheckEmail() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 205, 6);
      }
      return;
    } else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 205, 6);
      }
      return;
    }
  } else if ( txt_index == 3 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckPassword() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 205, 6);
      }
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 205, 6);
      }
      return;
    }
  } else if ( txt_index == 4 ) {
    txt_index_final = txt_index - 1;
    if  ( CheckCNFPassword() ) {
      if ( ($('#'+all_types[txt_index_final]).css('border') != error_border) && ($('#'+all_types[txt_index_final]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index_final], msg_of_types[txt_index_final], 205, 6);
      }
      return;
    }
    if ( CheckGender() ) {
      return;
    } else if ( CheckDate() ) {
      return;
    }
    else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 205, 6);
      }
      return;
    }
  } else if ( txt_index == 5 ) {
    txt_index_final = txt_index - 1;
    if ( CheckGender() ) {
      return;
    } else if ( CheckDate() ) {
      return;
    } else {
      if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
        show_help_tip(all_types[txt_index], msg_of_types[txt_index], 205, 6);
      }
      return;
    }
  } else if ( ($('#'+all_types[txt_index]).css('border') != error_border) && ($('#'+all_types[txt_index]).css('borderColor') != error_border_color) ) {
    show_help_tip(type, msg_of_types[i], 205, 6);
  }
}

function show_help_tip(field_id, text, a, b) {
  document.getElementById('bubble_body_green').style.display='block';
  document.getElementById('bubble_body').style.display='none';
  showToolTip_help(field_id, text, a, b);
}

function showToolTip_help(field_id, text, a, b){
  var field_obj = document.getElementById(field_id);
  var leftPos = findPosX(field_obj) + a;
  var rightPos = findPosY(field_obj) - b;
  var obj = document.getElementById('bubble_body_green');
  var obj2 = document.getElementById('bubble_text_green');
  obj2.innerHTML = text;
  obj.style.display = 'block';
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  var obj_height = obj.offsetHeight;
  var obj_width = obj.offsetWidth;
  obj.style.top = rightPos + 'px';
  $('#bubble_iframe').css({top:rightPos+'px',left:(leftPos+10)+'px',display:'block',height:obj_height+'px', width:(obj_width-15)+'px'});
}

function remove_bubble_or_error() {
  remove_bubble();
  var obj = document.register_form;
  var len = obj.elements.length;
  for ( var i = 0; i < len; i++ ) {
    if ( obj.elements[i].type == 'text' || obj.elements[i].type == 'password' || obj.elements[i].type == 'select-one' ) {
      obj.elements[i].style.border = fix_border;
    }
  }
}

function remove_bubble() {
  $('#bubble_body_green').css('display', 'none');
  $('#bubble_body').css('display', 'none');
  $('#bubble_iframe').css('display', 'none');
}

function forgot_password() {
  var user_name = $('#forgot_user_name').val();
  if ( !trim(user_name) ) {
    $('#forgot_password_msg').html('Username field cannot be left blank. Please enter your itimes username');
    $('#forgot_password').css('display', 'none');
    $('#forgot_password_msg').css('display', 'block');
    var set_time = setTimeout("$('#forgot_password').css('display', 'block');$('#forgot_password_msg').css('display', 'none');", 1500);
  } else {
    $.get(
      base_url + '/ajax/forgot_password.php?user_name='+user_name,
      {
      },
      function(response) {
        $('#forgot_password_msg').html(response);
        $('#forgot_password').css('display', 'none');
        $('#forgot_password_msg').css('display', 'block');
        var set_time = setTimeout("$('#forgot_password').css('display', 'block');$('#forgot_password_msg').css('display', 'none');", 1500);
      }
    );
  }
  //clearTimeout(set_time);
}

function click_to_activate_account(user_name) {
  $.get(
      base_url + '/ajax/click_to_activate_account.php?user_name='+user_name,
      {
      },
      function(response) {
      }
  );
}
function show_bubble_tip(field_id, text, a, b) {
  document.getElementById('bubble_body_green').style.display='none';
  document.getElementById('bubble_body').style.display='block';
  showToolTip_from(field_id, text, a, b);
}
function showToolTip_from(field_id, text, a, b){
  var field_obj = document.getElementById(field_id);
  var leftPos = findPosX(field_obj) + a;
  var rightPos = findPosY(field_obj) - b;
  var obj = document.getElementById('bubble_body');
  var obj2 = document.getElementById('bubble_text');
  obj2.innerHTML = text;
  obj.style.display = 'block';
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  var obj_height = obj.offsetHeight;
  var obj_width = obj.offsetWidth;
  obj.style.top = rightPos + 'px';
  $('#bubble_iframe').css({top:rightPos+'px',left:(leftPos+10)+'px',display:'block',height:obj_height+'px', width:(obj_width-15)+'px'});
}
function trim(field) {
  value = field;
  while (value.charAt(value.length-1) == " ") {
    value = value.substring(0,value.length-1);
  }
  while(value.substring(0,1) ==" ") {
    value = value.substring(1,value.length);
  }
  return value;
}
function show_hide_div(id) {
   if(document.getElementById(id).style.display=='block') {
    document.getElementById(id).style.display='none';
   } else {
      document.getElementById(id).style.display='block';
  }
}
function CheckDate(call_from) {
  var dob_month =Number(document.getElementById('dob_month').value);
  var dob_day =Number(document.getElementById('dob_day').value);
  var dob_year =Number(document.getElementById('dob_year').value);
  var source_date = new Date(dob_year,dob_month,dob_day);
  var myDate=new Date();
  myDate.setFullYear(dob_year, dob_month-1, dob_day);
  var today = new Date();
  today.setFullYear(today.getFullYear() - 18, today.getMonth(), today.getDay());
  var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;


  var dob = dob_month+'/'+dob_day+'/'+dob_year;

  if(dob_month==0) {
    show_bubble_tip('dob_month', 'Please specify month of birth', 68, 6);
    if(call_from == 'registration'){
      $('#dob_month').css('border', error_border);
    }else {
    document.getElementById('dob_month').focus();
    }
    return true;
  } else if(dob_day==0) {
    show_bubble_tip('dob_day', 'Please specify date of birth', 54, 6);
    if(call_from == 'registration'){
      $('#dob_day').css('border', error_border);
    }else {
    document.getElementById('dob_day').focus();
    }
    return true;
  } else if(dob_year==0) {
    show_bubble_tip('dob_year', 'Please specify year of birth', 59, 6);
    if(call_from == 'registration'){
      $('#dob_year').css('border', error_border);
    } else {
      document.getElementById('dob_year').focus();
    }
    return true;
  } else if (!(dob.match(RegExPattern))) {
     if(call_from == 'edit_profile'){
       show_bubble_tip('dob_month', 'Invalid date of birth', 85, 6);
       document.getElementById('dob_month').focus();
     } else {
      show_bubble_tip('dob_year', 'Invalid date of birth', 55, 6);
      $('#dob_month').css('border', error_border);
      $('#dob_day').css('border', error_border);
      $('#dob_year').css('border', error_border);
    }
    return true;
  } else if ( myDate > today ) {
    if(call_from == 'edit_profile'){
       show_bubble_tip('dob_year', 'Minimum age should be 18', 55, 6);
       document.getElementById('dob_year').focus();
     } else {
      show_bubble_tip('dob_year', 'Minimum age for registration is 18', 55, 6);
      $('#dob_month').css('border', error_border);
      $('#dob_day').css('border', error_border);
      $('#dob_year').css('border', error_border);
    }
    return true;
  }
  $('#bubble_body_green').css('display', 'none');
  $('#bubble_body').css('display', 'none');
  $('#bubble_iframe').css('display', 'none');
  if(call_from == 'registration'){
    $('#dob_month').css('border', fix_border);
    $('#dob_day').css('border', fix_border);
    $('#dob_year').css('border', fix_border);
  }
  return false;
}
function show_why_register_lead() {
  txt = "Sign up so that you can participate in the Lead India '09 communities, blog, and win contests and quizzes. Become a part of this nationwide movement; pledge your support";
  show_help_tip('why_register_lead', txt, 80, 0);
  var hide_bubble = "document.getElementById('bubble_body').style.display='none';document.getElementById('bubble_body_green').style.display='none';document.getElementById('bubble_iframe').style.display='none';";
  clear_bubble_hide = window.setTimeout(hide_bubble,3000);
}
function show_why_register_header() {
  txt = "Sign up so that you can participate in the Lead India '09 communities, blog, and win contests and quizzes. Become a part of this nationwide movement; pledge your support.Existing itimes members can use same username and password to signin.";
  show_help_tip('why_register_header', txt, 80, 0);
  document.getElementById('header_green_tick_img').style.display = 'none';
  var hide_bubble = "document.getElementById('bubble_body').style.display='none';document.getElementById('bubble_body_green').style.display='none';document.getElementById('bubble_iframe').style.display='none';";
  clear_bubble_hide = window.setTimeout(hide_bubble,3000);
}

function lead_login_popup (object, signin_url,delx,dely){ 
	
  delx = typeof(delx) != 'undefined' ? delx : 100;
  dely = typeof(dely) != 'undefined' ? dely : 35;
	
  $('#bubble_text').html("");
  var x = findPosX(object) + 0;  
  var y = findPosY(object) + 0;
  $('#login_bubble_body').css('display', 'block');
  var obj2 = $('#login_bubble_body');
  get_data = 'signin_url='+signin_url;
  $.ajax({
    type: "GET",
    url: base_url +"/ajax/lead_login_popup.php",
    data: get_data,
    success: function(response) {
      $('#login_bubble_body').html(response);
    }
  }); 

//  $('#login_bubble_body').css('left',x-100 +'px');
//  $('#login_bubble_body').css('top',y-35 +'px');

  $('#login_bubble_body').css('left',x-delx +'px');
  $('#login_bubble_body').css('top',y-dely +'px');


}
function lead_login_popup_close () {
  $('#login_bubble_body').css('display', 'none');
}