﻿var browser = navigator.userAgent;
var focusnow = 0;
var ClearFocus = 0;

//get the proper search entity landing page when the user return form the result/detail page
function init() 
{
    if (location.href.search('search.aspx?') !== -1) 
    {
        if (location.href.search('entity=licensors') !== -1) 
        {
            ShowSearch('licensors', '1');
        }

        if (location.href.search('entity=agents') !== -1) 
        {
            ShowSearch('agents', '1');
        }

        if (location.href.search('entity=licensees') !== -1) 
        {
            ShowSearch('licensees', '1');
        }

        if (location.href.search('entity=licensingservices') !== -1) 
        {
            ShowSearch('licensingservices', '1');
        }
    }
}

function ShowSearch(fval,type)
{
    if (type == '0') 
    {
        $('frmSearch').reset();
    }
    
    focusnow = 0;
     if(fval=='licensors') //Licensors
    {
      $('selSearchFor').selectedIndex = '0'; 
      $('dvBrandTrademark').show();
      $('dvGeneralFields').show();
      $('dvBrandTrademark').show();
      $('dvAgent').hide();
      $('dvAgentRep').hide();
      $('dvLicenseeProduct').hide();
      $('dvLicenseeServices').hide();
      $('hidEntity').value = fval;
    }
    else if(fval=='agents')//Agents
    {
      $('selSearchFor').selectedIndex = '2'; 
      $('dvGeneralFields').show();
      $('dvBrandTrademark').hide();
      $('dvAgent').show();
      $('dvAgentRep').show();
      $('dvLicenseeProduct').hide();
      $('dvLicenseeServices').hide();
      $('hidEntity').value = fval;
    }
    else if(fval=='licensees')//Licensees
    {
      $('selSearchFor').selectedIndex = '1'; 
      $('dvGeneralFields').show();
      $('dvBrandTrademark').hide();
      $('dvAgent').hide();
      $('dvAgentRep').hide();
      $('dvLicenseeProduct').show();
      $('dvLicenseeServices').hide();
      $('hidEntity').value = fval;
    }
    else if(fval=='licensingservices')//Licensing Services
    {
      $('selSearchFor').selectedIndex = '3'; 
      $('dvGeneralFields').show();
      $('dvLicenseeServices').show();
      $('dvBrandTrademark').hide();
      $('dvAgent').hide();
      $('dvAgentRep').hide();
      $('dvLicenseeProduct').hide();
      $('hidEntity').value = fval;
    }
 }
 
function FocusOnSubmit()
{
   if(browser.search(/Firefox/) != '-1')
   {
        $('btnSearch').focus();
   }
}


function Focus(type)
{
    if(type == 'adv')
    focusnow = 1;

    if(type == 'clear')
    ClearFocus = 1;
}
  
function OutFocus(type)
{
    if(type == 'adv')
    focusnow = 0;

    if(type == 'clear')
    ClearFocus = 0;
}  

function Clear()
{ 
    var obj = $('selSearchFor').selectedIndex; 
    $('frmSearch').reset();
    $('selSearchFor').selectedIndex = obj;
}

//Email Form

function ShowEmailForm()
{
    window.open("needhelp.aspx", "SolisXCFPicker", "width=550,height=500,left=" + ((window.screen.availWidth - 550) / 2) + ",top=" + ((window.screen.availHeight - 350) / 2), false);
}

function closepopup()
{
    if(false == window.closed)
	{
		window.close ();
	}
}

function EmailFormValidation()
{
    if($('txtName').value.length == 0)
    {
        alert('Please enter your name');
		$('txtName').focus();
		return false;
    }
    else if($('txtCompanyName').value.length == 0)
    {
        alert('Please enter the company name');
		$('txtCompanyName').focus();
		return false;
    }
    else if($('txtEmail').value.indexOf('@')< 0 || $('txtEmail').value.indexOf('.') < 0)
	{
		alert ("Please enter a Valid Email Address");
		$('txtEmail').focus();
		return false;
	}	
	else if($('txtPhone').value.length == 0)
    {
        alert('Please enter the phone number');
		$('txtPhone').focus();
		return false;
    }    
    else if($('txtTopic').value.length == 0)
    {
        alert('Please enter the topic');
		$('txtTopic').focus();
		return false;
    }
    else if($('txtPhone').value.length != 0)
	{
		var PhoneChar = $('txtPhone').value;
		var SpChar="!@$%^\\\';/\"&lt;&gt;?~`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for (var j=0; j < PhoneChar.length; j++)
		{
			if(SpChar.indexOf(PhoneChar.charAt(j))!=-1)
			{
				alert("Phone  Number must be a valid Numeric Entry.");
				$('txtPhone').value = "";
				$('txtPhone').focus();
				return false;
			}
		}		
	}
	else
	{
	    return true;
	}
}
