// JavaScript Document
var req=null;
var console=null;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
function sendRequest(url,params,HttpMethod)
{	
	if (!HttpMethod)
	{
		HttpMethod="POST";
	}
	req=initXMLHTTPRequest();
	if (req)
	{
		req.onreadystatechange=onReadyState;
		req.open(HttpMethod,url,true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(params);
	}
}
//****************************creating the XMLHTTPRequest object
function initXMLHTTPRequest()
{
	var xRequest=null;
	if (window.XMLHttpRequest)
	{
		xRequest=new XMLHttpRequest();
	} else if (window.ActiveXObject)
	{
		xRequest=new ActiveXObject
		("Microsoft.XMLHTTP");
	}
	return xRequest;
}

var root_path='http://www.vintelli.com/';
//var root_path='http://localhost/vintelli/';
//////////////////////// admin login ///////////////////////////////
function login()
{
	email=document.getElementById('email').value;
	password=document.getElementById('password').value;
	if(email=="") {document.getElementById('login_error').style.display='block'; document.getElementById('login_error').innerHTML='Please type your email address'}
	else if(password=="") {document.getElementById('login_error').style.display='block'; document.getElementById('login_error').innerHTML='Please type your password'}
	else sendRequest(root_path+"ajax/login.php","email="+email+"&password="+password,"POST");
}
//////////////////////// admin page ///////////////////////////////
function ajax_create_page()
{
	value=document.getElementById('create_page_name').value;
	if(value=="") document.getElementById('error_page_name').style.display='block';
	else sendRequest(root_path+"ajax/ajaxpage.php","mode=insert_page&PageName="+value,"POST");
}

function ajax_delete_page()
{
	value=document.getElementById('delete_page_name').value;
	sendRequest(root_path+"ajax/ajaxpage.php","mode=delete_page&PageName="+value,"POST");
}
//////////////////////// admin category ///////////////////////////////
function ajax_create_category()
{
	value=document.getElementById('create_category_name').value;
	if(value=="") document.getElementById('error_category_name').style.display='block';
	else sendRequest(root_path+"ajax/ajaxcategory.php","mode=insert_category&CatName="+value,"POST");
}

function ajax_subcategory_category()
{
	catvalue=document.getElementById('category_dropdown').value;
	subname=document.getElementById('create_subcategory_name').value;
	if(subname=="") document.getElementById('error_subcategory_name').style.display='block';
	else sendRequest(root_path+"ajax/ajaxsubcategory.php","mode=insert_subcategory&CatName="+catvalue+"&SubCatName="+subname,"POST");
}

function ajax_delete_category()
{
	value=document.getElementById('delete_category_name').value;
	sendRequest(root_path+"ajax/ajaxcategory.php","mode=delete_category&CatName="+value,"POST");
}

function ajax_delete_subcategory()
{
	value=document.getElementById('delete_subcategory_name').value;
	sendRequest(root_path+"ajax/ajaxsubcategory.php","mode=delete_subcategory&SubName="+value,"POST");
}
//////////////////////// admin state ///////////////////////////////
function ajax_create_state()
{
	value=document.getElementById('create_state_name').value;
	if(value=="") document.getElementById('error_state_name').style.display='block';
	else sendRequest(root_path+"ajax/ajaxstate.php","mode=insert_page&StateName="+value,"POST");
}

function ajax_delete_state()
{
	value=document.getElementById('delete_state_name').value;
	sendRequest(root_path+"ajax/ajaxstate.php","mode=delete_page&StateName="+value,"POST");
}
//////////////////////// admin account ///////////////////////////////
function ajax_create_account()
{
	value=document.getElementById('create_account_name').value;
	CatId=document.getElementById('category_dropdown').value;
	SubId=document.getElementById('subcategory').value;
	if(value=="") document.getElementById('error_account_name').style.display='block';
	else if(CatId=="") {document.getElementById('error_account_name').style.display='block';document.getElementById('error_account_name').innerHTML='Select Category';}
	else if(SubId=="") {document.getElementById('error_account_name').style.display='block';document.getElementById('error_account_name').innerHTML='Select Sub-Category';}
	else sendRequest(root_path+"ajax/ajaxaccount.php","mode=insert_account&AccName="+value+"&CatId="+CatId+"&SubId="+SubId,"POST");
}

function ajax_delete_account()
{
	value=document.getElementById('delete_account_name').value;
	sendRequest(root_path+"ajax/ajaxaccount.php","mode=delete_account&AccName="+value,"POST");
}


function GetCity(val)
{
	sendRequest(root_path+"ajax/city.php","location="+val,"POST");
}

function GetSubCategory(val)
{	
	sendRequest(root_path+"ajax/category.php","mode=get_subcat&CatId="+val,"POST");	
}
//////////////////////// admin blog ///////////////////////////////
function ajax_delete_blog()
{
	value=document.getElementById('delete_blog_name').value;
	sendRequest(root_path+"ajax/ajaxblog.php","mode=delete_blog&BlogName="+value,"POST");
}
//////////////////////// admin blog ///////////////////////////////
function check_Aword()
{
	val=document.getElementById('comment').value;
	sendRequest(root_path+"ajax/check_aword.php","location="+val,"POST");
}