﻿var cntSlideShow = 0;
var curImg;
var SlideShowEnabled = true;
var ScrollDir = 0;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
  {
    if (navigator.appName == 'Microsoft Internet Explorer') x.filters.blendTrans.Apply();  
    x.src=x.oSrc;
    if (navigator.appName == 'Microsoft Internet Explorer') x.filters.blendTrans.Play();    
  }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{ //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; 
    document.MM_sr=new Array; 
    
    for(i=0;i<(a.length-2);i+=3)
    {
        if ((x=MM_findObj(a[i]))!=null)
        {
            document.MM_sr[j++]=x; 
            
            if(!x.oSrc)
            {
                x.oSrc=x.src;
            }
            
            if (navigator.appName == 'Microsoft Internet Explorer') x.filters.blendTrans.Apply();  
            x.src=a[i+2];
            if (navigator.appName == 'Microsoft Internet Explorer') x.filters.blendTrans.Play(); 
        }
    }  
}

function strReplace(str, find, replace)
{
    if (str.indexOf(find) > -1)
    {
        str = str.replace(find, replace);
    }
    alert(str);
    return str;
}

function PrevPhoto(imgId, lblId, lnkId)
{    
    if (photoIdx > 0)
    {    
        cntSlideShow = 0;
        UpdatePhoto(imgId, lblId, lnkId, photoIdx--);     
    }
}

function NextPhoto(imgId, lblId, lnkId)
{
    if (photoIdx < photoArray.length-1)
    {
        cntSlideShow = 0;
        UpdatePhoto(imgId, lblId, lnkId, photoIdx++);                
    }
}

function UpdatePhoto(imgId, lblId, lnkId, idx)
{
    var img = document.getElementById(imgId);
    var lbl = document.getElementById(lblId);
    var lnk = document.getElementById(lnkId);  
    var divPhoto = document.getElementById('divPhoto');     

    if (navigator.appName == 'Microsoft Internet Explorer') img.filters.blendTrans.Apply();
    img.src = '/uploads/robond_photos.Photo/' + photoArray[photoIdx][2];
    if (navigator.appName == 'Microsoft Internet Explorer') img.filters.blendTrans.Play();    
    img.alt = photoArray[photoIdx][0];
    lbl.innerText = photoArray[photoIdx][0];
    lnk.href = photoArray[photoIdx][1];
    
    divPhoto.scrollTop = 0;
    ScrollDir = 0;
    
    if (img.offsetHeight > 265)
    {
        SlideShowEnabled = false;
        curImg = img;
        ScrollPhoto();
    }
}

function ScrollPhoto()
{
    var divPhoto = document.getElementById('divPhoto');               
    
    if (ScrollDir == 0)
    {
        if (divPhoto.scrollTop < curImg.offsetHeight - 260) 
        {
            divPhoto.scrollTop++;
        }
        else
        {        
            ScrollDir = 1;
        }
    }
    else if (ScrollDir == 1)
    {
        if (divPhoto.scrollTop > 0) 
        {
            divPhoto.scrollTop--;
        }
        else
        {
            SlideShowEnabled = true;
        }
    }       
    
    if (!SlideShowEnabled) setTimeout("ScrollPhoto()", 25);           
}

function valPhoneEmail(oSrc, args)
{
	var txtPhone = document.getElementById('ctl00$cphContent$txtPhone');
	var txtEmail = document.getElementById('ctl00$cphContent$txtEmail');
	args.IsValid = (txtPhone.value != "" || txtEmail.value != "");
}

function SlideShow(imgId, lblId, lnkId)
{
    var func = "SlideShow('" + imgId + "','" + lblId + "','" + lnkId + "');";
    
    if (cntSlideShow != 0 && SlideShowEnabled == true)
    {
        if (photoIdx == photoArray.length-1) photoIdx = 0;
        else photoIdx++;
        UpdatePhoto(imgId, lblId, lnkId, photoIdx);
    }    
    
    setTimeout(func, 5000);
    cntSlideShow++;
}

function ShowDivMenu(divId, imgId)
{
    var div = document.getElementById(divId);
    var img = document.getElementById(imgId);
    
    div.className = "divShowMenu";
}

function HideDivMenu(divId, btnId)
{
    var div = document.getElementById(divId);
    div.className = "divHideMenu";
}

function OnMenuItemClick(url, target)
{
    if (target != '')
    {
        window.open(url, target);
    }
    else
    {
        document.location.href = url;
    }
}

function OnMenuItemMouseOver(item)
{
    item.className = 'mnuItemOn';
}

function OnMenuItemMouseOut(item)
{
    item.className = 'mnuItem';
}

function StripHtmlTags(text)
{    
    if (text != undefined) return text.replace(/(<([^>]+)>)/ig,""); 
}

function ValidateNoHtml(oSrc, args)
{
    args.IsValid = (args.Value == StripHtmlTags(args.Value));
}

function ShowHide(imgId, tbodyId)
{
    var tbody, img, tblMenu, tbodys, imgs, idx, show;
    
    img = document.getElementById(imgId);
    tbody = document.getElementById(tbodyId);
    
    if (tbody)
    {
        tblMenu = document.getElementById('tblMenu');   
        
        tbodys = tblMenu.getElementsByTagName('tbody');
        imgs = tblMenu.getElementsByTagName('img');        
            
        show = (tbody.style.display == '');
        
        for (idx=0; idx<tbodys.length; idx++)
        {
            if (tbodys[idx]) if (tbodys[idx].id) tbodys[idx].style.display = 'none';        
            if (imgs[idx]) if (imgs[idx].id) imgs[idx].src = '/imgs/plus.jpg';
        }
        
        if (show)
        {
            tbody.style.display = 'none';
            img.src = '/imgs/plus.jpg';
            document.cookie = 'tbody=';
            document.cookie = 'img=';
        }
        else
        {
            tbody.style.display = '';
            img.src = '/imgs/minus.jpg';
            document.cookie = 'tbody=' + tbody.id;
            document.cookie = 'img=' + img.id;
        }
    }
}

function GetCookie(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;

	if ((!start) && (name != document.cookie.substring(0, name.length)))
	{
		return '';
	}
	
	if ( start == -1 ) return '';

	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function OnManageLoad()
{
    var tbodyId, imgId;
    
    tbodyId = GetCookie('tbody');
    imgId = GetCookie('img');
    
    if (tbodyId != '' && imgId != '')
    {
        ShowHide(imgId, tbodyId);
    }
}

//http://www.codeproject.com/KB/aspnet/EnterKeyToButtonClick.aspx
    function doClick(buttonName,e)
    {
//the purpose of this function is to allow the enter key to 

//point to the correct button to click.

        var key;

         if(window.event)
              key = window.event.keyCode;     //IE

         else
              key = e.which;     //firefox

    
        if (key == 13)
        {
            //Get the button the user wants to have clicked

            var btn = document.getElementById(buttonName);
            if (btn != null)
            { //If we find the button click it

                btn.click();
                event.keyCode = 0
            }
        }
   }

function imageClick(sender)
{
    document.location = document.getElementById(sender.id.replace("imgDetails", "lnkDetails")).href;
}
