// #### Start Cookie Functions ####
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
// #### End Cookie Functions ####

// mailto
function mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + location.href; 
location.href = mail_str;
}

// press section image popup
function viewimg(n, img, w, h)
{
  foto1= new Image();
  foto1.src=(img);

  viewFotos(n, img, w, h);
}
function viewFotos(name, img, w, h){
 features = "toolbar=no,location=no,directories=no,status=no,menubar=no," + "scrollbars=yes, resizable=yes, width=" + w + ", height=" + h;

 dlg = window.open ("","Details",features);
 dlg.moveTo(470,70);
 dlg.document.write("<html><head><title>" + name + " Zoom</title></head>");
 dlg.document.write("<body bgcolor=white><center>"); 
 dlg.document.write("<a href=# onClick=window.close();>");
 dlg.document.write("<table width=100%>");
 dlg.document.write("<tr><td align=center valign=middle>");
  dlg.document.write("<img src=" + img + "border=1>");
 dlg.document.write("</td></tr>");
 dlg.document.write("<tr><td align=center>");
 dlg.document.write("<a href=# onClick=window.close();>");
 dlg.document.write("<font size=1 face=verdana>click to close</font></a>");
 dlg.document.write("</td></tr>");
 dlg.document.write("</table></body></html>");
 dlg.document.close();

}

// resize popup window to fit image
function ResizeToFit(dlg, picHeight, picWidth) {
 var imgWidth;
 var imgHeight;
 imgWidth = picWidth + 60; 
 imgHeight = picHeight + 110;
 dlg.resizeTo(imgWidth, imgHeight);
}

// build popup window
function mssDisplayImages(img, name, width, height){
 features = 
    "toolbar=no,location=no,directories=no,status=no,menubar=no," +
    "scrollbars=no,resizable=no,width=" + width + ",height=" + height;
 dlg = window.open ("","Details",features);
 dlg.document.write("<html><head><title>" + name + " Zoom</title></head>");
 dlg.document.write("<body bgcolor=white onLoad=\"javascript:opener.ResizeToFit(self,  picImg.height, picImg.width);\"><center>");
 dlg.document.write("<table width=100% height=100%>");
 dlg.document.write("<tr><td align=center valign=middle>");
 dlg.document.write("<img name=\"picImg\" src=" + img + ">");
 dlg.document.write("</td></tr>");
 dlg.document.write("<tr><td align=center valign=middle>");
 dlg.document.write("<a href=# onClick=window.close();>");
 dlg.document.write("<font size=1 face=Arial>Click to close</font></a>");
 dlg.document.write("</td></tr>");
 dlg.document.write("</table></body></html>");
 dlg.document.close();
}

// switch alt image view
function changeImage(img) {
 var imageName;
 for (i = 1; i <= 9; i++) {
  imageName = "image" + i; 
  if (document.getElementById(imageName)) {
   document.getElementById(imageName).style.display='none';
  }
 }
 document.getElementById(img).style.display='block';
}

/*rollover image replacement script*/

function changeimage_bkp(imgURL)
{
//alert (document.getElementById("imgContainer").src);
	imgContainer.innerHTML = imgURL;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changeimage_new(i)
{      
//	document.autoimg.src = arr_img_new[i].src;
	main_img = document.getElementById("autoimg");
	main_img.src = arr_img_new[i].src;
	main_img.width = arr_img_new[i].width;
	main_img.height = arr_img_new[i].height;
}


function curryear()
 {
    var now = new Date();
	function fourdigits(number)	{
      return (number < 1000) ? number + 1900 : number;
	  }
       today = fourdigits(now.getYear());
	   document.getElementById("date").value=today;
  }

// bookmark function
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function showLayer(x){
  var el=document.getElementById(x);
  if (el)el.style.display="block";
}

// mss reviews
function findPos(obj, topChange, leftChange) {
   var curTop = 0;
   var curLeft = 0;
   if (obj.offsetParent) {
      do {
         curTop += obj.offsetTop;
         curLeft += obj.offsetLeft;
      }while(obj=obj.offsetParent)
   }
   curTop += topChange;
   curTop += 'px';
   curLeft += leftChange;
   curLeft += 'px';
   return [curTop, curLeft];
}

function createReviewModal(state, div, top, left){
	var clickToClose = true; // set to true to close modalby clicking anywhere
	var modal = document.getElementById('modalOverlay'); // modal div id
	var modalFrame = document.getElementById('modalOverlayFrame'); // modal div id
	var cHeight = findPos(document.getElementById('modalOverlay'), 100, 0)[0];
	var selects = document.getElementsByTagName('select');
	if(div == null){div = '';}
	if(top == null) {top=0;}
	if(left == null) {left=0;}
	function off(){
	   modal.style.height = '1px';
      modal.style.visibility='hidden';
      modalFrame.style.display='none';
      modal.style.top='auto';
      for (i=0;i<selects.length;i++){selects[i].style.visibility='visible';}
   }
	function on(){
      modal.style.height='1000px';
      modal.style.visibility='visible';
      modal.style.top='0px';
      var pos = findPos(document.getElementById('itemtype'), top, left);
      modalFrame.style.top= '20%';
      modalFrame.style.left= '34%';
      //modalFrame.style.top= '50%';
      //modalFrame.style.left= '50%';
      modalFrame.style.height='320px';modalFrame.style.display='block';
      for(i=0;i<selects.length;i++){selects[i].style.visibility='hidden';}
   }
	if(!modal||modal=='undefined'){modal=document.createElement('div');modal.id='modalOverlay';document.body.appendChild(modal);}
	if(!modalFrame||modalFrame=='undefined'){modalFrame=document.createElement('div');modalFrame.id='modalOverlayFrame';document.body.appendChild(modalFrame);}
	if (state=="on")on();
	if (state=="off")off();
	if (state="on") {
      modal.onclick=function(){
				if(clickToClose)off();
			}
      }
}

function createViewrevModal(state, div, top, left){
	var clickToClose = true; // set to true to close modalby clicking anywhere
	var modal = document.getElementById('modalOverlay2'); // modal div id
	var modalFrame = document.getElementById('modalOverlayFrame2'); // modal div id
	var cHeight = findPos(document.getElementById('modalOverlay2'), 100, 0)[0];
	var selects = document.getElementsByTagName('select');
	if(div == null){div = '';}
	if(top == null) {top=0;}
	if(left == null) {left=0;}
	function off(){
	   modal.style.height = '1px';
      modal.style.visibility='hidden';
      modalFrame.style.display='none';
      modal.style.top='auto';
      for (i=0;i<selects.length;i++){selects[i].style.visibility='visible';}
   }
	function on(){
      modal.style.height='1000px';
      modal.style.visibility='visible';
      modal.style.top='0px';
      var pos = findPos(document.getElementById('itemtype'), top, left);
      modalFrame.style.top= '20%';
      modalFrame.style.left= '34%';
      //modalFrame.style.top= '50%';
      //modalFrame.style.left= '50%';
      modalFrame.style.height='320px';modalFrame.style.display='block';
      for(i=0;i<selects.length;i++){selects[i].style.visibility='hidden';}
   }
	if(!modal||modal=='undefined'){modal=document.createElement('div');modal.id='modalOverlay2';document.body.appendChild(modal);}
	if(!modalFrame||modalFrame=='undefined'){modalFrame=document.createElement('div');modalFrame.id='modalOverlayFrame2';document.body.appendChild(modalFrame);}
	if (state=="on")on();
	if (state=="off")off();
	if (state="on") {
      modal.onclick=function(){
				if(clickToClose)off();
			}
      }
}


/* Fixes z-index issues
Version 1.1
This plugin fixes z-index issues typically occur in IE. It traverses up the DOM to make sure that all the ancestors of the target element have a high z-index value.
This fixes a common z-index issue that an element with high z-index is showing underneath its ancestor's sibling that has the same explicit or implicit (e.g. IE's implied zero z-index when position: relative is applied) z-index as the corresponding ancestor.
For IE 6's z-index issues with input boxes, see the jQuery bgiframe plugin.

www.davidtong.me/z-index-misconceptions-bugs-fixes/
param obj:
    recursive: boolean (default: true) - set to false to reduce the number of loops and if it still works, go for false
    exclude: string - a list of class names to be excluded in the fix
    msieOnly: boolean (default: false) - set to true to only apply the fix to IE browsers
    zIndex: string (default: '9999') - a big number that should just be high enough to make the element-to-be-fixed stay on top of other elements
*/
(function($) {
    $.fn.fixZIndex = function(params) {
        params = params || {};
        if (params.msieOnly && !$.browser.msie) return this;
        var num_of_jobj = this.length;
        for (var i = num_of_jobj; i--;) {
            var curr_element = this[i];
            var config_recursive = params.recursive || true;
            var config_exclude = params.exclude || null;
            while (curr_element != document.body) {
                if (!$(curr_element).hasClass(config_exclude) && ($(curr_element).css('position') == 'relative' || $(curr_element).css('position') == 'absolute')) {
                    if ($.data(curr_element, 'zIndex') == undefined) {
                        $.data(curr_element, 'zIndex', curr_element.style.zIndex || '-1');
                    }
                    curr_element.style.zIndex = params.zIndex || '9999';
                }
                curr_element = curr_element.parentNode;
                if (!config_recursive) break;
            }
        }
        return this;
    };

    // optional function to restore z-index if needed
    $.fn.restoreZIndex = function(params) {
        params = params || {};
        if (params.msieOnly && !$.browser.msie) return this;
        var num_of_jobj = this.length;
        for (var i = num_of_jobj; i--;) {
            var curr_element = this[i];
            var config_exclude = params.exclude || null;
            while (curr_element != document.body) {
                var currZIndex = $.data(curr_element, 'zIndex');
                if (currZIndex > -1 && !$(curr_element).hasClass(config_exclude)) {
                    curr_element.style.zIndex = currZIndex;
                    $.removeData(curr_element, 'zIndex');
                }
                else if (currZIndex == -1) {
                    curr_element.style.zIndex = '';
                }
                curr_element = curr_element.parentNode;
            }
        }
        return this;
    };
})(jQuery);



