﻿_editor_url = "inc/htmlarea/";
_editor_lang = "en";
function parser(str,tg_name){
	var start_result=(str.indexOf('<'+tg_name+'>'))+('<'+tg_name+'>').length;
	var end_result=(str.indexOf('</'+tg_name+'>'))-start_result;
	str=str.substr(start_result,end_result);
	return(str);
}

/*function initEditor() {
	question = new HTMLArea("question");
	var cfg = question.config; // this is the default configuration
	cfg.width = 400;
	cfg.height = 300;
	cfg.toolbar = new Array();
	cfg.registerButton({
		id        : "sanjesh-image",
		tooltip   : "insert an image",
		image     : _editor_url+question.config.imgURL+"ed_image.gif",
		textMode  : false,
  		action    : function(editor) {
			sanjesh_Image = window.open(_editor_url+question.config.popupURL+'insertImage.php?editor='+editor._textArea.name,'insert_Image', "" +
			"toolbar=no,menubar=no,personalbar=no,width=360,height=100,left=20,top=40,scrollbars=no,resizable=no");
		}
	});
	cfg.registerButton({
		id	: "sanjesh-formula",
		tooltip : "insert a formula",
		image	: _editor_url+question.config.imgURL+"formula.png",
		textMode: false,
		action	: function(editor) {
			sanjesh_Formula = window.open(_editor_url+question.config.popupURL+'insertFormula.php?editor='+editor._textArea.name,'insert_formula', "" +
			"toolbar=no,menubar=no,personalbar=no,width=600,height=500,left=20,top=40,scrollbars=no,resizable=no");
		}
	});
	cfg.pageStyle = "* { font-family: tahoma, arial; } body { direction: rtl; } img { vertical-align: middle; }";
	cfg.toolbar.push(["sanjesh-image", "sanjesh-formula", "separator","righttoleft", "lefttoright", "separator", "copy", "cut", "paste"]);
	HTMLArea.replaceAll(cfg);
}

function checkImages(){
	var tas = document.getElementsByTagName('textarea');
	var f = document.forms[0];
	for(var j=0; j<tas.length; j++){
		var HTML = eval('_'+tas[j].name+'.getHTML()');
		var _my_images = eval('_'+tas[j].name+'._my_images');
		var toBeDeleted = new Array();
		var exists = new Array();
		var founds = HTML.match(/view\.php\?b_id=([0-9]+)"/g);
		if(!founds)
			founds = new Array();
		else
			for(var ii in founds)
				founds[ii] = parseInt(founds[ii].substr(founds[ii].indexOf('=')+1,founds[ii].length-1));
		var founds = new String(','+founds.join(',')+',');
		for(var i in _my_images){
			if(founds.indexOf(','+_my_images[i]+',')==-1)
				toBeDeleted.push(_my_images[i]);
			else
				exists.push(_my_images[i]);
		}
		fToBeDelete = eval('f.'+tas[j].name+'_toBeDelete');
		fExists = eval('f.'+tas[j].name+'_exists');
		fToBeDelete.value = toBeDeleted.join(',');
		fExists.value = exists.join(',');
	}
}

function is_all_ws( nod ){
	// Use ECMA-262 Edition 3 String and RegExp features
	return !(/[^\t\n\r ]/.test(nod.data));
}

function is_ignorable( nod ){
	return ( nod.nodeType == 8) || // A comment node
	( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

function node_before( sib ){
	while ((sib = sib.previousSibling)) {
		if (!is_ignorable(sib)) return sib;
	}
	return null;
}

function node_after( sib ){
	while ((sib = sib.nextSibling)) {
		if (!is_ignorable(sib)) return sib;
	}
	return null;
}

function last_child( par ){
	var res=par.lastChild;
	while (res) {
		if (!is_ignorable(res))
			return res;
		res = res.previousSibling;
	}
	return null;
}

function first_child( par ){
	var res=par.firstChild;
	while (res) {
		if (!is_ignorable(res))
			return res;
		res = res.nextSibling;
	}
	return null;
}

function data_of( txt ){
	var data = txt.data;
	// Use ECMA-262 Edition 3 String and RegExp features
	data = data.replace(/[\t\n\r ]+/g, " ");
	if (data.charAt(0) == " ")
		data = data.substring(1, data.length);
	if (data.charAt(data.length - 1) == " ")
		data = data.substring(0, data.length - 1);
	return data;
}*/
function form_detect_contact(f,to_insert){
   var q=""; 
	if(f){
		for(var i = 0; i < f.elements.length; i++) {
			var e = f.elements[i];
			if(!e.name)
				continue;
			/*alert(e.type);*/
			if(e.type){
				if(e.type=='radio')
					if(!e.checked)
						continue;
				if(e.type=='checkbox')
					if(!e.checked)
						continue;
			}
			if(q!='')
				q+=',';
			q+='"'+e.name+'",\''+ e.value+'\''; 
		}
	}
   
   if(to_insert){
	   q+=',"'+'to_insert'+'",\''+ '1'+'\''; 
   }
   var re = new ajaxEngine();
   var result;
   re.method = "POST";
   re.url = url_root+"post_info_contact.php";  	
   //alert(q);
   eval('re.makeQuery('+q+');')
   
	document.getElementById('result_area').innerHTML = "<font color=\"red\">Sending request to server.....</font>";
	   re.readyState4 = function(){
		  result = re.getText();
		  //alert(result);
			/*if(result.substring(0,4) == "done")*/{
			   //window.setTimeout('hidePopulate(\''+controlToPopulate.name+'\')',500);
			   document.getElementById('result_area').innerHTML=result;
			}
	   };
		re.run();
}
function form_detect(f,to_insert){
   var q=""; 
	if(f){
		for(var i = 0; i < f.elements.length; i++) {
			var e = f.elements[i];
			if(!e.name)
				continue;
			//alert(e.type);
			if(e.type){
				if(e.type=='radio')
					if(!e.checked)
						continue;
				if(e.type=='checkbox')
					if(!e.checked)
						continue;
			}
			if(q!='')
				q+=',';
			q+='"'+e.name+'",\''+ e.value+'\''; 
		}
	}
   
   var re = new ajaxEngine();
   var result;
   re.method = "POST";
   re.url = url_root+"post_info.php";  	
   if(to_insert){
	   q+=',"'+'to_insert'+'",\''+ '1'+'\''; 
   }
   eval('re.makeQuery('+q+');')
  //alert(q);
   
	document.getElementById('main_content').innerHTML = "<font color=\"red\">Sending request to server.....</font>";
	   re.readyState4 = function(){
		  result = re.getText();
		  //alert(result);
			/*if(result.substring(0,4) == "done")*/{
			   //window.setTimeout('hidePopulate(\''+controlToPopulate.name+'\')',500);
			   document.getElementById('main_content').innerHTML=result;
			}
	   };
		re.run();
}
function getType(){
	if(document.getElementById('selected_lst').value!='non'){
		document.state_submit.action='http://www.aps-hoods.com/'+document.getElementById('selected_lst').value
		document.state_submit.submit();
		//window.location = 'http://localhost/aps-hoods/'+document.getElementById('selected_lst').value;
	}
}
function change_title(){
   var re = new ajaxEngine();
   var result;
   re.method = "GET";
   re.url = "lst_select/post_lst1.php";
   re.makeQuery("change_title",'1',"s",document.getElementById('schanged_title').value,"changed_title",document.getElementById('changed_title').value,"selected_lst",document.getElementById('selected_lst').value);
	//document.getElementById(controlToPopulate.name+"-load").innerHTML = load_;
	re.readyState4 = function(){
		result = re.getText();
		//alert(result);
		if(parser(result,'changed')!=''){
			document.getElementById('title_').innerHTML=parser(result,'changed');
			//alert(parser(result,'caption'));
		}
		/*else
			document.getElementById('title_').innerHTML='';*/
	};
	re.run();
}

function hidePopulate(elem){
	document.getElementById(elem+"-load").style.visibility = "hidden";
}
/////////////////////////////////////////////////////////////////////////////////////
