﻿function openWindow(theURL,winName,features) { 
    if(features=="")
        features = "scrollbars=0, menubars=0, toolbars=0, location=0, directories=0, status=0, width=350, height=218, top=200, left=300, resizable=0";    
  
    window.open(theURL,winName,features);
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
var msg="";
var msg1="";

function ValidateAskUs(form) {
var valid = true;
    if(form.txtName.value.trim()=="" && valid){
        msg="* Required field";
        form.txtName.focus();       
        valid=false;
    }    
    if((form.txtEmail.value.trim()=="" || !isValidEmail(form.txtEmail.value)) && valid){
        document.getElementById("msgAskus").innerHTML='Invalid email address.';
        return false;
    }
    
//    if(form.txtPhone.value.trim()=="" && valid){
//        msg="* Required field";
//        form.txtPhone.focus();       
//        valid=false;
//    }    
//    if(form.txtQ.value.trim()=="" && valid){
//        msg="* Required field";
//        form.txtQ.focus();       
//        valid=false;
//    }    
    if(valid){
        $.post('send.aspx?type=askus',{txtName : form.txtName.value, txtEmail : form.txtEmail.value, txtPhone : form.txtPhone.value, txtQ : form.txtQ.value});
        //form.action="send.aspx?type=askus";
        //form.submit();
            $("#divQPopUp input").attr("value","");
            $("#divQPopUp textarea").attr("value","");
            $("#divQPopUp").slideUp("normal");
        $.prompt("Thank you for submitting a question to QualiTest. You will receive a response within the next 2 business days.");
        
    }
    else{
        document.getElementById("msgAskus").innerHTML=msg;
    }

}

function ValidateAskUs2(i) {
var valid = true;
    if($('#txtName' + i).attr('value').trim()=="" && valid){
        msg="* Required field";
        //$('#txtName')get(0).focus();       
        valid=false;
    }  
    if(($('#txtEmail' + i).attr('value').trim()=="" || !isValidEmail($('#txtEmail' + i).attr('value'))) && valid){
        msg = 'Invalid email address.';
        valid=false;
    }
//    if(form.txtPhone.value.trim()=="" && valid){
//        msg="* Required field";
//        form.txtPhone.focus();       
//        valid=false;
//    }    
   
//    if($('#txtQ' + i).attr('value').trim()=="" && valid){
//        msg="* Required field";
//        //$('#txtQ').get(0).focus();       
//        valid=false;
//    }    
    if(valid){
        $.post("send.aspx?type=askus",{txtName : $('#txtName' + i).attr('value'), txtEmail : $('#txtEmail' + i).attr('value'), txtPhone : $('#txtPhone' + i).attr('value') , txtQ : $('#txtQ' + i).attr('value')},function(data){
            $.prompt("Thank you for submitting a question to QualiTest. You will receive a response within the next 2 business days.");
            $("input").attr("value","");
            $("textarea").attr("value","");
            $(".divQPopUp").slideUp("normal");
        });
    }
    else{
        document.getElementById("msgAskus" + i).innerHTML=msg;
    }

}

function ValidateTB(form,section) {
var valid = true;
    if(form.txtTBName.value.trim()=="" && valid){
        msg="* Required field";
        form.txtTBName.focus();       
        valid=false;
    }    
    if((form.txtTBEmail.value.trim()=="" || !isValidEmail(form.txtTBEmail.value)) && valid){
        msg="* Required field";
        form.txtTBEmail.focus();       
        valid=false;
    }    
    if(form.txtTBTitle.value.trim()=="" && valid){
        msg="* Required field";
        form.txtTBTitle.focus();       
        valid=false;
    }    
    if(valid){
        $.post("send.aspx?type=tb&section="+section, {txtTBName : form.txtTBName.value, txtTBEmail : form.txtTBEmail.value, txtTBTitle : form.txtTBTitle.value, txtTBComment : form.txtTBComment.value})
        //form.action="send.aspx?type=tb&section="+section;
        //form.submit();
        $.prompt("Thank you, Your message has been sent.");
    }
    else{
        document.getElementById("msgTB").innerHTML=msg;
    }
}

function ValidateContactForm(form) {
    var valid = true;
    if(form.txtFN.value.trim()==""){
        msg1 = msg1 + "* Required first name<br/>";
        form.txtFN.focus();       
        valid = false;
    }    
    if(form.txtLN.value.trim()==""){
        msg1 = msg1 + "* Required last name<br/>";
        form.txtLN.focus();       
        valid = false;
    }    
    if(!isValidEmail(form.txtEmail1.value) || (form.txtEmail1 == null || form.txtEmail1.value == ""))
    {
       msg1= msg1 + "* Invalid email<br/>";
       form.txtEmail1.focus();       
       valid = false;
    }    
    if(valid){
        $.post("send.aspx?type=contact",{
            txtFN : form.txtFN.value,
            txtLN : form.txtLN.value,
            txtTitle1 : form.txtTitle1.value,
            txtCompany1 : form.txtCompany1.value,
            txtEmail1 : form.txtEmail1.value,
            phone1 : form.phone1.value,
            //fax : form.fax.value,
            //website : form.website.value,
            address : form.address.value,
            city : form.city.value,
            state : form.state.options[form.state.selectedIndex].innerHTML,
            country : form.country.options[form.country.selectedIndex].innerHTML,
            comment1 : form.comment1.value
            });
        //form.action="send.aspx?type=contact";
        //form.submit();
        $.prompt("Thank you, Your message has been sent.");
    }
    else{
        $.prompt("<span style='color:red;'>" + msg1 + "</span>");
        msg1 = "";
    }
}

function isValidEmail(str) {
   return !(typeof(str) == 'undefined' || str == null) && ((str.indexOf(".") > 2) && (str.indexOf("@") > 0));
}

function SignIn(){
    openWindow("Sign.aspx", "loginwin", "");
//    openWindow("login.htm", "loginwin", "");
}

function SignOut(){
    self.location.href="userlogin.aspx?type=signout";    
}

function CheckLogin(form){
    form.action="userlogin.aspx?type=signin";
    form.submit();
}

function ShowTabContentByIndex(index)
{
    if(typeof($('#divTabsContent').get(0)) == 'undefined')
        return;
    if($("#divTabsContent div:eq(" + index + ")").css("display") == "block") return;
        
    $("#divTabsContent div").hide();
    $("#divTabsContent div:eq(" + index + ")").fadeIn('normal');
    
    $("#divTabs a").attr("class","TabOut");
    $("#divTabs a:eq(" + index + ")").attr("class","TabHover");
    $("#divTabs a:eq(" + index + ")").attr('href','thinktesting.html?page=' + index);
}

var initPage;
function ShowTabContent2ByIndex(index)
{
    if(typeof($('#divTabsContent2').get(0)) == 'undefined')
        return;
    if(initPage != -1)
    {
        initPage = querySt("page");
        if(initPage != null)
        {
            index = initPage;
            initPage = -1;
        }
    }
    if($("#divTabsContent2 div:eq(" + index + ")").get(0).style.display == "block") return;
    
    $("#divTabsContent2 div.item").hide();
    $("#divTabsContent2 div.item:eq(" + index + ")").fadeIn('normal');
    
    $("#divTabs a").attr("class","TabOut");
    $("#divTabs a:eq(" + index + ")").attr("class","TabHover");
}

function querySt(ji) 
 {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i=0;i<gy.length;i++) 
        {
            ft = gy[i].split("=");
            if (ft[0] == ji) 
            {
                return ft[1];
            }
    }
}
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 32)
		  {
		    ;
		  }
		else	{
                         
			 return false;
		  }
 		}
 return true;
}

function SearchClick()
{
    var searchValue = document.getElementById('txtSearch').value;
    if(alphanumeric(searchValue))
        location.href='search_' + document.getElementById('txtSearch').value+ '.html';
    else
        $.prompt("Only 0-9 and A-Z characters are allowed");
}

    function Search(e)
    {  
    var key = e.keyCode ? e.keyCode : e.which;
        if (key == 13) 
        {
            SearchClick();
            alert("You're being redirected to Search Results Page");
        }
        return true;
    }

function initMenu(openIndex) {
 
        $('#VMenu ul:not(.current)').hide();
        
        //$('#VMenu ul:first').show();
         
        $('#VMenu li a').click(
         
        function() {
         
            var checkElement = $(this).next();
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                $('#VMenu ul:visible').slideUp('normal');
                return false;
                }
         
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#VMenu ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
            return false;
             
        }
         
        }
     
    );
 
}

function initTicker()
{
    $("#divBar div").hide();
    $("#divBar div:first").show();
    setTimeout('RunTicker();',5000);
}

function RunTicker()
{
    $("#divBar div:visible").fadeOut(300,function(){
        if(!$(this).next().is("div"))
            $("#divBar div:first").fadeIn(500,function(){
            setTimeout('RunTicker();',5000);
            });
        else
        {            
            $(this).next().fadeIn(500,function(){
            setTimeout('RunTicker();',5000);
            });
        }
    });
}


function initBranchesMenu()
{
    $('#divBranchesMenu .items').hide();
    $('#divBranchesMenu .title').click(function(){
        if($(this).next().css("display") == "none")
        {
            $('#divBranchesMenu .items').slideUp("normal");
            $(this).next().slideDown("normal");
        }
        else
            $(this).next().slideUp("normal");
    });
}

function ValidateServiceForm(form) {
var valid = true;
    if(form.txtFN.value.trim()=="" && valid){
        msg1="* Required first name";
        form.txtFN.focus();       
        valid=false;
    }    
    if(form.txtLN.value.trim()=="" && valid){
        msg1="* Required last name";
        form.txtLN.focus();       
        valid=false;
    }    
    if(!isValidEmail(form.txtEmail1.value) || (form.txtEmail1 == null || form.txtEmail1.value == "") && valid)
    {
       msg1="* Invalid email";
       form.txtEmail1.focus();       
       valid = false;
    }    
    if(valid){
     $.post("send.aspx?type=service",{
            txtFN : form.txtFN.value,
            txtLN : form.txtLN.value,
            txtTitle1 : form.txtTitle1.value,
            txtCompany1 : form.txtCompany1.value,
            txtEmail1 : form.txtEmail1.value,
            phone1 : form.phone1.value,
            //fax : form.fax.value,
            //website : form.website.value,
            address : form.address.value,
            city : form.city.value,
            state : form.state.options[form.state.selectedIndex].innerHTML,
            country : form.country.options[form.country.selectedIndex].innerHTML,
            comment1 : form.comment1.value,
            interest : form.interest.options[form.interest.selectedIndex].innerHTML
            });
        //form.action="send.aspx?type=service";
        //form.submit();
        $.prompt("Thank you...");
    }
    else{
        document.getElementById("msg1").innerHTML=msg1;
    }
}
function InitTopMenu()
{
    $(document).ready(function(){   
  
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)   
  
    $("ul.topnav li span").click(function() { //When trigger is clicked...   
  
        //Following events are applied to the subnav itself (moving subnav up and down)   
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click   
  
        $(this).parent().hover(function() {   
        }, function(){   
            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up   
        });   
  
        //Following events are applied to the trigger (Hover events for the trigger)   
        }).hover(function() {   
            $(this).addClass("subhover"); //On hover over, add class "subhover"   
        }, function(){  //On Hover Out   
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"   
    });   
  
});  

}

function initInputSubmit()
{
    $('#divInputSubmit input').attr('value', '');
    $('#divInputSubmit input').keydown(function(e){
        if (e.which == 13 || e.keyCode == 13)$('#btnSubmit').click();
    });
}

function LogoFix()
{
    $('#aLogo').html("<img src='InnerData/Images/Logo.png' />");
}


function SignNewsLetter(i)
{
    var _email =  $('#txtNLEmail' + i).attr('value');
    if(isValidEmail(_email))
    {
        $.get("send.aspx",{type : 'newsletter', email : _email},function(data){
            $.prompt('Information was sent');
        });
        $('#txtNLEmail' + i).attr('value','');
    }
    else
        $.prompt("Invalid Email address");
}

function OpenTalkback(item)
        {
            $(item).next().slideToggle("fast");
            return false;
        }
        
        function TextBoxFocus(item, text)
        {
            if($(item).attr('value') == text)
            {
                $(item).attr('value','');
                $(item).removeClass('TextBoxBlur').addClass('TextBoxFocus');
            }
        }
        
        function TextBoxBlur(item, text)
        {
            if($.trim($(item).attr('value')) == '')
            {
                $(item).attr('value',text);
                $(item).removeClass('TextBoxFocus').addClass('TextBoxBlur');
            }
        }
        
        function AddTalkBack(PageID, FullName, Email, Title, Opinion)
        {
            $.get('Opinions.aspx',
            {add : 1, pageid : PageID, fullname : FullName , email : Email, title : Title, comment : Opinion},
            function(returned_data)
            {
                $('.TalkBackContainer').html(returned_data);
            });
}

//function InitDiggThis()
//{
//    digg_url = 'http://digg.com/programming/How_to_add_a_Digg_This_link_to_your_web_site';
//    $("#Icon2").html("<script src='http://digg.com/api/diggthis.js'></script>");
//}

function InitNewsletterBtn()
{
    $("#imgNewsletter").click(function(){
        SignNewsLetter(1);
    });
}

function PrintThisPage(obj)
{
    $(obj).attr('href','mailto:?subject=aaa');
}

function InitDevices()
{
        if(typeof($('#divDevices').get(0)) == 'undefined')
            return;
            
        $('#ddlCategories').addOption('All regions...', 'All regions...');            
        $('#divDevices .tblDevicesContainer th').each(function(){
            $('#ddlCategories').addOption($(this).html().replace('&amp;', '&'), $(this).html().replace('&amp;', '&'));
        });
        
//        $('#divDevices img').each(function(){
//            var name = GetCleaenDeviceName($(this).attr('src'));
//            var brand = $(this).closest('.tblDevicesContainer').find('th').html();
//            $(this).closest('table').find('td:eq(1)').html(name);
//            $(this).attr('alt',brand.replace('&amp;', '&') + ' - ' + name);
//        });
        $('#divDevices').each(function(){
            $(this).find(".SubmitResume").attr("href","SubmitResume.aspx?job=" + + $(this).find(".JobNumber td").html());
            $(this).find(".JobNumber").hide();
        });
        $('#ddlCategories').get(0).selectedIndex = 0;
        $('#ddlCategories').change(function(){
        var selectedIndex = $('#ddlCategories').get(0).selectedIndex;
            $('#divDevices table').hide();
            if(selectedIndex == 0)
            {
                $('#divDevices table').show(); 
            }
            else
            {
                $('#divDevices .tblDevicesContainer:eq(' + (selectedIndex - 1) + ')').fadeIn("normal");
                $('#divDevices .tblDevicesContainer:eq(' + (selectedIndex - 1) + ') table').fadeIn("normal");
            }
        });
}