// AJAX



var xmlHttp

var type  // Task Type
var ClientId // Get Value From 
var ClientId2 // Get Value From 
var WriteId //Write Text To
var obj
var obj2
var rzt = 3;
var subcategories;

var tnt = 2000;


var Atype ='' // Task Type
var AClientId // Get Value From 
var AClientId2 // Get Value From 
var AWriteId //Write Text To
var Aobj
var Aobj2
var Arzt = 3;

function fillddlgetbuyer(postid)
{
this.WriteId = postid;
this.type = 'GetBuyers';

	obj = document.getElementById('ddlBuyerList');

		for(var i=obj.length-1; i>=0; i--)
		{
			obj.options[i] = null;
		}
		
		Get_Values();
		
		var j=0;
		obj.options.length=0;


	/*	for(var i=0;i<subcategories.length;i++)
		{
			
				obj.options[i]=new Option(subcategories[i][1],subcategories[i][0]);
			
		}*/

}

function checkUserId(ClientId,WriteId)
{

this.type = 'CheckCustomerId';
this.ClientId = ClientId;
this.WriteId = WriteId;

this.Atype = 'CheckCustomerId';
this.AClientId = ClientId;
this.AWriteId = WriteId;
tnt = 2000;

var blnResult = true;



	obj = document.getElementById(ClientId);
	rzt=null;
	document.getElementById(WriteId).innerHTML = "";
		if(obj.value !='')
		{
			Get_Values();
				
			if(rzt == '0')
			{
				document.getElementById(WriteId).innerHTML = "";
				Arzt = null;
					
			}
			else if(rzt == '1')
			{		
					document.getElementById(WriteId).innerHTML = "<font color = red>This email address already exists.</font>";
				
			}
			
			tnt = 500;
		}
	//rzt = '3';
	
}

function checkNickName(ClientId,WriteId)
{

		
this.type = 'CheckNickName';
this.ClientId = ClientId;
this.WriteId = WriteId;

this.Atype = 'CheckNickName';
this.AClientId = ClientId;
this.AWriteId = WriteId;

		obj = document.getElementById(ClientId);
		document.getElementById(WriteId).innerHTML = "";
		if(obj.value !='')
		{
			Get_Values();
			
			if(rzt == '0')
			{
				document.getElementById(WriteId).innerHTML = "";
				Arzt = null;
				
			}
			else if(rzt == '1')
			{		
				document.getElementById(WriteId).innerHTML = "<font color = red>This User Name already exist choose another one.</font>";
				
				//obj.focus();
			}
		
		}
		


}

function AutoResponse()
{
//alert('hi');
		
				if(Atype == 'CheckLogin')
				{
				  checkLog(AClientId,AClientId2,AWriteId);
				}
				else if(Atype == 'CheckNickName')
				{
				  checkNickName(AClientId,AWriteId);
				}
				else if(Atype == 'CheckCustomerId')
				{
				  checkUserId(AClientId,AWriteId);
				}
				else
				{
				tnt = 50000;
				}
		

}

setInterval("AutoResponse()",tnt);


function checkLog(ClientId,ClientId2,WriteId)
{


this.type = 'CheckLogin';
this.ClientId = ClientId;
this.ClientId2 = ClientId2;
this.WriteId = WriteId;


this.Atype = 'CheckLogin';
this.AClientId = ClientId;
this.AClientId2 = ClientId2;
this.AWriteId = WriteId;

tnt = 2000

		rzt=null;
		obj = document.getElementById(ClientId);
		obj2 = document.getElementById(ClientId2);
		spacer(obj);
		spacer(obj2);
		document.getElementById(WriteId).innerHTML = "";
		
		if(obj.value != "" && obj2.value != "")
		{

			Get_Values();
			
			if(rzt == 1)
			{
				document.getElementById(WriteId).innerHTML = "";
				
			}
			else if(rzt == 0)
			{	
				document.getElementById(WriteId).innerHTML = "<font color = red>Invalid User Id or Password</font>";
				//obj.focus();
			}
			
		}
		WriteId = null;
		type=null;
		ClientId=null;
		ClientId2=null;
		obj = null;
		obj2 = null;
		
		tnt = 500
}
/*
 onblur="checkNickName('txtNick','CheckNick')"
 <span id="CheckNick" Class="errorMsg"></span>

*/

function spacer(str)
				{
					var tmp= str.value;
					
					while (tmp.substring(0,1) == ' ')
					{
					tmp = tmp.substring(1, tmp.length);
					}
					while (tmp.substring(tmp.length-1,tmp.length) == ' ')
					{
					tmp = tmp.substring(0,tmp.length-1);
					}
					
										
					str.value=tmp;
					
				}
				
				
				
function checkResellerCommision(ClientId,ClientId2,WriteId)
{


this.type = 'GetResellerCommision';
this.ClientId = ClientId;
this.ClientId2 = ClientId2;
this.WriteId = WriteId;

	
		Get_Values();
		//alert(Atype);
		if(Atype == '0.0')
		{
			document.getElementById(ClientId).value='';
			document.getElementById(ClientId2).value='';
				
		}
		else
		{
					
			document.getElementById(ClientId).value=Atype.substring(0,1);
			if(Atype.substring(2) !='')
			{
			document.getElementById(ClientId2).value=Atype.substring(2);
			}
			else
			{document.getElementById(ClientId2).value='0';}
			
		
		
		}
		Atype = null;
		GetCompanyDetail('txtCompanyDetail',WriteId)



}
function GetCompanyDetail(ClientId,WriteId)
{


this.type = 'GetCompanyDetail';
this.ClientId = ClientId;
this.WriteId = WriteId;

	
		Get_Values();
		
	//	alert(Atype);
		
		if(Atype == '')
		{
			document.getElementById(ClientId).value='';
							
		}
		else
		{
		//	alert('yes');
			
			document.getElementById(ClientId).value=Atype;
			
		}



}
function GetBuyerCustomerID(ClientId,WriteId)
{


this.type = 'GetBuyerCustomerID';
this.ClientId = ClientId;
this.WriteId = WriteId;

		rzt=1;
		Get_Values();

		return rzt;
}

function Get_Values()
{ 



xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="v1Include/ServerScript.aspx?"

if(type == 'CheckCustomerId')
{
	url=url+"custid="+obj.value+"&type="+type;
	//alert(url);
}
else if (type == 'CheckNickName')
{

	url=url+"custnick="+obj.value+"&type="+type;

}
else if (type == 'CheckLogin')
{
		obj = document.getElementById(ClientId);
		obj2 = document.getElementById(ClientId2);
	url=url+"custid="+obj.value+"&pwd="+obj2.value+"&type="+type;
	
	
}
else if(type == 'GetResellerCommision')
{
	obj = document.getElementById(WriteId);
	url="../"+url+"custid="+obj.value+"&type="+type;
	
}
else if(type == 'GetCompanyDetail')
{
	obj = document.getElementById(WriteId);
	url="../"+url+"custid="+obj.value+"&type="+type;
	
}
else if(type == 'GetBuyerCustomerID')
{
	url="../"+url+"custid="+ClientId+"&seid=WriteId&type="+type;
	
}
else if(type == 'GetBuyers')
{
	url="../"+url+"postid="+WriteId+"&type="+type;
	
	
}




xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}


function stateChanged() 
{ 

//alert(type);

if ((xmlHttp.readyState==4) || (xmlHttp.readyState=="complete"))
{ 


	if ((xmlHttp.status == 200)||(xmlHttp.status == 0)) 
	{
		
		if(type == 'CheckCustomerId')
		{
			rzt = xmlHttp.responseText ;
			Arzt = xmlHttp.responseText ;
			document.getElementById('e1').value = rzt;
		}
		else if (type == 'CheckNickName')
		{
			rzt = xmlHttp.responseText ;
			Arzt = xmlHttp.responseText ;
			document.getElementById('n1').value = rzt;
		}
		else if (type == 'CheckLogin')
		{
		
			rzt = xmlHttp.responseText ;
			Arzt = xmlHttp.responseText ;
			document.getElementById('errLogin').value = rzt;
			
		}
		else if(type == 'GetResellerCommision')
		{
			//alert(xmlHttp.responseText);
			Atype = xmlHttp.responseText ;
		}
		else if(type == 'GetCompanyDetail')
		{
			//alert(xmlHttp.responseText);
			Atype = xmlHttp.responseText ;
		}
		else if(type == 'GetBuyerCustomerID')
		{
			Arzt = xmlHttp.responseText ;
		}
		else if(type == 'GetBuyers')
		{
			//xmlHttp.responseText;
				alert(xmlHttp.responseText);
		}
		
		
	}
	else
	{
	if(type == 'GetResellerCommision')
		{
			//alert(xmlHttp.responseText);
			Atype = xmlHttp.responseText ;
		}
		//alert(Atype);
	
	}
	
	


} 


} 




// get XMLHTTP object
function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

