// function to fetch transaction history
function fetch_transaction_history( txnId, path )
{ 
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?txnId="+txnId+"&type=tranHistory&sec="+seconds;
	xmlHttp = GetXmlHttpObject( historyResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}


// Function to checkTitle ( handle response )
function historyResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		arr = xmlHttp.responseText.split('~');
		document.getElementById( 'c_'+trim(arr[0]) ).innerHTML = arr[1];
	}
}


// function to check max category limit
function checkTitle( title, path, module )
{ 	
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?title="+title+"&type=checktitle&module="+module+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( checkTitleResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}


// Function to checkTitle ( handle response )
function checkTitleResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		if ( trim( xmlHttp.responseText ) != "" )
		{
			alert( trim(xmlHttp.responseText) );
			document.getElementById( 'title' ).focus();
			return false;
		}	
	}
}


// function to check username
function checkUsername( uname, path )
{ 	
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?uname="+uname+"&type=checkname&sec="+seconds;
	xmlHttp = GetXmlHttpObject( checkUsernameResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}


// Function to checkusername ( handle response )
function checkUsernameResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		if ( trim( xmlHttp.responseText ) != "" )
		{
			alert( trim(xmlHttp.responseText) );
			document.getElementById( 'username' ).focus();
			return false;
		}	
	}
}


// function to check max category limit
function checkMaxCategory( qty, price, level, path, moduleType )
{ 	
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?qty="+qty+"&type=maxcategory&price="+price+"&level="+level+"&moduleType="+moduleType+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( checkMaxCategoryResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to checkMaxCategory ( handle response )
function checkMaxCategoryResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		document.getElementById( 'priceContainer' ).innerHTML = '$' + xmlHttp.responseText + '<input type="hidden" name="totalPrice" id="totalPrice" value="' + xmlHttp.responseText + '">';
		document.getElementById( 'totalPrice' ).value = trim( xmlHttp.responseText );
		
		if ( parseInt( xmlHttp.responseText ) > 0 )
		{
			document.getElementById('paymentMethodContainer').style.display = '';
			document.getElementById('paymentType').checked = true;
		}
		else
		{
			document.getElementById('paymentMethodContainer').style.display = 'none';
			document.getElementById('paymentType').checked = false;
		}
	}
}


// Function to show fax no
function showFax( listingId, type, path, moduleType )
{  
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?listingId="+listingId+"&type="+moduleType+"&listType="+type+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( showFaxResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get content ( handle response )
function showFaxResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		// trim response text alert(xmlHttp.responseText);
		message = trim(xmlHttp.responseText).split('|');
		document.getElementById( message['1'] ).innerHTML = message[0];
	}
}


// Function to show phone no
function showPhone( listingId, type, path, moduleType )
{  
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?listingId="+listingId+"&type="+moduleType+"&listType="+type+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( showPhoneResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get content ( handle response )
function showPhoneResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		
		// trim response text
		message = trim(xmlHttp.responseText).split('|');
		document.getElementById( message['1'] ).innerHTML = message[0];
	}
}


// Function to add list in my list
function addToMyList( listId, type, path )
{  
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path+"ajax_call.html?listId="+listId+"&type=mylist&listType="+type+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( addToMyListResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get content ( handle response )
function addToMyListResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		// trim response text
		message = trim(xmlHttp.responseText);
		
		if ( message )
		{
			alert( xmlHttp.responseText );
		}
	}
}



// Function to search pagename
function pageNameSearch( page_name, fromPage )
{  
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = "ajax_call.html?page_name="+page_name+"&type=checkpage&sec="+seconds+"&fromPage="+fromPage;
	xmlHttp = GetXmlHttpObject( pageNameResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}

// Function to get content ( handle response )
function pageNameResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		// trim response text
		message = trim(xmlHttp.responseText);
		
		if ( message )
		{
			alert( xmlHttp.responseText );
			document.getElementById( "pageName" ).focus();
		}
	}
}


// trim function
function trim(str)
{
	s = str.replace(/^(\s)*/, '');
	s = s.replace(/(\s)*$/, '');
	return s;
}


// Function to validate discount code
function validateCode( discountCode, moduleId )
{   
	// if discount code has some value
	if ( discountCode )
	{
		var Digital = new Date();
		var seconds = Digital.getSeconds();
		var url = "ajax_call.html?discountCode="+discountCode+"&moduleId="+moduleId+"&type=discount&sec="+seconds;
		xmlHttp = GetXmlHttpObject( validateCodeResponse );
		xmlHttp.open("GET", url , true );
		xmlHttp.send( null );
		
	}
}

// Function to get content ( handle response )
function validateCodeResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		// trim response text
		message = trim(xmlHttp.responseText);
				
		// if error has been occured.
		if ( message == "valid" )
		{
			document.getElementById( "addList" ).disabled = false;
		}
		else
		{
			alert( xmlHttp.responseText );
			document.getElementById( "discountCode" ).value = '';
			document.getElementById( "discountCode" ).focus();
			document.getElementById( "addList" ).disabled = false;
		}
	}
}


// Function to get content 
function changeContent( idval )
{   
	document.getElementById( 'business_bdr1_id').className="business_nav";
	document.getElementById( 'event_bdr1_id').className="business_nav";
	document.getElementById( 'classified_bdr1_id').className="business_nav";
	document.getElementById( 'article_bdr1_id').className="business_nav";
	document.getElementById( 'real_estate_bdr1_id').className="business_nav";
	document.getElementById( 'banner_bdr1_id').className="business_nav";
	
	document.getElementById( idval + '_id').className="business_nav_Sel";
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = "content_text.html?cid="+idval+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( content_response );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}

// Function to get content ( handle response )
function content_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		document.getElementById( "contentTxt" ).innerHTML = xmlHttp.responseText;
	}
	else if( xmlHttp.readyState != 4 )
	{
		;
	}
} 



// Function to get states (send request)
function front_getStates( path, idval, location, fromPage )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path + "admin_get_state.html?countryId="+idval+"&sec="+seconds+"&location="+location+"&fromPage="+fromPage;
	
	xmlHttp = GetXmlHttpObject( front_stateResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get states ( handle response )
function front_stateResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		document.getElementById( "stateTxt" ).innerHTML = xmlHttp.responseText;
	}
	else if( xmlHttp.readyState != 4 )
		document.getElementById( "stateTxt" ).innerHTML = 'Loading ......';
}



// Function to get city (send request)
function front_getCity( path, idval, location, fromPage )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = path + "admin_get_state.html?stateId="+idval+"&sec="+seconds+"&location="+location+"&fromPage="+fromPage; 
	
	xmlHttp = GetXmlHttpObject( front_cityResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get city ( handle response )
function front_cityResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		document.getElementById( "cityTxt" ).innerHTML = xmlHttp.responseText;
	}
	else if( xmlHttp.readyState != 4 )
		document.getElementById( "cityTxt" ).innerHTML = 'Loading ......';
}



// Function to get states (send request)
function get_states( idval, location, fromPage )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = "admin_get_state.html?countryId="+idval+"&sec="+seconds+"&location="+location+"&fromPage="+fromPage;
	
	document.getElementById('countryId1').value = idval;
	xmlHttp = GetXmlHttpObject( state_response );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get states ( handle response )
function state_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		document.getElementById( "stateTxt" ).innerHTML = xmlHttp.responseText;
	}
	else if( xmlHttp.readyState != 4 )
		document.getElementById( "stateTxt" ).innerHTML = 'Loading ......';
} 



// Function to get city (send request)
function get_city( idval, location, fromPage )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = "admin_get_state.html?stateId="+idval+"&sec="+seconds+"&location="+location+"&fromPage="+fromPage; 
	
	document.getElementById('stateId1').value = idval;
	xmlHttp = GetXmlHttpObject( city_response );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}



// Function to get city ( handle response )
function city_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		document.getElementById( "cityTxt" ).innerHTML = xmlHttp.responseText;
	}
	else if( xmlHttp.readyState != 4 )
		document.getElementById( "cityTxt" ).innerHTML = 'Loading ......';
} 




// show customer detail ( send request )
function show_detail( idval, URL )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = URL+"?id="+idval+"&sec="+seconds;
	
	xmlHttp = GetXmlHttpObject( show_detail_response );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );
}

// show customer detail ( handle response )
function show_detail_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		document.getElementById( 'div_id' ).style.display='inline';
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

		{
			document.getElementById("inner_area").innerHTML=xmlHttp.responseText;
		} 
		else if(xmlHttp.readyState!=4)
		{
			document.getElementById("inner_area").innerHTML = 'Loading ......';
		}
	}
}



// show search result of promotion
function show_promo_user( idval, URL )
{   
	
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = URL+"?username="+idval+"&sec="+seconds;
	xmlHttp = GetXmlHttpObject( show_promo_user_response );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );
}

// show customer detail ( handle response )
function show_promo_user_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		document.getElementById( 'searchId123' ).style.display='';
		document.getElementById("searchId123").innerHTML = xmlHttp.responseText;
	}
}


// show search result of promotion
function show_user_name( idval, URL, user )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = URL+"?FK_memberId="+idval+"&user="+user+"&sec="+seconds;
	
	xmlHttp = GetXmlHttpObject( show_user_response );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );
}

// show customer detail ( handle response )
function show_user_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		document.getElementById( 'searchId123' ).style.display='none';
		document.getElementById( 'accountName' ).style.display = '';
		document.getElementById( 'accountName' ).innerHTML = xmlHttp.responseText;
	}
}



// Function to get subcategory
function getSubCategoryList( catId, web_root )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = web_root + "ajax_call.php?type=subCat_list&catId="+catId+"&sec="+seconds; 
	xmlHttp = GetXmlHttpObject( getSubCategoryListResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}

// Function to autoresponder ( handle response )
function getSubCategoryListResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		
		arr = xmlHttp.responseText.split('|');
		if ( document.getElementById( 'catImg' + arr[1] ).src ==  arr[2] + 'minus.gif' )
		{
			document.getElementById( 'catImg' + arr[1] ).src = arr[2] + 'plus.gif';
			document.getElementById( arr[1] ).innerHTML = '';
		}
		else
		{
			document.getElementById( 'catImg' + arr[1] ).src = arr[2] + 'minus.gif';
			document.getElementById( arr[1] ).innerHTML = arr[3];
		}
	}
	else if( xmlHttp.readyState != 4 )
		;
}




// Function to get subcategory
function getSubCategory( catId, web_root )
{   
	var Digital = new Date();
	var seconds = Digital.getSeconds();
	var url = web_root + "ajax_call.php?type=subCat&catId="+catId+"&sec="+seconds; 
	xmlHttp = GetXmlHttpObject( getSubCategoryResponse );
	xmlHttp.open("GET", url , true );
	xmlHttp.send( null );
}

// Function to autoresponder ( handle response )
function getSubCategoryResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		
		arr = xmlHttp.responseText.split('|');
		if ( document.getElementById( 'catImg' + arr[1] ).src ==  arr[2] + 'minus.gif' )
		{
			document.getElementById( 'catImg' + arr[1] ).src = arr[2] + 'plus.gif';
			document.getElementById( arr[1] ).innerHTML = '';
		}
		else
		{
			document.getElementById( 'catImg' + arr[1] ).src = arr[2] + 'minus.gif';
			document.getElementById( arr[1] ).innerHTML = arr[3];
		}
	}
	else if( xmlHttp.readyState != 4 )
		;
} 



// Function to get city (send request)
function get_sub_category( moduleId )
{   
	if( moduleId == 0 || moduleId == "3" )
	{
		document.getElementById('FK_categoryId').disabled="disabled";
	}
	else
	{
	
		var Digital = new Date();
		var seconds = Digital.getSeconds();
		var url = "admin_get_subcategory.html?moduleId="+moduleId+"&sec="+seconds; 
		
		xmlHttp = GetXmlHttpObject( sub_cat_response );
		xmlHttp.open("GET", url , true );
		xmlHttp.send( null );
	}
}



// Function to get city ( handle response )
function sub_cat_response()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		//alert(xmlHttp.responseText);
		document.getElementById( "subcategoryTxt" ).innerHTML = xmlHttp.responseText;
	}
	else if( xmlHttp.readyState != 4 )
		document.getElementById( "subcategoryTxt" ).innerHTML = 'Loading ......';
} 





// Function for initialilize GetXmlHttpObject
function GetXmlHttpObject( handler )
{ 
	var objXmlHttp=null
	
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera") 
		return 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5") >= 0 )
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}



// Function for show helloworld tag
function showHello()
{
	if ( document.getElementById('hello_worldTr').style.display == 'none' )
		document.getElementById('hello_worldTr').style.display = 'inline';
	else
		document.getElementById('hello_worldTr').style.display = 'none';
}


// By Abhishek Anand

// Show Hide Module By Site Admin
function showHideModuleBySiteAdminRequest( moduleOrder , id )
{   
	var check = document.getElementById( id ).checked;	
	var url = "ajax_call.html?moduleOrder="+moduleOrder+"&type=showHideModule&checked="+check;
	
	xmlHttp = GetXmlHttpObject( showHideModuleBySiteAdminRequestResponse );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );
}

// show Hide Module By Site Admin( handle response )
function showHideModuleBySiteAdminRequestResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		return;
	}
}

// Show Hide Index Featured By Site Admin
function showHideFeaturedBySiteAdminRequest( moduleId , id )
{   
	var check = document.getElementById( id ).checked;	
	var url = "ajax_call.html?moduleId="+moduleId+"&type=showHidefeatured&checked="+check;
	xmlHttp = GetXmlHttpObject( showHideFeaturedBySiteAdminRequestResponse );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );
}

// show Hide Index Featured By Site Admin( handle response )
function showHideFeaturedBySiteAdminRequestResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		return;
	}
}

// Show font Group Name
function bannerFontSample( fontGroupName , fontFaceId )
{   
	var url = "ajax_call.html?type=getfontName&fontGroupName="+fontGroupName+"&fontFaceId="+fontFaceId;
	xmlHttp = GetXmlHttpObject( bannerFontSampleResponse );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );
}

// show Hide Index Featured By Site Admin( handle response )
function bannerFontSampleResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		document.getElementById( "bannerSampleFontDiv" ).innerHTML = xmlHttp.responseText;
	}
}

function getFormAdditionalFieldRequest( admin_id , formType )
{   
	var url = "ajax_call.html?admin_id="+admin_id+"&formType="+formType+"&type=getFormAdditionalField";
	xmlHttp = GetXmlHttpObject( getFormAdditionalFieldResponse );
	xmlHttp.open( "GET", url , true );
	xmlHttp.send( null );

}

function getFormAdditionalFieldResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		document.getElementById('formAdditionalField').innerHTML= xmlHttp.responseText;
		return;
	}
}

// add aditional field in contest drawing form
function addEditTextFieldRequest()
{   
	var fieldName = document.getElementById('fieldName').value;
	var formType = document.getElementById('formType').value;
	
	if(fieldName.replace(/^\s+|\s+$/g,"") =='' )
	{
		alert('Please enter values for field name');
		return false;
	}
	else
	{
		var PK_fieldId = document.getElementById('PK_fieldId').value;
		var url = "ajax_call.html?fieldName="+fieldName+"&PK_fieldId="+PK_fieldId+"&formType="+formType+"&type=addEditTextField";
		xmlHttp = GetXmlHttpObject( addEditTextFieldResponse );
		xmlHttp.open( "GET", url , true );
		xmlHttp.send( null );
	}
	
}

// show Hide Index Featured By Site Admin( handle response )
function addEditTextFieldResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		
		var response=xmlHttp.responseText;
		var resArr=response.split('~');
		if(resArr[1])
		{
			var fieldName = document.getElementById('fieldName').value='';
			var PK_fieldId = document.getElementById('PK_fieldId').value='';
			var formType = document.getElementById('formType').value;
			document.getElementById('addNewField').value= 'Add Text Field';
			getFormAdditionalFieldRequest( resArr[0] , formType );
		}
		else
			alert('Error')
		return;
	}
}

// add aditional field in contest drawing form
function deleteTextFieldRequest( PK_fieldId , formType )
{   
	if(confirm('Are you sure to delete?'))
	{
		var url = "ajax_call.html?PK_fieldId="+PK_fieldId+"&type=deleteTextField";
		xmlHttp = GetXmlHttpObject( deleteTextFieldResponse );
		xmlHttp.open( "GET", url , true );
		xmlHttp.send( null );
	}
	return false
}

// show Hide Index Featured By Site Admin( handle response )
function deleteTextFieldResponse()
{ 
	if ( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
	{
		
		var response=xmlHttp.responseText;
		var resArr=response.split('~');
		if(resArr[1])
		{
			var fieldName = document.getElementById('fieldName').value='';
			var PK_fieldId = document.getElementById('PK_fieldId').value='';
			var formType = document.getElementById('formType').value;
			getFormAdditionalFieldRequest( resArr[0] , formType );
		}
		else
			alert('Error')
		return;
	}
}

