function RegisterNewsletter(){
    var errors = "" ;
    x = $('#txtVisitorFirstName').val();
    if ((x == "") || (x == "First Name")) errors += 'First name must not be empty.\n'; 
    
    x = $('#txtVisitorLastName').val();
    if ((x == "") || (x == "Last Name")) errors += 'Last name must not be empty.\n';              

    x = $('#txtVisitorEmail').val(); 
    if ((x == "") || (x == "Email")) errors += 'Email must not be empty.\n';

    
    if (errors) 
        alert('Please fill-in the missing fields : \n' + errors);
    else {        
        $.ajax({
            type: "POST",
            url: "ajaxFc.php",
            data:   "visitorFirstName=" + $('#txtVisitorFirstName').val() + 
                    "&visitorLastName=" + $('#txtVisitorLastName').val() +
                    "&visitorEmail=" + $('#txtVisitorEmail').val() +
                    "&countryId=" + $('#cmbCountries').val() +
                    "&action=Newsletter",
            success: function(html){
                $("#divNewsletter").html(html);               
            }
        });
    }        
}

function contactUs(){
    var errors = "" ;
    x = $('#txtContactName').val();
    if ((x == "") || (x == "First Name")) errors += 'Name must not be empty.\n'; 
    
    x = $('#txtSubject').val();
    if ((x == "") || (x == "Last Name")) errors += 'Subject must not be empty.\n';              

    x = $('#txtContactEmail').val(); 
    if ((x == "") || (x == "Email")) errors += 'Email must not be empty.\n';

    
    if (errors) 
        alert('Please fill-in the missing fields : \n' + errors);
    else {        
        $.ajax({
            type: "POST",
            url: "ajaxFc.php",
            data:   "companyName=" + $('#txtCompanyName').val() + 
                    "&contactName=" + $('#txtContactName').val() +
                    "&contactEmail=" + $('#txtContactEmail').val() +
                    "&contactPhone=" + $('#txtContactPhone').val() +   
                    "&country=" + $('#cmbCountries').val() +   
                    "&subject=" + $('#txtSubject').val() +   
                    "&inquiry=" + $('#txtInquiry').val() +
                    "&action=ContactUs",
            success: function(html){
                $("#divContactUs").html(html);               
            }
        });
    }        
} 

function Login()
{
    
    var errors = "" ;
    x = $('#txtUsername').val();
    if ((x == "") || (x == "username")) errors += 'Username must not be empty.\n';          

    x = $('#txtPassword').val(); 
    if (x == "") errors += 'Password must not be empty.\n';

    
    if (errors) 
        alert('Please fill-in the missing fields : \n' + errors);
    else {
        
        $.ajax({
            type: "POST",
            url: "ajaxFc.php",
            data:   "username=" + $('#txtUsername').val()  + 
                    "&password=" + $('#txtPassword').val() +
                    "&securityCode=" + $('#txtSecurityCode').val() +
                    "&action=Login",
            success: function(html){;
                if ($.trim(html) == "OK") {
                   // $.fn.colorbox.close();
                   //parent.$.fn.colorbox.close();
                   //alert("You are logged in") ;
                   window.parent.location.href = 'client-tasks.php' ;
                } else {
                    $("#divLoginMsg").html(html);
                    clearDivForm("#divLogin") ; 
                }              
            }
        });
    }     
}

function clearDivForm(divName)
{
    divName = '#' + divName ;
    $(divName).children().find('input, select, checkbox, radio, textarea').each(function(){
        
       var type = this.type;
       var tag = this.tagName.toLowerCase();
       
      // alert(tag) ;
      if (type == 'text' || type == 'password' || tag == 'textarea')
        $(this).val('') ;
      else if (type == 'checkbox' || type == 'radio')
        this.checked = false;
      else if (tag == 'select')
       // $(this).selectedIndex = -1;
        this.selectedIndex = -1;   
      });    
}

/*Project paging*/
function gotoPage(pageNum, catId)
{
    var divName = "#divProjectsCat"  + catId ;
    
    $(divName).html("<div style='text-align:center; margin-top: 100px'><img src='images/loading_big.gif' alt='' /></div>");
        
    $.ajax({
        type: "POST",
        url: "ajaxFc.php",
        data:   "pageNum=" + pageNum + 
                "&catId=" + catId +
                "&action=ProjectPaging",
        success: function(html){
            $(divName).html(html); 
            
            /* for the project info overlay */
            $(".whiteTrans").show(); 
            $(".itemHolder").hover(function(){
                $(this).find('.whiteTrans').animate({height:"30px"}, 200);
            }, function(){
                $(this).find('.whiteTrans').animate({height:"12px"}, 100);
            }); 
            /* for the read more dimm (colorobx) */
            $("a.readMoreDim").colorbox({iframe:true, innerWidth:980, innerHeight:400});                       
        }
    });    
}

function nextProject(projectId)
{
    $("#divProjectContent").html("<div style='text-align:center; margin-top: 100px'><img src='images/loading_big.gif' alt='' /></div>");  
 
    $.ajax({
        type: "POST",
        url: "ajaxFc.php",
        data:   "projectId=" + projectId + 
                "&action=NextProject",        
        success: function(html){
            $("#divProjectContent").html(html);
          
            //after loading the page we call the slide function again  
            $('.anythingSlider').anythingSlider({
                easing: "easeInOutExpo",
                autoPlay: false,
                delay:5000,
                startStopped: false,
                animationTime:700,
                hashTags: true,
                buildNavigation: true,
                pauseOnHover: true,
                startText: "Go",
                stopText: "Stop",
                navigationFormatter: formatText
            });                                    
        }
    });    
    
}


/*News paging*/
function gotoNewsPage(pageNum, catId)
{
    var divName = "#divNewsCat"  + catId ;
    $(divName).html("<div style='text-align:center; margin-top: 100px'><img src='images/loading_big.gif' alt='' /></div>"); 
    
    $.ajax({
        type: "POST",
        url: "ajaxFc.php",
        data:   "pageNum=" + pageNum + 
                "&catId=" + catId +
                "&action=NewsPaging",
        success: function(html){
            $(divName).html(html); 
            
            /* for the read more dimm (colorobx) */
            $("a.readMoreDim").colorbox({iframe:true, innerWidth:980, innerHeight:400});                       
        }
    });    
}

function nextStory(articleId)
{
   $("#divNewsContent").html("<div style='text-align:center; margin-top: 100px'><img src='images/loading_big.gif' alt='' /></div>"); 
   
    $.ajax({
        type: "POST",
        url: "ajaxFc.php",
        data:   "articleId=" + articleId + 
                "&action=NextStory",        
        success: function(html){
            $("#divNewsContent").html(html); 
            
            $('.anythingSlider').anythingSlider({
                easing: "easeInOutExpo",
                autoPlay: false,
                delay:5000,
                startStopped: false,
                animationTime:700,
                hashTags: true,
                buildNavigation: true,
                pauseOnHover: true,
                startText: "Go",
                stopText: "Stop",
                navigationFormatter: formatText
            }); 
            
            $("#divWaitLoading").html("") ;                                     
        }
    });    
    
}

