// JavaScript Document
/*************************************
Module Name		: Registration
Args			: None
Module Type		: Procedure
Created By		: AJ@indopia
Created On		: Sept 26, 2006
Modified By		: 
Modified On		: 
Remarks			:
Description		: This is used for pulling up response asynchronously on submission of registration page
**************************************/

function XMLHTTPObject()
{
	var xmlhttp; 

	if (window.ActiveXObject) 
	{
		// Instantiate the latest Microsoft ActiveX Objects
		if (_XML_ActiveX)
		{
			xmlhttp = new ActiveXObject(_XML_ActiveX);
		
		}
		else
		{ 
			// loops through the various versions of XMLHTTP to ensure we're using the latest
			var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];			

			for (var i = 0; i < versions.length ; i++) 
			{ 
				try
				{
					// Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
					xmlhttp = new ActiveXObject(versions[i]); 
						
					if (xmlhttp) 
					{ 
						var _XML_ActiveX = versions[i];
						break;
					}
				}
				catch (e)
				{
					// TRAP
				};
			}
			;
		}			
	}// Well if there is no ActiveXObject available it must be firefox, opera, or something else

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try 
		{ 
			xmlhttp = new XMLHttpRequest(); 
		} 
		catch (e) 
		{
			xmlhttp = false; 
		}
	}
	
	return xmlhttp;
}

function processRequest(contentId,httpRequest,refreshContentOnFunction,parameterForRefresh)
{ 
	
	if (httpRequest.readyState == 4) 
	{ 
		if(httpRequest.status == 200)
		{ 
			results = httpRequest.responseText; // http.responseXML; which will lead to an XML based response, if we were to have some XML output from a server file
			
			//alert(results);
		
			var para = document.getElementById(contentId); //or whatever ID you gave your element. 			
			para.innerHTML = results;
			//alert(Url.href);
		//	document.location = "http://localhost/indopia/indopia/discussions/index.php?catid=2";
			if (refreshContentOnFunction != "null")
			{		
				refreshContent(refreshContentOnFunction,parameterForRefresh);	
							
			}
			
		}
		else 
		{ 
			var results = "Sorry, there was an error finding the server-side file. Please contact support."; 
			var para = document.getElementById(contentId); 
			para.innerHTML = results; 
		}
		
	}	

	
}


function populateMsg(formName)
{
	//alert(id);
	
	var httpRequest=null;

	var refreshContent = null;
	// Javascript validation block (if any)
	var arrFormValidation = new Array();

	var result;
	//Javascript validation
	arrFormValidation=
             				[ 
							
								[//Main category
                   				["dontselect=0","Please enter your category"]
								],
								
								[//Topic			
								 	["required","Please enter your topic"],["blankspace","Please enter your topic"]
															  
                   				],
                   				
								[//Description						  			
								  	["required","Please enter your description"]
                   				],
								[],
								[
								 ["required","Please enter security code"],["securityimage","Please enter security properly!"]
								]
	                   				                  
            				];

	objForm1 = document.forms[formName];
	
	//alert(objForm1.name);
	result = validateForm(objForm1,arrFormValidation);
     
	//alert(result);
	// End
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	//countryValue = eval("document."+formName+"."+countryId+".value");		
	
	
	
	
	//if (result!=false && id !=1){
	//window.open('../discussions/savediscussio.php?type=1','_new','status=0,toolbar=0,width=240px,height=360px,left=400,top=300');
	//}
	//{    window.open('../discussions/savediscussiontopic.php?type=1','_new','status=0,toolbar=0,width=240px,height=360px,left=400,top=300');
	
	//	httpRequest = XMLHTTPObject();			
		//var categoryName=document.getElementById("mainCategory");
		//var categoryID=categoryName.options[categoryName.selectedIndex].value;
		//var topicOBJ = document.getElementById("topic");
	 	//var topicValue = topicOBJ.value;	
	    //var descrOBJ = document.getElementById("descr");
	    //var descrValue = descrOBJ.value;
		//window.open ("http://www.javascript-coder.com","mywindow"); 
		//var varContentUrl =  "../discussions/savediscussiontopic.php?catg="+categoryID+"&topic="+topicValue+"&descr="+descrValue;				
				
		//var contentId="message";
	//	var para =document.getElementById(contentId);
		//para.innerHTML = "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b style='color:red;'>Loading States<img src='../resources/images/loading.gif'/></b></span>"; 
	
		//httpRequest.open("GET", varContentUrl, true); 
		//httpRequest.onreadystatechange = function () {processRequest1(contentId,httpRequest,refreshContent,""); } ;
	  
	  
		//httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		//httpRequest.send(null);	
		
		 //topicOBJ.value="";
		  //descrOBJ.value="";
		 //categoryName.options[0].text="Select main category"  ;
		  //categoryName.options[0].value=0;
		 // alert(categoryName.value);
	//}//if ends	
	//else
	return result;
  
}//function ends


function processRequest1(contentId,httpRequest,refreshContentOnFunction,parameterForRefresh)
{ 
	
	if (httpRequest.readyState == 4) 
	{ 
		if(httpRequest.status == 200)
		{ 
			results = httpRequest.responseText; // http.responseXML; which will lead to an XML based response, if we were to have some XML output from a server file
		//alert(results);
			if(results==1)
			{
			// alert("in if");
			window.open('../login/login.php?pgto=discussions','_self');
			}
			 else
			 {
				//alert("in else");
			 window.open('../discussions/savediscussiontopic.php?type=1','_new','status=0,toolbar=0,width=240px,height=360px,left=400,top=300');
			 }
			//var para = document.getElementById(contentId); //or whatever ID you gave your element. 			
			//para.innerHTML = results; 		
			//if (refreshContentOnFunction != "null")
			  //{		
				//refreshContent(refreshContentOnFunction,parameterForRefresh);	
			  //}
			}
			
		}
		
		
	}	
function codeValidate(code) {
//alert("amit");
	//alert("Blur"+code);
	var httpRequest=null;
    var refreshContent = "null";
	var result = true;
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	codeValue = eval("code");	
	
		httpRequest = XMLHTTPObject();	
	
		var varContentUrl =  "codevalidate.php?code="+codeValue;				
		
		var contentId = 'codevarify';	
//		alert(document.getElementById(contentId));
		var para = document.getElementById('codevarify');
       // alert(para);
	//para.innerHTML = '<span><img src="../../resources/images/loading.gif" /></span>';
	
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpRequest.send(null);	

}
	

function pagination(page,type)
{
	category=id;
  // alert(page);
 //alert("category="+category+"value="+value);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
		params = "?catg="+category+"&"+type+"_next_page="+page+"&type="+type;		
		//alert(params);

	httpRequest = XMLHTTPObject();	
	
	var varContentUrl =  "showtab.php"+params;				
	var contentId = "show1";				
//	alert(varContentUrl);
	var para = document.getElementById(contentId);
	para.innerHTML = "<span >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='../resources/images/loading.gif' /></span>"; 
	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	
}


/*function showposts(category, value, curpage, pagesize, moduleid) {
//	alert(document.getElementById(id).value);
//if(category==null)
//if(category==null)
//alert(category);
//if(category==null)
category=id;
//alert(category);
 //alert("category="+category+"value="+value);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
		params = "?catg="+category+"&type="+value+"&curPage="+curpage+"&pagesize="+pagesize+"&moduleid="+moduleid;		
		//alert(params);

	httpRequest = XMLHTTPObject();	
	
	var varContentUrl =  "showtab.php"+params;				
	var contentId = "show";				
//	alert(varContentUrl);
	var para = document.getElementById(contentId);
	para.innerHTML = "<span >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='../resources/images/loading.gif' /></span>"; 
	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	

}*/
/*function setcategory1(id) {
	setCookie("categoryId",id);
	//alert(id);
}

function setCookie(name, value, expires, path, domain, secure) { document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); 
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}*/


function showmyposts(category, value, curpage, pagesize, userid) {
//	alert(document.getElementById(id).value);
//if(category==null)
category=id;
//alert("category"+category);
//alert("userid"+userid);
 //alert("category="+category+"value="+value+"pagesize"+pagesize+"userid"+userid);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
		params = "?catg="+category+"&type="+value+"&curPage="+curpage+"&pagesize="+pagesize+"&userid="+userid;		
//alert(params);
	httpRequest = XMLHTTPObject();	
	
	var varContentUrl =  "showmytab.php"+params;				
	var contentId = "myshow";				
//	alert(varContentUrl);
	var para = document.getElementById(contentId);
	para.innerHTML = "<span class=LabelHeading><img src='../resources/images/loading.gif'></span>"; 
	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	

}

function pagination1(page,type)
{
	category=id;
//alert(page);
 //alert("category="+category+"value="+value);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
	// If there is no javascript error then go thru the processing/request response cycle	
	params = "?catg="+category+"&"+type+"_next_page="+page+"&type="+type;	
		//params = "?catg="+category+"&link="+page+"&type="+type;		
		//alert(params);

	httpRequest = XMLHTTPObject();	
	
	var varContentUrl =  "showmytab.php"+params;				
	var contentId = "myshow";				
//	alert(varContentUrl);
	var para = document.getElementById(contentId);
	para.innerHTML = "<span >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='../resources/images/loading.gif' /></span>"; 
	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	
}




/*function swap(id) {
	document.getElementById('rd').className="dismnuLNormal";
	document.getElementById('rp').className="dismnuNormal";
	
	document.getElementById('hd').className="dismnuNormal";
	document.getElementById('md').className="dismnuNormal";
	document.getElementById('mp').className="dismnuRNormal";
	document.getElementById(id).className="dismnuRNormal";
	if(id!='rd' && id!='mp')
		document.getElementById(id).className="dismnuSelect";
	else {
		if(id=='rd')
			document.getElementById(id).className="dismnuLSelect";
	//		break;
		if(id=='mp')
			document.getElementById(id).className="dismnuRSelect";
	}
	reportType=document.getElementById(id).id;
//	alert("Category => "+categoryId+" Report Type =>"+reportType);
}
*/
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
function swap(id) {
//alert("div"+id);

	document.getElementById('rd').className="distdL";
	document.getElementById('rp').className="distdN";
	document.getElementById('hd').className="distdN";
	document.getElementById('md').className="distdN";
	document.getElementById('mp').className="distdR";
	document.getElementById(id).className="distdR";
//		break;
	if(id!='rd' && id!='mp')
		document.getElementById(id).className="distdNselect";
	else {
		if(id=='rd')
			document.getElementById(id).className="distdLselect";
	//		break;
		if(id=='mp')
			document.getElementById(id).className="distdRselect";
	}
	reportType=document.getElementById(id).id;
}
/////////////////////////////////////////////////////////////////////////////////////
function swap1(id) {
//alert("link"+id);

	document.getElementById('a').className="disdeselecttab";
	document.getElementById('b').className="disdeselecttab";
	document.getElementById('c').className="disdeselecttab";
	document.getElementById('d').className="disdeselecttab";
	document.getElementById('e').className="disdeselecttab";
	
//		break;
	if(id!='a' && id!='e')
		document.getElementById(id).className="disselecttab";
		
	else {
		if(id=='a')
			document.getElementById(id).className="disselecttab";
	//		break;
		if(id=='e')
			document.getElementById(id).className="disselecttab";
	}
	
}

function swap2(id) {
//alert("link"+id);

	document.getElementById('f').className="disdeselecttab";
	document.getElementById('g').className="disdeselecttab";
	
//		break;
		if(id=='f')
			document.getElementById(id).className="disselecttab";
	//		break;
		if(id=='g')
			document.getElementById(id).className="disselecttab";
	

}
function swapMyProfile(id) {
	document.getElementById('mydis').className="distdL";
	
	document.getElementById('mypost').className="distdR";
	
		if(id=='mydis')
			document.getElementById(id).className="distdLselect";
	//		break;
		else
			document.getElementById(id).className="distdRselect";

	myreportType=document.getElementById(id).id;
//	alert("Category => "+categoryId+" Report Type =>"+reportType);
}
var myreportType='mydis';










function showTopic(categoryID) {
//	alert(document.getElementById(id).value);
    
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
	// If there is no javascript error then go thru the processing/request response cycle	
		params = "catg="+categoryID;		
     
	httpRequest = XMLHTTPObject();	
	
	var varContentUrl ="showdiscussiontopic.php?"+params;				
	var contentId = "show";				
//	alert(varContentUrl);
	var para = document.getElementById(contentId);
	para.innerHTML = "<span class=LabelHeading align=center>&nbsp;&nbsp;&nbsp;&nbsp;</span>"; 

	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	

}
	var reportType='rd';
   var id=0;
  //alert( reportType+id);
function setcategory(categoryId) {
	
	id=categoryId;
	
//alert("Category => "+categoryId+" Report Type =>"+reportType);
}
function subShow(categoryID) {
//	alert("id"+categoryID);
 if (categoryID==0)
 {
	 document.getElementById('sub').className='disselectedcat'; 
     var x=document.getElementsByName("linking");
      for(var intCnt=0;intCnt<x.length;intCnt++) {
 	//alert(x[intCnt].id);
	    document.getElementById(x[intCnt].id).className="dissubCategoryLink";
	       }
// document.getElementById(categoryID).className='disselectedcat';
	 
	 }
 else
 {
  document.getElementById('sub').className='dissubCategoryLink'; 
 var x=document.getElementsByName("linking");
 for(var intCnt=0;intCnt<x.length;intCnt++) {
 	//alert(x[intCnt].id);
	document.getElementById(x[intCnt].id).className="dissubCategoryLink";
	}
 document.getElementById(categoryID).className='disselectedcat';
 }

}

function dispsercherror()
{
    document.frmSearch.searchText.value = document.frmSearch.searchText.value.replace(/\r/g, " ");

	

  //There are regex switchs for printing /nonprinting characters 

  //but they stripped some characters either needed or left some not wanted,

  //thats why the following replacement exists.

  document.frmSearch.searchText.value = document.frmSearch.searchText.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");

 

  document.frmSearch.searchText.value = document.frmSearch.searchText.value.replace(/'/g, "");

  

  document.frmSearch.searchText.value = document.frmSearch.searchText.value.replace(/ +/g, " ");  

	

  document.frmSearch.searchText.value = document.frmSearch.searchText.value.replace(/^\s/g, "");

  document.frmSearch.searchText.value = document.frmSearch.searchText.value.replace(/\s$/g, "");	

 // alert(document.frmSearch.searchText.value)
//alert(document.frmSearch.searchText.value.length);
 if(document.frmSearch.searchText.value.length==0)
 {
 alert('please enter the value to search');
 return false; 
 }
	//var errMsg="<br><ul style='display: block; text-align: left'>";
	//var errCnt=0;
	//id=	document.getElementById("searcherror");
  //this code is added by umesh & amit to validate the postans.tpl	begin
	/*if(document.frmSearch.searchText.value.length<=0) {
			//errMsg+="<li>Please! Enter Proper Keyword To Search Database.</li>";
		//errCnt++;
		alert("Please! Enter Proper Keyword To Search Database.");
			return false;
		}
		else
		return true;*/
	//end
	/*if(errCnt==0) {
		id.style.visible="none";
		//searchMe();
		return true;
	}
	else{
		id.innerHTML=errMsg+"</ul>";
		id.style.display='';
		return false;
	}
	*/
}




/* function searchMe() {
var searchText=document.frmSearch.searchText.value;
//alert(searchText);

//showposts(1,'search',1,10,searchText);
return false;
}*/

function checkReply(formName)
{
	//alert("hi");
	

	// Javascript validation block (if any)
	var arrFormValidation = new Array();

	var result=false;
	//Javascript validation
	arrFormValidation=
             				[ 
								[//Topic			
								 	["required","Please enter your subject"],["blankspace","Please enter the topic"]
															  
                   				],
                   				
								[//Description						  			
								  	["required","Please enter your message"],["blankspace","Please enter the topic"]
                   				],[],[],[],
								[
								 ["required","Please enter security code"],["securityimage","Please enter security properly!"]
								],
								[],
	                   				                  
            				   [],[]
							];

	objForm = document.forms[formName];
	
	result = validateForm(objForm,arrFormValidation);
	
	return result;
}

function checkAlert(formName)
{
	
 
	// Javascript validation block (if any)
	var arrFormValidation = new Array();

	var result=false;
	//Javascript validation
	arrFormValidation=
             				[ 
							
								[],
								[],
								[],
								[],
								[],
								[],
								[//Description						  			
								  	["required","Please enter your reason"],["blankspace","Please enter the topic"]
                   				],[],
								[
								 ["required","Please enter security code"],["securityimage","Please enter security properly!"]
								],
							   [],[]
							];

	objForm = document.forms[formName];
	
	result = validateForm(objForm,arrFormValidation);
	
	return result;
}

function checkpostReply(formName)
{
	

	// Javascript validation block (if any)
	var arrFormValidation = new Array();

	var result=false;
	//Javascript validation
	arrFormValidation=
             				[ 
							      [//Topic			
								 	["required","Please enter your subject"],["blankspace","Please enter the topic"]
															  
                   				],
                   				
								[//Description						  			
								  	["required","Please enter your message"],["blankspace","Please enter the value"]
                   				],
	                   				                  
            				   [],[],[],[],
							   [
								 ["required","Please enter security code"],["securityimage","Please enter security properly!"]
								],
								[],
	                   				                  
            				   [],[],[],[]
							   
							];

	objForm = document.forms[formName];
	
	result = validateForm(objForm,arrFormValidation);
	
	return result;
}


/*function searchtext(curpage, pagesize, searchText) {
	var httpRequest=null;
	var refreshContent ="null";
	// If there is no javascript error then go thru the processing/request response cycle	
	params = "?curPage="+curpage+"&pagesize="+pagesize+"&searchText="+searchText;		
	alert(params);
	httpRequest = XMLHTTPObject();	
	var varContentUrl="search1.php"+params;				
	var contentId="search";	
	alert(varContentUrl);
	httpRequest.open("GET", varContentUrl, true); 
	alert(contentId);
	httpRequest.onreadystatechange = function () {
		processRequest(contentId,httpRequest,refreshContent,"");
		} ;
	
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		alert("after ready ");
	httpRequest.send(null);	
	alert(curpage+searchText+pagesize)	
	
  }*/
  
  function searchtext(curpage, pagesize, searchText) {
	var httpRequest=null;
	var refreshContent = "null";
	
		params = "?curPage="+curpage+"&pagesize="+pagesize+"&searchText="+searchText;		
//alert(params);
	httpRequest = new XMLHTTPObject();	
	
	var varContentUrl =  "search1.php"+params;				
	var contentId = "content";				
//	alert(varContentUrl);

	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
	
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	

}
  
  
function display(obj1)
{

 	var id1=document.getElementById(obj1);
	id1.style.display='';
	/*if(id1.style.display=='') 
		{
		id1.style.display='none';
		alert("in if");
		}
	else
	{
		id1.style.display='';
	
	alert("in else");
	}*/
		 
/*var id2=document.getElementById(obj2);
	if(id2.style.display=='') 
		id2.style.display='none';
	else
		id2.style.display='';
*/


}

function displaydisinnews(obj1)
{
 
 	var id1=document.getElementById(obj1);
	id1.style.display='';
	/*if(id1.style.display=='') 
		{
		id1.style.display='none';
		alert("in if");
		}
	else
	{
		id1.style.display='';
	
	alert("in else");
	}*/
		 
/*var id2=document.getElementById(obj2);
	if(id2.style.display=='') 
		id2.style.display='none';
	else
		id2.style.display='';
*/


}