//document.body.onload = norightclick;
//document.oncontextmenu = nocontextmenu;
//document.onmousedown = norightclick;
//document.onmouseup = norightclick;

if (window.Event)
{
	document.captureEvents(Event.MOUSEUP);
}

function nocontextmenu() 
{
    
    event.cancelBubble = true, event.returnValue = false;
    return false;
} 

/*/function norightclick(e) 
{	 
    if (window.Event) 
    {	
        if (e.which == 2 || e.which == 3) 
        {
            return false;
        }
        else if (event.button == 2 || event.button == 3) 
        {
            event.cancelBubble = true, event.returnValue = false;
            return false;
        }
    }
}
*/
if (document.layers)
{
    document.captureEvents(Event.MOUSEDOWN);
}




	function sortRecords(fieldName, direction) {
		window.document.ProductForm.Sort.value=fieldName;
		window.document.ProductForm.SortDirection.value=direction;
		window.document.ProductForm.submit();
	}
	
 
function getXMLHTTP() {
      //alert("in getXMLHTTP()");
      
      var xmlHttpRequest = null;
      try {
            xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e) {
            try {
                  xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(oc) {
                  xmlHttpRequest = null;
            }
      }
      
      if(!xmlHttpRequest && typeof XMLHttpRequest != "undefined") {
            xmlHttpRequest = new XMLHttpRequest();
      }
      
      return xmlHttpRequest;
}

function downloadRec(ClientAccountID,ClientUserID,ProductID,ProductInstancesID,file) 
{ 
	//alert('Click OK button to download ur file:');
    //  Get a XMLHttpRequest object
    var xmlHttp = getXMLHTTP();
    var currentTime = new Date();
       
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	var DateOfAccess = month+'/'+day+'/'+year;
    if(xmlHttp && xmlHttp.readyState != 0)
		{
					alert("not ready for xmlHTTP call");
		}
		
		if(xmlHttp)
		{
			
			xmlHttp.open("POST", "/MyAccount/downloadRecord.asp", true);
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			xmlHttp.send("ClientAccountID="+ClientAccountID+"&ClientUserID="+ClientUserID+"&DateOfAccess="+DateOfAccess+"&ProductID="+ProductID+"&ProductInstancesID="+ProductInstancesID);
			//alert('ClientAccountID' + ClientAccountID +'ClientUserID' + ClientUserID + 'DateOfAccess +'+month+'/'+day+'/'+year +'ProductID'+ProductID+'ProductInstancesID '+ProductInstancesID);
			
				xmlHttp.onreadystatechange = function()
				 
				{
						
					if (xmlHttp.readyState == 4)// && xmlHttp.responseXML)
					
					{
										
						if(xmlHttp.status == 200)
						{
							
							var XMLString = xmlHttp.responseText;												
							//alert(XMLString);
							if(XMLString == "True")// should be true : for testing written false.
							
							{
								window.open("dataTracker.htm?key="+file, "winName", "width=450,height=200,scrollbars=no,resizable=yes,status=yes,top=200, left=200");
   
							}											
							if(XMLString == "False")
							
							{
								//window.open("download.htm?"+file, "winName2", "width=450,height=320,scrollbars=no,resizable=yes,status=yes,top=200, left=200");
								window.location.assign("download.htm?"+file);
   
							}
						
						
						}
										
					}
								 				 
				} 
	 	}
}


function select_innerHTML(objeto,innerHTML){

    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.indexOf("<option")<0){
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}
