// JavaScript Document
//Home page NORA image click function
function openNominateWindow(){var strNORAurl="http://www.norauk.com/nomination-material/vote.php?id=4c0faa0bb32c1";var iNORATop=100;var iNORALeft=(screen.availWidth-520)/2;open(strNORAurl,"","width=520, height=470,toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes,copyhistory=no, resizable=yes,top="+iNORATop+",left="+iNORALeft);return false}
/*
//Home page Image slider
$(document).ready(function() {
	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 3000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});*/

//Confirmation delete alert
function ConfirmDelete(val)
{
    ret=confirm("Are you sure? You want to delete selected rows");
    if(ret==true)
        return true;
     else
     return false;
}
//Set color for tabs
function setColor(id)
{
    for(var i=1;i<=4;i++)
    {
        if(i==id){
                document.getElementById("lnk"+i).style.backgroundColor="White"; 
                document.getElementById("lnk"+i).style.color="#1637A4";
            }
        else {
            document.getElementById("lnk"+i).style.backgroundColor="#1637A4"; 
            document.getElementById("lnk"+i).style.color="White";
       }
    }
        
    return false;
}
//Set color for region
function setColor_Region(id)
{
    for(var i=1;i<=4;i++)
    {
        if(i==id){
                document.getElementById("lnkR"+i).style.backgroundColor="White"; 
                document.getElementById("lnkR"+i).style.color="#104FFE";
            }
        else {
            document.getElementById("lnkR"+i).style.backgroundColor="#104FFE"; 
            document.getElementById("lnkR"+i).style.color="White";
       }
    }
        
    return false;
}
//this is the javascript function called when the textbox's onkeypress event is fired
function IsNumeric(TextBox,strType)
// check for valid numeric strings
{
    if (strType="Decimal")
    {
        var strValidChars = "0123456789.";
    }
    else if (strType="integer")
    {
        var strValidChars = "0123456789";
    }
    var strString;
    var strChar;
    strString=TextBox.value;

    for (i = 0; i < strString.length; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            TextBox.value = TextBox.value.substring(0, i);
            TextBox.value.length = i;
            event.returnValue = false;
        }
    }
} 
// For E-Time management reset text box on ckick.
function changetext(val,txtControl)
{
    if(trim(document.getElementById(txtControl).value) == val)
    {
        document.getElementById(txtControl).value='';
        //document.getElementById(txtControl).className='';
    }
    else if(trim(document.getElementById(txtControl).value)=="")
    {
        document.getElementById(txtControl).value = val ;
        //document.getElementById(txtControl).className='txtbox_bg';
    }
}
// For Job/Jobseeker Search reset text box on ckick.
function changetextSearch(val,txtControl)
{
    if(trim(document.getElementById(txtControl).value) == val)
    {
        document.getElementById(txtControl).value='';
        document.getElementById(txtControl).className='left_textbox';
    }
    else if(trim(document.getElementById(txtControl).value)=="")
    {
        document.getElementById(txtControl).value = val ;
        document.getElementById(txtControl).className='eg_text';
    }
}
function trim(str)
{
    result=str.replace(/(^ +| +$)/, "");
    return result;
}
function doEnterClick(evt,bt)
{
 var evt = evt ? evt : window.event;
  var bt = document.getElementById(bt);
  if (bt)
  {
      if (evt.keyCode == 13)
      {
            bt.click();
            return false;
      }
  }
}
/*For tag system */
  function getNextSibling(startBrother) {
    endBrother = startBrother.nextSibling;

    if (endBrother == null)
        endBrother = startBrother;

    while (endBrother.nodeType != 1) {
        if (endBrother.nextSibling != null)
            endBrother = endBrother.nextSibling;
        else
            break;
    }

    if (endBrother.nodeType == 3)
        endBrother = startBrother;

    return endBrother;
}

function getPreviousSibling(startBrother) {
    endBrother = startBrother.previousSibling;

    if (endBrother == null)
        endBrother = startBrother;

    while (endBrother.nodeType != 1) {
        if (endBrother.previousSibling != null)
            endBrother = endBrother.previousSibling;
        else
            break;
    }

    if (endBrother.nodeType == 3)
        endBrother = startBrother;

    return endBrother;
}

function ExpandColasp(img) {
    var img1 = getNextSibling(img.parentNode);
    img1 = getNextSibling(img1)

    if (img.src.indexOf('add') != -1) {
        img.src = "../images/remove.png";
        //img1 = getNextSibling(img1.childNodes[0]).style.display = "block";
        lstdiv = img1.getElementsByTagName('div')
        for (i = 0; i <= lstdiv.length - 1; i++) {
            if (lstdiv[i].id == "div31") {
                lstdiv[i].style.display = "block";
                break;
            }
        }
    }
    else {
        img.src = "../images/add.png";
        //img1 = getNextSibling(img1.childNodes[0]).style.display = "none";
        lstdiv = img1.getElementsByTagName('div')
        for (i = 0; i <= lstdiv.length - 1; i++) {
            if (lstdiv[i].id == "div31") {
                lstdiv[i].style.display = "none";
                break;
            }
        }
    }
}

function ExpandColaspSection(img) {
    objParent = getNextSibling(img)

    if (img.src.indexOf('add') != -1) {
        img.src = "../images/remove.png";
        objParent.style.display = "block";
    }
    else {
        img.src = "../images/add.png";
        objParent.style.display = "none";
    }

}

function CheckUncheck(checkbox, summ, hdnCtrl) {
    var i = 0;
    checkbox1 = getNextSibling(checkbox.parentNode)
    checkbox1 = getNextSibling(checkbox1.childNodes[0])

    for (i = 0; i <= checkbox1.childNodes.length - 1; i++) {
        checkbox2 = checkbox1.childNodes[i]

        if (checkbox2.childNodes.length > 0)
            checkbox2 = getNextSibling(checkbox2.childNodes[0])

        checkbox2.checked = checkbox.checked;
    }

    SelectionSummery(checkbox1.parentNode.parentNode.parentNode, document.getElementById(summ),document.getElementById(hdnCtrl));
}
function CheckUncheckParent(checkbox, summ,hdnCtrl) {
    checkbox1 = getNextSibling(checkbox.parentNode)
    checkbox1 = getNextSibling(checkbox1.parentNode)

    var allunchecked = true;
    var listcheckbox = checkbox1.getElementsByTagName('input');
    for (i = 0; i < listcheckbox.length; i++) {
        if (listcheckbox[i].type == "checkbox") {
            if (!listcheckbox[i].checked) {
                allunchecked = false;
                break;
            }
        }
    }

    checkbox1 = getNextSibling(checkbox1.parentNode)
    checkbox1 = getPreviousSibling(checkbox1);
    checkbox1.getElementsByTagName('input')[0].checked = allunchecked;
    SelectionSummery(checkbox1.parentNode.parentNode, document.getElementById(summ),document.getElementById(hdnCtrl));
}
function SelectionSummery(objparent, objsumm, objhdnCtrl) {
    var InputValues = "";
    var InputIds = "";
    var checkboxInput = objparent.getElementsByTagName("input");
    var i = 0;
    for (i = 0; i <= checkboxInput.length - 1; i++) {
        if (checkboxInput[i].type == "checkbox" && checkboxInput[i].checked == true) {
            if (InputValues == "") {
                InputValues = checkboxInput[i].name;
                InputIds=checkboxInput[i].value;
            }
            else {
                if (objsumm.type == "text"){
                    InputValues = InputValues + ", " + checkboxInput[i].name;
                    InputIds = InputIds + "," + checkboxInput[i].value;
                    }
                else{
                    InputValues = InputValues + "<br/>" + checkboxInput[i].name;
                    InputIds = InputIds + "," + checkboxInput[i].value;
                    }
            }
        }
    }
    if (objsumm.type == "text"){        
        objsumm.value = InputValues;
        objhdnCtrl.value = InputIds;
        }
    else
        {        
        objsumm.innerHTML = InputValues;
        objhdnCtrl.value = InputIds;
        }
}

//Reset all controls
function ResetTags(ContainerId,label) 
{
objparent = document.getElementById(ContainerId)
var checkboxInput = objparent.getElementsByTagName("input");

var i = 0;
for (i = 0; i <= checkboxInput.length - 1; i++) 
    {
        if (checkboxInput[i].type == "checkbox") 
        {
            checkboxInput[i].checked="";
         }
    }
document.getElementById(label).innerHTML="";
document.getElementById('ctl00_ContentPlaceHolder1_ucTagAssignment_txtKeyword').value="";

document.getElementById('ctl00_ContentPlaceHolder1_ucTagAssignment_hdnSector').value="";
document.getElementById('ctl00_ContentPlaceHolder1_ucTagAssignment_hdnLocation').value="";
}
function ValidateTagInput(lblSector,lblLocation)
{
    returnVal=true;

    if (document.getElementById(lblSector).innerHTML.trim()=="")
    {
        document.getElementById("ctl00_ContentPlaceHolder1_ucTagAssignment_lblMsg").innerHTML="<p class='msg warning'>Sector required!.</p>";
        return false;
        
    }
        
    if (document.getElementById(lblLocation).innerHTML.trim()=="")
    {
        document.getElementById("ctl00_ContentPlaceHolder1_ucTagAssignment_lblMsg").innerHTML="<p class='msg warning'>Location required!.</p>";
        return false;
    }

//    if (document.getElementById('ctl00_ContentPlaceHolder1_ucTagAssignment_txtKeyword').value.trim()=="")
//    {
//        document.getElementById("ctl00_ContentPlaceHolder1_ucTagAssignment_lblMsg").innerHTML="<p class='msg warning'>Keyword required!.</p>";
//        return false;
//     }
    return returnVal;     
}
//To select on load
function loadCheckBoxesOnEdit(hdn,container,summ)
{
    var Values=document.getElementById(hdn).value.split(",");

    container = document.getElementById(container)
    
    var checkboxInput = container.getElementsByTagName("input");

    var i = 0;
    for (i = 0; i <= checkboxInput.length - 1; i++) 
    {
        if (checkboxInput[i].type == "checkbox") 
        {
            var hdn=0;
            for (hdn = 0; hdn <= Values.length - 1; hdn++) 
            {
                if (checkboxInput[i].value.trim() == Values[hdn].trim()) 
                {
                    checkboxInput[i].checked="checked";
                }
            }
        }
    } 
    SelectionSummery(container,document.getElementById(summ),document.getElementById(hdn)); 
}
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
/*Check all and uncheck function add this on evey page <asp:Literal ID="GridCheckBoxIDsArray" runat="server"></asp:Literal>*/
function funSearch(key)
{
    if(key.keyCode==13)
    {           
        key.keyCode=0;
        document.getElementById("btnSearch").click();
    }
}
function ChangeCheckBoxState(id, checkState)
{
    var cb = document.getElementById(id);
    if (cb != null)
       cb.checked = checkState;
}
        
function ChangeAllCheckBoxStates(checkState, val)
{
    if (val == 0){
        // Toggles through all of the checkboxes defined in the CheckBoxIDs array
        // and updates their value to the checkState input parameter
        if (CheckBoxIDs != null)
        {
            for (var i = 0; i < CheckBoxIDs.length; i++)                 
               ChangeCheckBoxState(CheckBoxIDs[i], checkState);
        }
    }else{
        if (GridCheckBoxIDs != null)
        {
            for (var i = 0; i < GridCheckBoxIDs.length; i++)
                   ChangeCheckBoxState(GridCheckBoxIDs[i], checkState);
        }
    }
}
function ChangeHeaderAsNeeded(val)
{
    // Whenever a checkbox in the GridView is toggled, we need to
    // check the Header checkbox if ALL of the GridView checkboxes are
    // checked, and uncheck it otherwise
    if (val == 0)
    {
        if (CheckBoxIDs != null)
        {
            // check to see if all other checkboxes are checked
            for (var i = 1; i < CheckBoxIDs.length; i++)
            {
                var cb = document.getElementById(CheckBoxIDs[i]);
                if (!cb.checked)
                {
                    // Whoops, there is an unchecked checkbox, make sure
                    // that the header checkbox is unchecked
                    ChangeCheckBoxState(CheckBoxIDs[0], false);
                    return;
                }
            }
            // If we reach here, ALL GridView checkboxes are checked
            ChangeCheckBoxState(CheckBoxIDs[0], true);
        }
    }
    else
    {
        if (GridCheckBoxIDs != null)
        {
            // check to see if all other checkboxes are checked
            for (var i = 1; i < GridCheckBoxIDs.length; i++)
            {
                var cb = document.getElementById(GridCheckBoxIDs[i]);
                if (!cb.checked)
                {
                    // Whoops, there is an unchecked checkbox, make sure
                    // that the header checkbox is unchecked
                    ChangeCheckBoxState(GridCheckBoxIDs[0], false);
                    return;
                }
            }
            // If we reach here, ALL GridView checkboxes are checked
            ChangeCheckBoxState(GridCheckBoxIDs[0], true);
        }
    }
}
//For location sector dropdowns
function toggleRepeatorSelection(source, targetID) {
    //Commented line
    //var target = source.parentNode.parentNode.parentNode.parentNode;
      var target = source.parentNode;
      
    // Find all checkboxes   
    var inputs = target.getElementsByTagName('input');
    //Check all   
// Commented to let select individual    
//    if (source.checked)
//        for (var i = 0; i < inputs.length; i++) {
//            if (inputs[i].type == "checkbox")
//                inputs[i].checked = true;
//        }
//    // Uncheck all   
//    else
//        for (var i = 0; i < inputs.length; i++) {
//            if (inputs[i].type == "checkbox")
//                inputs[i].checked = false;

//        }
}  
function setRepeatorSelectionValuesToTextBox(source,textBox,btnShowValues,hdLocation)
{
    var target = source.parentNode.parentNode.parentNode.parentNode;
    var inputs = target.getElementsByTagName('input');

    //values to set to Textbox
    var selections="";
    var selectionsValues="";
    
    //Select max 5
    var maxSelection=5;
    
    for (var i = 0; i < inputs.length; i++) {
      //lOGIC FOR SELECT FIRST 5
      if (inputs[i].type == "checkbox" && inputs[i].checked == true)
        {
            //Check only first 5
            maxSelection=maxSelection-1;
            if (maxSelection<0)
            {
                inputs[i].checked = false;
                continue;
            }
        }
        if (inputs[i].type == "checkbox" && inputs[i].checked == true)
        {
            if (selections=="")
            {
                selections=inputs[i].nextSibling.innerHTML;
                selectionsValues=inputs[i].nextSibling.nextSibling.nextSibling.value;
            }
            else
            {
                selections=selections+", "+inputs[i].nextSibling.innerHTML;
                selectionsValues=selectionsValues+","+inputs[i].nextSibling.nextSibling.nextSibling.value;
            }
        }
    }
    
    //Set all text values
    document.getElementById(textBox).value=selections;        
    document.getElementById(textBox).title=selections;        
    document.getElementById(btnShowValues).title=selections;        
    
    //Set Values
    document.getElementById(hdLocation).value=selectionsValues;        
    //alert(document.getElementById(hdLocation).value);
}
