// function for emptying out a dynamic div - usually: target=loadDIV
function emptyDiv(target){
	 document.getElementById(target).innerHTML = '';
}
// JAH DELETE function
function confirmJah(itemName,jahURL,jahDIV){
	var agree=confirm("Are you sure you want to delete "+itemName+"?");
		if (agree){
			
			jah(jahURL,jahDIV,'GET','Processing...');
			//emptyDiv(itemID);
			// document.getElementById(itemID).innerHTML = ''
		}
		else
			return false;
}
// DELETE confirm
function confirmDelete(itemName) {
	return confirm("Are you sure you want to remove "+itemName+"?")
}
// dynamic publishing/loading of info 
function jah(url,target,httpmethod,loadMsg) {
	//	GET, POST, PUT, and DELETE
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = loadMsg;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open(httpmethod, url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open('GET', url, true);
            req.send();
        }
    }
}    
function jahDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML="jah error:\n" +
                req.statusText;
        }
    }
}
// for adding site links popup div - no full URLS - only profile name or IDs
function formCheck(fieldID){
	if (document.getElementById('linkDiv').style.display == "block" && document.getElementById(fieldID).value == "")
		{alert("You must enter the Profile Name or UserID for the selected site.");
		document.getElementById(fieldID).focus();
		return false;
		}
	if(document.getElementById('linkDiv').style.display == "block" && 
							   document.getElementById(fieldID).value.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i)){
    	alert("Sorry we were not clear in the directions.\nPlease do not enter the full URL,\nonly your ProfileName or UserID.\nSee the example on the page.");
    	document.getElementById(fieldID).select();
    	document.getElementById(fieldID).focus();
    	return false;}
	else {
		submit('http://socialnetwork.in/ajaxCall.cfm','POST','addCommform','formDiv');
        }
}
function setPrivacy(privacyValue)
		  {document.getElementById('privacySetting').value=privacyValue;}
		  
//for comparing sites popup div 
var NewCount = 1
function CountBoxes(theElement) {
	var boxGroup =theElement;
	updatelist(boxGroup);
	if (NewCount == 6)
		{alert('Sorry, you may only compare up to 5 sites at once.');
		boxGroup.checked = false; 
		updatelist(boxGroup);
		return;}
}

function updatelist(theElement) {
	 var sitelist = '';
	 var sitecount = 0;
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].checked == true){
		  	sitecount=sitecount+1;
	  	if(!sitelist == ''){
	  		sitelist = sitelist + ', ' + theForm[z].value;
			}
		else{sitelist =theForm[z].value;}
	  }
     }
		document.getElementById('siteList').innerHTML=sitelist;
		document.getElementById('sitesField').value=sitelist;
		document.getElementById('chartDiv').innerHTML='';
		if (sitecount == 1)
			{document.getElementById('cntr').innerHTML = sitecount + ' site selected';}
		else {
			document.getElementById('cntr').innerHTML = sitecount + ' sites selected';}
		NewCount=sitecount;
}

function checkBoxCount(theElement) {
	 var hasChecks = 0;
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].checked == true){
	  hasChecks = hasChecks+1;
	  }
     }
	 if(hasChecks == 0)
	{alert('Please select up to 5 sites to compare.');}
	else{submit('http://socialnetwork.in/ajaxCall.cfm','POST','compareForm','chartDiv');} 
    }

//Textarea counter - Dynamic Version by: Nannette Thacker 	http://www.shiningstar.net 
//Original by :  Ronnie T. Moore		Web Site:  The JavaScript Source
function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) 
	field.value = field.value.substring(0, maxlimit);
	else
	cntfield.value = maxlimit - field.value.length;
}

//This function checks the required field and makes sure that user input some data in those and it is not just empty spaces
function CheckReqField(FormID){
 var blnReturn = true;
 var alertMsg = '';
 var thisForm=document.getElementById(FormID);
 for (var i=0;i<thisForm.length;i++){
   var strTemp = Trim(thisForm.elements[i].value);
   if (strTemp == ''){
    blnReturn = false;
	alertMsg='Please fill out all fields before submitting the form.';
   }
   if (blnReturn == true && thisForm.elements[i].name == 'userEmail'){
	    blnReturn = checkEmail(thisForm.elements[i].value);
		alertMsg='Please enter a valid email address.';
   }
 }
 
 if (blnReturn){
  thisForm.submit();
 }
 else{
  alert(alertMsg);
 }
}
//This function takes out all the spaces from a string from both sides and the middle and returns the result.
//It is used in conjunction with the above funtion to make sure the user simply didn't put it spaces in the input text field
function Trim(strInput){
 var strTrimmmed = '';
 for (var i = 0;i<strInput.length; i++){
  if (strInput.charCodeAt(i)!=32){
   strTrimmmed += strInput[i];
  }
 }
 return strTrimmmed;
}

function checkEmail(emailField){
	//emailField =document.getElementById(emailField);
	regexPattern=/^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$/;
	return (regexPattern.test(emailField));
}
/*Select and Copy form element script- By Dynamicdrive.com http://www.dynamicdrive.com */
var copytoclip=1;
//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
function HighlightAll(theField) {
	var tempval=eval("document."+theField);
	tempval.focus();
	tempval.select();
	if (document.all&&copytoclip==1){
		therange=tempval.createTextRange();
		therange.execCommand("Copy");
		window.status="Contents highlighted and copied to clipboard!";
		setTimeout("window.status=''",1800);
	}
}