﻿/* File          : Common.js
   Created by    : Dayakar
   Date and time : Sep 18,2009
   Purpose       : To keep all common javascript methods in this.
   Version       : 1.0 
 */
 
 // Check whether the user has entered any text in the search box before clicking on the "Search" button.
 // if the user hasn't entered any, then give an alert saying that the value is required.
 // Server side asp:RequiredFieldValidator could not be used because there is not enough space near the search box to display the error message.
 function CheckIfSearchTextIsNull()
 {
    if(document.getElementById('ucSearchBox_txtSearch')!=null && document.getElementById('ucSearchBox_txtSearch').value != "")
    {
        var searchText = document.getElementById('ucSearchBox_txtSearch').value;
        return true;
    }
    else
    {
        alert("The search text cannot be left blank. Pleae enter valid search text.");
        document.getElementById('ucSearchBox_txtSearch').focus();
        return false;
    }
 }

function getSubContent(_subContentID){
    // Make the specific div visible.
    //alert(_subContentID);
    
    if(_subContentID == 'divProductId1')
    {
        if(null != document.getElementById('divProductId1'))
	        document.getElementById('divProductId1').style.display = 'block';
	    if(null != document.getElementById('divProductId2'))
	        document.getElementById('divProductId2').style.display = 'none';
	    if(null != document.getElementById('divProductId3'))
	        document.getElementById('divProductId3').style.display = 'none';
	    if(null != document.getElementById('divProductId4'))
	        document.getElementById('divProductId4').style.display = 'none';
	    if(null != document.getElementById('divProductId5'))
	        document.getElementById('divProductId5').style.display = 'none';
    }
    else if(_subContentID == 'divProductId2')
    {
	    if(null != document.getElementById('divProductId1'))
	        document.getElementById('divProductId1').style.display = 'none';
	    if(null != document.getElementById('divProductId2'))
	        document.getElementById('divProductId2').style.display = 'block';
	    if(null != document.getElementById('divProductId3'))
	        document.getElementById('divProductId3').style.display = 'none';
	    if(null != document.getElementById('divProductId4'))
	        document.getElementById('divProductId4').style.display = 'none';
	    if(null != document.getElementById('divProductId5'))
	        document.getElementById('divProductId5').style.display = 'none';
    }
    else if(_subContentID == 'divProductId3')
    {
	    if(null != document.getElementById('divProductId1'))
	        document.getElementById('divProductId1').style.display = 'none';
	    if(null != document.getElementById('divProductId2'))
	        document.getElementById('divProductId2').style.display = 'none';
	    if(null != document.getElementById('divProductId3'))
	        document.getElementById('divProductId3').style.display = 'block';
	    if(null != document.getElementById('divProductId4'))
	        document.getElementById('divProductId4').style.display = 'none';
	    if(null != document.getElementById('divProductId5'))
	        document.getElementById('divProductId5').style.display = 'none';
    }
    else if(_subContentID == 'divProductId4')
    {
	    if(null != document.getElementById('divProductId1'))
	        document.getElementById('divProductId1').style.display = 'none';
	    if(null != document.getElementById('divProductId2'))
	        document.getElementById('divProductId2').style.display = 'none';
	    if(null != document.getElementById('divProductId3'))
	        document.getElementById('divProductId3').style.display = 'none';
	    if(null != document.getElementById('divProductId4'))
	        document.getElementById('divProductId4').style.display = 'block';
	    if(null != document.getElementById('divProductId5'))
	        document.getElementById('divProductId5').style.display = 'none';
    }
    else if(_subContentID == 'divProductId5')
    {
	    if(null != document.getElementById('divProductId1'))
	        document.getElementById('divProductId1').style.display = 'none';
	    if(null != document.getElementById('divProductId2'))
	        document.getElementById('divProductId2').style.display = 'none';
	    if(null != document.getElementById('divProductId3'))
	        document.getElementById('divProductId3').style.display = 'none';
	    if(null != document.getElementById('divProductId4'))
	        document.getElementById('divProductId4').style.display = 'none';
	    if(null != document.getElementById('divProductId5'))
	        document.getElementById('divProductId5').style.display = 'block';
	}

}

// Navigate to the specified url.
function navigateURL(productName,conceptName)
{
    //alert(productName +" : "+conceptName);
    var url = "frmPomoCode.aspx?type=Promo&product="+productName+"&title="+conceptName;
    
    // Redirect to the frm promo code url in a popup.
    window.open(url,'promocode','width=1020, height=720','scrollbars=1');
}

// Check for valid email id.
function isValidEmail(str) 
{
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
       //alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       //alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        //alert("Invalid E-mail ID")
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
        //alert("Invalid E-mail ID")
        return false
     }
	
     if (str.indexOf(" ")!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     return true					
}
