
//-----------------------------------------------------------------//
//TIMER

var secs
var timerID = null
var timerRunning = false
var delay = 125

function InitializeTimer(){
	//SET THE LENGTH OF THE TIMER, IN SECONDS
	secs = 1
	StopTheClock()
	StartTheTimer()
}

function StopTheClock(){
	if(timerRunning)
		clearTimeout(timerID)
	timerRunning = false
}

function StartTheTimer(){
	if (secs==0)
	{
		StopTheClock();
		//RESETS THE TEXTS AFTER n SECONDS PASSED.
		resetText();
	}
	else
	{
		self.status = secs
		secs = secs - 1
		timerRunning = true
		timerID = self.setTimeout("StartTheTimer()", delay)
	}
}

//-----------------------------------------------------------------//
//-----------------------------------------------------------------//	
var selectedobj;
var pic = new Array(5);
//var pic_text = new Array(5);
var pic_title = new Array(5);

selectedobj = '';

//Img IDs
	pic[0] = 'rating_rating_0';
	pic[1] = 'rating_rating_1';
	pic[2] = 'rating_rating_2';
	pic[3] = 'rating_rating_3';
	pic[4] = 'rating_rating_4';
	pic[5] = 'rating_rating_5';
	
//Titles
	pic_title[0] =  '<span style="color:red">DO NOT TRUST</span>';
	pic_title[1] = 'Not Trustworthy';
	pic_title[2] = 'Less Trustworthy';
	pic_title[3] = 'Trustworthy';
	pic_title[4] = 'Very Trustworthy';
	pic_title[5] = 'Most Trustworthy';

//Texts
	//pic_text[0] = 'This reputation choice is reserved for confirmed scam artists, thieves, and harrassers. These people are viewed by society as criminals. Use this reputation only when you are certain that the person in question is the worst of the worst; otherwise you might want to choose &quot;Not Trustworthy&quot;.';
	//pic_text[1] = 'This reputation choice is for an interaction or transaction that did not meet any reasonable standard of performance of behavior. The person was rude; lied; insulted you; took forever to pay or ship; or otherwise is not someone that you (or anybody you don\'t hate) would want to deal with.';
	//pic_text[2] = 'This reputation choice is for an interaction or transaction that did not quite meet your standards of performance or behavior. Perhaps the person was sharing advice that wasn\'t optimal; or the item you received wasn\'t entirely as advertised; or payment got messy, though ultimately got sorted out.';
	//pic_text[3] = 'This reputation choice is for an interaction or transaction that met your standards of performance or behavior. The majority of your interactions and transactions will be "Trustworthy". Achieving higher reputation than this requires behavior above and beyond what is reasonable expected of folks.';
	//pic_text[4] = 'This reputation choice is reserved for an interaction or transaction that went above and beyond your standards of performance or behavior. Very few of your interactions or transactions will achieve this level of reputation.';
	//pic_text[5] = 'This reputation choice is reserved for people who wildly exceed your and society\'s expectations for performance or behavior. These instances are exceptionally rare, and this should be used extremely sparingly. These folks are saints, without equals.';
//-----------------------------------------------------------------//	
//IMGOVER: Sets texts and stops the timer

function imgmover(index){
	StopTheClock();
	settext('repselector_title', pic_title[index]);
	//settext('repselector_text', pic_text[index]);
}

//-----------------------------------------------------------------//
//IMGOUT: Starts the timer that after n seconds restores the text

function imgmout(id){
	alert('venky');
	InitializeTimer();
}

//-----------------------------------------------------------------//	
//SETTEXT: Sets the text based on the ID of the selected pic. "text" is string.

function settext(id, text){
	var obj = document.getElementsByTagName(id);
	obj.innerHTML = text;
}


function setingtext(id, text){
	
	var objrep = document.getElementById( id );
	//var text=objrep.value;

    if(id =='identity_name')
		    {
            if (objrep.value == '')
            {           
	objrep.value = 'denisedemo@gmail.com';
	removeAllOptions('source_type');
	}
	}
}

//-----------------------------------------------------------------//	
//SELECTREP: Selects the box and text

function selectrep(id)
	{
		if (id != 'i-1') 
			{
				//DEACTIVATES PREVIOUS SELECTION
				for(i=0; i<6; i++)
					{
						var obj;
						obj = document.getElementById(pic[i])
						if (pic[i] == id) 
						{
							selectedobj = i;
						}
					}							
					//SETS THE VALUE TO THE HIDDEN FIELD NAMED "reputation_value"
					var objrep = document.getElementById('reputation_value');
					objrep.value = selectedobj;
					document.getElementById(id).checked = true;
					rate_people_image(id);
			}
	}

//-----------------------------------------------------------------//
//RESETTEXT: Restores the text once the timer has completed n seconds to either the standard text or the selected box's text.

function resetText(){
	if (selectedobj === '') {
		settext('ratingbot', "Choose a reputation level.");
		//settext('repselector_text', "Mouse over each icon to learn more about what it represents, and for examples of when it is appropiate to use for your interaction of transaction.");
	}else{
		settext('ratingbot', pic_title[selectedobj]);
		//settext('repselector_text', pic_text[selectedobj]);
	}
	
}

//-----------------------------------------------------------------//
//-----------------------------------------------------------------//
//-----------------------------------------------------------------//

//TEXTAREA
function removeAllOptions(selectbox)
{

var x = document.getElementById(selectbox);

x.selectedIndex = 0;
}


function selecttext(id)
{
    var objrep = document.getElementById( id );
	var text=objrep.value;
	
    if(objrep.value=='denisedemo@gmail.com')
		    {
            objrep.select();
            }
     
		   
    

}
function clicktext(id)
{

var selectedtextarea;
selectedtextarea = 0;
    if (!selectedtextarea) 
        {
		  var objrep = document.getElementById( id );
		  var text=objrep.value;
		  	  
		  if (objrep.innerHTML == 'Enter any textual information you would like about this experience and/or individual. Enter as much or as little as you like. Please respect their privacy, and do not include any identifying or personal information.') 
            {
             objrep.innerHTML = '';
			 objrep.value = ''; // This clears text in comment box including Linux's Mozilla Browser.
            }	
		  else if(objrep.value=='TrustPlus ID')
		    {
            objrep.value = '';
            
            }
  		  else if(objrep.value=='Password')
		    {
            objrep.value = '';
            }
            
            selectedtextarea=1;
		   } 
	   
}
//TABS
function HideObj( id ) {
	var obj = document.getElementById( id );
	obj.style.display = "none";
	return 0;
}

function ShowObj( id ) {
	var obj = document.getElementById( id );
	obj.style.display = "";
	return 0;
}


function selectTab(index){
	for(i=0; i<tabs.length;i++){
		//Hide all divs
		HideObj( tabs[i][0] );
		//OFF all images
		var obj = document.getElementById( tabs[i][1] );
		obj.src = tabs[i][3];
	}

	//ON selected image
		var obj = document.getElementById( tabs[index][1] );
		obj.src = tabs[index][2];
	
	//ON selected DIV
		ShowObj( tabs[index][0] );
	
	selectedtabindex = index;
	document.getElementById('rating_transactional').value = (index == 0) ? 1 : 0	
}


//-----------------------------------------------------------------------//
//-------------------------------------------------------------------------//
//  CREATE REPUTATION FORM IS USING THE FOLLOWING FUNCTIONS.-Kishore
    
    function checkTransaction()
    { 
        document.forms[repform]['rating[transactional]'].value= 1
		document.forms[repform]['rating[txn_value]'].disabled=false
		
		$("rating_context_type_id_1").checked = true;
        if (document.forms[repform]['rating[txn_value]'].value=="")
            {document.forms[repform]['rating[txn_value]'].value="0.00";}
    }
    
    function checkInteraction(value)
    {        
        if (value == 0) 
            { 
                checkTransaction();
                return               
            }
         else if(value == 1)
            {
                $("rating_context_type_id_3").checked = true; 
            }
        else if(value == 2)
            {                
                $("rating_context_type_id_7").checked = true;
                $("rating_interaction_type_1").checked = false;
                $("rating_interaction_type_2").checked = false;
                $("rating_interaction_type_3").checked = true;
                //document.forms[repform]['rating[interaction_type]'].value = 3;
             } 
        document.forms[repform]['rating[transaction_type]'][0].checked=true;
        document.forms[repform]['rating[transaction_type]'][1].checked=false;
        $("rating_context_type_id_1").checked = false;
        $("rating_context_type_id_2").checked = false;        
        document.forms[repform]['rating[transaction_type]'].value = value;
        document.forms[repform]['rating[transactional]'].value = 0;
       /* Whenever a user switched from any tab to the "A Transaction" tab, radio button "No" should be highlighted.
       		document.forms[repform].txn_completed_checkbox.checked=false;
       		document.forms[repform].txn_completed_checkbox.disabled=false; */
        $("txn_uncheckbox").checked = true;         
		document.forms[repform]['rating[txn_value]'].value="";
        document.forms[repform]['rating[txn_value]'].disabled=false;
        document.forms[repform]['rating[txn_completed]'].value="false"

    }
    // setTransactionCompletion will be called only on press of YES or NO radio button, hence "else if" condition is replaced by "else"
    function setTransactionCompletion(x)
    {	
		if (x.id == "txn_uncheckbox")
		{
			document.getElementById("txn_completed").value = "false";
		}
		else //if(x.checked && x.id == "txn_completed_checkbox")
        {
          document.forms[repform]['rating[txn_completed]'].value="true";
          if (document.forms[repform]['rating[txn_value]'].value=="")
            {document.forms[repform]['rating[txn_value]'].value="0.00";}
        } 
       /*  else
       {
        document.forms[repform]['rating[txn_completed]'].value="false"
          if (document.forms[repform]['rating[txn_value]'].value=="")
            {document.forms[repform]['rating[txn_value]'].value="0.00";}
       } */
    }
	
	function set_context_type(x)
	{
		//alert($("context_type_gNs_1").value);
	}

    function MM_goToURL() 
    { //v3.0
      var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
      for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
    }

 
    function resetForm()
    {
        selectrep('rating_rating_3');
        resetText();
        checkTransaction();
        document.forms[repform].reset();
    }