﻿// JScript File

function setContentWidth() {
	var fixedWidthForPanel = 425;
	var minWidth = 710;
	var centerContent = document.getElementById("tableProduct");
	var currentWidth;
	//alert(centerContent);
	if (centerContent && centerContent !== null) {
		currentWidth = getWindowWidth();
		if ((currentWidth - fixedWidthForPanel) < minWidth) {
			centerContent.style.width = minWidth + "px";
			document.getElementById("tableHeader").style.width = minWidth + "px";
			// document.getElementById("tableHeaderRecommended").style.width = minWidth + "px";
			// document.getElementById("divRows").style.width = minWidth + "px";
			// document.getElementById("tableRows").style.width = minWidth + "px";
			document.getElementById("framework-base-content").style.width = minWidth + "px";

		}
		else {
			centerContent.style.width = (currentWidth - fixedWidthForPanel) + "px";
			document.getElementById("tableHeader").style.width = (currentWidth - fixedWidthForPanel) + "px";
			// document.getElementById("tableHeaderRecommended").style.width = (currentWidth - fixedWidthForPanel) + "px";
			// document.getElementById("divRows").style.width = (currentWidth - fixedWidthForPanel) + "px";
			// document.getElementById("tableRows").style.width = (currentWidth - fixedWidthForPanel) + "px";
			document.getElementById("framework-base-content").style.width = (currentWidth - fixedWidthForPanel) + "px";
		}
		//alert(centerContent.style.width);
	}
}

function getWindowWidth() {

	var windowWidth = 0;
	if (typeof (window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}


function trim(s) {
	var temp = s;
	return temp.replace(/^\s+/, '').replace(/\s+$/, '');
}

function openCCOPage() {
	window.open('WhatsCCOID.htm', '', 'width=300,height=200,location=yes');
}

function showPopup(popupId) {
	setTimeout("showPopup2( '" + popupId + "', true );", 100);
	return false;
}

function showPopup2(popupId, appendToForm) {
	var body = document.body, doc = document.documentElement, barrier, popup;

	barrier = document.createElement("div");
	barrier.id = "divBarrier_" + popupId;
	barrier.className = "popupBarrier";
	barrier.style.position = "absolute";
	barrier.style.top = "1px";
	barrier.style.left = "1px";

	if (appendToForm) {
		document.forms[1].appendChild(barrier);
	} else {
		body.appendChild(barrier);
	}

	popup = document.getElementById(popupId);
	popup.style.position = "absolute";
	popup.style.display = "";

	if (appendToForm) {
		document.forms[1].appendChild(popup);
	} else {
		body.appendChild(popup);
	}

	recalculatePopup(popup, barrier);
	window.onresize = function (evt) { recalculatePopup(popup, barrier); };
	window.onscroll = function (evt) { recalculatePopup(popup, barrier); };

	return false;
}

function recalculatePopup(popup, barrier) {
	var body = document.body, doc = document.documentElement;

	barrier.style.width = (document.documentElement.scrollWidth - 2) + "px";
	barrier.style.height = (document.documentElement.scrollHeight - 2) + "px";

	popup.style.top = ((doc.clientHeight / 2) - (popup.offsetHeight / 2)) + doc.scrollTop + "px";
	popup.style.left = ((doc.clientWidth / 2) - (popup.offsetWidth / 2)) + doc.scrollLeft + "px";

	if (popup.style.top == "-50px") {
		popup.style.top = "309px";
		popup.style.left = "100px";
	}
	//			alert(popup.style.top);
	//			alert(popup.style.left);
}

function hidePopup(popupId, target, argument) {
	var barrier = document.getElementById("divBarrier_" + popupId);
	document.forms[1].removeChild(barrier);
	if (argument == 'hide') {
		var popup = document.getElementById(popupId);
		popup.style.display = "none";
	}
	window.onresize = null;
	window.onscroll = null;

	__doPostBack(target, argument);

	return false;
}

function checkDate(sender, args) {
	if (sender._selectedDate < new Date()) {
		alert("You cannot select a Start date earlier than today or an End date earlier than tomorrow.");
		sender._selectedDate = new Date();
		// set the date back to the current date
		sender._textbox.set_Value(sender._selectedDate.format(sender._format))
	}
}

function resetServiceLevelEndDate(combo) {
	var combo = document.getElementById(_cboCoveragePeriod);
	var txt1 = document.getElementById(_txtServiceLevelStartDate);
	var txt2 = document.getElementById(_txtServiceLevelEndDate);
	alert(txt1.value);
	if (combo.value != "-1" && txt2 && txt1.value != null && txt1.value.length > 0 && (txt1.initialValue != txt1.value || combo)) {
		alert('made it in the gates');
		QDV.validateDateFormat(txt1.value);
		QDV.testedDate.setFullYear(QDV.testedDate.getFullYear() + parseInt(combo.value));

		if (subtractDayFromEndDate != null) {
			if (subtractDayFromEndDate == 'True') {
				QDV.testedDate = new Date(QDV.testedDate.getFullYear(), QDV.testedDate.getMonth(), QDV.testedDate.getDate() - 1);
			}
		}

		txt2.value = QDV.dateToString(QDV.testedDate);
		txt2.initialValue = txt2.value;
	}
}


