var isIE = document.all;

function $(id) {
    return document.getElementById(id);
}

function WindowSize() {
  this.myWidth = 0;
  this.myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    this.myWidth = window.innerWidth;
    this.myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    this.myWidth = document.documentElement.clientWidth;
    this.myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    this.myWidth = document.body.clientWidth;
    this.myHeight = document.body.clientHeight;
  }
  this.getWindowHeight = function() {
      return this.myHeight;
  }
  this.getWindowWidth = function() {
      return this.myWidth;
  }
}

function showModalWnd(workWnd, h, w){
    
    if(isIE){
        var pageYPos = document.documentElement.scrollTop;
    } else {
        var pageYPos = window.pageYOffset;
    }
    if (h == undefined)
        h = 469;
    if (w == undefined)
        w = 636;       
    
    var winSize = new WindowSize();
    var winHeight = winSize.getWindowHeight();
    var winWidth = winSize.getWindowWidth();
    var popUpTop = ((winHeight - h)/2) + pageYPos;//((winHeight - 269)/2) + pageYPos;
    var popUpLeft = (winWidth - w)/2;//(winWidth - 436)/2;
    var pageWidth = document.body.offsetWidth;
    var pageHeight = document.body.offsetHeight;

    $("opacity").style.height = pageHeight + "px";
    $("opacity").style.width = pageWidth + "px";
    $("opacity").style.display = "block";
    $(workWnd).style.display = "block";
    $(workWnd).style.top = popUpTop + "px";
    $(workWnd).style.left = popUpLeft + "px";
	
	//Handle flash assests
	//toggleDisplayByClass("login_asset");
}

function closeModalWnd(id) {
    $("opacity").style.display = 'none';
    $(id).style.display = 'none';
    
}

function switchPic(toId, imgId) {
    $(imgId).src = '/images/mockups/' + toId;
}

function showUserMsg(id, msg, showIndicator) {
    var box = $(id);
    if (showIndicator) {
        showIndicator(id);
    }
    box.innerHTML = msg;
    box.style.display = 'block';
    var hide = hideUserMsg(id);
    setTimeout(hide, 2000);
}

function hideUserMsg(id) {
    return (function() {$(id).style.display = 'none'});
}

function showIndicator(id) {
}

function setSelected(lstBox, selVal) {
    for (var i = 0; i < lstBox.options.length; i++) {
        if (lstBox.options[i].value == selVal) {
            lstBox.options[i].selected = true;
            return;
        }
    }
}

function toggleCatTxtBox(lstbox) {
    var val = lstbox.options[lstbox.options.selectedIndex].text.toLowerCase();
    var txt = $(lstbox.id.replace(/lst/, "txt"));
    if (val.indexOf('other') == -1) {
        txt.style.display = 'none';
        txt.value = val;
    }
    else {
        txt.style.display = 'block';
        //txt.value = '';
        txt.focus();
    }
    
}

function setValue(id, val) {
    $(id).value = val;
}

function showDemo(demo, load) {
    var so = new SWFObject( "/demo/" + demo, "csSWF", "640", "498", "9.0.28", "#1a1a1a");
	so.addParam( "quality", "best" );
	so.addParam( "allowFullScreen", "true" );
	so.addParam( "scale", "showall" );
	so.addParam( "allowScriptAccess", "always" );
	so.addVariable( "autostart", "true" );
	so.write("demoPackViewer");			
	
	if (load) {
	    showModalWnd("demoPack");
	}
}

function sendToFriend(id) {
    window.location.href = '/sendtofriend.aspx?pid=' + id;
}

function printPack() {
    var movie = getFlashMovie('Powerpack');
    
    window.open('/Powertools/PrintPack.aspx?pid=' + movie.GetPackId().toString(), 'print', 'toolbar=0,location=0');
}

function sendToFriend2() {
    var movie = getFlashMovie('Powerpack');
    window.open('/SendToFriend.aspx?pid=' + movie.GetPackId().toString(), 'sendfriend', 'toolbar=0,location=0,scrollbars=1');
}

function del(msg) {
    if (confirm(msg)) {
        return true;
    }
    
    return false;
}

function del2(eventTarget) {
	if (confirm("Please confirm 'DELETE' action!")) {
		__doPostBack(eventTarget, '');
	}	
	else {
		return false;	
	}

}

function getPwd() {
    
    var res = lmg.Ajax.AjaxMethods.GetPwd($('forgotpwdbox').value);
    
    if (res.value) {
        $('msgboxForgotPwd').innerHTML = "Your password has been sent!";
        $('msgboxForgotPwd').style.display = 'block';
        setTimeout(function() { closeModalWnd('forgotPass') }, 2000);
    }
    else {
        $('msgboxForgotPwd').style.display = 'block';
    }
    
}

function showForgoPwdResult(success, msg) {
    showModalWnd('forgotPass', 150, 300)
    $('msgboxForgotPwd').innerHTML = msg;
    $('msgboxForgotPwd').style.display = 'block';
    if (success) {
        setTimeout(function() {closeModalWnd('forgotPass')}, 1500);
    }
}