
function showHideFlash(panelId,flashDivId,Type,NodeId,userControlTypeId,docId)
{
        var browser= navigator.appName;
        var version= navigator.userAgent.substring(navigator.userAgent.lastIndexOf("Firefox/")+8);
        if(browser=="Netscape" && version.substring(0,1)=="2")
        {
            if(!document.all)
            {
                document.getElementById(panelId).childNodes[1].style.display='';
            }
            else
            {
                document.getElementById(panelId).childNodes[0].style.display='';
            }
        }
        else
        {
             if(!document.all)
            {
                document.getElementById(panelId).childNodes[1].style.display='none';
            }
            else
            {
                document.getElementById(panelId).childNodes[0].style.display='none';
            }
            var container = document.getElementById(panelId);
            var RND = Math.floor(Math.random()*100000);
            var RND2 = RND + Math.ceil(Math.random()*200000);
            //help for the object below : http://blog.deconcept.com/swfobject 
            var flash = new SWFObject("../flash/TagMap.swf?"+RND, "flaOb", "905", "385", "9", "#ffffff");
		    //RECRUITER | PUBLIC | USER
		    flash.addVariable("viewMode", Type);
		    if (Type == 'USER')
		    {
		        flash.addVariable("tagmapUrl","../xmltree.aspx");
		    }
		    else
		    {
	            flash.addVariable("tagmapUrl","../xmltree.aspx?Docid="+docId+"-2-"+RND);
		    }
		    flash.addVariable("docNodeId", NodeId);
		    flash.addVariable("userControlType",userControlTypeId);
            flash.write(flashDivId);
        }
}


var flashRequest;

function InitializeFlashRequest()
{
	if (window.XMLHttpRequest)
    {
        flashRequest = new XMLHttpRequest();
    } 
    else
    {
        try { flashRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
        try { flashRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
        flashRequest = false; } }
    }
}


var TagType;  
function updateNode(prodNodeId, text, rating, active,name,docNodeId,userControlType)
{
    // handle data 
    var args = [prodNodeId,text,rating,active,name,docNodeId];
    var skillsData=rating+"~!~"+text+"~!~"+prodNodeId+"~!~"+"skillsMapType"+"~!~"+active+"~!~"+docNodeId+"~!~"+name;
        var mainDivId;
        var mainDiv;  
        
        if(userControlType.indexOf("pr_")>=0 || userControlType.indexOf("ShortProEdt_")>=0)
        {
            mainDivId=userControlType;
            skillsData+="~!~7";
            TagType=7;
        }
        else if (userControlType.indexOf("Education_")>0 || userControlType.indexOf("ed_")>0)
        {
            mainDiv=Dom.getElementsBy(function(el) {if (el.id.indexOf(docNodeId) > 0&&el.id.indexOf("webPart") > 0) return true; else return false; },'div','')
            mainDivId=mainDiv[0].id;
            skillsData+="~!~8"
            TagType=8;
        }
        else if(userControlType.indexOf("WorkExperience_")>0 || userControlType.indexOf("we_")>0)
        {
            mainDiv=Dom.getElementsBy(function(el) {if (el.id.indexOf(docNodeId) > 0&&el.id.indexOf("webPart") > 0) return true; else return false; },'div','')
            mainDivId=mainDiv[0].id;
            skillsData+="~!~6"
            TagType=6;
        }
        else if(userControlType.indexOf("JobAd")>0)
        {            
            mainDiv=Dom.getElementsBy(function(el) {if (el.id.indexOf("JobAd") > 0&&el.id.indexOf("webPart") > 0) return true; else return false; },'div','')
            mainDivId=mainDiv[0].id;
            skillsData+="~!~10"
            TagType=10;
        }
        else if(userControlType.indexOf("AdvancedSearchSkillsMap")>0)
        {
            mainDiv=Dom.getElementsBy(function(el) {if (el.id.indexOf("AdvancedSearchSkillsMap") > 0&&el.id.indexOf("webPart") > 0) return true; else return false; },'div','')
            mainDivId=mainDiv[0].id;
            skillsData+="~!~9"
            TagType=9;
        }
        else
        {
            mainDivId=userControlType;
            skillsData+="~!~7";
            TagType=7;
        }
        if(rating==0)
        {
            rating=1;
        }
        if(userControlType.indexOf("JobAd")>0)
        {
            if(docNodeId ==0)
            {
                btnAddTagClickNoSave('null',skillsData,mainDivId);
            }
            else
            {
                AddSkillTag(prodNodeId,docNodeId,text,mainDivId,name,TagType,rating);   
            }
        }
        else
        {
	        AddSkillTag(prodNodeId,docNodeId,text,mainDivId,name,TagType,rating);   
	    }
}

var skillRating=1;
function AddSkillTag(prodId,docNodeId,note,mainDivId,skillTagTxt,skillTagType,rating)
{
    var RND = Math.floor(Math.random()*100000);
    TagCmd='Add'
    skillRating=rating;
    var tblRating=Dom.getElementsBy(function(el) {if (el.id.indexOf('tblTagsRating') >= 0 ) return true; else return false; },'table',mainDivId)[0];
    tblMainTags=tblRating;
    var flag=CheckTagExist(mainDivId,skillTagTxt) 
    if(flag)
    {  
        alert('There is already tag added with this name before');
        return false;
    }
    if(skillTagType==9)
    {
        mainTagDiv=mainDivId;
        url="TagSearchOperations.ashx?Cmd=Add&"+"TagText="+skillTagTxt+"&Rating="+rating+"&"+RND;
        InitializeSkillTagXMLRequest(url);
    }
    else
    {
        url="TagOperations.ashx?SkillTag=true&Cmd=Add&Rating="+rating+"&TagText="+skillTagTxt+"&Note="+note+"&TagType="+skillTagType+"&DocNodeId="+docNodeId+"&ProductId="+prodId+"&"+RND;
        InitializeSkillTagXMLRequest(url);
    }
}
function InitializeSkillTagXMLRequest(url)
{
    InitializeFlashRequest();
    flashRequest.onreadystatechange=ProcessRequestSkillTag;
    flashRequest.open("GET", url, true);
    flashRequest.send(null);
} 


function ProcessRequestSkillTag()
{
    if(flashRequest.readyState == 4)//If the readyState is in the "Ready" state
	{
		if(flashRequest.status == 200)//If the returned status code was 200. Everything was OK.
	    {
	        if(TagCmd=='Add')
	        {
	            var tagsInfo=flashRequest.responseText;
	            var arrTagsInf=tagsInfo.split('***');
	            for(i=0;i<arrTagsInf.length;i++)
	            {
	                var tagId=arrTagsInf[i].split('&&&')[0];
	                var tagTxt=arrTagsInf[i].split('&&&')[1];
	                AddNewSkillTagRow(tblMainTags,tagTxt,tagId,skillRating);
	            }
	        }
	        else if (TagCmd=='Update')
	        {
	            lblSaveTag.style.visibility='hidden';
	        }
	        else if(TagCmd=='Delete')
	        {
	            tagRow.parentNode.parentNode.deleteRow(tagRow.rowIndex);
	        }
		}
	}
}

//this for adding new row for skillTag
function AddNewSkillTagRow(tblRat,tagText,tagId,rating)
{
    var tblRowsCount=tblRat.rows.length;
    tblRat.parentNode.style.display='block'
    var root=tblRat.getElementsByTagName('tr')[0].parentNode;//the TBODY
    var clone=document.getElementById('tblTagsRating').getElementsByTagName('tr')[0].cloneNode(true);//the clone of the first row
    root.appendChild(clone);//appends the clone
    clone.style.display='';
    clone.style.visibility='visible';
    clone.id=clone.id+(tagId)
        clone.onmouseover=function()
        {
            if(TagType==9)
            {
                MouseOverSerachRatingTags(this);
            }
            else
            {
                MouseoverRatingTags(this);
            }
        }
        clone.onmouseout=function()
        {
            MouseoutRatingTags(this);
        }
    
    var div=tblRat.rows[tblRowsCount].getElementsByTagName('td')[1].getElementsByTagName('div')[0];
    div.id+='divNum'+(tagId)
    var inputs=clone.getElementsByTagName('span');
    clone.getElementsByTagName('input')[0].id=clone.getElementsByTagName('input')[0].id+(tagId);
    inputs[6].innerHTML=Trim(tagText);
    //here check if tagtype searchType then save the search id in inputs[9]
    if(TagType==9||TagType==10)
    {
        //search tag
        inputs[9].innerHTML=tagId;
    }
    else
    {
        //normal tag
        inputs[7].innerHTML=tagId;
    }
    var stars=div.getElementsByTagName('span');
    stars[0].parentNode.getElementsByTagName('input')[0].value=rating;
    for(j=0;j<stars.length;j++)
    {
        stars[j].id=stars[j].id+'order'+(tagId)
        if(j<rating)
        {
            stars[j].className='ratingStar filledRatingStar';
        }
        else
        {
            stars[j].className='ratingStar emptyRatingStar'; 
        }
        stars[j].onmouseover=function()
        {
            var rowNumber=this.id.substring(this.id.indexOf('order')+5);
            var divId=div.id.substring(0,div.id.indexOf('divNum'))+'divNum'+rowNumber
            MouseOverStar(this.getAttribute('index'),'ratingStar filledRatingStar','ratingStar emptyRatingStar',divId);
        }

   } //end for  
}

function selectNode(nodeId, active) {
    // handle data
    var args = [nodeId,active];
   
}

function showNode(nodeId) {
    // handle data
    nodeid = 'asfsaf';
   
    
}

function confirmLoadSkillTag()
{
}

function showFlash(flashDivId,docId,type)
{
    var RND = Math.floor(Math.random()*100000);
    var flash = new SWFObject("../flash/TagMap.swf", "rec", "585", "385", "9", "#ffffff");
	flash.addVariable("viewMode", type);
	flash.addVariable("tagmapUrl","../xmltree.aspx?Docid="+docId+"-"+RND );
    flash.write(flashDivId);
}
