﻿var win = null;
function newWindow(mypage,myname,w,h,features) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	if (win == null) alert(popupmessage);
	else win.window.focus();
}

function findPosY(obj){
  var curtop = 0;
  if(obj.offsetParent)
	  while(1)
	  {
	    curtop += obj.offsetTop;
	    if(!obj.offsetParent)
		  break;
	    obj = obj.offsetParent;
	  }
  else if(obj.y)
	  curtop += obj.y;
  return curtop;
}


//function showVariantBox(objId, isSearch) {
//	//var height = findPosY(document.getElementById(objId));
//	
//	//alert(parseInt(id) % 2)
////	if (parseInt(objId.substring(15)) % 2 == 0) {
////		document.getElementById('variantBox').style.marginLeft=0+'px';
////	}
////	else {
////		document.getElementById('variantBox').style.marginLeft=250+'px';
////	}
//    
//    /*
//    var left = (screen.width/2)-(290/2);
//    var top = (screen.height/2)-(323/2); 
//    
//    document.getElementById('variantCont').style.marginLeft=left+'px';
//    document.getElementById('variantCont').style.marginTop=top+'px';
//    */

//	//if (isSearch)
//	//  document.getElementById('variantBox').style.marginTop = height - 140 + 'px';
//	//else
//	//  document.getElementById('variantBox').style.marginTop = height - 290 + 'px';
//	  
//	//document.getElementById('variantCont').style.display='block';
//}


function doSearch(){
  window.location = "/Pages/Search.aspx?search=" + document.getElementById("search").value;
}
function inputDoSearch(e){
  var keycode;  

  if (window.event) 
    keycode = window.event.keyCode; 
  else if (e)
    keycode = e.which;  
  else 
    return true;
  
  if (keycode == 13) {
    doSearch();
    return false;
  }
}

function changeInputType(
	  oldElm,
	  iType,
	  iValue,
	  blankValue,
	  noFocus) {
    if (!oldElm || !oldElm.parentNode || (iType.length < 4) ||
		!document.getElementById || !document.createElement) return;
    var isMSIE = /*@cc_on!@*/false;
    if (!isMSIE) {
        var newElm = document.createElement('input');
        newElm.type = iType;
    } else {
        var newElm = document.createElement('span');
        newElm.innerHTML = '<input type="' + iType + '" name="' + oldElm.name + '">';
        newElm = newElm.firstChild;
    }
    var props = ['name', 'id', 'className', 'size', 'tabIndex', 'accessKey'];
    for (var i = 0, l = props.length; i < l; i++) {
        if (oldElm[props[i]]) newElm[props[i]] = oldElm[props[i]];
    }
    newElm.onfocus = function() {
        return function() {
            if (this.hasFocus) return;
            var newElm = changeInputType(this, 'password', iValue,
		  (this.value.toLowerCase() == iValue.toLowerCase()) ? true : false);
            if (newElm) newElm.hasFocus = true;
        }
    } ();
    newElm.onblur = function() {
        return function() {
            if (this.hasFocus)
                if (this.value == '' || (this.value.toLowerCase() == iValue.toLowerCase())) {
                changeInputType(this, 'text', iValue, false, true);
            }
        }
    } ();
    newElm.hasFocus = false;
    if (!blankValue) newElm.value = iValue;
    oldElm.parentNode.replaceChild(newElm, oldElm);
    if (!isMSIE && !blankValue) newElm.value = iValue;
    if (!noFocus || typeof (noFocus) == 'undefined') {
        window.tempElm = newElm;
        setTimeout("tempElm.hasFocus=true;tempElm.focus();", 1);
    }
    return newElm;
}

function toggleItem(id){
     Element.toggle(id);
}

jQuery(function () {
    jQuery("#slide-captions").cycle({
        speed: 300,
        timeout: 0,
        fx: "blindY",
        sync: 0,
        cleartypeNoBg: true
    });

    var mainSlideCycling = false;
    jQuery('#main-slideshow').cycle({
        speed: 1400,
        timeout: 5000,
        pager: '#nav',
        slideExpr: 'a',
        cleartypeNoBg: true,
        before: function (curr, next, opts, fwFlag) {
            if (mainSlideCycling)
                jQuery("#slide-captions").cycle(opts.nextSlide);
            else mainSlideCycling = true;
        }
    });

    jQuery("a", "#nav").text("");

    if (jQuery.browser.msie) {
        jQuery("#main-slideshow").corner("top cc:#fff");
        jQuery("#slide-captions").corner("bottom cc:#fff");
    }
});
