﻿// Local variable
var regex_Email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; 
var    ie=(document.all);

// Function written to validate Email Id
function validate(email){  
     if (!regex_Email.test(email)) {
        return false;  
     }
     else
     {
        return true;
     }
}
//function to trim leading white spaces on left side of the string
//----------------------------------------------------------------
function LeftTrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

//function to trim trailing white spaces on right side of the string
//------------------------------------------------------------------
function RightTrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//function to trim leading and trailing white spaces
//---------------------------------------------------
function Trim(str, chars) {
    return LeftTrim(RightTrim(str, chars), chars);
}
function Redirect(url)
{
    //Redirection
    window.location.href="./"+url;
}
function MailTo(email)
{
    // MailTo
    window.location.href = 'mailto:' + email;    
}
// function written to change mouseover image and show the submenu
function Show(jid)
{
    document.getElementById('divSubMenuOuter').style.display="inline";
    var imgPath = new String();    
    imgPath = document.getElementById(jid).style.backgroundImage;    
    if (ie)
    {
      if (imgPath == "url(./images/Button.jpg)" || imgPath == "url(./images/ButtonHiglight.jpg)" || imgPath == "") {
        document.getElementById(jid).style.backgroundImage = "url(./images/ButtonOver.jpg)";
        }
    }
    else
    {
        if (imgPath == 'url("./images/Button.jpg")' || imgPath == 'url("./images/ButtonHiglight.jpg")' || imgPath == "") {
        document.getElementById(jid).style.backgroundImage = 'url("./images/ButtonOver.jpg")';
        }
    }
}
// function written to hide the submenu
function Hide()
{
    document.getElementById('divSubMenuOuter').style.display="none";  
}

// onmouseoverimgsrc function to change the image source on Mouseover
function onmouseoverimgsrc(jid) {
    var imgPath = new String();    
    imgPath = document.getElementById(jid).style.backgroundImage;    
    if (ie)
    {
      if (imgPath == "url(./images/Button.jpg)" || imgPath == "url(./images/ButtonHiglight.jpg)" || imgPath == "") {
        document.getElementById(jid).style.backgroundImage = "url(./images/ButtonOver.jpg)";
        }
    }
    else
    {
        if (imgPath == 'url("./images/Button.jpg")' || imgPath == 'url("./images/ButtonHiglight.jpg")' || imgPath == "") {
        document.getElementById(jid).style.backgroundImage = 'url("./images/ButtonOver.jpg")';
        }
    }    
    document.getElementById('divSubMenuOuter').style.display="none";
}
// onmouseoutimgsrc function to change the image source on Mouseout
function onmouseoutimgsrc(jid,menuh) {
    var imgPath = new String();    
    imgPath = document.getElementById(jid).style.backgroundImage;        
    if (ie)
    {    
        if (menuh=='MenuHighlight')
        {   
           document.getElementById(jid).style.backgroundImage = "url(./images/ButtonHiglight.jpg)";            
        }
        else
        {
            document.getElementById(jid).style.backgroundImage = "url(./images/Button.jpg)";            
        }               
    }
    else
    {
        if (menuh=='MenuHighlight')
        {   
            document.getElementById(jid).style.backgroundImage = 'url("./images/ButtonHiglight.jpg")';            
        }
        else
        {
            document.getElementById(jid).style.backgroundImage = 'url("./images/Button.jpg")';         
        }            
    }   
}
// function wriiten to show underline on mouse over the label
function MouseOverOfLabel(id)

{
    document.getElementById(id).style.textDecoration='underline';
}
// function wriiten to hide underline on mouse out of the label
function MouseOutOfLabel(id)
{
    document.getElementById(id).style.textDecoration='none';
}
// function written to clear all the values of the caontact us form
function ClearAllValues()
{  
    //clear all text box values
    //-------------------------
    document.getElementById('txtName').value='';
    document.getElementById('txtCompany').value='';
    document.getElementById('txtCountry').value='';
    document.getElementById('txtZip').value='';
    document.getElementById('txtEmail').value='';
    document.getElementById('txtPhone').value='';
    document.getElementById('txtMessage').value='';
    //fcous
    document.getElementById('txtName').focus();    
}

//function to check submitted details
//-----------------------------------
function SubmitDetails()
{
    var post=true;

    //Trim() function is called to trim leading and trailing white spaces in a string
    //-------------------------------------------------------------------------------
    document.getElementById('txtName').value=Trim(document.getElementById('txtName').value,'');
    document.getElementById('txtCompany').value=Trim(document.getElementById('txtCompany').value,'');
    document.getElementById('txtCountry').value=Trim(document.getElementById('txtCountry').value,'');
    document.getElementById('txtZip').value=Trim(document.getElementById('txtZip').value,'');
    document.getElementById('txtEmail').value=Trim(document.getElementById('txtEmail').value,'');
    document.getElementById('txtPhone').value=Trim(document.getElementById('txtPhone').value,'');
    document.getElementById('txtMessage').value=Trim(document.getElementById('txtMessage').value,'');

    if (document.getElementById('txtName').value=='')
    {
        alert("Please give Name");   
        document.getElementById('txtName').focus();
        post=false;
    }    
    else if (document.getElementById('txtEmail').value=='' && document.getElementById('txtPhone').value=='')
    {
        alert("Please give Email / Phone details");
        document.getElementById('txtEmail').focus();
        post=false;
    }
    else if (validate(document.getElementById('txtEmail').value) == false && document.getElementById('txtEmail').value != '')
    {
        alert("Please give valid email");
        document.getElementById('txtEmail').focus();
        post=false;
    }
    else if (document.getElementById('txtMessage').value=='')
    {
        alert("Please give message");   
        document.getElementById('txtMessage').focus();
        post=false;
    }
    else if (document.getElementById('txtMessage').value.length>300)
    {
        alert("Exceeds maximum length");        
        document.getElementById('txtMessage').focus();
        post=false;
    }
    else
    {
        post=true;        
    }
    return post;
}
