function GetElementById(elementid)
{
	var obj;

	if (document.all)
		{
		eval("obj = document.all[\"" + elementid + "\"]");
		}
	else if (document.layers)
	{		
		eval("obj = document.layers[\"" + elementid + "\"]");
	}
	else if (document.getElementById)
	{
		eval ("obj = document.getElementById (\"" + elementid + "\")");		
	}
	else	
		obj =  undefined;

	return obj;
}

function SetInputClass(ControlID, ClassName)
{
	if (!GetElementById(ControlID))
	{
		//alert(ControlID);
	}
	else
		GetElementById(ControlID).className = ClassName;
}

function SetInputVisibility(ControlID, action)
{
	if (!GetElementById(ControlID))
	{
		//alert(ControlID);
	}
	else
	{
		if (action == 1)
			GetElementById(ControlID).className = "";
		else
			GetElementById(ControlID).className = "noview";
	}
}

function SetInput(inputId, inputValue){
	if(GetElementById(inputId))
		GetElementById(inputId).value = inputValue;
}
function SetSelect(sel_name, sel_index){
	var optionCounter = 0
	if(GetElementById(sel_name)) {
		sel_length = GetElementById(sel_name).length;
		for (optionCounter = 0; optionCounter < sel_length; optionCounter++) {
			if ( GetElementById(sel_name).options[optionCounter].value == sel_index ) {
				GetElementById(sel_name).selectedIndex = optionCounter;
			}
		}
	}
}
function doLink(section, params){
	
	var parts = section.split(".");
	var module = parts[0];
	var page = parts[1];
	
	var send_to_file, base_path;
	
	var array_params = Array();
	var i = 0;
	var send_params = "";
	var param = Array();
	var URL_REWRITE = "off";
	var PATH_INDEX = "";
	array_params = params.split("&");
	
	if (URL_REWRITE == "on") {
	
		var force_files = SUBDOMAINS_FORCE_FILES_JS.split(",");
		if (SUBDOMAINS_STATUS == "on" && !js_in_array(section, force_files)) {
			var res_file = section.split(".");
			send_to_file = res_file[1];
			if (res_file[0] == "site") {
				res_file[0] = "www";
			}
			base_path = "http://" + res_file[0] + "." + DOMAIN_BASE;
		}
		else {
			send_to_file = section.replace(".", "-");
			base_path = PATH;
		}
	
		while (i < array_params.length){
			if (array_params[i] != "") {
				param = array_params[i].split("=");
				send_params = send_params + param[0] + "-" + param[1];
				if(i < (array_params.length - 1)) {
					send_params = send_params + "~";
				}
			}
			i ++;
		}
	
		if (send_params != "") {
			the_link = base_path + "/" + send_to_file + "~" + send_params + ".html";
		}
		else {
			the_link = base_path + "/" + send_to_file + ".html";
		}
		
	}
	
	else {
		the_link = PATH_INDEX + "?_init=" + module + "." + page + "&" + params;
	}
	return "#";
	return the_link;
}
function checkAll(currentobject)
{
	var currentchecked;
	currentchecked = currentobject.checked;

	for (var i = 0; i < objectList.length; i++)
	{	var obj;
		obj = GetElementById(objectList[i])
		obj.checked=currentchecked;
	}
}
function checkOneFromList(objCheched)
{
	var allChecked = 0;
	var firstStatus = false;
	firstStatus = objCheched.checked
	
	for (var i = 0; i < objectList.length; i++)
	{
		var obj;
		obj = GetElementById(objectList[i])

		if (obj.checked == firstStatus)
			allChecked ++;
	}
	
	if(allChecked == objectList.length)
		GetElementById(objAll).checked = firstStatus;
	else
		GetElementById(objAll).checked = false;
}

// for testing in questions
function DeselectByCheckbox(currentobject, objectList)
{
if (currentobject.checked)
{

	for (var i = 0; i < objectList.length; i++)
	{	var obj;
		obj = GetElementById(objectList[i])
		if (currentobject != obj)
		{
			obj.checked = false;
		}
	}
}
}
//used in questions
function SetCheckBox(objCheched, objReferred, objectList)
{
if (objCheched.checked)
{
	if (GetElementById(objReferred))
		GetElementById(objReferred).checked=false;
}
else
{
	var allChecked = 0;
	var firstStatus = false;
	firstStatus = objCheched.checked
	
	for (var i = 0; i < objectList.length; i++)
	{
		var obj;
		obj = GetElementById(objectList[i])


		if (obj.checked == firstStatus && obj != GetElementById(objReferred))
			allChecked ++;
	}
	if(allChecked == objectList.length)
		GetElementById(objReferred).checked = !firstStatus;
	else
		GetElementById(objReferred).checked = false;
}		
}

function SetRadio(objCheched, objectList)
{
	var firstStatus = false;
	firstStatus = objCheched.checked
	
	var itemsListArray = objectList.split(',');
	
	for (var i = 0; i < itemsListArray.length; i++)
	{
		var obj;
		obj = GetElementById(itemsListArray[i])

		if (obj.checked == firstStatus && obj != objCheched)
			obj.checked = false;
	}
}
function ChangeRelation(profilesId, action, value, retUrl)
{
	var domain = "";
	domain = location.host;
	MakePostRequest('http://' + domain + '/Home/Account/Action.aspx?','profilesId=' + profilesId + '&action=' + action + '&value=' + value + '&retUrl=' + retUrl);
}
   
function MakePostRequest(url, parameters) {
	var httpRequest = false;
    httpRequest = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
        httpRequest.overrideMimeType('text/xml');
        }
    } 
	else if (window.ActiveXObject) { // IE
        try {
        httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        try {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
        }
    }
    if (!httpRequest) {
        //alert('Cannot create XMLHTTP instance');
        return false;
    }
    
    httpRequest.onreadystatechange = function(){
	var result;
		if (httpRequest.readyState == 4) 
		{
			if (httpRequest.status == 200) 
			{
			result = httpRequest.responseText;
			ChangeOnResult(result);
			} 
			else {
			alert('There was a problem with the request.');
			}
		}
	}
    httpRequest.open('POST', url, true);
    httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpRequest.setRequestHeader("Content-length", parameters.length);
    httpRequest.setRequestHeader("Connection", "close");
    httpRequest.send(parameters);
}
// ctlQuestionnaireSelect BEGIN
function hideQuestion(questionsId, itemsList)
{
var itemsListArray = itemsList.split(',');
var i = 0;
for(i=0; i<itemsListArray.length; i++)
{
	var cObj = GetElementById('AnswerBox' + itemsListArray[i]);
	if (cObj)
	{
		cObj.className = "noview";
	}
}
var obj = GetElementById('QuestionBox' + questionsId);
if (obj)
	obj.className = "noview";
}

function showQuestionnaireItems(object, questionsId, itemsList)
{
var itemSelected = object.options[object.selectedIndex].value;
var itemsListArray = itemsList.split(',');
var i = 0;
if (itemSelected < 0)
	itemSelected = 0;
itemSelected = itemSelected * 1;

for(i=0; i<itemsListArray.length; i++)
{
//alert("itemSelected=" + itemSelected);
//alert("itemsListArray[i]=" + itemsListArray[i]);
	if (itemSelected != itemsListArray[i])
	{
		var cObj = GetElementById('AnswerBox' + itemsListArray[i]);
		if (cObj)
		{
			cObj.className = "noview";
		}
	}
}
var obj = GetElementById('AnswerBox' + itemSelected);
if (obj)
{
//alert("obj_OK=" + 'AnswerBox' + itemSelected);
	obj.className = "";
	GetElementById('QuestionBox' + questionsId).className = "";
}
else
{
//alert("obj_NO=" + 'AnswerBox' + itemSelected);
	if (GetElementById('QuestionBox' + questionsId) )
		GetElementById('QuestionBox' + questionsId).className = "noview";
}
}
function SetDefault(answerBox)
{
	var obj = GetElementById('AnswerBox' + answerBox);
	if (obj)
		obj.className = "";
}
function ShowDatetime(selectedDate)
{
	//returns a datetime in DD-MMM-YYYY format
	var retValue = "";
	var arrayMonths = Array();
	var arrDate = selectedDate.split('/');
	arrayMonths[1] = "Jan";
	arrayMonths[2] = "Feb";
	arrayMonths[3] = "Mar";
	arrayMonths[4] = "Apr";
	arrayMonths[5] = "May";
	arrayMonths[6] = "Jun";
	arrayMonths[7] = "Jul";
	arrayMonths[8] = "Aug";
	arrayMonths[9] = "Sep";
	arrayMonths[10] = "Oct";
	arrayMonths[11] = "Nov";
	arrayMonths[12] = "Dec";
	
	if (arrDate.length > 0)
	{
		retValue = arrDate[0] + "-" + arrayMonths[parseInt(arrDate[1],10)] + "-" + arrDate[2];
	}
	return retValue;
}
// ctlQuestionnaireSelect END

function DisableAndSubmit(obj){
	if (obj)
	{
		obj.disabled = true;
		document.forms[0].submit();
	}
}

function PopupImage(ImageId, ImageWidth, ImageHeight)
{
	if (ImageId > 0)
	{
		window.open("/Home/Account/Uploadpopup.aspx?uploadsId=" + ImageId, "Milojee", "height=" + ImageHeight + " width=" + ImageWidth + "resizable=no menubar=no scollbars=no" );
	}
	else
	{
		return false;
	}
}
function checkAll1(currentobject)
{
	var currentchecked;
	currentchecked = currentobject.checked;

	var obj2 = GetElementById(objRoot2)
	if (obj2)
	{
		if (currentchecked)
			obj2.checked = !currentchecked;
	}
	
	var aobjectList1 = objectList1.split(',');
	var aobjectList2 = objectList2.split(',');

	for (var i = 0; i < aobjectList1.length; i++)
	{	var obj;
		obj = GetElementById(aobjectList1[i])
		if (obj)
			obj.checked=currentchecked;
	}
	if (currentchecked)
	{
		for (var i = 0; i < aobjectList2.length; i++)
		{	var obj;
			obj = GetElementById(aobjectList2[i])
			if (obj)
				obj.checked= !currentchecked;
		}
	}
}
function checkAll2(currentobject)
{
	var currentchecked;
	currentchecked = currentobject.checked;

	var obj1 = GetElementById(objRoot1)
	if (obj1)
	{
		if (currentchecked)
			obj1.checked = !currentchecked;
	}
	
	var aobjectList1 = objectList1.split(',');
	var aobjectList2 = objectList2.split(',');

	for (var i = 0; i < aobjectList2.length; i++)
	{	var obj;
		obj = GetElementById(aobjectList2[i])
		if (obj)
			obj.checked=currentchecked;
	}
	if (currentchecked)
	{
		for (var i = 0; i < aobjectList1.length; i++)
		{	var obj;
			obj = GetElementById(aobjectList1[i])
			if (obj)
				obj.checked= !currentchecked;
		}
	}
}
function checkOneFromList1(objCheched, otherObj, itemId)
{
	var allChecked = 0;
	var firstStatus = false;
	firstStatus = objCheched.checked
	
	var aobjectList1;
	var aobjectList2;
	var obj1;
	var obj2;

	if (itemId == 1)
	{
		aobjectList1 = objectList1.split(',');
		aobjectList2 = objectList2.split(',');
		obj1 = objRoot1;
		obj2 = objRoot2;
	}
	else
	{
		aobjectList1 = objectList2.split(',');
		aobjectList2 = objectList1.split(',');
		obj1 = objRoot2;
		obj2 = objRoot1;
	}

	if (objCheched.checked)
	{
		GetElementById(otherObj).checked = !objCheched.checked;
		GetElementById(obj2).checked = !objCheched.checked;

		for (var i = 0; i < aobjectList1.length; i++)
		{
			var obj;
			obj = GetElementById(aobjectList1[i])

			if (obj.checked == firstStatus)
				allChecked ++;
		}
		
		if(allChecked == aobjectList1.length)
			GetElementById(obj1).checked = firstStatus;
		else
			GetElementById(obj1).checked = false;
	}
	else
	{
		GetElementById(obj1).checked = false;
	}
}
var isOpera=navigator.userAgent.indexOf("Opera")>-1;

