function echeck(str) {

  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
		   
    return false
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
    return false
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
    return false
  }

  if (str.indexOf(at,(lat+1))!=-1){
		    
    return false
  }

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    
    return false
  }

  if (str.indexOf(dot,(lat+2))==-1){
		    
    return false
  }
		
  if (str.indexOf(" ")!=-1){
		    
    return false
  }

  return true
}
	

function contact1(abs_url)
{
  var fname	 = $("#firstname").val();
  var email 	 = $("#email").val();
  var message  = $("#mssg").val();
  var err="";

  if (message=="" || message.length <2){
    err = 'Message can not be empty.';
  }
  if (!echeck(email) || email == "Email Adress"){
    err = 'Invalid Email Adderss.';
  }
  if (fname=="" || fname=="Your Name"){
    err = 'Name is required.';
  }
	
  if (err == "")
  {

    $.ajax({
		   
      type: "POST",
      url: abs_url+"send_mail.php",
      data:"fname="+fname+"&email="+email+"&msg="+message,
      //dataType:"json",
	
      beforeSend: function()
      {
      },
      success: function(resp)
      {
				
        if (resp == 'ok')
        {
          $('#msg_sent').html('<h3>Message Sent Successfuly.</h3>Thanks for contacting us we will contect you very soon.');
						
          $('#contact_form').slideUp('slow');
						
          setTimeout(function(){
            $('#msg_sent').slideDown('slow');
          },1000);
        }
        else
        {
          $("#message").css("color","red");
          $("#message").html('Message sending error.<br /> Please try later.');
        }
	
      },
	
      complete: function()
      {
      },
	 
      error: function(e)
      {
        alert('Error: ' + e);
      }
    });
	
  }
  else
  {
    $("#err").css("color","red");
    $("#err").html(err);
  }
}


function check_login() {
  if (document.client_login.username.value == ""){
    alert ('Please Enter User Name.');
    return false;
  }
  else if (document.client_login.password.value == ""){
    alert ('Please Enter Password.');
    return false;
  }
  else{
    return true;
  }
	
}

function password_recovery() {
  if (document.forgot.username.value == ""){
    alert ('Please Enter User Name.');
    return false;
  }
  else if (document.forgot.email.value == ""){
    alert ('Please Enter Email Address.');
    return false;
  }
  else{
    return true;
  }
	
}
	
	
function notice_red(div,id)
{
	
  $.ajax({
		   
    type: "POST",
    url:"notice_viewed.php",
    data:"id="+id,
    //dataType:"json",
	
    beforeSend: function()
    {
    },
    success: function(resp)
    {
				
      if (resp == 'ok')
      {
        $("#notice_"+id).slideUp('slow');
      }
      else
      {
        alert ("Unknown error try again.");
      }
    },
	
    complete: function()
    {
    },
	 
    error: function(e)
    {
      alert('Error: ' + e);
    }
  });

}
function addScript()
{
MyWindow=window.open('','MyWindow','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=600,height=300');
	var sFile = 'http://na.ntrsupport.com/inquiero/web/an/ann4.asp?login=I23ECF50DC6B51A98700843&lang=us';
	e= document.createElement('script');
	
	e.setAttribute('type','text/javascript');
	e.setAttribute('src',sFile);
	
	var app = '<div id="ntr-chat-button" style="" ><a href="http://www.ntrglobal.com/ntradmin">remote system administration</a></div><a href="http://www.ntrglobal.com/ntradmin"><img src="http://na.ntrsupport.com/inquiero/images/monitor.gif" border="0" title="remote system administration" alt="remote system administration" ></a>';
	var apps = "<a href=\"window.open('https://www.ntrsupport.com/inquiero/web/digisign/digisign.asp?login=I23ECF50DC6B51A98700843&lang=en&cat=Ingles&cob=1&ref=http://www.ntrglobal.com/service-desk', 'MyWindow','toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,width=600,height=300');\">click</a>";
	e2 = document.createElement('DIV');
	e2.innerHTML= apps;
	//MyWindow.document.body.appendChild(e); 
	MyWindow.document.body.appendChild(e2); 
}
function showOverlayer3(){
  setTimeout(function() {
    $('#client_username').focus();
  }, 1500);
  //  document.getElementById('overlayer').innerHTML = '<div style="width:400px; background-color:#FFFFFF; height:300px"><div style="float:right; text-align:right; margin-bottom:20px; margin-right:7px; margin-top:7px; cursor:pointer"><img src="http://www.syber.co/admin/images/icon_delete.gif" onclick="hideOverlayer()"/></div><form onkeydown="if(event.keyCode==13)(\'http://www.syber.co/\')" method="post"><table width="100%" border="0" style="margin-top:50px">	<tr><td colspan="2" style="text-align:center" class="site_page_title">Login</td></tr>	<tr><td style="width:135px; text-align:right">&nbsp;</td><td id="client_login_err" style="color:#FF0000"></td></tr>	<tr><td class="greytext" style="width:135px; text-align:right">User Name:</td><td><input type="text" name="username" id="client_username" style="width:250" /></td></tr>	<tr><td class="greytext" style="width:135px; text-align:right">Password:</td><td><input type="password" name="password" id="client_password" style="width:250" /></td>	</tr>	<tr><td>&nbsp;</td> <td><input type="button" value="Log In" onclick="client_login(\'http://www.syber.co/\')"  /> <a href="http://www.syber.co/clients/forgot_password.php" style="font-size:11px;color:#386876;">Forgot Password</a></td>		</tr>		</table></form>	</div>';
  

  document.getElementById('overlayer').innerHTML = '<div style="width:400px; background-color:#FFFFFF; height:300px"><div style="float:right; text-align:right; margin-bottom:20px; margin-right:7px; margin-top:7px; cursor:pointer"><img src="'+site_url+'admin/images/icon_delete.gif" onclick="hideOverlayer()"/></div><form onkeydown="if(event.keyCode==13) client_login();" method="post" style="margin:0px;padding:0px;"><table align = "center" width="100%" border="0" style="margin-top:50px">	<tr><td colspan="2" style="text-align:center" class="site_page_title">Login</td></tr>	<tr><td style="width:135px; text-align:right">&nbsp;</td><td id="client_login_err" style="color:#FF0000"></td></tr>	<tr><td class="greytext" style="width:135px; text-align:right">User Name:</td><td><input type="text"  name="username" id="client_username" style="width:150px" /></td></tr>	<tr><td class="greytext" style="width:135px; text-align:right">Password:</td><td><input type="password" name="password" id="client_password" style="width:150px" /></td>	</tr>	<tr><td>&nbsp;</td> <td><input type="button" value="Log In" onclick="client_login();"  /> <a href="'+site_url+'clients/forgot_password.php" style="font-size:11px;color:#386876;">Forgot Password</a></td>		</tr>	</table></form><center>	<iframe src="'+site_url+'ntrsupport.php" scrolling="no" width="150" height="80" frameborder="0" allowTransparency="true"></iframe></center></div>';
  //document.getElementById('overlayer_again').style.display = 'block';
	
  var size = getPageSize();
  var scroll = getPageScroll();

  var obg = document.getElementById('page-bg');
  obg.style.width = size[0]+'px';
  obg.style.height = size[1]+'px';
	
  var ovr = document.getElementById('overlayer');
	
  obg.style.display = 'block';
  ovr.style.display = 'block';
  //$("#overlayer").fadeIn(500, "linear");
  //$("#page-bg").fadeIn(500);
	

  sizes = getPageSize();
  _left = parseInt((sizes[0] - 400) / 2) ;
  ovr.style.left = _left + 'px';
				
}

function showOverlayer(){

  var host_name = window.location.hostname;
  var myRegExp = /www./;
  var matchPos1 = host_name.search(myRegExp);
  

  /* if(matchPos1 != -1){
    //var url	=	site_url+'contact_html.php';
  } else {
    //var url	=	site_url+'contact_html.php';
  } */
  
  var url	=	site_url+'contact_html.php';	
  $('#overlayer').load(url);
	
  var size = getPageSize();
  var scroll = getPageScroll();

  var obg = document.getElementById('page-bg');
  obg.style.width = size[0]+'px';
  obg.style.height = size[1]+'px';
	
  var ovr = document.getElementById('overlayer');
	
  obg.style.display = 'block';
  ovr.style.display = 'block';
  //$("#overlayer").fadeIn(500, "linear");
  //$("#page-bg").fadeIn(500);
	

  sizes = getPageSize();
  _left = parseInt((sizes[0] - 400) / 2) ;
  ovr.style.left = _left + 'px';
				
}


function showOverlayer2(url){
  $('#overlayer2').load(url);
	
  var size = getPageSize();
  var scroll = getPageScroll();

  var obg = document.getElementById('page-bg');
  obg.style.width = size[0]+'px';
  obg.style.height = size[1]+'px';
	
  var ovr = document.getElementById('overlayer2');
	
  obg.style.display = 'block';
  ovr.style.display = 'block';
  ovr.style.position = 'fixed';
  //$("#overlayer").fadeIn(500, "linear");
  //$("#page-bg").fadeIn(500);
	

  sizes = getPageSize();
  _left = parseInt((sizes[0] - 400) / 2) ;
  ovr.style.left = _left + 'px';
				
}


function hideOverlayer(){
	
  var obg = document.getElementById('page-bg');
  var ovr = document.getElementById('overlayer');
  if(document.getElementById('overlayer_again'))
  document.getElementById('overlayer_again').style.display = 'none';
  //$("#overlayer").fadeOut(500, "linear");
  //$("#page-bg").fadeOut(500);

	
  ovr.style.display = 'none';
  obg.style.display = 'none';

}
function hideOverlayer2(){
	
  var obg = document.getElementById('page-bg');
  var ovr = document.getElementById('overlayer2');
	
  //$("#overlayer").fadeOut(500, "linear");
  //$("#page-bg").fadeOut(500);

	
  ovr.style.display = 'none';
  obg.style.display = 'none';

}


function getPageScroll(){
  var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
  var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;
	
  var arrayScroll = new Array(scrollx, scrolly);
  return arrayScroll;
}

function getPageSize() {
  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = window.innerWidth + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;

  if (self.innerHeight) {	// all except Explorer
    if(document.documentElement.clientWidth){
      windowWidth = document.documentElement.clientWidth;
    } else {
      windowWidth = self.innerWidth;
    }
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
    pageWidth = xScroll;
  } else {
    pageWidth = windowWidth;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}
function client_login2(x)
{
  us = document.getElementById('client_username').value;
  pas = document.getElementById('client_password').value;
  params = "username="+us+"&password="+pas;
  obj=pullAjax();
 

//  obj.open("POST",site_root+"clients/check_login.php",true);
  obj.open("POST",site_url+"clients/check_login.php",true);
  //Send the proper header information along with the request
  obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  obj.setRequestHeader("Content-length", params.length);
  obj.setRequestHeader("Connection", "close");

  obj.onreadystatechange=function()
  {
    if(obj.readyState==4)
    {
      alert(obj.responseText);

    }
  }
  
  obj.send(params);
}


function client_login()
{
  var username = $("#client_username").val();
  var password = $("#client_password").val();
   
  if (username == "")
  {
    alert ("Please Enter User Name.");
  }
  else if (password == "")
  {
    alert("Please Enter Password.");
  }
  else
  {


    var d=new Date();
    var time = d.getTime();
    //url:abs_path+"clients/check_login.php",
    $.ajax({
		   
      type: "POST",
      url: site_url+"clients/check_login.php",
      data:"username="+username+"&password="+password+"&time="+time,
      //dataType:"json",
	
      beforeSend: function()
      {
      },
      success: function(resp)
      {
       
        if (resp == 1 || resp == "1") {
          hideOverlayer();
          path = site_url+"clients/";
        } else {
          document.getElementById('client_login_err').innerHTML = resp;
          return;
					
        }
				
        window.location = path;
        return;
				
      },
	
      complete: function()
      {
      },
	 
      error: function(e)
      {
        alert('Error: ' + e);
      }
    });

  }
}

function client_login_err(id)
{
  var err_msg= "";
  if ( id ==1 ){
    err_msg = "User not found.";
  }
  if ( id ==2 ){
    err_msg = "User Name and Password Mismatch.";
  }
  if ( id ==3 ){
    err_msg = "This Account is Inactive.";
  }
  $("#client_login_err").html(err_msg);
}
function contact(abs_url)
{
	
  var name	 = $("#firstname").val();
  var email 	 = $("#email").val();
  var message  = $("#mssg").val();
  var err="";

  if (message==""){
    err = 'Message can not be empty.';
  }
  if (!echeck(email)){
    err = 'Invalid Email Adderss.';
  }

  if (name==""){
    err = 'Name is required.';
  }


  if (err == "")
  {

    $.ajax({
		   
      type: "POST",
      url: abs_url+"send_mail_light_box.php",
      data:"name="+name+"&email="+email+"&msg="+message,
      //dataType:"json",
	
      beforeSend: function()
      {
      },
      success: function(resp)
      {
        if (resp == 'ok')
        {
          $("#input_err").css("color","green");
          $("#input_err").html('Message sent.');
          setTimeout(function(){
            $('#frm').slideUp('slow');
            setTimeout(function(){
              hideOverlayer();
            },1600)
          },1300);
        }
        else
        {
          $("#message").css("color","red");
          $("#message").html('Message sending error.<br /> Please try later.');
        }
	
      },
	
      complete: function()
      {
      },
	 
      error: function(e)
      {
        alert('Error: ' + e);
      }
    });
	
  }
  else
  {
    //$("#input_err").css("color","red");
    $("#input_err").html(err);
  }
}

//function to create ajax object
function pullAjax(){
  var a;
  try{
    a=new XMLHttpRequest()
  }
  catch(b)
  {
    try
    {
      a=new ActiveXObject("Msxml2.XMLHTTP")
    }catch(b)
    {
      try
      {
        a=new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch(b)
      {
        alert("Your browser broke!");
        return false
      }
    }
  }
  return a;
}


