/*
*****************
*  PRODUCT INQUIRY *
*****************
*/

function AddProductInQ(ProdID)
{
	if(ProdID.value == ""){
		return false;
	}
	ShowLoading(1);
	document.getElementById('InquiryBox').innerHTML = '';	
	x_AddProductInQ(ProdID,AddProductInQResult);
}

function AddProductInQResult(Result)
{
	HideLoading(1);
	if(Result==0)
	{
		alert("Product Already Added In InQuiry List");
	}else
	if(Result>0)
	{
		document.getElementById('InquiryBox').innerHTML = 'Inquiry Product Count :'+Result;	
	}
}

/*
*****************
*  CATEGORY RELATED *
*****************
*/
var TempStore;
function IsCategoryNameExists(TextBox,CatID)
{

	if(TextBox.value == ""){
		return false;
	}

	var CatName = TextBox.value;
	ShowLoading(1);
	HideMessage(1);
	TempStore=TextBox;
	x_IsDuplicateCategoryName(CatName,CatID,IsCatNameExistsResult);
}

function IsCatNameExistsResult(Result)
{
	if(Result==-1)
	{
		HideLoading(1);
		ShowMessage('Category Nam is already Exists, Please choose another Name',1);
		TextBox = TempStore;
		TextBox.value='';
		TextBox.focus();
		return false
	}
	else		
	{
		HideLoading(1);
		HideMessage(1);	
		return true;
	}
}

/*
*****************
*  PRODUCT RELATED *
*****************
*/

function IsProdCodeExists(TextBox)
{
	if(TextBox.value == ""){
		return false;
	}

	var ProdCode = TextBox.value;
	ShowLoading(1);
	HideMessage(1);
	TempStore=TextBox;
	x_GetProductByCode(ProdCode,IsProdCodeExistsResult);
}

function IsProdCodeExistsResult(Result)
{
	if(Result==1)
	{
		HideLoading(1);
		ShowMessage('Product Code is already exists, Please Choose another.',1);
		TextBox = TempStore;
		TextBox.value='';
		TextBox.focus();
		return false
	}
	else		
	{
		HideLoading(1);
		HideMessage(1);	
		return true;
	}
}

function SearchSpcProduct(TextBox)
{

	document.getElementById('SearchResults').innerHTML = '';
	if(TextBox.value == ""){
		return false;
	}
	var ProdCode = TextBox.value;
	ShowLoading(1);
	HideMessage(1);
	TempStore=TextBox;
	x_SearchSpecialProduct(ProdCode,SearchSpecialProductResult);
}

function SearchSpecialProductResult(Result)
{

	if(Result==1)
	{
		HideLoading(1);
		ShowMessage('No Product Found For this ProductID/Code.',1);		
		TextBox.value='';
		TextBox.focus();
		return false
	}
	else		
	{
		HideLoading(1);
		HideMessage(1);	
		document.getElementById('SearchResults').innerHTML = Result;
		return true;
	}
}

function GenerateNewPassword(ProdID)
{
	document.getElementById('SearchResults').innerHTML = '';
	if(ProdID == ""){
		return false;
	}
	ShowLoading(1);
	HideMessage(1);
	TempStore=ProdID;
	x_GenerateNewPassword(ProdID,GenerateNewPasswordResult);
}

function GenerateNewPasswordResult(Result)
{

	if(Result==1)
	{
		HideLoading(1);
		ShowMessage('No Special/Feature Product Found For this ProductID/Code.',1);		
		TextBox.value='';
		TextBox.focus();
		return false
	}
	else		
	{
		HideLoading(1);
		HideMessage(1);	
		document.getElementById('SearchResults').innerHTML = Result;
		return true;
	}
}
/*
*****************
* CITY STATE COUNTRY PAGE *
*****************
*/

function FetchCountries(CountryID)
{
	if (!document.getElementById("DDCountry")){
		return;
	}
	if(!CountryID)
	{
	CountryID='';
	}		
	HideMessage(101);
	ShowLoading(101);
	x_GetCountries(CountryID,FetchCountriesResult);

}

function FetchCountriesResult(Result)
{
	HideLoading(101);
	HideMessage(101);
	SetCountries(Result);		
}

function SetCountries(Value)
{
	document.getElementById('DDCountry').innerHTML=Value;
}

/*  STATES */

function FetchStates(CountryCode,StateID)
{
	if (!document.getElementById("DDState")){
		return;
	}
	if(CountryCode=="")
	{
		return false;
	}
	if(!StateID)
	{
		StateID = "";
	}
	HideMessage(102);		
	ShowLoading(102);
	x_GetStates(CountryCode,StateID,FetchStatesResult);

}

function FetchStatesResult(Result)
{
	HideLoading(102);
	HideMessage(102);
	SetStates(Result);		
}

function SetStates(Value)
{
	document.getElementById('DDState').innerHTML=Value;
}

/*  CITIES */

function FetchCities(StateID,CityID)
{
	if (!document.getElementById("DDCity")){
		return;
	}
	if(StateID=="")
	{
		return false;
	}
	if(!CityID)
	{
		CityID = "";
	}
	HideMessage(103);		
	ShowLoading(103);
	x_GetCities(StateID,CityID,FetchCitiesResult);

}

function FetchCitiesResult(Result)
{
	HideLoading(103);
	HideMessage(103);
	SetCities(Result);		
}

function SetCities(Value)
{
	document.getElementById('DDCity').innerHTML=Value;
}	


/*
*****************
* IMAGE GALLERY PAGE *
*****************
*/
var CurrentImgID=0;
var MaxID = 0;
var MinID = 0;
function GetPhotoPagination(AlbumID,CurrentPage)
{
	if(!AlbumID)
		return false;
	if(!CurrentPage)
		CurrentPage = 1;

	x_GetPhotoPagination(AlbumID,CurrentPage,SetPhotoPagination);
}
function SetPhotoPagination(Result)
{
	document.getElementById('PhotoPaging').innerHTML = Result;
}

function GetPhotoThumbs(AlbumID,CurrentPage)
{
	if(!AlbumID)
		return false;
	if(!CurrentPage)
		CurrentPage = 1;

	ShowLoading(106);
	SetPhotoThumbs('');
	SetAlbumTitle('');
	x_GetPhotoThumbnail(AlbumID,CurrentPage,HandlePhotoThumbs)
	GetPhotoPagination(AlbumID,CurrentPage);
}
function HandlePhotoThumbs(Result)
{
	HideLoading(106);
	if(Result==-1)
	{
		SetPhotoThumbs('This Photo Album is empty.');
		SetAlbumTitle('');
	}else
	{
		var OutPut = Result.split('||');
		MinID = OutPut[2];
		MaxID = OutPut[3];
		SetPhotoThumbs(OutPut[1]);
		SetAlbumTitle(OutPut[0]);
		GetBigPhoto(OutPut[2]);
	}
}
function SetPhotoThumbs(Value)
{
	document.getElementById('PhotoThumbnail').innerHTML=Value;
}
function SetAlbumTitle(Value)
{
	document.getElementById('AlbumTitle').innerHTML=Value;
}
function GetBigPhoto(ImageID)
{
	if(!ImageID)
		return false;

	SetBigPhotoCaption('');
	ShowLoading(107);
	SetCurrentImageID(ImageID);
	x_GetBigPhoto(ImageID,HandleBigPhoto);
}
function HandleBigPhoto(Result)
{
	HideLoading(107);
	if(Result==-1)
	{
		SetBigPhoto('Image Not Found');
		SetBigPhotoCaption('');
	}else
	{
	var OutPut = Result.split('||');
		SetBigPhoto(OutPut[1]);
		SetBigPhotoCaption(OutPut[0]);
	}
}
function Next()
	{
		if(CurrentImgID==MaxID && MinID>0){
			GetBigPhoto(MinID);
		}else{
		x_NextImage(CurrentImgID,GetBigPhoto);  
		}
	}
function Previous()
	{
		if(CurrentImgID==MinID && MaxID>0){
			GetBigPhoto(MaxID);
		}else{
		x_PreviousImage(CurrentImgID,GetBigPhoto);
		}
	}
function SetBigPhoto(Value)
{
	document.getElementById('BigPhoto').innerHTML=Value;
}
function SetBigPhotoCaption(Value)
{
	document.getElementById('BigPhotoCaption').innerHTML=Value;
}
function SetCurrentImageID(Value)
{
	CurrentImgID=Value;
}
function GetCurrentImageID()
{
	return CurrentImgID;
}

/*
*****************
* GET NTRP RATING
*****************
*/

function GetRating(FirstName,LastName,ResultDiv,FieldID)
{
	if(!(FirstName) && !(LastName))
	{
		return false;
	}

	ShowLoading(108);
	TempStore = ResultDiv+"||"+FieldID;
	document.getElementById(ResultDiv).style.display = 'none';
	document.getElementById(ResultDiv).innerHTML = '';
	x_GetNTRPRating(FirstName,LastName,HandleGetRating)
}

function HandleGetRating(Result)
{
	var TempArray = TempStore.split('||');
	var ResultDiv = TempArray[0];
	var FieldID = TempArray[1];

	HideLoading(108);
	document.getElementById(ResultDiv).style.display = 'block';
	if(Result==-1)
	{
		document.getElementById(ResultDiv).innerHTML = 'Sorry Rating Not Found.';
		return false;
	}
	document.getElementById(ResultDiv).innerHTML = Result
}

function ChooseRating(Val)
{
	var TempArray = TempStore.split('||');
	var ResultDiv = TempArray[0];
	var FieldID = TempArray[1];
	document.getElementById(FieldID).value = Val;
	document.getElementById(ResultDiv).style.display = 'none';
}

/*
*****************
* COMMON *
*****************
*/

function ShowLoading(Number)
{
	if(!Number){
		Number = 1;
	}
	var Loading = 'Loading'+Number;
	if(document.getElementById(Loading))
	{
		document.getElementById(Loading).style.display = 'block';
		document.getElementById(Loading).innerHTML = 'Pleae Wait ... <img Src="../images/loading.gif" alt="Loading..."/>';
	}
}

function HideLoading(Number)
{
	if(!Number){
		Number = 1;
	}
	var Loading = 'Loading'+Number;
	if(document.getElementById(Loading))
	{
		document.getElementById(Loading).innerHTML = '';
		document.getElementById(Loading).style.display = 'none';
	}
}

function ShowMessage(Msg,Number)
{
	if(!Number){
		Number = 1;
	}
	var Message = 'Message'+Number;
	if(document.getElementById(Message))
	{
		document.getElementById(Message).style.display = 'block';
		document.getElementById(Message).innerHTML = Msg;
	}
}

function HideMessage(Number)
{
	if(!Number){
		Number = 1;
	}
	var Message = 'Message'+Number;
	if(document.getElementById(Message))
	{
		document.getElementById(Message).innerHTML = '';
		document.getElementById(Message).style.display = 'none';
	}
}
