// file was created by eron armstrong
// for task: 26327
// this file is used to store necessary reusable methods


// js method updates the photo_id parameter of page url
// because we need to save the state each time an image
// is clicked. cliclets(digg, delicious, etc) needs to
// know the state of page. this should be put into a class
// but i didnt have time to do it. the class method would
// take paramName, newValue, and the full url with querystring,
// and it would return the new modified url. note: this will
// only work with parameters that are equal to numbers, such as
// photo_id=323432
function modifyStateUrl(urlState, parameterName, newValue, type /* int|string */)
{
  	// if url has photo_id in it, modify it
	if(urlState.indexOf(parameterName) > 0)
 	{
		var regEx;
 	 	if(type == 'int') 
		{
 	  		regEx = new RegExp(parameterName + "=([0-9])*");
 	  	}
		urlState =  urlState.replace(regEx,parameterName+ "=" +newValue)
	}
	// else, add it on
	else
	{
	 	urlState += urlState.indexOf("?") > 0 ? "&" +parameterName+ "=" + newValue : "?"+parameterName+"=" + newValue; 
	}
	
	return urlState;
}



var pageStateUrl = 'http://example.com/?url=urlname&years=7483&someothervalue=false';
function modifyPageStateUrl(parameterName, newValue, type /* int|string */)
{


  	// if url has photo_id in it, modify it
	if(pageStateUrl.indexOf(parameterName) > 0)
 	{
		var regEx;
 	 	if(type == 'int') 
		{
 	  		regEx = new RegExp(parameterName + "=([0-9])*");
 	  	}
 	  	if(type == 'string')
 	  	{
 	  	
			// this reg expression doesnt work with things like dashes, etc
			// you would have to modifiy it to include all that
 	  	    	regEx = new RegExp(parameterName + "=[a-zA-Z_0-9% ]*");
 
 	  	}
 
        
		pageStateUrl =  pageStateUrl.replace(regEx,parameterName+ "=" +newValue)
	}
	// else, add it on
	else
	{
	 	pageStateUrl += pageStateUrl.indexOf("?") > 0 ? "&" +parameterName+ "=" + newValue : "?"+parameterName+"=" + newValue; 
	}
}




function URLencode(sStr) {
    return escape(sStr)
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27');
  }
  
  
  
  
  
  
  
  
  
  /* Standards Compliant rollover script Author : Daniel Nolan wwwdotbleedingegodotcodotuk/webdevdotphp */ 
  // usage: <img src="App_Dependencies/img/home.gif" class="imgover" />
  // if you link is an active image then just add the class 'imgactive' like: <img src="App_Dependencies/img/home.gif" class="imgover imgactive" />
  // this function will auto be attaached b/c of the class name and it will substitute home_o.gif, so
  // make sure those images are in the directory too
function initrollovers() 
{ 
    if (!document.getElementById) return;
    var aPreLoad = new Array(); var sTempSrc; 
    var aImages = document.getElementsByTagName('img'); 
    for (var i = 0; i < aImages.length; i++) 
    { 
        
        if (aImages[i].className.indexOf('imgover') > -1) 
        { 

            var src = aImages[i].getAttribute('src'); 
            var ftype = src.substring(src.lastIndexOf('.'), src.length); 
            var hsrc = src.replace(ftype, '_o'+ftype); 
            aImages[i].setAttribute('hsrc', hsrc); 
            
            
            // lets check if this is the image 
            // which is the active image
            if(aImages[i].className.indexOf('imgactive') > -1)
            {
                aImages[i].className = aImages[i].className.replace('imgover', '');
                //aImages[i].setAttribute('src', hsrc);
                aImages[i].src = hsrc;
                //alert(aImages[i].className );
                continue;
            }
            
            
            aPreLoad[i] = new Image(); 
            aPreLoad[i].src = hsrc; 
            aImages[i].onmouseover =function() 
                                    { 
                                        sTempSrc = this.getAttribute('src'); 
                                        this.setAttribute('src', this.getAttribute('hsrc')); 
                                    } 
            aImages[i].onmouseout = function() 
                                    { 
                                        if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype); 
                                        this.setAttribute('src', sTempSrc); 
                                    } 
        } 
    } 
} 
 

if(window.addEventListener){ // Mozilla, Netscape, Firefox
	            this.addEventListener('load', initrollovers, false);
            } else { // IE
	            this.attachEvent('onload', initrollovers);
            }
            
            
            
            
            
            
            
            
// submits a form on enter click
// usage: put -> onKeyPress="return submitenter(this,event)" 
// on your input field that you want the enter press to be tracked on
// example: <INPUT NAME=password TYPE=PASSWORD SIZE=10 onKeyPress="return submitenter(this,event)">
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
 
 
 
// use when you dont want a button to track teh enter keypress 
function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}