// JavaScript Document
function showdivs(divid){
	var element=document.getElementById(divid).style.display;
	if (element=='block')	
	document.getElementById(divid).style.display='none';
	else document.getElementById(divid).style.display='block';
}
function taketootherpage(page){
	document.location=page;
}
function validatenumber(str){

if ( isNaN( str ) )	{
	return false;
}	
else return true;
}

function incrementfromdb(id){
window.open("updatehitcount.php?advid="+id);

}
window.onload = function()
{
  initCheckBehavior();
}
function initCheckBehavior()
{
  var i, a;

  for (i = 0; i < document.links.length; ++i) {
    a = document.links[i];
    if (a.id.indexOf('UncheckAll_') != -1) {
      a.onclick = doCheckBehavior;
      a._CBNAME_ = a.id.substr(11) + '[]';
      a._CBCHECKED_ = false;
    }
    else if (a.id.indexOf('CheckAll_') != -1) {
      a.onclick = doCheckBehavior;
      a._CBNAME_ = a.id.substr(9) + '[]';
      a._CBCHECKED_ = true;
    }
  }
}
function doCheckBehavior()
{
  var i, cb = document.getElementsByName(this._CBNAME_);
  for (i = 0; i < cb.length; ++i) {
    cb[i].checked = this._CBCHECKED_;
  }
  return false;
}

function seeifanyoneischecked(){
	var elems=document.getElementById('form1').elements.length;
	var str="";
	 for(i=0; i<elems; i++)
	 	if (document.getElementById('form1').elements[i].id=="checkbox" && document.getElementById('form1').elements[i].checked)
		 	str+=document.getElementById('form1').elements[i].value+',';
	if(str==""){
		alert("Please select the records to delete.");
		return false;
	}
	if(confirm("Are you sure you want to delete the selected records?")==true){
		return true;
	}
	else return false;
}

function isZip(s) 
{
 
     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 
     if (!reZip.test(s)) {
        //  alert("Zip Code Is Not Valid");
          return false;
     }
 
return true;
}

function trimAll( strValue ) {
	var objRegExp = /^(\s*)$/;
	
		//check for all spaces
		if(objRegExp.test(strValue)) {
		   strValue = strValue.replace(objRegExp, '');
		   if( strValue.length == 0)
			  return strValue;
		}
	
	   //check for leading & trailing spaces
	   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	   if(objRegExp.test(strValue)) {
		   //remove leading and trailing whitespace characters
		   strValue = strValue.replace(objRegExp, '$2');
		}
	  return strValue;
}

function validateNotEmpty( strValue ) {
	var strTemp = strValue;
	   strTemp = trimAll(strTemp);
	   if(strTemp.length > 0){
		 return true;
	   }
	   return false;
}

function ConfirmDelete(){
	boolReturn = confirm(" Are you sure you wish to delete this record?");
	if (boolReturn)
	return true;
	else
	return false;
}
function ConfirmContinue(){
	boolReturn = confirm(" Are you sure you wish to continue?");
	if (boolReturn)
	return true;
	else
	return false;
}

function learnRegExp(strval){
  return /^(ftp|https?):\/\/+(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(learnRegExp.arguments[0]);
}


function popUpad(URL,w,h) {
	day = new Date();
	id = day.getTime();
	if (w=='') var w=650;
	if (h=='') var h=550;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height= " + h + ",left = 262,top = 134');");
}


function getHTTPObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}
var http = getHTTPObject(); // We create the HTTP Object