// JavaScript Document
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
			 
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function getState(countryId) {		
		
		var strURL="index.php?option=com_product&view=ajax&format=raw&display=sortByProductList&country="+countryId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
  
 function getLine(brandId) {		
		
		var strURL="index.php?option=com_product&view=ajax&format=raw&display=sortByProductList&brandId="+brandId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('lineDiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	} 
  
  
  
	function getStockStatus(productId, sizeId) {		
		
		var strURL="http:/administrator/components/com_product/views/product/tmpl/findStockStatus.php?product="+productId+"&size="+sizeId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	
	
	function toggleDiv(element){
     if(document.getElementById('hid').value == 'none')
     {
       document.getElementById(element).style.display = 'table-row';
         document.getElementById('hid').value = 'table-row'
         
     }
     else if(document.getElementById('hid').value == 'table-row')
     {
       document.getElementById(element).style.display = 'none';
         document.getElementById('hid').value = 'none'
        
     }
}



function checkedEvent()
{
var checked = document.getElementById('boxchecked');
if(checked)
{
checked.value = 1;
}
}
	
	
	
	
	
	
	
	 /*Changes the main image on the product page*/
	function changeMainImage(type, fileName, pid)
  {
     img = "<img class='prodImg' style='width:350px;' id='"+type+"-"+fileName+"' src='components/com_product/img/"+type+"/"+fileName+"'  />";
     
     document.getElementById('mainImage').innerHTML = img; 
  }
	
  
  /*Performs the database delete of an image*/
  function deleteImage(imgId, type, pid) {		
		document.getElementById('thumbsOfSelectedImage').innerHTML = "loading...";
		var strURL="index.php?option=com_product&view=ajax&format=raw&display=imageDelete&imgId="+imgId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						queryImages(type, pid)						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
  
  
	/*Displays little images of the images for an image type*/
	function queryImages(repId) {		
		document.getElementById('repImg').innerHTML = "loading...";
		var strURL="repImageAjax.php?repId="+repId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('repImg').innerHTML=req.responseText;
            toggleImgHide();				
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
  
  
	
  
 function getAdImg()
 {
 var NumberOfImagesToRotate = 2;
 var folder="adImg/";
 var prefix = "adImg";
 var ext = ".jpg";
 var imgNum = Math.ceil(Math.random() * NumberOfImagesToRotate);
 document.getElementById('adImg').src = folder+prefix+imgNum+ext;
 } 
  
  
  /*Creates pop up window*/
  function popitup(url) {
	newwindow=window.open(url,'name','height=250,width=300');
	if (window.focus) {newwindow.focus()}
	return false;
}




  
  
  
  
  
  /*Shipping*/
  
 function toggleShipping(directive)
 {
   if(directive == "on")
   {
    document.getElementById('standardOptions').style.display = "";
   }
    if(directive == "off")
   {
    document.getElementById('standardOptions').style.display = "none";
   }
 }
 
 
 
 
 /*Add Releated Product*/
 function addRelatedProduct(url)
 {
 
    /*create window*/
   newwindow=window.open(url,'name','height=350,width=960');
	 if (window.focus) {newwindow.focus()}
	
  
  return false;
 }
 
 function addRelated(prodId, uniqueId, relatedId)
 {
   document.getElementById('relatedDisplay').innerHTML = "loading...";
  		var strURL="index.php?option=com_product&view=ajax&format=raw&display=relatedAdd&uniqueId="+uniqueId+"&relatedId="+relatedId+"&prodId="+prodId;
  		var req = getXMLHTTP();
  		
  		if (req) {
  			
  			req.onreadystatechange = function() {
  				if (req.readyState == 4) {
  					// only if "OK"
  					if (req.status == 200) {						
  						document.getElementById('relatedDisplay').innerHTML=req.responseText;	
              toggleHide();					
  					} else {
  						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
  					}
  				}				
  			}			
  			req.open("GET", strURL, true);
  			req.send(null);
  		}		
 
 }
  function deleteRelated(currProd, uniqueId, relatedProd)
  {
   document.getElementById('relatedDisplay').innerHTML = "loading...";
  		var strURL="index.php?option=com_product&view=ajax&format=raw&display=relatedDelete&uniqueId="+uniqueId+"&relatedId="+relatedProd+"&prodId="+currProd;
  		var req = getXMLHTTP();
  		
  		if (req) {
  			
  			req.onreadystatechange = function() {
  				if (req.readyState == 4) {
  					// only if "OK"
  					if (req.status == 200) {						
  						document.getElementById('relatedDisplay').innerHTML=req.responseText;	
              toggleHide();					
  					} else {
  						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
  					}
  				}				
  			}			
  			req.open("GET", strURL, true);
  			req.send(null);
  		}		
 
 }
 
 function deletePDF(pid, uniqueId, type)
  {
   document.getElementById(type+'td').innerHTML = "loading...";
  		var strURL="index.php?option=com_product&view=ajax&format=raw&display=pdfDelete&uniqueId="+uniqueId+"&type="+type+"&prodId="+pid;
  		var req = getXMLHTTP();
  		
  		if (req) {
  			
  			req.onreadystatechange = function() {
  				if (req.readyState == 4) {
  					// only if "OK"
  					if (req.status == 200) {						
  						document.getElementById(type+'td').innerHTML=req.responseText;						
  					} else {
  						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
  					}
  				}				
  			}			
  			req.open("GET", strURL, true);
  			req.send(null);
  		}		
 
 }
 
 
 
function adjustAddInfo(type)
{
    if(type == "Projector")
   {
    document.getElementById('projectorTable').style.display = "";
   }
    if(type == "General")
   {
    document.getElementById('projectorTable').style.display = "none";
   }


} 
 
 
function loadPDFVal(pdfType, fileName)
{

    document.getElementById(pdfType).value = fileName;   
}
 
 
 
 
function confirmation(pid, uniqueId, type) {
	var answer = confirm("Delete This PDF?")
	if (answer){
		
		deletePDF(pid, uniqueId, type)
	}
	else{
		
	} 
} 
 

function setCheckBox() 
{

          if (document.adminForm.retcheck.checked) {
             document.getElementById('returnable').value = 1; 
          }
          else
          {
           document.getElementById('returnable').value = 0;
          }
          
          if (document.adminForm.activecheck.checked) {
             document.getElementById('active').value = 1; 
          }
          else
          {
           document.getElementById('active').value = 0;
          }
} 

  
