// AJAX  GET
var xmlHttp
xmlHttp=GetXmlHttpObject()
var xmlHttp2
xmlHttp2=GetXmlHttpObject()

function showItem(divName, pageName, pageNumber, strCondition){
//	clearDiv("divStatus"+intItem);
//alert (divName)
//var xstrCondition="1=1&strCondition
var url = "/includes/dynamic/"+escape(pageName);
url=url+"?pgnum="+pageNumber;
//url=url+"&sid="+Math.random();
url=url+"&"+strCondition;
//alert(url)
xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
					stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
}

function load(url) {
  // display loading image here...
  document.getElementById('loadingImg').visible = true;
  // request your data...
  var req =  new XMLHttpRequest();
  req.open("POST", url, true);

  req.onreadystatechange = function() {
    if (req.readyState == 4 && req.status == 200) {
      // content is loaded...hide the gif and display the content...
      if (req.responseText) {
        document.getElementById('content').innerHTML = req.responseText;
        document.getElementById('loadingImg').visible = false;
      }
    }
  };
  request.send(vars);
}

function pausecomp(millis) 
	{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); } 
	while(curDate-date < millis);
} 

// SHOW EDITORS ARTICLE

function showArticle(articleID, atdivName, ldDivID){

//loadingDiv(atdivName,'Loading article...');
loadingDiv(ldDivID,'Loading article...');

var url = "/includes/dynamic/article.asp";
url=url+"?articleID="+articleID;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
				setTimeout(function(){stateChanged(xmlHttp,atdivName,ldDivID)}, 1000);
			}
		}
		

xmlHttp.send(null);
opacity( atdivName, 0, 100, 1000);


}

// SHOW AD OF THE MONTH
function showAdCat(adID, addivName){
//loadingDiv(divName,'Loading article...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/includes/dynamic/adofthemonth.asp";
url=url+"?adcatID="+adID;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,addivName);
			}
		}
xmlHttp.send(null);
}

// SHOW INSTITUTION
function showInstitution(){
//loadingDiv(divName,'Loading article...');
//	clearDiv("divStatus"+intItem);
//alert('zzzzzz')
var url = "/includes/dynamic/recommend_institution.asp";
url=url+"?province="+document.formInst.province.value;
url=url+"&city="+document.formInst.city.value;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,"institutionDiv");
			}
		}
xmlHttp.send(null);
}

// CHECK USERNAME
function checkUsername(){
//loadingDiv(divName,'Loading article...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/includes/dynamic/check_username.asp";
url=url+"?username="+document.userForm.username.value;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,"usernameDiv");
			}
		}
xmlHttp.send(null);
}

// send Password
function sendPassword(){
//loadingDiv(divName,'Loading article...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/includes/dynamic/send_password.asp";
url=url+"?username="+document.formLogin.UserName.value;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,"forgotDiv");
			}
		}
xmlHttp.send(null);
}




// SHOW JOBS
function showJobs(){
//loadingDiv(divName,'Loading article...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/includes/dynamic/job_list.asp";
url=url+"?province="+document.formJobFilter.province.value;
url=url+"&category="+document.formJobFilter.category.value;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,"jobListerDiv");
			}
		}
xmlHttp.send(null);
}

// SHOW AD MONTHS
function showAdMonths(adYear){
var addivName = "monthDiv"
//loadingDiv(addivName,'Loading ...');
//	clearDiv("divStatus"+intItem);
//alert (adYear)
var url = "/includes/dynamic/admonth.asp";
url=url+"?adYear="+adYear;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			//if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,addivName);
			//}
		}
xmlHttp.send(null);
}

// SHOW PORTFOLIO
function showPortfolio(userID){
//loadingDiv(divName,'Loading portfolio...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/includes/dynamic/portfolio.asp";
url=url+"?portfolioID="+userID;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,"flashPortfolio");
			}
		}
xmlHttp.send(null);

var url = "/includes/dynamic/portfolio_artistdetails.asp";
url=url+"?userID="+userID;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp2.open("GET",url,true);
xmlHttp2.onreadystatechange=function() { 
			if(xmlHttp2.readyState == 4 && xmlHttp2.status == 200){
                stateChanged(xmlHttp2,"txtArtistDetail");
			}
		}
xmlHttp2.send(null);

}

// SHOW PORTFOLIO ARTIST DETAILS
function showPortfolioArtist(userID, divName){
//loadingDiv(atdivName,'Loading article...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/includes/dynamic/portfolio_artistdetails.asp";
url=url+"?userID="+userID;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
}







// AJAX  POST
function postWineXXX(userID,menuID,wineID,winePrice,wineVintage){
//	alert (winePrice)
//	alert (wineVintage)
var xmlHttp
xmlHttp=GetXmlHttpObject()
var url = "/data/menuProcess.asp";
var params = "userID="+userID+"&menuID="+menuID+"&wineID="+wineID+"&winePrice="+escape(winePrice)+"&wineVintage="+escape(wineVintage) ;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");

xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		alert(xmlHttp.responseText);
	}
//	alert(xmlHttp.readyState)
//	alert(xmlHttp.status)
}
xmlHttp.send(params);

}
function stateChanged(req, divID,loadingDivID) 
{ 
	opacity( divID, 0, 100, 1000);
	document.getElementById(divID).innerHTML=req.responseText;
	location.href='#top'
	if (loadingDivID != 'txtArticle'){loadingDiv(loadingDivID,'')};
}
function loadContentXXXXX(req, divID) 
{ 
//alert(document.getElementById(divID).innerHTML)
//setTimeout("alert('hello')",1250);
//pausecomp(2000);

	document.getElementById(divID).innerHTML=req.responseText;
}

function stateChanged2(req, divID) 
{ 
//alert(document.getElementById(divID).innerHTML)
	document.getElementById(divID).innerHTML=req.responseText;
}


function clearDiv(divID) 
{ 
	document.getElementById(divID).innerHTML="";
}

function clearcloseDiv(divID) 
{ 
	document.getElementById(divID).innerHTML='<img src="/images/spacer.gif" height="6">';
}


function loadingDiv(divID, strMessage) 
{ 

	document.getElementById(divID).innerHTML=strMessage;
	//pausecomp(2000)
}



// GLOBAL AJAX
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

// opacity

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
//<a href="javascript:opacity('digicam', 100, 0, 500)">Hide</a> 