
function getWindowSize() 
{
	var myWidth = 0, myHeight = 0;

	if (typeof(window.innerWidth) == 'number') 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if (document.documentElement &&
		(document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	//alert('Width = ' + myWidth);
	//alert('Height = ' + myHeight);

	return myWidth;
}

function setLightboxWidth(divElement, marginWidth)
{
	var lightboxDiv = document.getElementById(divElement);
	var width = getWindowSize();

	if (lightboxDiv != null)
	{
		lightboxDiv.style.width = width - marginWidth;
	}

}

/*
Function to validate if the textbox is empty
*/
function isEmpty(textBox)
{
	var textBoxValue = document.getElementById(textBox).value;
	if (textBoxValue == null || textBoxValue == "")
	{
		return true;
	}

	return false;
}

/*
Function to set the enter key on key press of a particular control
*/
function setEnterKey(buttonToClick)
{
	
	if (event.keyCode == 13)
	{
		
		event.cancelBubble = true;
		event.returnValue = false;
		
		if(typeof(document.getElementById)== 'undefined'){
			eval('document.all.' + buttonToClick + '.click();');
		}else{
			document.getElementById(buttonToClick).click();
		}
	}
}
function setEnterKey(buttonToClick,evt)
{
	
	var e = evt? evt : window.event; 
	if(!e) return; 
	
	if (e.keyCode == 13)
	{
	
		e.cancelBubble = true;
		e.returnValue = false;
		
		var item;
		if(typeof(document.getElementById(buttonToClick))== 'undefined'){
			item  = eval('document.all.' + buttonToClick);
		}else{
			
			item = document.getElementById(buttonToClick);
		}
		if(item.type.toLowerCase()=="text")
		{
			//add value so that change event will fire
			item.value='buttonClicked';
			//call textbox postback method
			__doPostBack(item.id.replace('_','$'),'');
		}else{
			item.click();
		}
		return false;
	}
}
/*
Function to set the focus to a particular control
*/
function setFocus(id)
{
	var element = document.getElementById(id);
	element.focus();
	return false;
}

/*
This is triggered by the onclick event of a select all button.
The purpose is to add all values from the source text box into the destination text box.
*/
function addAllValues(toTextBoxId, fromTextBoxId)
{
	// Get a reference to the text boxes
	var toTextBox = document.getElementById(toTextBoxId);
	var fromTextBox = document.getElementById(fromTextBoxId);

	// Get values of the destination text box
	var destValues = toTextBox.value;
	
	// Get values of the source text box
	var srcValues = fromTextBox.value;

	if (srcValues != "")
	{
		// Split the values into array
		imageID_srcArray = srcValues.split(",");
		srcValues = "";

		// Loop through each value and check accordingly
		var index = 0;     
		while (index < imageID_srcArray.length)
		{
			var checkBox = document.getElementById(imageID_srcArray[index]);
			if (checkBox != null)
			{
				if (checkBox.disabled != true)
				{           
					if (index != 0)
					{
						srcValues = srcValues + "," + imageID_srcArray[index];
					}
					else
					{
						srcValues = imageID_srcArray[index];
					}
				}
			}
			index += 1;
		}
	}

	// If there is nothing in the destination textbox
	if (destValues == "")
	{
		// Copy everything and return
		toTextBox.value = srcValues;	
		return;
	}

	// If there is some value from the source
	if (srcValues != "")
	{
		// Split the source values into array
		imageID_srcArr = srcValues.split(",");

		// Split the destination values
		imageID_destArr = destValues.split(",");
		
		// Loop through each value in the source array and check accordingly
		var i = 0;
		var j = 0
		while (i < imageID_srcArr.length)
		{
			// Search the destination array
			while (j < imageID_destArr.length)
			{
				// If the image ID is the same
				if (imageID_srcArr[i] == imageID_destArr[j])
				{
					break;
				}

				j++;
			}

			// If image ID not found in the destination array
			if (j >= imageID_destArr.length)
			{
				// Add the image ID to destination values
				destValues += "," + imageID_srcArr[i];
			}

			i++;
			j = 0;
		}

		// Update the destination textbox value
		toTextBox.value = destValues;
	}
}

/*
This is triggered by the onclick event of a deselect all button.
The purpose is to remove all values on the destination text box that are contained 
in the source text box.
*/
function removeAllValues(toTextBoxId, fromTextBoxId)
{
	// Get a reference to the text boxes
	var toTextBox = document.getElementById(toTextBoxId);
	var fromTextBox = document.getElementById(fromTextBoxId);

	// Get values of the destination text box
	var destValues = toTextBox.value;

	// Get values of the source text box
	var srcValues = fromTextBox.value;

	// If there is nothing in the destination textbox
	if (destValues == "")
	{
		return;
	}

	// If there is some value from the source
	if (srcValues != "")
	{
		// Split the source values into array
		imageID_srcArr = srcValues.split(",");

		// Split the destination values
		imageID_destArr = destValues.split(",");

		// Loop through each value in the source array and check accordingly
		var i = 0;
		var j = 0
		while (i < imageID_srcArr.length)
		{
			while (j < imageID_destArr.length)
			{
				// If the image ID is the same
				if (imageID_srcArr[i] == imageID_destArr[j])
				{
					// Set a -1 flag to be removed from destination values
					imageID_destArr[j] = -1;
				}

				j++;
			}

			i++;
			j = 0;
		}

		// Construct the new destination values
		i = 0;
		destValues = "";
		while (i < imageID_destArr.length)
		{
			if (imageID_destArr[i] != -1)
			{
				destValues += imageID_destArr[i] + ",";
			}
			
			i++;
		}

		// Remove the last comma
		destValues = destValues.substring(0, destValues.length -1);

		// Update the destination textbox value
		toTextBox.value = destValues;
	}
}

/*
Function to construct a list of values as a comma-delimited string on a textbox given the ID.
The value will be added on and off the textbox depending upon the checked status.
This is triggered by the onclick event of a checkbox.
*/
function toggleValue(textBoxId, value)
{
	// Get a reference to the text box
	var textBox = document.getElementById(textBoxId);
	
	// Get the current value of the text box
	var currentValue = textBox.value;

	// Search for the value to be added in the current textbox value
	var index = currentValue.indexOf(value);

	// If the value to be added in does NOT exist
	if (index <= -1)
	{
		if (currentValue == "")
		{
			textBox.value = value;
		}
		else
		{
			textBox.value = currentValue + "," + value;
		}
	}
	else // If the value already exists
	{
		// Construct left hand side value
		var leftValue = currentValue.substring(0, index);
		var rightValue = currentValue.substring(index, currentValue.length);

		// Construct right hand side value
		// Find the next occurence of comma
		var nextIndex = rightValue.indexOf(",");
		
		// If there is no more comma on the right hand side value
		if (nextIndex <= -1)
		{
			// Remove comma on the left hand side value
			leftValue = leftValue.substring(0, leftValue.length -1);
			rightValue = "";
		}
		else
		{
			// Else, get the right hand side value after the comma
			rightValue = rightValue.substring(nextIndex +1, rightValue.length);
		}

		// Set the value
		textBox.value = leftValue + rightValue;
	}
}

/*
Function to set checkboxes based on a list of values of a textbox.
*/
function setImageCheckBoxes(textBoxId)
{
	// Get a reference to the text box
	var textBox = document.getElementById(textBoxId);

	// Get values of the text box
	var values = textBox.value;

	// If there is some value
	if (values != "")
	{
		// Split the values into array
		imageID_array = values.split(",");

		// Loop through each value and check accordingly
		var index = 0;	
		while (index < imageID_array.length)
		{
			var checkBox = document.getElementById(imageID_array[index]);
			if (checkBox != null)
			{
				if (checkBox.disabled != true)
				{	
					checkBox.checked = true;
				}
			}

			index += 1;
		}
	}
}

/*
Function to reset checkboxes based on a list of values of a textbox.
*/
function resetImageCheckBoxes(textBoxId)
{
	// Get a reference to the text box
	var textBox = document.getElementById(textBoxId);

	// Get values of the text box
	var values = textBox.value;

	// If there is some value
	if (values != "")
	{
		// Split the values into array
		imageID_array = values.split(",");

		// Loop through each value and check accordingly
		var index = 0;	
		while (index < imageID_array.length)
		{
			var checkBox = document.getElementById(imageID_array[index]);
			if (checkBox != null)
			{
				checkBox.checked = false;
			}

			index += 1;
		}
	}
}

function d_helloworld()
{
	alert("hello from default.js");
}
function ShowHideExclamationMark(ExclamationMark,errorTextSpan,ErrorSummarySpan){
	ExclamationMark.style.display="none";
	
	if(errorTextSpan.innerHTML != '')
		ExclamationMark.style.display="";
	if(ErrorSummarySpan != null && ErrorSummarySpan.style.visibility=="visible")
		ExclamationMark.style.display="";
		
}
function displayDefaultImage(img,appPath){
	img.src= appPath + 'resources/images/imageoffline.gif';
	img.width="170";
	img.height="119";
	img.style.width='170px';
	img.style.height='119px';
}
