function ChangeFieldName (val, limit) {
        //--------------------------------------
        contents = document.FieldName.CATEGORY.value; 
        contentsJB = document.FieldName.JBPOT.value;
        contentsCC = document.FieldName.CATC.value; 
        //--------------------------------------
        
        var myString = contentsJB;
        var mySplitResult = myString.split("onClick");
        for(i = 0; i < mySplitResult.length; i++){ } 
        //--------------------------------------

		if(limit==undefined) limit = 1;

        if (i<=limit) {
                mySplitResult = val.split("|");
                
                if (mySplitResult[0]!="--") {        
                        
                        document.FieldName.CATC.value=i;
                        
                        document.FieldName.CATEGORY.value=contents+mySplitResult[0];
                        
                        document.FieldName.JBPOT.value=contentsJB+"<div id="+mySplitResult[0]+">"+mySplitResult[1]+
                    " <input type=\"button\" value=\"Delete\" onClick=\"DeleteThis('"+mySplitResult[0]+"|"+mySplitResult[1]+"')\"><br><\/div> ";
                        
                        document.getElementById('elmID').innerHTML=contentsJB+"<div id="+mySplitResult[0]+">"+mySplitResult[1]+
                        " <input type=\"button\" value=\"Delete\" onClick=\"DeleteThis('"+mySplitResult[0]+"|"+mySplitResult[1]+"')\"><br><\/div> ";
                }
        } 
        //--------------------------------------
}

function DeleteThis(s) {
        //--------------------------------------
        mySplitResult = s.split("|");
        //--------------------------------------
        document.FieldName.CATC.value=0;
        var cat = document.getElementById('CATEGORY');  
        cat.value = cat.value.replace(mySplitResult[0],'');

        //--------------------------------------

        var oNodeToRemove = document.getElementById("CATEGORY");
        oNodeToRemove
        
        //--------------------------------------
        
        var cat = document.getElementById('jbpot');
        cat.value = cat.value.replace('<div id='+mySplitResult[0]+'>'+mySplitResult[1]+' <input type="button" value="Delete" onClick="DeleteThis(\''+mySplitResult[0]+'|'+mySplitResult[1]+'\')"><br><\/div> ','');

        var oNodeToRemove = document.getElementById("jbpot");
        oNodeToRemove

        //--------------------------------------

        var ele = document.getElementById(mySplitResult[0]);
        ele.parentNode.removeChild(ele);

//--------------------------------------
}


function isValidURL(url) {
        var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
        if (urlRegxp.test(url) != true) {
                return false;
        } else {
                return true;
        }
}

function validateListing()	{
	
	var themessage="";
	
	var tomatch= /http:\/\//;

	var catc = document.FieldName.CATC.value;

	if(catc=="" || catc==0) {
	  themessage += "Select a category\n";
	}



	if (document.FieldName.TITLE.value=="") {
	  themessage += "Enter a title for your listing\n";
	}

	 if (document.FieldName.COUNTRY.value=="") {
	  themessage += "Select your country\n";
	}

	if (document.FieldName.CITY.value=="") {
	  themessage += "Enter your City name\n";
	}

	var Phone=/^([0-9\d]{3,3})+\-(\[?)([0-9\d]{3,3})+\-([0-9]{2,5})(\]?)$/;

	if(!Phone.test(document.FieldName.PHONE.value)){
	  themessage += "Enter Phone Number Format 555-555-555\n";
	}
	
	 if(document.FieldName.WEBSITE && document.FieldName.WEBSITE.value != "")
	{
			 //if (!tomatch.test(document.FieldName.WEBSITE.value)){
					// themessage += "Enter valid website Url.";
			 //}
	}

	return themessage;

}

function load_section() {

//alert(obj.innerHTML);
        c_code = document.getElementById("COUPON_CODE").value;
        var url = "coupon_ajax.php?c_code="+c_code;

        //alert(url);
        $.ajax({
        url: url,
        type: 'GET',
        dataType: 'html',
        timeout: 1000,
        async:false,
        before: $("#loader-").show(),
        success: function(msg){
        //alert("something");
        //hideLoading();
        $("#coupon_msg").html(msg);
    if($("#coupon_success").val()!=undefined) {
      $("#coupon_div").slideUp("slow");
      $('input[name=frm_submit]').focus();
    } else  {
      $("#COUPON_CODE").val("")
    }
        }
        })
}

function replaceOptions(idEle) {
  var selElem = document.getElementById("package_option_sel");
  selElem.options.length = 0;
  var elSel = document.getElementById("package_option_"+idEle);//'rem_hours'
  var i;
  //alert(elSel.length);
  for (i = 0; i < elSel.length; i++) {
    var elOptNew = document.createElement('option');
    elOptNew.text = elSel.options[i].text;
    elOptNew.value = elSel.options[i].value;
    if(elSel.options[i].selected) {
      elOptNew.selected=true;
     };
    try {
      selElem.add(elOptNew, null); // standards compliant; doesn't work in IE
    } catch(ex) {
      selElem.add(elOptNew); // IE only
    }
  }
}

function validateRegistration()	{
	
	var themessage = "";

	if (document.form.USERNAME.value=="") {
		themessage = themessage + " | Username";
	}

	if (document.form.PASSWORD.value=="") {
		themessage = themessage + " | Password";
	}
	
	if (document.form.PASSWORD2.value=="") {
		themessage = themessage + " | Verify Password";
	}

	if (echeck(document.form.EMAIL.value)==false) {
		themessage = themessage + " | Valid Email Address";
	}

	if (document.form.FNAME.value=="") {
		themessage = themessage + " | First Name";
	}
	if (document.form.LNAME.value=="") {
		themessage = themessage + " | Last Name";
	}

	if (document.form.CATEGORY.value=="") {
		themessage = themessage + " | Primary Service";
	}

	if (document.form.BUSINESSNAME.value=="") {
		themessage = themessage + " | Business Name";
	}

	if (document.form.DESCRIPTION.value=="") {
		themessage = themessage + " | Business Description";
	}

	if (document.form.WEBSITE.value!="" && !isValidURL(document.form.WEBSITE.value)) {
		themessage = themessage + " | Valid Website address";
	}

	if (isValidPhoneUS(document.form.PHONE.value)==false) {
		themessage += " | Phone Number Format 555-555-555";
	}

	if (document.form.CITY.value=="") {
		themessage = themessage + " | City Name";
	}	

	if (document.form.STREET.value=="") {
		themessage = themessage + " | Address Line 1";
	}

	if (document.form.ZIP.value=="") {
		themessage = themessage + " | Zip Code";
	}

	if (document.form.SCODE.value=="") {
		themessage = themessage + " | Verification Text ";
	}

	return themessage
}

function echeck(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 isValidPhoneUS(val)	{
		var Phone=/^([0-9\d]{3,3})+\-(\[?)([0-9\d]{3,3})+\-([0-9]{2,5})(\]?)$/;
		if(!Phone.test(val)) return false
		return true
	}



