// JavaScript Document
<!--//
function Ajax_load_page(url, target) {
  document.getElementById(target).innerHTML = '';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {Ajax_load_page_Done(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function Ajax_load_page_Done(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function Ajax_page(name, div) {
    Ajax_load_page(name,div);
    return false;
}

//	AJAX FUNCTION TO GET VALUE FROM PAGE INTO STRING
function Ajax_load_value(url) {
if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  req.open("GET", url, false);
  req.send("");
  return req.responseText;	
}  





//	SUBMIT FORM VIA AJAX
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
       //     document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj,objid) {
	   var message=document.getElementById("message"+objid).value;
      var poststr = "message=" + encodeURI( document.getElementById("message"+objid).value )
	  + "&toid=" + encodeURI( document.getElementById("toid"+objid).value )
	  + "&touser=" + encodeURI( document.getElementById("touser"+objid).value )
	  + "&fromuser=" + encodeURI( document.getElementById("fromuser"+objid).value )
	  + "&chatid=" + encodeURI( document.getElementById("chatid"+objid).value )
	  + "&fromid=" + encodeURI( document.getElementById("fromid"+objid).value );
      if(message)
	  makePOSTRequest('writer.php', poststr);
	  send(objid);
   }

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

//	javascript functions
function replaceSubstring (inputString, badString, goodString, caseSensitive) {
  fixedReplace = "";
  UI = inputString;
  UB = badString;
  if ((caseSensitive != 1) && (caseSensitive != true)) {
  UI = inputString.toUpperCase();
     UB = badString.toUpperCase();
     }
  badEnd = -1;
  badLoc = UI.indexOf(UB);
  if (badLoc != -1) {
     for (x=1; (badLoc != -1); x++) {
        fixedReplace = fixedReplace + 
                       inputString.substring((badEnd +
                       1), badLoc) + goodString
        badEnd = badLoc + UB.length - 1;
        badLoc = UI.indexOf(UB, (badLoc + 1)); }
     fixedReplace = fixedReplace + 
                    inputString.substring((badEnd + 1),
                    inputString.length); }
     else { fixedReplace = inputString;    }
return fixedReplace;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

//-->
//FORUM EDITOR
function addtag(tag,single) {
	var txt = document.getElementById('txtarea');
	if(document.selection) {
		txt.focus();
		sel = document.selection.createRange();
		if(single == true) {
			sel.text = '[' + tag + ']';
		} else {
		    sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
		}
	} else if(txt.selectionStart || txt.selectionStart == '0') {
		if(single == true) {
			txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		} else {
			txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		}
	} else {
		if(single) {
			txt.value = '[' + tag + ']';
		} else {
			txt.value = '[' + tag + '][/' + tag + ']';
		}
	}
	return true;
}
function addurltag() {
	var txt = document.getElementById('txtarea');
	var link = prompt("Type the address:", "http://");
	if(link.length == 0 || link == "http://") {
		return;
	} else {
		var link = "=" + link;
		var text;
		var sel2 = "";
		if(document.selection) {
			txt.focus();
			sel = document.selection.createRange();
			sel2 = sel.text;
		} else if(txt.selectionStart || txt.selectionStart == '0') {
			sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
		}
		if(sel2.length > 0) {
			text = sel2;
		} else {
			text = prompt("Enter the link text:", "");
		}
	}
	if(document.selection) {
		txt.focus();
		sel = document.selection.createRange();
		sel.text = "[url" + link + "]" + text + "[/url]";
	} else {
		txt.value = (txt.value).substring(0, txt.selectionStart) + "[url" + link + "]" + text + "[/url]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
	}
	return;
}
function doImage()
{
var textarea = document.getElementById('txtarea');
var url = prompt('Enter the Image URL:','http://');

	if (document.selection) 
			{
				textarea.focus();
				var sel = document.selection.createRange();
				sel.text = '[img]' + url + '[/img]';
			}
   else 
    {
		var len = textarea.value.length;
	    var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		
        var sel = textarea.value.substring(start, end);
	    //alert(sel);
		var rep = '[img]' + url + '[/img]';
        textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
	}

}
function addvaluetag(sValue,tag) {
	if(sValue=="") {
		return;
	}
	var txt = document.getElementById('txtarea');
	if(document.selection) {
		txt.focus();
		sel = document.selection.createRange();
		sel.text = '["+tag+"=' + sValue + ']' + sel.text + '[/"+tag+"]';
	} else if(txt.selectionStart || txt.selectionStart == '0') {	
		txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"="+sValue+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
	} else {
		txt.value = '["+tag+"=' + sValue + '][/"+tag+"]';
	}
	return;
}

// GOOGLE ADSENSE CODE

// These variables are for maintaining state when using ad skip
var google_num_ads = 0;
var google_last_ad_type = '';
function google_ad_request_done(google_ads) {
	/*
	* This function is required and is used to display
	* the ads that are returned from the JavaScript
	* request. You should modify the document.write
	* commands so that the HTML they write out fits
	* with your desired ad layout.
	*/
	var s;
	/*
	* Verify that there are actually ads to display.
	*/
	if (google_ads.length == 0) return;
	google_num_ads += google_ads.length;
	google_last_ad_type = google_ads[0].type;
	/*
	* If an image or Flash ad is returned, display that ad.
	* If a rich media ad is returned, display that as "as is."
	* Otherwise, build a string containing all of the ads and
	* then use a document.write() command to print that string.
	*/
	s = '<a class="ad_attribution" href="'+google_info.feedback_url+'">Ads by Google</a><br>';
	if (google_ads[0].type == "text") {
		// Adjust text sizes to occupy the majority of ad space.
		if (google_ads.length == 1) {
			ad_title_class = 'ad_title_large';
			ad_text_class = 'ad_text_large';
			ad_url_class = 'ad_url_large';
		} else {
			ad_title_class = 'ad_title';
			ad_text_class = 'ad_text';
			ad_url_class = 'ad_url';
		}
		for(var i=0; i < google_ads.length; i++) {
			s += '<br><a class="' + ad_title_class + '" href="'	+ google_ads[i].url + '" >' +
			google_ads[i].line1 + '</a><br><span class="' +
			ad_text_class + '">' +
			google_ads[i].line2 + '<br>' +
			google_ads[i].line3 + '</span><br>' +
			'<a class="' + ad_url_class + '" href="' +
			google_ads[i].url + '" >' +
			google_ads[i].visible_url + '</a><br>';
		}
	}
	document.write(s);
	return;
}

/*
* This section is responsible for setting the parametersof the ad call
* Customize this section to your needs with input from your account manager
*/
// The following parameters should be modified appropriately
google_ad_client = 'ca-yehey-stir_js'; // substitute your client_id
//google_ad_channel = 'entertainment'; // substitute your channel
google_ad_output = 'js'; // leave this value as js
google_max_num_ads = '3'; // specify the number of maximum ads
google_ad_type = 'text'; // type of ads to display
google_safe = 'high'; // specify the ad safety
google_feedback = 'on';
google_hints = 'showbiz,celebrity';
// The following parameter is required if you are displaying image, Flash or rich media ads.
// google_image_size = '300x250'; // the size of the ad block
// The following parameters are options you can specify as necessary
// google_encoding = 'utf8'; // specify the output language of the ads
// google_language = 'en'; // override the default page language
// The following parameter should be used only during testing
google_adtest = 'off'; // remove this line on launch day
//google_hints = 'philippines'

// END OF GOOGLE ADSENSE CODE