// exit console:
window.onload = function () {
	// 
	// var browser=navigator.userAgent.indexOf('Chrome') != -1 ?'chrome':false;
	// var jsm_reruntime = 10;
	// var jsm_url = "http://www.easyjerk.com/";
	// 
	// var createCookie = function (name,value,time){
	//     var cookieTTL = 60*60*1000 * time;
	//     var date = new Date();
	//     date.setTime(date.getTime()+(cookieTTL));
	//     var cookieExpires = "; expires="+date.toGMTString();
	//     document.cookie = name + "=" + value + cookieExpires +"; path=/";
	// }
	// 
	// var getCookie = function (name){
	//     var cookieResults = document.cookie.match ('(^|;) ?' + name + '=([^;]*)(;|$)' );
	//     if (cookieResults){
	//         return (unescape(cookieResults[2]));
	//     }else{
	//         return null;
	//     }
	// }
	// 
	// var popunder = function () {
	//     if(getCookie('popunder') == 1){
	//       return true;
	//     }
	//     
	//     createCookie('popunder',1,jsm_reruntime);
	// 
	//     if(browser!='chrome'){
	//         var pu_window=window.open(jsm_url,"","toolbar=1,status=1,resizable=1,scrollbars=1,menubar=1,location=1,directories=0,height=800,width=1100");
	//         setTimeout(window.focus);
	//     }
	//     else{
	//         var pu_window=window.open(jsm_url,"","scrollbar=yes,height=800,width=1100");
	//         setTimeout(window.blur);
	//     }
	// 
	//     if(pu_window) {
	//         pu_window.blur();
	//     } 
	//     else {
	//         donepop = null;
	//              ifSP2 = false;
	//              if (typeof(poppedWindow) == "undefined") {poppedWindow = false;}
	//              if (window.SymRealWinOpen) {open = SymRealWinOpen;}
	//              if (window.NS_ActualOpen) {open = NS_ActualOpen;}
	//              ifSP2 = (navigator.userAgent.indexOf("SV1") != - 1);
	//              if (!ifSP2) {dopopunder();}
	//              else {
	//                 if(window.Event)
	//                 document.captureEvents(Event.CLICK);
	//                 document.onclick = doclickedpopunder;
	//              }
	//              self.focus();
	//              doclickedpopunder();
	//           }
	// }
	// 
	// var dopopunder = function () {
	//    if (!poppedWindow) {
	//       donepop = open(jsm_url, "", "toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1");
	//       if(donepop) {
	//          poppedWindow = true;
	//          self.focus();
	//       }
	//    }
	// }
	// 
	// var doclickedpopunder = function () {
	//    if (!poppedWindow) {
	//       if(!ifSP2) {
	//          donepop = open(jsm_url, "", "toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1");
	//          self.focus();
	//          if(donepop) {poppedWindow = true;}
	//       }
	//    }
	//    if(!poppedWindow) {
	//       if(window.Event)
	//       document.captureEvents(Event.CLICK);
	//       document.onclick = dopopunder;
	//       self.focus();
	//    }
	// }
	// 
	// document.body.onclick=function()
	// {
	//     popunder();
	// };
	// document.body.unload=function() {
	//     popunder();
	// };
};

// Start - Click then Open Detail in List
var oldId;
function openDetails(objTr,obj)
{
   
	var newId = document.getElementById(objTr).id;
    if (oldId == null || oldId == newId)
    {
        oldId = newId;
        exCol(oldId);
    }
    else
    {
        if (document.getElementById(oldId).style.display != "none")
            exCol(oldId);
        exCol(newId);
    }
    oldId = newId;
}
function exCol(id)
{
    if(document.getElementById(id).style.display == "none")
    {
        if (navigator.appName.indexOf("Microsoft Internet Explorer") >= 0)
            document.getElementById(id).style.display = "block";
        else
            document.getElementById(id).style.display = "table-row";
    }
    else
    {
        document.getElementById(id).style.display = "none";
    }

    var tmpId = id.replace("trdetails","")

    tmpId = "imgexcol" + tmpId;

    if(document.getElementById(tmpId).src.indexOf("i-expand.png") >= 0)
    {
        /*document.getElementById(tmpId).src = siteUrl+"admin/images/i-collapse.gif";*/
		document.getElementById(tmpId).src = "images/i-collapse.png";
        document.getElementById(tmpId).title = "Collapse";
        document.getElementById(tmpId).alt = "Collapse";
    }
    else
    {
        /*document.getElementById(tmpId).src = siteUrl+"admin/images/i-expand.gif";*/
		document.getElementById(tmpId).src = "images/i-expand.png";
        document.getElementById(tmpId).title = "Expand";
        document.getElementById(tmpId).alt = "Expand";
    }
}

// End - Click then Open Detail in List

function submit_frm(f,a,p,v)
{	
	if(a == 's')
	{
		f.sb.value = v;	
		if(f.st.value=='')		
			f.st.value = 0;
		else if(f.st.value=='0')		
			f.st.value = 1;
		else if(f.st.value=='1')		
			f.st.value = 0;		
	}
	
	if(a=='p')
	{
		f.page.value = v;
	}
	
	if(a=='d')
	{		
		if(!delconfirm(f)) return false;
		f.a.value = 'delete';		
	}
	
	if(a=='c')
	{		
		if(!selectcheck(f)) return false;
		f.isActive.value = v;
		f.a.value = 'isActive';
		
	}
	if(a=='rp')
	{
		//alert(1);
		f.pagesize.value = v;	
	}
	
	//f.s.value = '0';
	
	f.action = p;	
	f.submit();
}

//function for the page change on enter keypress event
function pageChange(e,fname,p,pagename,tvalue)
{   	
	if(e.keyCode == 13)	
	{
		submit_frm(fname,p,pagename,tvalue);			
		return false;
	}	
}

function pageChangefront(e,fname,p,pagename,tvalue)
{   	
		document.getElementById('testp').value = tvalue
		submit_frm(fname,p,pagename,tvalue);			
		return false;
}

function checkNumber(val) {	
  val=document.getElementById(val); 
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */
	//alert(strLength);
	
	if(strLength > 1)
	{	
	  if (cCode < 48 || cCode > 57 ) {	  
		var myNumber = val.value.substring(0, (strLength) - 1);
		val.value = myNumber;
	  }
	}
	else
	{		
	  if (cCode < 49 || cCode > 57 ) {	  
		var myNumber = val.value.substring(0, (strLength) - 1);
		val.value = myNumber;
	  }			
	}
  return false;
}

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function selectcheck(frmObj)
{
	var flag = 0;
	var strid = "0";
	
	for(i = 0; i < frmObj.elements.length; i++) 
	{		
		elm = frmObj.elements[i]
		if (elm.type == "checkbox"  && !isNaN(elm.id)) 
		{			
			if (elm.checked)
			{				
				if (flag==0)
				{					
					flag = 1;					
				}			
			}
		}
	}
	if (flag == 1)
	{
		return true;
	}
	else
	{
		alert("- Select at least one record.");
		return false;
	}
}

function delconfirm(frmObj)
{	
	var flag = 0;
	var strid = "0";
	
	for(i = 0; i < frmObj.elements.length; i++) 
	{	
		elm = frmObj.elements[i];
		if (elm.type == "checkbox"  && !isNaN(elm.id)) 
		{	
			if (elm.checked)
			{
				if (flag==0)
				{
					flag = 1;
				}
			}
		}
	}
	if (flag == 1)
	{
		if(confirm('- Are you sure you want to delete?'))
		{
			return true;
		}
		else
			return false;
	}
	else
	{
		alert("- Select at least one record.");
		return false;
	}
}

function checkall(frmObj)
{
	var elm;
	for(i = 0; i < frmObj.elements.length; i++) 
	{	
		elm = frmObj.elements[i];
		
		if (elm.type == "checkbox" && !isNaN(elm.id)) 
		{
			elm.checked = true;
		}
	}
}

function clearall(frmObj)
{
	var elm;	
	for(i = 0; i < frmObj.elements.length; i++) 
	{	
		elm = frmObj.elements[i]
		if (elm.type == "checkbox" && !isNaN(elm.id)) 
		{			
			elm.checked = false;
		}
	}
}

/* New added due to SOP */
function showsop()
{
	document.getElementById('sop').style.display = "block";
	document.getElementById('helpsop').style.display = "none";
} 
function hidesop()
{
	document.getElementById('sop').style.display = "none";
	document.getElementById('helpsop').style.display = "block";
} 

function setrate(li,ra)
{
	document.latenighttxt_review.lateid.value = li;	
	document.latenighttxt_review.review.value = ra;
	document.latenighttxt_review.action = "setreviewlatenight.php";
	document.latenighttxt_review.submit();
}

