﻿// JScript File composed by SHASHANK SHEKHAR
// Contact at s_sekh@rediffmail.com       

//Function to restrict user to enter only numeric value in textbox
//validation controls for the home master page flash
function Flash(lo,w,h,t)
{
document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'" id="flashID">');
document.write ('<param name="movie" value="'+lo+'">');
document.write ('<param name="quality" value="high">');
document.write ('<param name="wmode" value="'+t+'">');
document.write ('<embed src="'+lo+'" quality="high" wmode="'+t+'" width="'+w+'" height="'+h+'" name="flashID" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ></embed>');
document.write ('</object>');
}


$(document).ready(function()
{    
// PERFORM ACTION WHEN BODY IS FULLY LOADED.
$(window).load(
function(e)
{
// DISPLAY HOME PAGE POPUP WHEN DOCUMENT IS READY
if ($("#online_trade_data").length)
{       
    $("#online_trade_data").delay(2500).animate({height: ['toggle', 'swing'], opacity: 'toggle'}, 950, function() {});    
    
    // EVENT FOR CLOSING MPE ON USER REQUEST
    $("a[name='close_mpe']").click(function(e){$('#online_trade_data').slideUp('fast', function(){}); e.preventDefault();}).clearQueue();
}

});



// USER LOGIN FORM VALIDATION
$("input[id$='btn_Login']")
.click
(
function (e) 
{    
    var id_len= $("input[id$='txtlogin']").val().length;
    var pwd_len= $("input[id$='txtpass']").val().length;
    if (id_len === 0)
    {    
        $("input[id$='txtlogin']").css('background-color', '#FFDEAD'); alert("Please enter your Login Id Or Email Id."); 
        $("input[id$='txtlogin']").focus();
        e.preventDefault();
    }
    else
    {
        if(pwd_len === 0)
        {
            $("input[id$='txtpass']").css('background-color', '#FFDEAD'); alert("Please enter a valid password.");            
            $("input[id$='txtpass']").focus();
            e.preventDefault();
        }
        else
        {
            return true;
        }        
    }    
}//end of function (e)
);  //end of click()  

// HANDLING ANIMATED BACKGROUND OF USER LOGIN PANEL TEXTBOX
$("input[id$='txtlogin']").change(function(e){if($(this).val().length > 0) {$(this).css('background-color', '#fefefe');} 
else{$(this).css('background-color', '#FFDEAD');}});

$("input[id$='txtpass']").change(function(e){if($(this).val().length > 0){$(this).css('background-color', '#fefefe');}
else {$(this).css('background-color', '#FFDEAD');}}); 
// END OF USER LOGIN VALIDATION



// ENQUIRY FORM VALIDATION
$("input[id$='btn_submit']")
.click
(
function (e) 
{    

    var name_len= $("input[id$='txt_name']").val().length;
    var num_len= $("input[id$='txt_PhoneNumber']").val().length;
    var mail_len= $("input[id$='txt_Email']").val().length;
    var cap_len= $("input[id$='txt_captcha_verification']").val().length;
        
    
    if (name_len === 0)
    {    
        $("input[id$='txt_name']").css('background-color', '#FFDEAD'); alert("Please enter the Name of Contact Person."); 
        $("input[id$='txt_name']").focus();
        e.preventDefault();
    }
    else
    {
        if(num_len === 0)
        {
            $("input[id$='txt_PhoneNumber']").css('background-color', '#FFDEAD'); alert("Please enter a valid Contact Number.");            
            $("input[id$='txt_PhoneNumber']").focus();
            e.preventDefault();
        }
        else
        {
            if(mail_len === 0)
            {
              $("input[id$='txt_Email']").css('background-color', '#FFDEAD'); alert("Please enter a valid email id.");            
              $("input[id$='txt_Email']").focus();
              e.preventDefault();
            }
            else
            {
                if(mail_len != 0)
                {                  
                   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;         
                   if( !emailPattern.test( $("input[id$='txt_Email']").val()) )                        
                    {
                        $("input[id$='txt_Email']").css('background-color', '#FFDEAD'); alert("Email id doesn\'t seem valid, Please enter a valid email id.");            
                        $("input[id$='txt_Email']").focus().select();
                        e.preventDefault();                                                
                    }
                    else
                    {
                       if (cap_len === 0)
                        {    
                            $("input[id$='txt_captcha_verification']").css('background-color', '#FFDEAD'); alert("Please enter the security code being displayed in the above image."); 
                            $("input[id$='txt_captcha_verification']").focus();
                            e.preventDefault();
                        }
                        else
                        {
                            return true;
                        }
                    }                                    
                }
            }
        }        
    }    
}//end of function (e)
);  //end of click()  


// HANDLING ANIMATED BACKGROUND OF TEXTBOX
$("input[id$='txt_name']").change(function(e){if($(this).val().length > 0) {$(this).css('background-color', '#fefefe');} 
else{$(this).css('background-color', '#FFDEAD');}});

$("input[id$='txt_PhoneNumber']").change(function(e){if($(this).val().length > 0) {$(this).css('background-color', '#fefefe');} 
else{$(this).css('background-color', '#FFDEAD');}});

$("input[id$='txt_Email']").change(function(e){if($(this).val().length > 0) {$(this).css('background-color', '#fefefe');} 
else{$(this).css('background-color', '#FFDEAD');}});

$("input[id$='txt_captcha_verification']").change(function(e){if($(this).val().length > 0) {$(this).css('background-color', '#fefefe');} 
else{$(this).css('background-color', '#FFDEAD');}});

// IF REQUEST IS COMING FROM A URL THAT HAS BEEN RE-WRITTEN,
// CAPTCHA IMAGE WILL NOT DISPLAY, IN THIS CASE, JUST HIDE THEM
$("div.CAPTCHA_ENQUIRY>img").error
(
    function()
    {
        $("tr.captcha_hide").hide();
        $("input[id$='txt_captcha_verification']").val("VIRTUAL_URL");        
    }
);


// RESET ENQUIRY BUTTON CLICK EVENT
$("input[id$='btn_reset']")
.click
(
    function (e) 
    {   
        $("input[id$='txt_name']").val("").css('background-color', '#fefefe');
        $("input[id$='txt_CompanyName']").val("");
        $("input[id$='txt_CompanyAddress']").val("");
    
        $("input[id$='txt_PhoneNumber']").val("").css('background-color', '#fefefe');
        $("input[id$='txt_Email']").val("").css('background-color', '#fefefe');
        $("input[id$='rdb_export']").checked = true;
        $("input[id$='rdb_Import']").checked = false;
        $("input[id$='rdb_both']").checked = false;

        $("input[id$='txt_Products']").val("");
        $("textarea[id$='txt_InfoSought']").val("");
        $("input[id$='txt_captcha_verification']").val("");
        
        e.preventDefault();
        
}//end of function (e)
);  //end of click()  


// CALL US DIV ANIMATION FOR HOME PAGE 
// POPUP WINDOW.
$("div.call_us_div").hover
(
function(){$("div.call_us_div").css('border','#696969 2px dotted').css('background-color','#fefefe').css('color','#dc6f26').css('cursor','pointer');},
function(){$("div.call_us_div").css('border','#cccccc 2px dotted').css('background-color','#fefefe').css('color','#4682b4').css('cursor','default');}
);


//FOLLOWING FUNCTION TO REDIRECT TO GOOGLE FOR SEARCH CRITERIA ON HOWE PAGE
$("input[id$='btnsrchcyb']").click(function(e)
{   
    var srchval = $.trim($("input[id$='txtsrchcyb']").val());        
    if (srchval.length !== 0)
    {
        window.location.href = "http://www.google.com/search?q=" + srchval.replace(/\s/g,'+') + "&sitesearch=cybex.in" 
    }else { alert('Please enter text for search!!!'); }
    e.preventDefault();
});


// TRANSLATE BUTTON CODING THROUGH 
// JQUERY IMPLEMENTED HERE
$("input[id$='btn_translate']").click
(
function(e)
{

var sel_val = $("select[id$='translateDDL']").val();
var new_url = "http://google.com/translate?langpair=en%7C" + sel_val + "&u=http:////www.cybex.in/Default.aspx";
window.location.href=new_url;
e.preventDefault();
}

);


// IF REQUESTED PAGE IS FAQ PAGE, IMPLEMENT ALL DEFINITION FOR
// FAQ PAGE DIVS 
if($("#faq_main").length)
{
$("div.faq").click(function(e)
{       
    var cur_mode=$(this).next().css("display");      
	if(cur_mode!="block")
	{
	$('div.ans').slideUp("slow");	                                               // HIDE ALL ANS DIVS
	$(this).next().fadeIn(1200, function(){}).slideDown("slow").focus();           // SHOW CURRENT ANS DIV		
	
	$(".ans ul li").css("margin-top", "1px").css("margin-bottom", "3px");           // ADD RUN TIME CSS UL	
	var targetOffset=$(this).prev().offset().top +7;
	$("html,body").animate({scrollTop:targetOffset}, 1400);                        // SCROLL THE SCROLL BAR TO CURRENT ITEM
	}
	else
	{
	    $('div.ans').slideUp("slow");	                // HIDE ALL ANS DIVS
	}
});

// Hide all FAQ ANS DIVS ON THE DOM LOAD
$("div.ans")
.hide()
.append("<div id=\"close\" style=\"width:100%; text-align:right; font-size:0.8em; color:#dc6f26;cursor:pointer;\"><span onclick=\"$('div.ans').slideUp('slow');\">Close</span> | <span onclick=\"location.href='#top';\">Top</span></div>")
.hover(function(e){$(this).css('border','#dc6f26 1px dotted')}, function(e){$(this).css('border','#4682b4 1px dotted')});

// Attach target attribute to all anchors of answer divs
// except those already specified.
$(".ans a[target!='_self']").attr("target", "_blank");                     // ADD RUN TIME BEHAVIOUR TO ANCHORS 

}


// THIS CODE TO RUN ONLY ON ALL PAGES FOR ADDING
// SCROLLING EFFECT TO THE LATEST NOTIFICATIONS.
    if($("span[id$='LB_EXIM_NOTIFICATIONS']").length)
    {
    function SCROLLING_EFFECTS()
    {   
    // APEND FIRST CHILD TO THE LAST
    $("span[id$='LB_EXIM_NOTIFICATIONS']").find("ul").delay(800).append($("span[id$='LB_EXIM_NOTIFICATIONS']").find("ul li:first").fadeIn(950, function(){}));
    // FADE OUT THE FIRST CHILD
//    $("span[id$='LB_EXIM_NOTIFICATIONS']").find("ul li:first").stop("true", "true").delay(1800).slideUp(500 , 
//    function(){SCROLLING_EFFECTS();});    
    }   
    
    $("span[id$='LB_EXIM_NOTIFICATIONS'] a").attr("target", "_blank");                     // ADD RUN TIME BEHAVIOUR TO ANCHORS 
    // run this code when dom is ready
    SCROLLING_EFFECTS();    
    }

// THIS CODE TO RUN ONLY ON ALL PAGES FOR ADDING
// SCROLLING EFFECT TO THE LATEST EXIM NEWS
    if($("span[id$='LB_EXIM_NEWS']").length)
    {
    function SCROLLING_EFFECTS_NEWS()
    { 
    // APEND FIRST CHILD TO THE LAST
    $("span[id$='LB_EXIM_NEWS']").find("ul").delay(800).append($("span[id$='LB_EXIM_NEWS']").find("ul li:first").fadeIn(950, function(){}));
    // FADE OUT THE FIRST CHILD
//    $("span[id$='LB_EXIM_NEWS']").find("ul li:first").stop("true", "true").delay(1400).slideUp(500 , 
//    function(){SCROLLING_EFFECTS_NEWS();});    
    }   
    
//    $("span[id$='LB_EXIM_NEWS'] a").attr("target", "_blank");                     // ADD RUN TIME BEHAVIOUR TO ANCHORS     
    // run this code when dom is ready
    SCROLLING_EFFECTS_NEWS();    
    }


// ADD OVERFLOW PROPERTY TO THE LEFT COLUMN OF MASTER PAGE overflow-x:scroll;
//$("td.LeftCol").css("overflow-x", "scroll").css("max-width", "780px").css("background-color", "red");






}); //end of document.ready of Jquery()
