function activateUser(UserID,Active_F,URL,aid){
	window.location = URL+'?aid='+aid+'&userID='+UserID+'&ActUser='+Active_F;
}

function deleteMsg(UserID,Delete_F,URL,aid){
  var ConfirmMsg;
	
	ConfirmMsg = confirm("Are you sure that you want to delete the following record permanently!");
	if(ConfirmMsg){
	  window.location = URL+'?aid='+aid+'&userID='+UserID+'&DelUser='+Delete_F;
	}
}


//show hide divs
var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

function hide(divID) {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById(\''+divID+'\')');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.all[\''+divID+'\']');
  else
     document.poppedLayer = eval('document.layers[\''+divID+'\']');
  
	if(document.poppedLayer.style.visibility == "hidden"){
		document.poppedLayer.style.visibility = "visible";
	}else{
	  document.poppedLayer.style.visibility = "hidden";
	}
}

//this will determine browsers and try to get the corrisponding layer
function getDiv(LayerID){

  if(document.Layer){
    returnLayer = document.layers[LayerID];
  }else if(document.getElementById){ 
    returnLayer = document.getElementById(LayerID);
  }else{
    returnLayer = document.all(LayerID);	
  }
  return returnLayer;
}

//did not want to break anything so added this
function hide_b(divID) {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById(\''+divID+'\')');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.all[\''+divID+'\']');
  else
     document.poppedLayer = eval('document.layers[\''+divID+'\']');

     document.poppedLayer.style.visibility = "hidden";
}


function show(divID) {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById(\''+divID+'\')');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.all[\''+divID+'\']');
  else
     document.poppedLayer = eval('document.layers[\''+divID+'\']');
  document.poppedLayer.style.visibility = "visible";
}

function clearSearchForm(form){
	form.username.value 				 	 = '';
	form.firstname.value 				   = '';
    	form.lastname.value 				   = '';
	form.postalcode.value 				 = '';
	form.laddername.value 				 = '';
	form.memberid.value 					 = '';
	form.ccnumber.value 					 = '';
	form.expiredate.value 				 = '';
	form.amountcharged.value 			 = '';
	form.emailaddress.value 					 = '';
	form.ip_address.value					 = "";
}

function getUrl(strUrl){
	window.location.href=strUrl;
}

function setDropDownValue(dropDownField,value){
 var ddlSelectedIndex = 0;
 for(i=0;i<dropDownField.length;i++){
   if(dropDownField.options[i].value.toLowerCase() == value.toLowerCase()){
    ddlSelectedIndex = i;
   }   
 }

 dropDownField.selectedIndex = ddlSelectedIndex; 
}

function isEmpty(strVar){
 if(strVar == "" || strVar == null){
  return 1;
 }else{
  return 0;
 }
}

function isEmail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }

		 return true					
}

function showRateReady(){
 oPos         = objRef('div_prorate');
 oPosShow     = objRef('div_proRateForm');
 thePos       = findPos(oPos);
 thePos[1]    = thePos[1] + 5;

 setPos(oPosShow,thePos);
 show('div_proRateForm');
}

function setRadioButtonValue(formRadio,checkedValue){
 for(var i=0;i<formRadio.length;i++){
      if(formRadio[i].value == checkedValue){
         formRadio[i].checked = true;
      }
   }
}

function setFrameSource(frameID,source){
	frames[frameID].location.href = source;
}

/** checks ecard form for proper values **/
function eCardSubmit(toName,toEmail,fromEmail){
	returnVal = 1;
	
	if(isEmpty(toName)){
		displayErrorDiv('idMsg','Invalid To Name');
		returnVal = false;
	}
	if(!isEmail(toEmail)){
		displayErrorDiv('idMsg','Invalid To Email');
		returnVal = false;
	}
	if(!isEmpty(fromEmail)){
		if(!isEmail(fromEmail)){
			displayErrorDiv('idMsg','Invalid From Email');
			returnVal = false;
		}
	}
	
	return returnVal;
}

/** fills in ddl correct and fills in text field correct **/
function ladderFill(ddlField,textField,fillType){
	if(fillType == "ddl"){
		//fill in the text field
		textField.value = ddlField.options[ddlField.selectedIndex].value;
	}else{
		//fill in the drop down
		setDropDownValue(ddlField,textField.value);
	}
}

function previewEcard(frameID,template,toNameField,toEmailField,msgField,fromNameField,fromEmailField,giftType){
	msg		= msgField.value;
	//parse out any bad stuff

	strPos	= msg.indexOf("#");
	
	msg = msg.substr(0,(strPos-1)) + msg.substr((strPos+1),msg.length);
	
	if(strPos > 0){
		alert('You cannot preview your ecard please be sure your message does not contain any #');
		return 0;
	}else{
		params	= "to_Name="+toNameField.value;
		params	= params + "&to_Email="+toEmailField.value;
		params	= params + "&Message="+msg;
		params	= params + "&from_Email="+fromEmailField.value;
		params	= params + "&from_Name="+fromNameField.value;
		params	= params + "&tempID="+template;
		params	= params + "&gift_type="+giftType.value;
		url	= "/gift/templates.php?"+params;
		
		setFrameSource(frameID,url);	
	}	
}