var cap_res = "";
// LTrim(string) : Returns a copy of a string without leading spaces.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}
/**
 * Verifies if the string is in a valid email format
 * @param	string
 * @return	boolean
 */
function isEmail( text )
{
	var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp( pattern );
	return regex.test( text );
}

function rand(l,u) // lower bound and upper bound
 {
     return Math.floor((Math.random() * (u-l+1))+l);
 }


function sendNewsletter()
{

   var form = document.forms[0];

		// do field validation
	       if (trim(form.name.value) == "")
               {
			alert('Please enter your name!');
                        form.name.focus();
                        return false;
		}
               else if(isEmail(form.email.value) == false)
               {
                       alert('Please enter a valid email!');
                       form.email.focus();
                       return false;
              }
		else
              {
	        Dialog.info("Please wait...", {width:200, height:100, showProgress: true}); 
                var data = $('frm_newsletter').serialize(true);
                 var url="index.php";
                 new Ajax.Request(url, {
					  method: 'post',
					  parameters:data,
					  onSuccess: function(transport) {
                      Dialog.closeInfo();
                      Dialog.alert(transport.responseText, {className: "alphacube", width:300, okLabel: "Close",ok:function(win){Dialog.closeInfo();}});  
                     }
                   
           });
        } 
}

function showNews(url)
{
    Dialog.info("Please wait...", {width:200, height:100, showProgress: true}); 
               new Ajax.Request(url, {
					  method: 'post',
					  parameters:null,
					  onSuccess: function(transport) {
                                          Dialog.closeInfo();
                              var result = transport.responseText;
                              var data = result.split("<!-- news_content -->");
                             $("news_content").innerHTML = data[1];
                              Lightbox.initialize();
                     }
                   
           });      
  
}

function showExtendedContent()
{
var txt = $('extended_content').innerHTML;
var content_height = $('extended_content').getHeight(); 

if(content_height <= 500 )
     Dialog.alert(txt, {className: "alphacube", width:500, okLabel: "Close"});
else
     Dialog.alert(txt, {className: "alphacube", width:500,height:500, okLabel: "Close"});
}

function openMap(url)
{
 
     var win = new Window({className: "alphacube", title: "Client Locations", width:800, height:500,zIndex:1300,resizable:false, url:url});
     win.showCenter(true);
}

function openClientEmail()
{alert('test');}

function InsertMailToTag( userName, domainName)
{
var EmailId;
var atSign = "&#64;"
var fullStop = "&#46";

EmailId = userName;
EmailId = "" + EmailId + atSign; 
EmailId = EmailId + domainName;

document.write( "<a href='mail" + "to:" + EmailId + "'>" + EmailId
+"</A>" );
}

function sendContact(url)
{
    Dialog.info("Please wait...", {width:200, height:100, showProgress: true}); 
    var data = $('frm_contact').serialize();
    Form.reset('frm_contact');
               new Ajax.Request(url, {
					  method: 'post',
					  parameters:data,
					  onSuccess: function(transport) {
                                      Dialog.closeInfo();
                      Dialog.alert(transport.responseText, {className: "alphacube", width:350, okLabel: "Close",ok:function(win){Dialog.closeInfo();}});  
                    
                  }
                   
           });      
  
}

/* captcha */

function displayCaptcha()
{   var num1 = rand(0,9);
    var num2 = rand(0,9);
    cap_res = eval(num1)+eval(num2);

    $('cap_num_1').update(num1);
    $('cap_num_2').update(num2);
    $('captcha').style.display ='block';
}

