var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer(page)
{
    // Set the length of the timer, in seconds
    secs = 2
    StopTheClock()
    StartTheTimer(page)
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}
function StartTheTimer(page)
{
    if (secs==0)
    {
        StopTheClock()
        window.location.href=page;
    }
    else
    {
      	self.status = secs
        secs = secs - 1
        timerRunning = true
    	timerID = self.setTimeout("StartTheTimer(\""+page+"\")", delay)
    }
}

// ------------------ For Hide and dispay Div having Absolute Property
function showPosition1()
  {
    var oElement = document.all.oCell;
    
    alert("The TD element is at (" + oElement.offsetLeft + 
          "," + oElement.offsetTop + ")\n" + "The offset parent is " 
          + oElement.offsetParent.tagName );
  }

function showPosition(evt,pos)
{
	xy = getEventOffsetXY( evt );

	
	topPos = xy[1];
	leftPos =xy[0]+20;
	subcontent = "subcontent" + pos;
	document.getElementById(subcontent).style.left = "200px";
	document.getElementById(subcontent).style.top = "300px";	//getposOffset(curobj, "top")+"px";
	document.getElementById(subcontent).style.display="";

};

function getEventOffsetXY( evt )
{

    var obj = evt.target || evt.srcElement;
   	setPageTopLeft( obj );
    return [ ( obj.pageTop+evt.clientX) , (  obj.pageLeft) ];
};

function setPageTopLeft( o )
{
    var top = 0,
    left = 0,
    obj = o;

    while ( o.offsetParent )
     {
         left += o.offsetLeft ;
         top += o.offsetTop ;
         o = o.offsetParent ;
    };

    obj.pageTop = top;
    obj.pageLeft = left;

};
function clearInfo(pos)
{
	subcontent = "subcontent" + pos;
	document.getElementById(subcontent).style.display="none";
}

function overlayclose(subobj)
{
	document.getElementById(subobj).style.display="none";
}

///////////////////////// Function For Comapre Products /////////////////////////////

function compareCounter_en(obj, testMin, cnt) {
	
	var ctr=0,i=1;
	var max=4;
	var min=2;
	str = "";
	
	if(testMin == "pdaCheck")
	{
		var pp_id = "comp_pda_";
		var productType = "pda";
	}
		
	if(testMin == "minCheck")
	{
		var pp_id = "comp_mob_";
		var productType = "mob";
	}		
	
	for(j=1;j<=cnt;j++)
	{
		if(document.getElementById(pp_id+j).checked==true)
		{	
			prod_val = document.getElementById(pp_id+j).value;
			str = str+prod_val+"_"; 
			ctr = ctr+1;
		}	
		
	}	
	
	if (ctr > max) {
		obj.checked = false;
		alert('Only choose ' + max + ' checkboxes.\nTo pick this option unselect one of the others.');
	}
	
	if (testMin == 'pdaCheck') {
		if (ctr < min) {
			alert('Please choose between ' + min + ' and ' + max + ' checkboxes.');
			return false;
		}
	}
	
	if (testMin == 'minCheck') {
		if (ctr < min) {
			alert('Please choose between ' + min + ' and ' + max + ' checkboxes.');
			return false;
		}
	}
	
	if(ctr>1 && ctr<5)
	{
		window.location.href="compare_prod.php?comp="+ productType + "&prod_id=" + str;	
	}
}
