//header.js - called from  all pages
//for smooth scrolling
/*
$(function(){

    $('a[href*=#]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $target = $(this.hash);
            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            
            if ($target.length) {
            
                var targetOffset = $target.offset().top;
                
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                    
                return false;
                
            }
            
        }
        
    });
    
});
*/


function searchmgr(searchsrc,host){
    switch(searchsrc){
       case 1:
           searchwords = document.forms['navinfo'].sw1.value;		//from header search box
           document.forms['navinfo'].searchsrc.value = 1;
           scope       = "i";				//search images
           boolmode = "a";  
           break;
       case 2:
           searchwords = document.forms['navinfo'].sw2.value;		//advanced search opts
           document.forms['navinfo'].searchsrc.value = 2;
           scope = getCheckedValue(document.forms['navinfo'].scope);
           if (document.forms['navinfo'].boolmode[0].checked)   
               boolmode = "o";
           else 
               boolmode = "a";   
           break;
    } 

    var swords = "";
    //filter out illegal chars
    for(x=0;x<searchwords.length;x++)
    {
        if (searchwords.substr(x,1) != '#' &&
            searchwords.substr(x,1) != '|' &&
            searchwords.substr(x,1) != '%' &&
            searchwords.substr(x,1) != '?' &&
            searchwords.substr(x,1) != '*')
            {
                swords +=searchwords.substr(x,1);
            }
    }

    //if (form.sw.value.length < 3)
    if (swords.length < 3)
    {
        alert('Please enter one or more keywords to search on in the entry area\n(words must be longer than 2 characters)');
        return;
    }


//alert('swords '+swords+' scope '+scope);
    if (scope == "i"){ 		//scope = i)mages
        //submitInfo(host,'search-'+swords+'-'+searchcode+'.php',0);
        document.forms['navinfo'].pgname.value='search-'+swords+'-1.php';
        //submitInfo(host,'search-'+swords+'-1.php',0);
        submitInfo(host,'poster.php',0);
   }
    else		//scope = w)ebsite	
        submitInfo(host,'searchsite-'+swords+'-'+boolmode+'.php',0);


}

function searchsite(form)
{
    if (form.sw.value.length < 3)
    {
        alert('Please enter one or more keywords to search on in the entry area\n(words must be longer than 2 characters)');
        return;
    }

    if (form.boolmode[0].checked)   
       boolmode = "o";
    else 
       boolmode = "a";   
    document.location.replace('searchsite-'+form.sw.value+'-'+boolmode+'.php');

}

function searchimages()
{
    //search source  = 3 - the body

    if (document.searchimages.sw.value[0] == '#')
        document.searchimages.sw.value = document.searchimages.sw.value.substr(1);

    if (document.searchimages.sw.value.length < 3)
    {
        alert('Please enter one or more keywords to search on in the entry area\n(words must be longer than 2 characters)');
        return;
    }

    if (document.searchimages.boolmode[0].checked)
        boolmode = "o";
    else
        boolmode = "a";
                
    //append "3" to boolmode for search source = body
    //document.location.replace('/search-'+window.document.searchimages.sw.value+'-'+boolmode+'3.php');
    document.forms['navinfo'].action = 'search-'+window.document.searchimages.sw.value+'-1.php';
    document.forms['navinfo'].submit();    
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function tog(labID,parID,chdID,galid){
    var style2 = document.getElementById(chdID).style;
    if (style2.display == "block")	//set to invisible
    {
        //readGal(galid,chdID);
        style2.display = "none";
        document.getElementById(labID).style.fontWeight = 'normal';
        document.getElementById(parID).style.fontWeight = 'normal';
        document.getElementById(parID).value = '+';
        return;	//exit sendRequest
    }
    else  //div contains data,don't sendRequest,just make visible
    {
        //readGal(galid,chdID,'a');	//already read in headfunc.inc
        style2.display = "block";
        document.getElementById(parID).value = '-';
        document.getElementById(parID).style.fontWeight = 'bold';
        document.getElementById(labID).style.fontWeight = 'bold'; //'-' looks better bold
        return;	//exit sendRequest
    }
}

function readGal(galid,chdID)
{
    var mode = '';
    var style2 = document.getElementById(chdID).style;
    if (style2.display == 'block')
        mode = 'del';
    else
        mode = 'add';
        
    document.getElementById(chdID).className = "sbarbrdr"; 


    //var href = './getgal.php?galid='+galid+'&mode='+mode;
    //ajaxpage(href,chdID);

    var url = 'getgal.php';			//AJAX 'bridge' program
    var params = 'galid='+galid+'&mode='+mode;
    doajax(url, chdID, params);

}	
 

//url=page formater,targid=div id/name, params=passed in vars
function doajax(url, targid, params){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e){
            try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
             catch (e){}
            }
        }
    else
        return false
    page_request.onreadystatechange=function(){
    ldpage(page_request, targid)
    }
    //page_request.open('GET', url, true)
    page_request.open('POST', url, true)

//for POST Send the proper header information along with the request
page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
page_request.setRequestHeader("Content-length", params.length);
page_request.setRequestHeader("Connection", "close");
 
    //page_request.send(null)
    page_request.send(params)
}

function ldpage(page_request, targid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
//alert('resp '+page_request.responseText);
        document.getElementById(targid).innerHTML=page_request.responseText;
    }
}

function toggle(id){

    var state = document.getElementById(id).style.display;
    if (state == 'block'){
        document.getElementById(id).style.display = 'none';
        document.getElementById('optlabl').innerHTML = 'Show Search Options';
    }else{
        document.getElementById(id).style.display = 'block';
        document.getElementById('optlabl').innerHTML = 'Hide Search Options';
    }
}

//external callback functions found in homeshow.fla, slideshow.fla

function startShow(delay) {
    //var t=setTimeout("document.getElementById('slideshow').dostartShow()",delay);
    var t=setTimeout("document.getElementById('homeshow').dostartShow()",delay);
}

function stopShow() {
    //document.getElementById('slideshow').dostopShow();
    document.getElementById('homeshow').dostopShow();
}

function firstPage(){
    //var swf = document.getElementById('slideshow');
    var swf = document.getElementById('homeshow');
    if (swf)
        swf.dofirstPage();
}


function setViewportWidth(url) {
  var width = 0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  if (document.forms['navinfo'].portwd.value != width){
      document.forms['navinfo'].portwd.value = width;
      document.forms['navinfo'].pgname.value = url;
      document.forms['navinfo'].action = 'poster.php';
      document.forms['navinfo'].submit();
  }
}

function getViewportHeight() {
  var height = 0;
  if( document.documentElement && document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
}

