﻿// JScript File
//*******************************************************************************************
// General Javascript functions when Enter clicked on keyboard
//*******************************************************************************************
function clickButton(e, buttonid){ 
	var bt = document.getElementById(buttonid); 
	if (bt){ 
			if(navigator.appName.indexOf("Netscape")>(-1)){ 
				if (e.keyCode == 13){ 
						bt.click(); 
						return false; 
				} 
			} 
			if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
				if (event.keyCode == 13){ 
						bt.click(); 
						return false; 
				} 
			} 
	}
} 
function confirm_delete()
{
	if (confirm("Are you sure you want to perform this action.")==true)
		return true;
	else
		return false;
}
function confirm_delete_Modal()
{
	if (confirm("Are you sure you want to perform this action.")==true)	    
		return true;
	else	
		return false;
}

//***********************************************************************************************************
// Checks if the value entered is Numeric or not and for spaces while validations and for valid email format
//***********************************************************************************************************
function IsNumeric(sText)
{
	var ValidChars = "01234567890.";
	var IsNumber = true;
	var Char,dotcount;
	dotcount=0;	
	for(i=0; i<sText.length && IsNumber==true; i++)
	{
		Char=sText.charAt(i);
		if(Char==".")
		dotcount=dotcount+1;
		if(ValidChars.indexOf(Char)==-1)
		{
			IsNumber=false;
		}
	}
		if(dotcount>1)
		IsNumber=false;
		return IsNumber;
}
function trim(str)
{
	str=lTrim(str);
	str=rTrim(str);
	return str;
}
//Function Ltrim
function lTrim(strTemp)
{
	var iIndex;
	var charTemp;
	for(iIndex=0; iIndex< strTemp.length;iIndex++)
	{
		charTemp = strTemp.substring(iIndex, iIndex+1);
		if(charTemp != ' ') break;
	}
	strTemp = strTemp.substring(iIndex, strTemp.length);
	return strTemp;
}
//Function Rtrim
function rTrim(strTemp)
{
	var iIndex;
	var charTemp;
	for(iIndex=strTemp.length; iIndex>0;iIndex--)
	{
		charTemp = strTemp.substring(iIndex-1, iIndex);
		if(charTemp != ' ') break;
	}
	strTemp = strTemp.substring(0,iIndex);
	return strTemp;
}
// Validates the email address format
var testresults
function checkemail(id)
{
	var str=id;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true;
	else{
	//alert("Please enter a valid email address!")
	testresults=false;
	}
	return (testresults);
}
function checkbase(id)
{
	if (document.layers||document.getElementById||document.all)
	{
		return checkemail(id);
	}
	else
	{
		return true;
	}
}
//*******************************************************************************************
// General Javascript functions when Enter clicked on keyboard
//*******************************************************************************************
function clickButton(e, buttonid){ 
	var bt = document.getElementById(buttonid); 
	if (bt){ 
			if(navigator.appName.indexOf("Netscape")>(-1)){ 
				if (e.keyCode == 13){ 
						bt.click(); 
						return false; 
				} 
			} 
			if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
				if (event.keyCode == 13){ 
						bt.click(); 
						return false; 
				} 
			} 
	}
}
//*******************************************************************************************
// Validate Article Entry
//*******************************************************************************************
//*******************************************************************************************
// Validate League Entry
//*******************************************************************************************
function ValidateLeague()
{
	if (trim(document.getElementById('txtLeagueName').value) == '')
	{
		alert("Please enter League Name");
		return false;
	}	
}

//******************************************************************
//Validate Contact
//******************************************************************
function ValidateContact()
{
	if (trim(document.getElementById('Content1_UpdatePanel3_tabContact_TabPanel1_txtContactName').value) == '')
	{
		alert("Please enter Name");
		return false;
	}
	if (trim(document.getElementById('tabContact_txtContactPhone').value) == '')
	{
		alert("Please enter Subject");
		return false;
	}
	if (trim(document.getElementById('tabContact_txtContactEmail').value) == '')
	{
		alert("Please enter Email Address");
		return false;
	}
	if (checkbase(document.getElementById('tabContact_txtContactEmail').value) != true)
	{
		alert("Please enter a valid Email Address");
		return false;
	}
	var Component = document.getElementById("tabContact_ddlContactType").selectedIndex;
	if (Component == 0)
	{
		alert("Plese select Type");
		return false;
	}	
}
//*****************************************************************************************
//Validate New Entity
//*****************************************************************************************
function ValidateEntityFirst()
{
    var Type = document.getElementById("ddlEntityType").selectedIndex;
    if(Type==0)
    {
        alert("Please select entity type")
        return false;
    }
    var relation = document.getElementById("ddlRelation").selectedIndex;
    if(relation==0)
    {
        alert("Please select relationship")
        return false;
    }    
}

function ValidateEntitySecond()
{

   if (trim(document.getElementById('txtBusinessName').value) == '')
	{
		alert("Please enter business name");
		return false;
	}
	if (trim(document.getElementById('txtAddress1').value) == '')
	{
		alert("Please enter address1");
		return false;
	}
	if (trim(document.getElementById('txtCity').value) == '')
	{
		alert("Please enter city");
		return false;
	}
    var State = document.getElementById("ddlstate").selectedIndex;
    if(State==0)
    {
        alert("Please select state")
        return false;
    }    
}
//*******************************************************************************************
// Validate Media
//*******************************************************************************************
function ValidateMedia()
{
    if (trim(document.getElementById('txtMediaName').value) == '')
	{
		alert("Please enter Name");
		document.getElementById('txtMediaName').focus();
		return false;
	}
	if (trim(document.getElementById('txtMediaEmail').value) == '')
	{
		alert("Please enter Email Address");
		document.getElementById('txtMediaEmail').focus();
		return false;
	}
	if (checkbase(document.getElementById('txtMediaEmail').value) != true)
	{
		alert("Please enter a valid Email Address");
		document.getElementById('txtMediaEmail').focus();
		return false;
	}	
}
//*******************************************************************************************
// Validate DropDown     
//*******************************************************************************************
function ValidateRequest()
{
//alert("Plese select Entity");
    var Entity=document.getElementById('cboEntity').selectedIndex
    if(Entity == 0)
    {
        alert("Plese select Entity");
		return false;
    }
}

function ValidatePermission()
{
    var Entity=document.getElementById('cboEntityPer').selectedIndex
    if(Entity == 0)
    {
        alert("Plese select Entity");
		return false;
    }
}

//********************************
//Move List Box
//********************************
    function listbox_moveacross(sourceID, destID) {
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
 
    for(var count=0; count < src.options.length; count++) {
 
        if(src.options[count].selected == true) {
                var option = src.options[count];
 
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                try {
                         dest.add(newOption, null); //Standard
                         src.remove(count, null);
                 }catch(error) {
                         dest.add(newOption); // IE only
                         src.remove(count);
                 }
                count--;
        }
    }
}
    function listbox_move(listID, direction) {
 
    var listbox = document.getElementById(listID);
    var selIndex = listbox.selectedIndex;
 
    if(-1 == selIndex) {
        alert("Please select an option to move.");
        return;
    }
 
    var increment = -1;
    if(direction == 'up')
        increment = -1;
    else
        increment = 1;
 
    if((selIndex + increment) < 0 ||
        (selIndex + increment) > (listbox.options.length-1)) {
        return;
    }
 
    var selValue = listbox.options[selIndex].value;
    var selText = listbox.options[selIndex].text;
    listbox.options[selIndex].value = listbox.options[selIndex + increment].value
    listbox.options[selIndex].text = listbox.options[selIndex + increment].text
 
    listbox.options[selIndex + increment].value = selValue;
    listbox.options[selIndex + increment].text = selText;
 
    listbox.selectedIndex = selIndex + increment;
}
//*********************************
//Video Script
//*************************************

function PlayVideo(videoCode, width, height) {
        //if a video is playing, close it first
        var VideoDiv = document.getElementById('video-div');
        if (VideoDiv != null) {
            RemoveDiv();
        }
        //play a new video
        CreateVideoDiv('video-div', 'video-div', videoCode, width, height);
        CreateCloseDiv("close-div", "close-div", "<a href=# onclick=RemoveDiv();><img src=\"Images/close.jpg\" width=\"16\" height=\"16\" border=\"0\"/></a>", width, height, 16, 16);

    }
   function CreateVideoDiv(id, className, contentToDisplay, width, height) {
       //create a div and center it inside the browser window       
        var NewDiv = CreateDiv(id, className, contentToDisplay, width, height);        
        NewDiv.style.marginLeft = -(parseInt(width) / 2) + "px";
        //NewDiv.class="modalBackground";        
        NewDiv.style.marginTop = -(parseInt(height) / 2) + "px";        
    }

    function CreateCloseDiv(id, className, contentToDisplay, videoWidth, videoHeight, closeImageWidth, closeImageHeight) {
        //place the "close" image at the top right corner of the video div
        var NewDiv = CreateDiv(id, className, contentToDisplay, closeImageWidth, closeImageHeight);
        NewDiv.style.marginLeft = (parseFloat(videoWidth) / 2) - parseFloat(closeImageWidth)*1.5 + 60 + "px";
       // NewDiv.class="modalBackground";              
        NewDiv.style.marginTop = -(parseFloat(videoHeight) / 2) + parseFloat(closeImageHeight)/2 - 8 + "px";        
    }

    function CreateDiv(id, className, contentToDisplay, width, height) {
        var NewDiv = document.createElement("div");
        NewDiv.id = id;
        NewDiv.className = className;
        NewDiv.innerHTML = contentToDisplay;
        NewDiv.style.position = "absolute";
        NewDiv.style.width = width + "px";
        NewDiv.style.height = height + "px";
        NewDiv.style.top = "50%";
        NewDiv.style.left = "50%";
        NewDiv.style.display = "block";
        document.body.appendChild(NewDiv);

        return NewDiv;
    }

    function RemoveDiv() {
        var mydiv = document.getElementById("video-div");
        document.body.removeChild(mydiv);
        var mydiv = document.getElementById("close-div");
        document.body.removeChild(mydiv);
    }

//*******************************************************************************************
// Modal PopUp
//*******************************************************************************************
function ok()
{
    $find('programmaticModalPopup_new').show();    
}

function gup(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}

 function calculateCoordinates() {

        var txtAddress1 = gup("Add1")
        var txtAddress2 = gup("Add2")        
        var txtPostcode = gup("Zip")        

        var address = txtAddress1.value + ', ';
        address += txtAddress2.value + ', ';        
        address += txtPostcode.value;        
        alert(address);
        var geocoder;
        geocoder = new GClientGeocoder();
        geocoder.getLatLng(address, function(latlng) {
            if (!latlng) {
                alert(address + ' not found');
            } else {
                txtLatitude.value = latlng.lat();
                txtLongitude.value = latlng.lng();
            }
        });

    }
