ajaxpageclass//******************************************************************
//Class 		:	Validation
//Created on	:	Mar 19, 2009
//Created By	:	Sheik
//******************************************************************
//Added By Monimekalai June-23 //
function reset_question()
{
    for(j=document.searchtempaltes.subtopic.options.length-1;j>=0;j--)
	{
		document.searchtempaltes.subtopic.remove(j);
	}
	make_select_box_reset(document.searchtempaltes.subtopic,1);
}
//End By Monimekalai...
function temp_validate()
{
	/*var randomnumber= document.getElementById("random").value;
        		
	  if(document.templates.new_sub_topic)
	  {
		    if(document.templates.sub_topic_select.value == "blank" && document.templates.new_sub_topic.value == "")
			{
				  alert("Enter new question.");
				  return false;
			}
		    if(document.templates.sub_topic_select.value == "blank" && document.templates.new_sub_topic.value != "")
			{
				  alert("Save the new Question you entered");
				  return false;
			}
	  }
	if(document.templates.sub_topic_select.value == "")
	{
		alert("please Select The Question!");
		document.templates.sub_topic_select.focus();
		return false;
    }*/

	if(document.templates.title.value == "Enter Title...")
	{
		alert("please Enter Title!");
		document.templates.title.focus();
		return false;
	}
	
	if(document.templates.title.value == "")
	{
		alert("please Enter Title!");
		document.templates.title.focus();
		return false;
	}
	
	var oEditor1 = FCKeditorAPI.GetInstance( 'objFCK1' ) ;
	var cont1 = oEditor1.GetXHTML(true) ;
	
	var len1=removeHTMLTags(cont1); 
	
	if(len1==0 || typeof(len1)=='undefined'){
		alert('Content Required!');
		//document.templates.len1.focus();		
		return false;
	}
	if(len1>10000){
		alert('The Maximum allowed number of characters is 10000. Please reduce your content in this Page!');
		return false;
	}
	if(document.templates.q.value != randomnumber)
	{
	alert("Please Enter Correct Number");
	document.templates.q.focus();
	return false;
	}
return true;
}
    //Modified by SHEIK on APR 16
    //Modified by sudha on Mar 27
				/*if(document.templates.useexternal.checked == true)
				{
					if(document.templates.tages.value == "")
						{
							alert("Please Enter Tags / Key Words!");
							document.templates.tages.focus();
							return false;
						}
						else
						{
							var my_colors=trim(document.templates.tages.value);
							var col_array=my_colors.split(",");
							var part_num=0;
							while (part_num < col_array.length)
							{
							 if(trim(col_array[part_num]) == "")
							 {
								 alert("Please Enter Valid Tags / Key words seperated by Commas");
								 return false;  
							 }
							 else
							  part_num+=1;
							}
							
						}
				}*/
				 //Modified by SHEIK on APR 16 END
    


/*Date 22 , Sheik*/

/*Modified by sudha on Mar 24*/
function searchtemp_validate()
{
	//alert(trim(document.searchtempaltes.tags.value));return false;
	tag =trim(document.searchtempaltes.tags.value);
		if(document.searchtempaltes.pub_rad.value == "" && document.searchtempaltes.maintopic.value  == "" && document.searchtempaltes.subtopic.value ==""  && document.searchtempaltes.title.value == ""  && (tag == "" || tag == "Enter Tags...") )
		{
		alert("Please Select atleast any of the options");
		document.searchtempaltes.ownerid.focus();
		return false;
		}
		if(tag!='' && tag!='Enter Tags...'){
			var col_array=tag.split(",");
			var part_num=0;
			while (part_num < col_array.length)
			{
			if(col_array[part_num] == "")
			{
			alert("Please Enter Valid Tags / Key words seperated by Commas");
			return false;
			}
			else
			part_num+=1;
			}
		}
		return true;

}
/*End*/
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	//Added by sudha on Mar 31
	function make_select_box_reset(combo,status)
	{
		var cb=combo.name;
		var arr = cb.split("_");
		var text = toProperCase(arr[0]);
		 if(text == 'Subtopic') text = 'Sub';
		if(text!='Title') text = text+ ' Topic';
		if (status==1){
			var optn = document.createElement("OPTION");
			optn.text = '<-- Choose '+text+' -->';
			optn.value ='';
			combo.options.add(optn);
		}
		if(status==2 || status==3){
			var optn = document.createElement("OPTION");
			optn.text = '<-- Enter Some Text -->';
			optn.value ='blank';
			combo.options.add(optn);
		}
	}
	//End
	//Modified by sudha on Mar 31
	function GetMainTopic(OwnerId) {		
		var strURL="General.php?action=FindMainTopic&OwnerId="+OwnerId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				  if(req.readyState == 1)
				  {
					   document.getElementById('ld_img').style.display ='inline';
				  }
				if (req.readyState == 4) {
					if (req.status == 200) 
					{						
					    document.getElementById('ld_img').style.display ='none';
						document.getElementById('maintopic').innerHTML=req.responseText;		
						
					    if(document.getElementById('subtopic'))
						{
								for(j=document.searchtempaltes.subtopic.options.length-1;j>=0;j--)
								{
									document.searchtempaltes.subtopic.remove(j);
								}
								make_select_box_reset(document.searchtempaltes.subtopic,1);
						}
						if(document.getElementById('title'))
						{
								for(j=document.searchtempaltes.title.options.length-1;j>=0;j--)
								{
									document.searchtempaltes.title.remove(j);
								}
								make_select_box_reset(document.searchtempaltes.title,1);
						}
						/*if(document.getElementById('tags'))
						{
								for(j=document.searchtempaltes.tags.options.length-1;j>=0;j--)
								{
									document.searchtempaltes.tags.remove(j);
								}
								make_select_box_reset(document.searchtempaltes.tags,1);
						}*/

					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function getsubtopic(MainTopic,OwnerId) {		
  	    var strURL="General.php?action=FindSubTopic&OwnerId="+OwnerId+"&MainTopic="+MainTopic;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				 if(req.readyState == 1)
				  {
					   document.getElementById('ld_img1').style.display ='inline';
				  }
				  if (req.readyState == 4) {
					// only if "OK"
					 document.getElementById('ld_img1').style.display ='none';
					if (req.status == 200) {						
						document.getElementById('subtopic').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
	function gettitle(SubTopic,MainTopic,OwnerId) {
	
		var strURL="General.php?action=FindTitle&OwnerId="+OwnerId+"&MainTopic="+MainTopic+"&SubTopic="+SubTopic;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if(req.readyState == 1)
				  {
					   document.getElementById('ld_img2').style.display ='inline';
				  }
				if (req.readyState == 4) {
					// only if "OK"
					 document.getElementById('ld_img2').style.display ='none';
					if (req.status == 200) {						
						document.getElementById('title').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
var r={
'special':/^[\s\\,]*/i
}
function valid(o,w){
o.value = o.value.replace(r[w],'');
if(o.vaue.indexOf("  ")>1)
o.value=o.value.replace("  ","")
}
function alphabetsonly(myfield, e, dec) {
  var key;
  var keychar;
 
  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);
  
  // control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
return true;

//SHEIK Date 21
else if ((key==48) || (key==49) || (key==50) || (key==51) || (key==52) || (key==53) || (key==54) || (key==55) || (key==56) || (key==57) )
return true;
//SHEIK Date 21 END
  
  else if (key==46)
    return false;
 
  else if (((" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,").indexOf(keychar) > -1))
    return true;
 
   else
    return false;
}
	
    function check_restrict()
	{
		if(document.getElementById('temp_reg_users').value == ""  &&  document.getElementById('temp_unreg_users').value == "")
		{
			  alert("Please enter all details");
               return false;
		}
		 
	}
	function Sub_Title_Relation() {		
	
	 if(document.getElementById('sel_sub_topics').value == "")
	 {
		   alert("Please select the Questions");
		   return false;
	 }
	 if(document.getElementById('sel_main_topics').value == "")
	 {
		   alert("Please select the Categories");
		   return false;
	 }
	 var main_id, subid;
	 main_id=document.getElementById('sel_main_topics').value;
	 subid = document.getElementById('sel_sub_topics').value;
	 alert(main_id);
	 return;
	   var strURL="General.php?action=sub_main_relation&sel_main_topics="+main_id+"&sel_sub_topics="+subid;
		
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('subtopic').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
	////Sheik Apr 09 Ajax Paging/////
var ajaxpageclass=new Object()
ajaxpageclass.loadstatustext="Requesting content, please wait..." // HTML to show while requested page is being fetched:
ajaxpageclass.ajaxbustcache=false // Bust cache when fetching pages?
ajaxpageclass.paginatepersist=true //enable persistence of last viewed pagination link (so reloading page doesn't reset page to 1)?
ajaxpageclass.pagerange=4// Limit page links displayed to a specific number (useful if you have many pages in your book)?
ajaxpageclass.ellipse="..." // Ellipse text (no HTML allowed)

/////////////// No need to edit beyond here /////////////////////////

ajaxpageclass.connect=function(pageurl, divId){
	var page_request = false
	var bustcacheparameter=""
	if (window.XMLHttpRequest && !document.all) // if Mozilla, Safari etc (skip IE7, as object is buggy in that browser)
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	//SHEIK Date Apr 17
	//document.getElementById(divId).innerHTML=this.loadstatustext //Display "fetching page message"
	   //SHEIK Date Apr 17 END
	page_request.onreadystatechange=function(){ajaxpageclass.loadpage(page_request, divId)}
	if (this.ajaxbustcache) //if bust caching of external page
		bustcacheparameter=(pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', pageurl+bustcacheparameter, true)
	page_request.send(null)
}

ajaxpageclass.loadpage=function(page_request, divId){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(divId).innerHTML=page_request.responseText
	}
}

ajaxpageclass.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
}

ajaxpageclass.setCookie=function(name, value){
	document.cookie = name+"="+value
}

ajaxpageclass.getInitialPage=function(divId, pageinfo){
	var persistedpage=this.getCookie(divId)
	var selectedpage=(this.paginatepersist && this.getCookie(divId)!=null)? parseInt(this.getCookie(divId)) : pageinfo.selectedpage
	return (selectedpage>pageinfo.pages.length-1)? 0 : selectedpage //check that selectedpage isn't out of range
}

ajaxpageclass.createBook=function(pageinfo, divId, paginateIds){//MAIN CONSTRUCTOR FUNCTION
	this.pageinfo=pageinfo //store object containing URLs of pages to fetch, selected page number etc
	this.divId=divId
	this.paginateIds=paginateIds //array of ids corresponding to the pagination DIVs defined for this pageinstance
	//NOTE: this.paginateInfo stores references to various components of each pagination DIV defined for this pageinstance
	//NOTE: Eg: divs[0] = 1st paginate div, pagelinks[0][0] = 1st page link within 1st paginate DIV, prevlink[0] = previous link within paginate DIV etc
	this.paginateInfo={divs:[], pagelinks:[[]], prevlink:[], nextlink:[], previouspage:null, previousrange:[null,null], leftellipse:[], rightellipse:[]}
	this.dopagerange=false
	this.pagerangestyle=''
	this.ellipse='<span style="display:none">'+ajaxpageclass.ellipse+'</span>' //construct HTML for ellipse
	var initialpage=ajaxpageclass.getInitialPage(divId, pageinfo)
	this.buildpagination(initialpage)
	this.selectpage(initialpage)
}

ajaxpageclass.createBook.prototype={

	buildpagination:function(selectedpage){ //build pagination links based on length of this.pageinfo.pages[]
		this.dopagerange=(this.pageinfo.pages.length>ajaxpageclass.pagerange) //Bool: enable limitpagerange if pagerange value is less than total pages available
		this.pagerangestyle=this.dopagerange? 'style="display:none"' : '' //if limitpagerange enabled, hide pagination links when building them
		this.paginateInfo.previousrange=null //Set previousrange[start, finish] to null to start
		if (this.pageinfo.pages.length<=1){ //no 0 or just 1 page
			document.getElementById(this.paginateIds[0]).innerHTML=(this.pageinfo.pages.length==1)? "Page 1 of 1" : ""
			return
		}
		else{ //construct paginate interface
			var paginateHTML='<div class="pagination"><ul>\n'
			paginateHTML+='<li><a href="#page1" rel="0"> << </a></li>\n' //First link HTML
                        //paginateHTML+='<li><a href="#page'+(selectedpage)+'" rel="'+(selectedpage-1)+'"> < </a></li>\n' //First link HTML
			for (var i=0; i<this.pageinfo.pages.length; i++){

                                var ellipses={left: (i==0? this.ellipse : ''), right: (i==this.pageinfo.pages.length-1? this.ellipse : '')} //if this is 1st or last page link, add ellipse next to them, hidden by default
                                
				if(i==0)
				{
					paginateHTML+='<li>'+ellipses.right+'<a href="#page'+(i+1)+'" rel="'+(i)+'" style="display:inline">'+'<'+'</a>'+ellipses.left+'</li>\n'
				}
				if((i!=0) || (i!=(this.pageinfo.pages.length)))
				{
                                    paginateHTML+='<li>'+ellipses.right+'<a href="#page'+(i+1)+'" rel="'+(i)+'" '+this.pagerangestyle+'>'+(i+1)+'</a>'+ellipses.left+'</li>\n'
				}
				if(i == ((this.pageinfo.pages.length)))
				{
				paginateHTML+='<li>'+ellipses.right+'<a href="#page'+(i+1)+'" rel="'+(i)+'" >></a>'+ellipses.left+'</li>\n'
				}/**/
				//paginateHTML+='<li>'+ellipses.right+'<a href="#page'+(i+1)+'" rel="'+i+'" '+this.pagerangestyle+'>'+(i+1)+'</a>'+ellipses.left+'</li>\n'
			}
                        //paginateHTML+='<li><a href="#page'+(selectedpage+1)+'" rel="'+(selectedpage+1)+'"> ></a></li>\n' //next link HTML
			paginateHTML+='<li><a href="#page'+(this.pageinfo.pages.length)+'" rel="'+(this.pageinfo.pages.length)+'"> >></a></li>\n' //last link HTML
			paginateHTML+='</ul></div>'
		}// end construction
		this.paginateInfo.previouspage=selectedpage //remember last viewed page
		for (var i=0; i<this.paginateIds.length; i++){ //loop through # of pagination DIVs specified
			var paginatediv=document.getElementById(this.paginateIds[i]) //reference pagination DIV
			this.paginateInfo.divs[i]=paginatediv //store ref to this paginate DIV
			paginatediv.innerHTML=paginateHTML
			var paginatelinks=paginatediv.getElementsByTagName("a")
			var ellipsespans=paginatediv.getElementsByTagName("span")
			this.paginateInfo.prevlink[i]=paginatelinks[0]
			if (paginatelinks.length>0)
				this.paginateInfo.nextlink[i]=paginatelinks[paginatelinks.length-1]
			this.paginateInfo.leftellipse[i]=ellipsespans[0]
			this.paginateInfo.rightellipse[i]=ellipsespans[1]
			this.paginateInfo.pagelinks[i]=[] //array to store the page links of pagination DIV
			for (var p=1; p<paginatelinks.length-1; p++){
				this.paginateInfo.pagelinks[i][p-1]=paginatelinks[p]
			}
			var pageinstance=this
			paginatediv.onclick=function(e){
				var targetobj=window.event? window.event.srcElement : e.target
				if (targetobj.tagName=="A" && targetobj.getAttribute("rel")!=""){
					if (!/disabled/i.test(targetobj.className)){ //if this pagination link isn't disabled (CSS classname "disabled")
						pageinstance.selectpage(parseInt(targetobj.getAttribute("rel")))
					}
				}
				return false
			}
		}
	},

	selectpage:function(selectedpage){
		//replace URL's root domain with dynamic root domain (with or without "www"), for ajax security sake:
		if (this.pageinfo.pages.length>0){
			var ajaxfriendlyurl=this.pageinfo.pages[selectedpage].replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
			ajaxpageclass.connect(ajaxfriendlyurl, this.divId) //fetch requested page and display it inside DIV
		}
		if (this.pageinfo.pages.length<=1) //if this book only contains only 1 page (or 0)
			return //stop here
		var paginateInfo=this.paginateInfo
		for (var i=0; i<paginateInfo.divs.length; i++){ //loop through # of pagination DIVs specified
			//var paginatediv=document.getElementById(this.paginateIds[i])
			paginateInfo.prevlink[i].className=(selectedpage==0)? "prevnext disabled" : "prevnext" //if current page is 1st page, disable "prev" button
			paginateInfo.prevlink[i].setAttribute("rel", selectedpage-1) //update rel attr of "prev" button with page # to go to when clicked on
			paginateInfo.nextlink[i].className=(selectedpage==this.pageinfo.pages.length-1)? "prevnext disabled" : "prevnext"
			paginateInfo.nextlink[i].setAttribute("rel", selectedpage+1)
			paginateInfo.pagelinks[i][paginateInfo.previouspage].className="" //deselect last clicked on pagination link (previous)
			paginateInfo.pagelinks[i][selectedpage].className="currentpage" //select current pagination link
		}
		paginateInfo.previouspage=selectedpage //Update last viewed page info
		/*Jeyakumar-Apr-22*/
			//ajaxpageclass.setCookie(this.divId, selectedpage)
		/*Jeyakumar-Apr-22-End*/

		this.limitpagerange(selectedpage) //limit range of page links displayed (if applicable)
	},

	limitpagerange:function(selectedpage){
		//reminder: selectedpage count starts at 0 (0=1st page)
		var paginateInfo=this.paginateInfo
		if (this.dopagerange){
			var visiblelinks=ajaxpageclass.pagerange-1 //# of visible page links other than currently selected link
			var visibleleftlinks=Math.floor(visiblelinks/2) //calculate # of visible links to the left of the selected page
			var visiblerightlinks=visibleleftlinks+(visiblelinks%2==1? 1 : 0) //calculate # of visible links to the right of the selected page
			if (selectedpage<visibleleftlinks){ //if not enough room to the left to accomodate all visible left links
				var overage=visibleleftlinks-selectedpage
				visibleleftlinks-=overage //remove overage links from visible left links
				visiblerightlinks+=overage //add overage links to the visible right links
			}
			else if ((this.pageinfo.pages.length-selectedpage-1)<visiblerightlinks){ //else if not enough room to the left to accomodate all visible right links
				var overage=visiblerightlinks-(this.pageinfo.pages.length-selectedpage-1)
				visiblerightlinks-=overage //remove overage links from visible right links
				visibleleftlinks+=overage //add overage links to the visible left links
			}
			var currentrange=[selectedpage-visibleleftlinks, selectedpage+visiblerightlinks] //calculate indices of visible pages to show: [startindex, endindex]
			var previousrange=paginateInfo.previousrange //retrieve previous page range
			for (var i=0; i<paginateInfo.divs.length; i++){ //loop through paginate divs
				if (previousrange){ //if previous range is available (not null)
					for (var p=previousrange[0]; p<=previousrange[1]; p++){ //hide all page links
						paginateInfo.pagelinks[i][p].style.display="none"
					}
				}
				for (var p=currentrange[0]; p<=currentrange[1]; p++){ //reveal all active page links
					paginateInfo.pagelinks[i][p].style.display="inline"
				}
				paginateInfo.pagelinks[i][0].style.display="inline" //always show 1st page link
				paginateInfo.pagelinks[i][this.pageinfo.pages.length-1].style.display="inline" //always show last page link
				paginateInfo.leftellipse[i].style.display=(currentrange[0]>1)? "inline" : "none" //if starting page is page3 or higher, show ellipse to page1
				paginateInfo.rightellipse[i].style.display=(currentrange[1]<this.pageinfo.pages.length-2)? "inline" : "none" //if end page is 2 pages before last page or less, show ellipse to last page
			}
		}
			paginateInfo.previousrange=currentrange
	},

	refresh:function(pageinfo){
	this.pageinfo=pageinfo
	var initialpage=ajaxpageclass.getInitialPage(this.divId, pageinfo)
	this.buildpagination(initialpage)
	this.selectpage(initialpage)
	}
}

	////Sheik Apr 09 END Ajax Paging/////

//Google Map Sheik Sep 23 //
function toggle(chkbox, group) { 
    var visSetting = (chkbox.checked) ? "visible" : "hidden"; 
    document.getElementById(group).style.visibility = visSetting; 
} 
function swap(radBtn, group) { 
    var modemsVisSetting = (group == "modems") ? ((radBtn.checked) ? "" : "none") : "none"; 
    document.getElementById("modems").style.display = modemsVisSetting; 
} 

//Google Map Sheik Sep 23 END//
